def _create_widgets(self): self._optionlist = OptionList() label = gtk.Label('Items at the %s ' % self._name) self._box = gtk.HPaned() ol = self._optionlist ol.reload() self.vbox.pack_start(label, False, False, 0) self._box.add(ol) self.vbox.pack_start(self._box) self._box.show_all() self._move_box = HIGVBox() self._add_bt = HIGButton(stock='gtk-add') self._add_bt.connect('clicked', self._on_add_press) self._remove_bt = HIGButton(stock='gtk-remove') self._remove_bt.connect('clicked', self._on_remove_press) #XXX - moves don't work yet: lack the connect self._move_up_bt = HIGButton(stock='gtk-go-up') self._move_down_bt = HIGButton(stock='gtk-go-down') self._move_box.pack_start(self._add_bt, False, False) self._move_box.pack_start(self._remove_bt, False, False) self._move_box.pack_start(self._move_up_bt, False, False) self._move_box.pack_start(self._move_down_bt, False, False) self._create_option_tv() self._box.set_position(200) self._box_other = gtk.HPaned() self._box.add(self._box_other) self._box_other.add(self._move_box) self._box_other.add(self._sw) self._move_box.show_all() self.vbox.show_all() label.show()
class ListManager(gtk.Dialog): ''' ListManager - manage the OptionList Tricks: - To works with the Command Manager it save at __init__ the list of options. After that. Add to CommandManager when clicked 'Ok Button' with the new and old list. ''' def __init__(self, name, section, profilecore, widget, title): gtk.Dialog.__init__(self,title) self.set_size_request(450, 300) self._name = name self._section = section self._profilecore = profilecore self._widget = widget self._list = self._profilecore.get_list_opt(self._section, self._name) self._new_list = self._profilecore.get_list_opt(self._section, self._name) self._create_widgets() self.show() self._load_option_list() self._create_action_area() def _create_widgets(self): self._optionlist = OptionList() label = gtk.Label('Items at the %s ' % self._name) self._box = gtk.HPaned() ol = self._optionlist ol.reload() self.vbox.pack_start(label, False, False, 0) self._box.add(ol) self.vbox.pack_start(self._box) self._box.show_all() self._move_box = HIGVBox() self._add_bt = HIGButton(stock='gtk-add') self._add_bt.connect('clicked', self._on_add_press) self._remove_bt = HIGButton(stock='gtk-remove') self._remove_bt.connect('clicked', self._on_remove_press) #XXX - moves don't work yet: lack the connect self._move_up_bt = HIGButton(stock='gtk-go-up') self._move_down_bt = HIGButton(stock='gtk-go-down') self._move_box.pack_start(self._add_bt, False, False) self._move_box.pack_start(self._remove_bt, False, False) self._move_box.pack_start(self._move_up_bt, False, False) self._move_box.pack_start(self._move_down_bt, False, False) self._create_option_tv() self._box.set_position(200) self._box_other = gtk.HPaned() self._box.add(self._box_other) self._box_other.add(self._move_box) self._box_other.add(self._sw) self._move_box.show_all() self.vbox.show_all() label.show() def _create_option_tv(self): self._sw = HIGScrolledWindow() self._model = gtk.TreeStore(gobject.TYPE_STRING) self._tv = gtk.TreeView(self._model) column = gtk.TreeViewColumn() column.set_title('Name') render = gtk.CellRendererText() column.pack_start(render, expand=True) column.add_attribute(render, 'text', 0) self._tv.append_column(column) self._sw.add(self._tv) self._sw.show_all() def _load_option_list(self): list = self._list for i in list : iter = self._model.insert_before(None, None) self._model.set_value(iter, 0, i) def _create_action_area(self): self._button_ok = HIGButton(stock='gtk-ok') self._button_cancel = HIGButton(stock='gtk-cancel') self._button_cancel.connect('clicked', self._on_cancel_press) self._button_ok.connect('clicked', self._on_ok_press) self.action_area.pack_start(self._button_cancel) self.action_area.pack_start(self._button_ok) self.action_area.show_all() def _on_add_press(self, widget): log.debug('<<< Add Option to OptionList') option_selected = self._optionlist.get_selected() iter = self._model.insert_before(None, None) self._model.set_value(iter, 0, option_selected) self._new_list.append(option_selected) def get_selected(self): """ Returns the string with name of selected option """ try: treeselection = self._tv.get_selection() (model,iter) = treeselection.get_selected() return model.get_value(iter,0) except: return None def get_selected_option(self): ''' @return: iter and model of option treeview selected ''' treeselection = self._tv.get_selection() (model,iter) = treeselection.get_selected() return model, iter def _on_remove_press(self, widget): log.debug('<<< Remove Option from OptionList') selected = self.get_selected() (model, iter) = self.get_selected_option() if selected!=None: self._new_list.remove(selected) self._model.remove(iter) def _on_ok_press(self, widget): # Lists: list2 = self._list list1 = self._new_list cmd = CommandUpdateOptionList(self._widget, list1, list2, self._profilecore, True) command_manager.add_command(cmd) self.destroy() def _on_cancel_press(self, widget): self.destroy()
class ListManager(gtk.Dialog): ''' ListManager - manage the OptionList Tricks: - To works with the Command Manager it save at __init__ the list of options. After that. Add to CommandManager when clicked 'Ok Button' with the new and old list. ''' def __init__(self, name, section, profilecore, widget, title): gtk.Dialog.__init__(self, title) self.set_size_request(450, 300) self._name = name self._section = section self._profilecore = profilecore self._widget = widget self._list = self._profilecore.get_list_opt(self._section, self._name) self._new_list = self._profilecore.get_list_opt( self._section, self._name) self._create_widgets() self.show() self._load_option_list() self._create_action_area() def _create_widgets(self): self._optionlist = OptionList() label = gtk.Label('Items at the %s ' % self._name) self._box = gtk.HPaned() ol = self._optionlist ol.reload() self.vbox.pack_start(label, False, False, 0) self._box.add(ol) self.vbox.pack_start(self._box) self._box.show_all() self._move_box = HIGVBox() self._add_bt = HIGButton(stock='gtk-add') self._add_bt.connect('clicked', self._on_add_press) self._remove_bt = HIGButton(stock='gtk-remove') self._remove_bt.connect('clicked', self._on_remove_press) #XXX - moves don't work yet: lack the connect self._move_up_bt = HIGButton(stock='gtk-go-up') self._move_down_bt = HIGButton(stock='gtk-go-down') self._move_box.pack_start(self._add_bt, False, False) self._move_box.pack_start(self._remove_bt, False, False) self._move_box.pack_start(self._move_up_bt, False, False) self._move_box.pack_start(self._move_down_bt, False, False) self._create_option_tv() self._box.set_position(200) self._box_other = gtk.HPaned() self._box.add(self._box_other) self._box_other.add(self._move_box) self._box_other.add(self._sw) self._move_box.show_all() self.vbox.show_all() label.show() def _create_option_tv(self): self._sw = HIGScrolledWindow() self._model = gtk.TreeStore(gobject.TYPE_STRING) self._tv = gtk.TreeView(self._model) column = gtk.TreeViewColumn() column.set_title('Name') render = gtk.CellRendererText() column.pack_start(render, expand=True) column.add_attribute(render, 'text', 0) self._tv.append_column(column) self._sw.add(self._tv) self._sw.show_all() def _load_option_list(self): list = self._list for i in list: iter = self._model.insert_before(None, None) self._model.set_value(iter, 0, i) def _create_action_area(self): self._button_ok = HIGButton(stock='gtk-ok') self._button_cancel = HIGButton(stock='gtk-cancel') self._button_cancel.connect('clicked', self._on_cancel_press) self._button_ok.connect('clicked', self._on_ok_press) self.action_area.pack_start(self._button_cancel) self.action_area.pack_start(self._button_ok) self.action_area.show_all() def _on_add_press(self, widget): log.debug('<<< Add Option to OptionList') option_selected = self._optionlist.get_selected() iter = self._model.insert_before(None, None) self._model.set_value(iter, 0, option_selected) self._new_list.append(option_selected) def get_selected(self): """ Returns the string with name of selected option """ try: treeselection = self._tv.get_selection() (model, iter) = treeselection.get_selected() return model.get_value(iter, 0) except: return None def get_selected_option(self): ''' @return: iter and model of option treeview selected ''' treeselection = self._tv.get_selection() (model, iter) = treeselection.get_selected() return model, iter def _on_remove_press(self, widget): log.debug('<<< Remove Option from OptionList') selected = self.get_selected() (model, iter) = self.get_selected_option() if selected != None: self._new_list.remove(selected) self._model.remove(iter) def _on_ok_press(self, widget): # Lists: list2 = self._list list1 = self._new_list cmd = CommandUpdateOptionList(self._widget, list1, list2, self._profilecore, True) command_manager.add_command(cmd) self.destroy() def _on_cancel_press(self, widget): self.destroy()