Index: mygtk.py ================================================================== --- mygtk.py +++ mygtk.py @@ -411,7 +411,42 @@ def msg(text, style=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CLOSE): m = gtk.MessageDialog(None, 0, style, buttons, message_format=text) m.show() m.connect("response", lambda *w: m.destroy()) + + +# Implement text combobox, +# because debian packages lack the binding https://bugzilla.gnome.org/show_bug.cgi?id=660659 +class ComboBoxText(gtk.ComboBox): + + ls = None + + def __init__(self, entries): + + # prepare widget + gtk.ComboBox.__init__(self) + 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) + for value in entries: + self.ls.append([value, value]) + + # activate dropdown of given value + def set_default(self, value): + for index,row in enumerate(self.ls): + if value in row: + self.set_active(index) + pass + + # fetch currently selected text entry + def get_active_text(self): + index = self.get_active() + if index >= 0: + return self.ls[index][0] + Index: st2.py ================================================================== --- st2.py +++ st2.py @@ -80,11 +80,11 @@ sys.path.insert(0, "/usr/share/streamtuner2") # pre-defined directory for modules sys.path.append( "/usr/share/streamtuner2/bundle") # external libraries sys.path.insert(0, ".") # development module path # gtk modules -from mygtk import pygtk, gtk, gobject, ui_file, mygtk, ver as GTK_VER +from mygtk import pygtk, gtk, gobject, ui_file, mygtk, ver as GTK_VER, ComboBoxText # custom modules from config import conf # initializes itself, so all conf.vars are available right away from config import __print__, dbg import ahttp @@ -778,10 +778,13 @@ if type(w) is gtk.Entry: w.set_text(str(val)) # checkmark elif type(w) is gtk.CheckButton: w.set_active(bool(val)) + # dropdown + elif type(w) is ComboBoxText: + w.set_default(val) # list elif type(w) is gtk.ListStore: w.clear() for k,v in val.items(): w.append([k, v, True]) @@ -794,10 +797,13 @@ w = main.get_widget(prefix + key) if w: # text if type(w) is gtk.Entry: config[key] = w.get_text() + # + elif type(w) is ComboBoxText: + config[key] = w.get_active_text() # boolean elif type(w) is gtk.CheckButton: config[key] = w.get_active() # dict elif type(w) is gtk.ListStore: @@ -861,15 +867,20 @@ c = self.channels.get(name) or self.features.get(name) for opt in c.config: # default values are already in conf[] dict (now done in conf.add_plugin_defaults) - # display checkbox or text entry + # display checkbox if opt["type"] == "boolean": cb = gtk.CheckButton(opt["description"]) #cb.set_line_wrap(True) self.add_( "config_"+opt["name"], cb ) + # drop down list + elif opt["type"] == "select": + cb = ComboBoxText(opt["select"].split("|")) # custom mygtk widget + self.add_( "config_"+opt["name"], cb, opt["description"] ) + # text entry else: self.add_( "config_"+opt["name"], gtk.Entry(), opt["description"] ) # spacer self.add_( "filler_pl_"+name, gtk.HSeparator() ) @@ -878,11 +889,12 @@ # Put config widgets into config dialog notebook def add_(self, id, w, label=None, color=""): w.set_property("visible", True) main.widgets[id] = w if label: - w.set_width_chars(11) + if type(w) is gtk.Entry: + w.set_width_chars(11) w = self.hbox(w, self.label(label)) if color: w = mygtk.bg(w, color) self.plugin_options.pack_start(w)