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 __init__(self, controls): super(FSPerspective, self).__init__() self.tabhelper = TabHelperControl(controls) self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.add_button = ButtonIconText(_("Add Folder(s) in tree"), "list-add", spacing=10) self.add_button.connect( "clicked", lambda *a: self.tabhelper.get_current_tree().add_folder()) self.vbox.pack_start(self.add_button, False, False, 0) self.vbox.pack_start(self.tabhelper, True, True, 0) self.vbox.show_all()
def __init__(self, controls): super(FSPerspective, self).__init__() self.tabhelper = TabHelperControl(controls) self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.add_button = ButtonIconText(_("Add Folder(s) in tree"), "list-add", spacing=10) self.add_button.connect("clicked", lambda *a: self.tabhelper.get_current_tree().add_folder()) self.vbox.pack_start(self.add_button, False, False, 0) self.vbox.pack_start(self.tabhelper, True, True, 0) self.vbox.show_all()
class FSPerspective(BasePerspective, Filterable): def __init__(self, controls): super(FSPerspective, self).__init__() self.tabhelper = TabHelperControl(controls) self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.add_button = ButtonIconText(_("Add Folder(s) in tree"), "list-add", spacing=10) self.add_button.connect( "clicked", lambda *a: self.tabhelper.get_current_tree().add_folder()) self.vbox.pack_start(self.add_button, False, False, 0) self.vbox.pack_start(self.tabhelper, True, True, 0) self.vbox.show_all() def get_tabhelper(self): ## temporary duplicate for get_widget() return self.tabhelper @idle_task def hide_add_button(self): self.add_button.hide() @idle_task def show_add_button(self): self.add_button.show() def get_id(self): return "fs" def get_icon(self): return "drive-harddisk" def get_name(self): return _("Music") def get_tooltip(self): return _("Music Navigation (Alt+1)") def get_widget(self): return self.vbox ## LoadSave implementation def on_load(self): self.tabhelper.on_load() def on_save(self): self.tabhelper.on_save() ## Filterable implementation def filter_by_file(self, value): self.tabhelper.get_current_tree().filter_by_file(value) def filter_by_folder(self, value): self.tabhelper.get_current_tree().filter_by_folder(value)
class FSPerspective(BasePerspective, Filterable): def __init__(self, controls): super(FSPerspective, self).__init__() self.tabhelper = TabHelperControl(controls) self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.add_button = ButtonIconText(_("Add Folder(s) in tree"), "list-add", spacing=10) self.add_button.connect("clicked", lambda * a: self.tabhelper.get_current_tree().add_folder()) self.vbox.pack_start(self.add_button, False, False, 0) self.vbox.pack_start(self.tabhelper, True, True, 0) self.vbox.show_all() def get_tabhelper(self): ## temporary duplicate for get_widget() return self.tabhelper @idle_task def hide_add_button(self): self.add_button.hide() @idle_task def show_add_button(self): self.add_button.show() def get_id(self): return "fs" def get_icon(self): return "music" def get_name(self): return _("Music") def get_tooltip(self): return _("Music Navigation (Alt+1)") def get_widget(self): return self.vbox ## LoadSave implementation def on_load(self): self.tabhelper.on_load() def on_save(self): self.tabhelper.on_save() ## Filterable implementation def filter_by_file(self, value): self.tabhelper.get_current_tree().filter_by_file(value) def filter_by_folder(self, value): self.tabhelper.get_current_tree().filter_by_folder(value)
def __init__(self, text, controls, filename, all_icons=temp_list): 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, -1) self.entry.set_property("margin", 0) if filename: self.entry.set_text(filename) else: filename = "" self.all_icons = all_icons self.modconst = ModelConstructor(all_icons) self.combobox.set_model(self.modconst.model) 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, False) self.combobox.add_attribute(pix_render, 'pixbuf', 0) button_1 = ButtonIconText(_("Choose"), "folder-open") button_1.set_property("always-show-image", True) button_1.connect("clicked", self.on_file_choose) button_2 = ButtonIconText(_("Delete"), "edit-delete") button_2.set_property("always-show-image", True) button_2.connect("clicked", self.on_delete) 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(button_1, False, False, 0) self.pack_start(button_2, False, False, 0) self.combobox.connect("changed", self.on_change_icon)
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))