View Single Post
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#245
Originally Posted by ejasmudar View Post
I have edited my www2sms.py to show contacts in first name last name order, but I think a better way would be if in the name selection combo box, if we can search both first name and last name simultaneously.

ie, if I search for 'St' I should get a result with both "Stephanopoulos, George" and "Jobs, Steve"

At present, it will only move the list to names starting with St, Is it possible to change that behaviour?
Well, we should add an checkbox in the configuration dialog to allow the user to either sort contacts by first or last name.

Furthermore I got some testing code (with help from #python) which I did not jet integrate into www2sms.

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *

#if you use the validator, transform strings to lowercase before comparing them, and the filterproxymodel can be turned case insenstive with one method call
#.setFilterCaseSensitivity(Qt.CaseInsensitive)
class ModelPresenceValidator(QValidator):
	def __init__(self, model, role=Qt.DisplayRole, column=0, parent=None):
		QValidator.__init__(self, parent)
		self.model = model
		self.column = column
		self.role = role
	def validate(self, text, pos):
		lastresort = (QValidator.Invalid, pos)
		for r in xrange(self.model.rowCount()):
			d = self.model.data(self.model.index(r, self.column), self.role).toString()
			print d
			if d == text:
				return (QValidator.Acceptable, pos)
			elif str(d).startswith(str(text)):
				lastresort = (QValidator.Intermediate, pos)
		return lastresort

a = QApplication([])

cb = QComboBox()
cb.addItems(['Albert', 'Alexis', 'Arthur', 'Jane', 'Joe', 'John'])

cb.setEditable(True) # so the user can type
filterproxy = QSortFilterProxyModel()
datmodel = cb.model()
filterproxy.setSourceModel(datmodel) # the filter applies to original data
datmodel.setParent(a) # segfault without this line
cb.setModel(filterproxy) # the combobox will display the filtered content
cb.lineEdit().textEdited.connect(filterproxy.setFilterWildcard) # connect the input to the filter
cb.setValidator(ModelPresenceValidator(datmodel))

cb.show()
a.exec_()
This code removes non matching contacts from the list but only matches the characters from the beginning of the line.
(Just execute the code on your Desktop)

You might want to play with it.

Cheers,
Bjoern
 

The Following User Says Thank You to blubbi For This Useful Post: