Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
487367f7
Commit
487367f7
authored
Mar 24, 2010
by
Dan Pascu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added search capabilities to the contact list
parent
26f8e83a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
__init__.py
blink/__init__.py
+7
-2
contacts.py
blink/contacts.py
+25
-1
No files found.
blink/__init__.py
View file @
487367f7
...
...
@@ -20,7 +20,7 @@ import sys
_qt_application
=
QApplication
(
sys
.
argv
)
from
blink
import
ui
from
blink.contacts
import
ContactDelegate
,
ContactModel
from
blink.contacts
import
ContactDelegate
,
ContactModel
,
ContactSearchModel
from
blink.resources
import
Resources
...
...
@@ -38,6 +38,11 @@ class Blink(object):
self
.
main_window
.
contact_list
.
setItemDelegate
(
ContactDelegate
(
self
.
main_window
.
contact_list
))
self
.
contact_model
.
test
()
self
.
contact_search_model
=
ContactSearchModel
(
self
.
contact_model
,
self
.
main_window
)
self
.
main_window
.
search_list
.
setModel
(
self
.
contact_search_model
)
self
.
main_window
.
search_list
.
setItemDelegate
(
ContactDelegate
(
self
.
main_window
.
search_list
))
self
.
main_window
.
search_box
.
textChanged
.
connect
(
self
.
contact_search_model
.
setFilterFixedString
)
self
.
main_window
.
main_view
.
setCurrentWidget
(
self
.
main_window
.
contacts_panel
)
self
.
main_window
.
contacts_view
.
setCurrentWidget
(
self
.
main_window
.
contact_list_panel
)
self
.
main_window
.
search_view
.
setCurrentWidget
(
self
.
main_window
.
search_list_panel
)
...
...
@@ -85,7 +90,7 @@ class Blink(object):
def
text_changed
(
self
,
text
):
active_widget
=
self
.
main_window
.
contact_list_panel
if
text
.
isEmpty
()
else
self
.
main_window
.
search_panel
self
.
main_window
.
contacts_view
.
setCurrentWidget
(
active_widget
)
active_widget
=
self
.
main_window
.
search_list_panel
if
len
(
text
)
<
3
else
self
.
main_window
.
not_found_panel
active_widget
=
self
.
main_window
.
search_list_panel
if
self
.
contact_search_model
.
rowCount
()
else
self
.
main_window
.
not_found_panel
self
.
main_window
.
search_view
.
setCurrentWidget
(
active_widget
)
def
test_add_contact
(
self
):
...
...
blink/contacts.py
View file @
487367f7
...
...
@@ -2,7 +2,7 @@
#
from
PyQt4.QtCore
import
Qt
,
QAbstractListModel
,
QModelIndex
,
QSize
from
PyQt4.QtGui
import
QColor
,
QPainter
,
QPalette
,
QPixmap
,
QStyle
,
QStyledItemDelegate
from
PyQt4.QtGui
import
QColor
,
QPainter
,
QPalette
,
QPixmap
,
QStyle
,
QS
ortFilterProxyModel
,
QS
tyledItemDelegate
from
application.python.util
import
Null
from
functools
import
partial
...
...
@@ -251,3 +251,27 @@ class ContactModel(QAbstractListModel):
self
.
addGroup
(
test_group
)
class
ContactSearchModel
(
QSortFilterProxyModel
):
def
__init__
(
self
,
model
,
parent
=
None
):
super
(
ContactSearchModel
,
self
)
.
__init__
(
parent
)
self
.
setSourceModel
(
model
)
self
.
setDynamicSortFilter
(
True
)
def
data
(
self
,
index
,
role
=
Qt
.
DisplayRole
):
data
=
super
(
ContactSearchModel
,
self
)
.
data
(
index
,
role
)
return
data
.
toPyObject
()
if
role
==
Qt
.
DisplayRole
else
data
def
filterAcceptsRow
(
self
,
source_row
,
source_parent
):
source_model
=
self
.
sourceModel
()
source_index
=
source_model
.
index
(
source_row
,
0
,
source_parent
)
item
=
source_model
.
data
(
source_index
,
Qt
.
DisplayRole
)
if
type
(
item
)
is
ContactGroup
:
return
False
search_string
=
unicode
(
self
.
filterRegExp
()
.
pattern
())
return
search_string
in
item
.
name
.
lower
()
or
search_string
in
item
.
uri
.
lower
()
def
lessThan
(
self
,
left
,
right
):
print
"lessThan"
,
left
,
right
,
left
.
model
()
.
data
(
left
,
Qt
.
DisplayRole
)
return
super
(
ContactSearchModel
,
self
)
.
lessThan
(
left
,
right
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment