def body(self, parent): import notebook notebook = notebook.notebook(parent, side=TOP) for group in self.opts: tab = Frame(notebook()) for optnumber, option in enumerate(group): optf = Frame(tab) label = Label(optf, text=getPrettyName(option)) label.pack(fill=Y, side=LEFT) if option.type in ( 'String', 'Integer', 'Password' ): if option.type == 'Password': edit = Entry(optf, show='*') else: edit = Entry(optf) val = option.getValue() if val and val is not NoDefaultOption: edit.insert(0,str(val)) edit.pack(fill=BOTH, side=RIGHT) get = edit.get edit = ( optf, label, edit ) elif option.type == 'Choice': rbf = Frame(optf) buttons = [] name = option.name val = option.value self.choiceoptions[name] = val for c in [x.value for x in option]: if c == val: E = 1 else: E = 0 b = Radiobutton(rbf, text=c, indicatoron=1, variable=self.choiceoptions[name], value=c, command=lambda o=self.choiceoptions, n=name, c=c: o.__setitem__(n,c) ) if E: b.select() else: b.deselect() b.pack(side=LEFT) buttons.append(b) rbf.pack(side=RIGHT, fill=BOTH) get = lambda opt=name: self.choiceoptions[opt] edit = ( rbf, buttons ) elif option.optionType == 'Boolean': name = option.name val = option.value self.booloptions[name] = val b = Checkbutton(optf, variable=self.booloptions[name], command=lambda o=self.booloptions, n=name: o.__setitem__(n, not o[n]) ) b.pack(side=RIGHT, fill=BOTH) edit = b get = lambda opt=name: self.booloptions[opt] else: raise ValueError, "unknown option type %s"%(option.optionType) optf.pack(fill=X, side=TOP, ipady=4) if edit is not None: self.options[option.name] = ( option.type, get, edit ) notebook.add_screen(tab, group.name) return notebook()
def setupDialog(self, parent): self.dialog = gtk.Dialog("Preferences", parent, gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)) self.widgets = [] self.tooltips = gtk.Tooltips() notebook = gtk.Notebook() notebook.set_border_width(4) self.dialog.vbox.set_border_width(4) self.dialog.vbox.pack_start(notebook) #self.dialog.add(vbox) for group in self.opts: if not group.getGUI(): continue tab = gtk.VBox(False, 8) tab.set_border_width(8) #print "tab", tab desc = gtk.Label(group.description) tab.pack_start(desc, False, False) for optnumber, option in enumerate(group): optBox = gtk.HBox(spacing=8) l = gtk.Label(getPrettyName(option)) self.tooltips.set_tip(l, option.description) optBox.pack_start(l, False, True) if option.type in ('String', 'Integer', 'Password'): entry = gtk.Entry() if option.type == 'Password': entry.set_visibility(False) val = option.value if val and val is not NoDefaultOption: entry.set_text(str(val)) self.tooltips.set_tip(entry, option.description) optBox.pack_end(entry, False, True) self.widgets.append( (option.type, option.name, entry.get_text)) elif option.type == 'Choice': choices = option.getChoices() combo = gtk.combo_box_new_text() combo.append_text(_('Select one')) active_num = 0 for n, c in enumerate(choices): combo.append_text(c) if c == option.value: active_num = n + 1 combo.set_active(active_num) optBox.pack_end(combo, False, True) self.tooltips.set_tip(combo, option.description, None) def getter(combo=combo): model = combo.get_model() active = combo.get_active() if active == 0: return None return model[active][0] self.widgets.append((option.type, option.name, getter)) elif option.type == 'Boolean': entry = gtk.CheckButton("") self.tooltips.set_tip(entry, option.description) if option.value: entry.set_active(True) else: entry.set_active(False) optBox.pack_end(entry, False, True) self.widgets.append( (option.type, option.name, entry.get_active)) else: print "unknown option", option.type tab.pack_start(optBox, False, False) notebook.append_page(tab, gtk.Label(group.name)) self.tooltips.enable()
def body(self, parent): from . import notebook notebook = notebook.notebook(parent, side=TOP) for group in self.opts: tab = Frame(notebook()) for optnumber, option in enumerate(group): optf = Frame(tab) label = Label(optf, text=getPrettyName(option)) label.pack(fill=Y, side=LEFT) if option.type in ('String', 'Integer', 'Password'): if option.type == 'Password': edit = Entry(optf, show='*') else: edit = Entry(optf) val = option.getValue() if val and val is not NoDefaultOption: edit.insert(0, str(val)) edit.pack(fill=BOTH, side=RIGHT) get = edit.get edit = (optf, label, edit) elif option.type == 'Choice': rbf = Frame(optf) buttons = [] name = option.name val = option.value self.choiceoptions[name] = val for c in [x.value for x in option]: if c == val: E = 1 else: E = 0 b = Radiobutton(rbf, text=c, indicatoron=1, variable=self.choiceoptions[name], value=c, command=lambda o=self.choiceoptions, n= name, c=c: o.__setitem__(n, c)) if E: b.select() else: b.deselect() b.pack(side=LEFT) buttons.append(b) rbf.pack(side=RIGHT, fill=BOTH) get = lambda opt=name: self.choiceoptions[opt] edit = (rbf, buttons) elif option.optionType == 'Boolean': name = option.name val = option.value self.booloptions[name] = val b = Checkbutton(optf, variable=self.booloptions[name], command=lambda o=self.booloptions, n=name: o.__setitem__(n, not o[n])) b.pack(side=RIGHT, fill=BOTH) edit = b get = lambda opt=name: self.booloptions[opt] else: raise ValueError("unknown option type %s" % (option.optionType)) optf.pack(fill=X, side=TOP, ipady=4) if edit is not None: self.options[option.name] = (option.type, get, edit) notebook.add_screen(tab, group.name) return notebook()
def setupDialog(self, parent): self.dialog = gtk.Dialog("Preferences", parent, gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)) self.widgets = [] self.tooltips = gtk.Tooltips() notebook = gtk.Notebook() notebook.set_border_width(4) self.dialog.vbox.set_border_width(4) self.dialog.vbox.pack_start(notebook) #self.dialog.add(vbox) for group in self.opts: if not group.getGUI(): continue tab = gtk.VBox(False,8) tab.set_border_width(8) #print "tab", tab desc = gtk.Label(group.description) tab.pack_start(desc, False, False) for optnumber, option in enumerate(group): optBox = gtk.HBox(spacing=8) l = gtk.Label(getPrettyName(option)) self.tooltips.set_tip(l, option.description) optBox.pack_start(l, False, True) if option.type in ('String', 'Integer', 'Password'): entry = gtk.Entry() if option.type == 'Password': entry.set_visibility(False) val = option.value if val and val is not NoDefaultOption: entry.set_text(str(val)) self.tooltips.set_tip(entry, option.description) optBox.pack_end(entry, False, True) self.widgets.append((option.type, option.name, entry.get_text)) elif option.type == 'Choice': choices = option.getChoices() combo = gtk.combo_box_new_text() combo.append_text(_('Select one')) active_num = 0 for n, c in enumerate(choices): combo.append_text(c) if c == option.value: active_num = n+1 combo.set_active(active_num) optBox.pack_end(combo, False, True) self.tooltips.set_tip(combo, option.description, None) def getter(combo=combo): model = combo.get_model() active = combo.get_active() if active == 0: return None return model[active][0] self.widgets.append((option.type, option.name, getter)) elif option.type == 'Boolean': entry = gtk.CheckButton("") self.tooltips.set_tip(entry, option.description) if option.value: entry.set_active(True) else: entry.set_active(False) optBox.pack_end(entry, False, True) self.widgets.append((option.type, option.name, entry.get_active)) else: print "unknown option", option.type tab.pack_start(optBox, False, False) notebook.append_page(tab, gtk.Label(group.name)) self.tooltips.enable()