* src/AutoComp.py (StandardCustomSelector): Add autocompletion.

svn: r4745
This commit is contained in:
Alex Roitman 2005-05-31 18:40:17 +00:00
parent 476fdeafb7
commit 7db59a7cab
2 changed files with 15 additions and 1 deletions

View File

@ -4,6 +4,8 @@
* src/RelLib.py (Witness): Remove class, as it is obsoleted by the * src/RelLib.py (Witness): Remove class, as it is obsoleted by the
EventRef class. EventRef class.
* src/AutoComp.py (StandardCustomSelector): Add autocompletion.
2005-05-30 Alex Roitman <shura@gramps-project.org> 2005-05-30 Alex Roitman <shura@gramps-project.org>
* src/RelLib.py: Move constants back to RelLib, as class attributes. * src/RelLib.py: Move constants back to RelLib, as class attributes.
* src/Utils.py: Move constant mappings from const.py.in. * src/Utils.py: Move constant mappings from const.py.in.

View File

@ -104,19 +104,31 @@ class StandardCustomSelector:
@param active_key: The key for the entry to make active upon creation @param active_key: The key for the entry to make active upon creation
@type active_key: int @type active_key: int
""" """
# set variables
self.mapping = mapping self.mapping = mapping
self.custom_key = custom_key self.custom_key = custom_key
self.active_key = active_key self.active_key = active_key
self.active_index = 0 self.active_index = 0
# make model # make model
self.store = gtk.ListStore(gobject.TYPE_INT,gobject.TYPE_STRING) self.store = gtk.ListStore(gobject.TYPE_INT,gobject.TYPE_STRING)
# fill it up using mapping # fill it up using mapping
self.fill() self.fill()
# create combo box entry # create combo box entry
self.selector = gtk.ComboBoxEntry(self.store,1) self.selector = gtk.ComboBoxEntry(self.store,1)
if self.active_key: if self.active_key:
self.selector.set_active(self.active_index) self.selector.set_active(self.active_index)
# make autocompletion work
completion = gtk.EntryCompletion()
completion.set_model(self.store)
completion.set_minimum_key_length(1)
completion.set_text_column(1)
self.selector.child.set_completion(completion)
def fill(self): def fill(self):
keys = self.mapping.keys() keys = self.mapping.keys()
keys.sort(self.by_value) keys.sort(self.by_value)
@ -163,7 +175,7 @@ if __name__ == "__main__":
gtk.main_quit() gtk.main_quit()
s = StandardCustomSelector({0:'a',1:'b',2:'c'},0) s = StandardCustomSelector({0:'abc',1:'abd',2:'bbe'},0)
w = gtk.Dialog() w = gtk.Dialog()
w.child.add(s.selector) w.child.add(s.selector)
w.connect('delete-event',here) w.connect('delete-event',here)