class IconBlock(Gtk.Box): def __init__(self, text, controls, filename, all_icons): Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.controls = controls self.combobox = Gtk.ComboBox() self.entry = Gtk.Entry() self.entry.set_size_request(300, 30) self.entry.set_property("margin", 0) if filename: self.entry.set_text(filename) else: filename = "" self.orig_list = all_icons self.all_icons = all_icons[:] self.modconst = ModelConstructor(self.all_icons) self.combobox.set_model(self.modconst.model) self.choose_button = ButtonIconText(_("Choose"), "folder-open") self.delete_button = ButtonIconText(_("Delete"), "edit-delete") self.choose_button.set_property("always-show-image", True) self.delete_button.set_property("always-show-image", True) self.choose_button.connect("clicked", self.on_file_choose) self.delete_button.connect("clicked", self.on_delete) if filename in self.all_icons: self.combobox.set_active(self.all_icons.index(filename)) else: self.combobox.set_active(0) self.on_change_icon() logging.warning("Icon " + filename + " is absent in list of icons") pix_render = Gtk.CellRendererPixbuf() self.combobox.pack_start(pix_render, 0) self.combobox.add_attribute(pix_render, 'pixbuf', 0) label = Gtk.Label.new(text) if text: # if iconblock without label label.set_size_request(80, -1) self.pack_start(label, False, False, 0) self.pack_start(self.combobox, False, False, 0) self.pack_start(self.entry, True, True, 0) self.pack_start(self.choose_button, False, False, 0) self.pack_start(self.delete_button, False, False, 0) self.combobox.connect("changed", self.on_change_icon) self.on_change_icon() def on_file_choose(self, *a): file = file_chooser_dialog("Choose icon") if not file: return None self.entry.set_text(file[0]) self.modconst.append_icon(self, file[0], True) self.all_icons.append(file[0]) def on_change_icon(self, *a): active_id = self.combobox.get_active() icon_name = "" if active_id >= 0: icon_name = self.combobox.get_model()[active_id][1] self.entry.set_text(icon_name) if not (icon_name.startswith('/') or icon_name.startswith(':', 1)): self.delete_button.set_sensitive(False) else: self.delete_button.set_sensitive(True) def get_active_path(self): active_id = self.combobox.get_active() return self.combobox.get_model()[active_id][1] def on_delete(self, *a): active_id = self.combobox.get_active() rem_icon = self.entry.get_text() iter = self.modconst.model.get_iter(active_id) try: if self.all_icons.index(rem_icon) > 4: self.all_icons.remove(rem_icon) self.modconst.delete_icon(iter) self.combobox.set_active(0) else: error_window = ChildTopWindow("Error") label = Gtk.Label.new("You can not remove a standard icon") error_window.add(label) error_window.show() except ValueError, e: logging.error("There is not such icon in the list" + str(e))