446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467 | # Can use a list[] of entries or a key->value dict{}, where the value becomes
# display text, and the key the internal value.
#
class ComboBoxText(gtk.ComboBox):
ls = None
def __init__(self, entries):
# prepare widget
gtk.ComboBox.__init__(self)
self.set_property("visible", True)
cell = gtk.CellRendererText()
self.pack_start(cell, True)
self.add_attribute(cell, "text", 1)
# collect entries
self.ls = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.set_model(self.ls)
if type(entries[0]) is not tuple:
entries = zip(entries, entries)
for key,value in entries: |
|
>
>
| 446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469 | # Can use a list[] of entries or a key->value dict{}, where the value becomes
# display text, and the key the internal value.
#
class ComboBoxText(gtk.ComboBox):
ls = None
def __init__(self, entries, no_scroll=1):
# prepare widget
gtk.ComboBox.__init__(self)
self.set_property("visible", True)
cell = gtk.CellRendererText()
self.pack_start(cell, True)
self.add_attribute(cell, "text", 1)
if no_scroll:
self.connect("scroll_event", self.no_scroll)
# collect entries
self.ls = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.set_model(self.ls)
if type(entries[0]) is not tuple:
entries = zip(entries, entries)
for key,value in entries: |
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492 | self.set_active(index + 1)
# fetch currently selected text entry
def get_active_text(self):
index = self.get_active()
if index >= 0:
return self.ls[index][0]
# Expand A=a|B=b|C=c option list into (key,value) tuple list, or A|B|C just into a list.
@staticmethod
def parse_options(opts, sep="|", assoc="="):
if opts.find(assoc) >= 0:
return [ (k,v) for k,v in (x.split(assoc, 1) for x in opts.split(sep)) ]
else:
return opts.split(sep) #dict( (v,v) for v in opts.split(sep) )
|
>
>
>
>
>
| 479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499 | self.set_active(index + 1)
# fetch currently selected text entry
def get_active_text(self):
index = self.get_active()
if index >= 0:
return self.ls[index][0]
# Signal/Event callback to prevent hover scrolling of ComboBox widgets
def no_scroll(self, widget, event, data=None):
return True
# Expand A=a|B=b|C=c option list into (key,value) tuple list, or A|B|C just into a list.
@staticmethod
def parse_options(opts, sep="|", assoc="="):
if opts.find(assoc) >= 0:
return [ (k,v) for k,v in (x.split(assoc, 1) for x in opts.split(sep)) ]
else:
return opts.split(sep) #dict( (v,v) for v in opts.split(sep) )
|