def create_widgets(self): self.store = gtk.ListStore(gtk.gdk.Pixbuf, str, int) self.combo = gtk.ComboBox(self.store) self.icon = None pix = gtk.CellRendererPixbuf() txt = gtk.CellRendererText() txt.set_property('font', Prefs()['gui.views.property_tab.font'].value \ or 'Monospace 8') self.combo.pack_start(pix, False) self.combo.pack_start(txt) self.combo.set_attributes(pix, pixbuf=0) self.combo.set_attributes(txt, text=1) self.odict = backend.get_field_enumeration_i2s(self.field) self.odict.sort() idx = 0 set = False for value, key in self.odict: self.store.append([self.icon, key, value]) if not set: if self.value == value: set = True continue idx += 1 if set: self.combo.set_active(idx) self.store.append([self.icon, _("Set manually"), -1]) self.int_editor = IntEditor((self.protocol, self.field)) self.undo_btn = MiniButton(stock=gtk.STOCK_UNDO) self.undo_btn.set_size_request(24, 24) self.int_editor.pack_start(self.undo_btn, False, False) self.int_editor.show()
class EnumEditor(Editor): def create_widgets(self): self.store = gtk.ListStore(gtk.gdk.Pixbuf, str, int) self.combo = gtk.ComboBox(self.store) self.icon = None pix = gtk.CellRendererPixbuf() txt = gtk.CellRendererText() txt.set_property('font', Prefs()['gui.views.property_tab.font'].value \ or 'Monospace 8') self.combo.pack_start(pix, False) self.combo.pack_start(txt) self.combo.set_attributes(pix, pixbuf=0) self.combo.set_attributes(txt, text=1) self.odict = backend.get_field_enumeration_i2s(self.field) self.odict.sort() idx = 0 set = False for value, key in self.odict: self.store.append([self.icon, key, value]) if not set: if self.value == value: set = True continue idx += 1 if set: self.combo.set_active(idx) self.store.append([self.icon, _("Set manually"), -1]) self.int_editor = IntEditor((self.protocol, self.field)) self.undo_btn = MiniButton(stock=gtk.STOCK_UNDO) self.undo_btn.set_size_request(24, 24) self.int_editor.pack_start(self.undo_btn, False, False) self.int_editor.show() def pack_widgets(self): self.pack_start(self.combo) def connect_signals(self): self.last = len(self.store) - 1 self.combo.connect('changed', self.__on_changed) self.undo_btn.connect('clicked', self.__on_switch_back) def __on_changed(self, combo): if self.combo.get_active() == self.last: self.remove(self.combo) self.pack_start(self.int_editor) self.int_editor.show_all() else: iter = self.combo.get_active_iter() if iter: model = self.combo.get_model() self.value = model.get_value(iter, 2) def __on_switch_back(self, btn): self.remove(self.int_editor) self.pack_start(self.combo) self.combo.show_all()