def pick_icon(self, button): chooser = Gtk.FileChooserDialog(title=_("Choose an icon"), parent=self.dialog, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) chooser.add_shortcut_folder("/usr/share/pixmaps") chooser.add_shortcut_folder("/usr/share/icons") fn = get_icon_string(self.image) if GLib.path_is_absolute(fn): chooser.set_filename(fn) else: theme = Gtk.IconTheme.get_default() icon_info = theme.lookup_icon(fn, 64, 0) icon_info_fn = icon_info.get_filename() if icon_info != None else None if icon_info_fn: chooser.set_filename(icon_info_fn) filter = Gtk.FileFilter(); filter.add_pixbuf_formats (); chooser.set_filter(filter); preview = Gtk.Image() chooser.set_preview_widget(preview) chooser.connect("update-preview", self.update_icon_preview_cb, preview) response = chooser.run() if response == Gtk.ResponseType.ACCEPT: set_icon_string (self.image, chooser.get_filename()) chooser.destroy()
def build_widget(self, a): row = Gtk.ListBoxRow() grid = Gtk.Grid() grid.set_column_spacing(10) if not a.get_name(): return None screen = Gdk.Screen.get_default() icon_theme = Gtk.IconTheme.get_for_screen(screen) icon = a.get_icon() if icon: if GLib.path_is_absolute(icon.to_string()): iconfile = icon.to_string() shown_icon = GdkPixbuf.Pixbuf.new_from_file_at_scale(iconfile, 24, 24, True) img = Gtk.Image.new_from_pixbuf(shown_icon) else: pixbuf = icon_theme.load_icon(icon.to_string(), 24, Gtk.IconLookupFlags.FORCE_SIZE) img = Gtk.Image.new_from_pixbuf(pixbuf) else: img = Gtk.Image.new_from_gicon(Gio.ThemedIcon.new(DEFAULT_ICON), Gtk.IconSize.LARGE_TOOLBAR) grid.attach(img, 0, 0, 1, 1) img.props.hexpand = False label = Gtk.Label(label=a.get_name(), xalign=0) grid.attach_next_to(label, img, Gtk.PositionType.RIGHT, 1, 1) label.props.hexpand = True label.props.halign = Gtk.Align.START label.props.vexpand = False label.props.valign = Gtk.Align.CENTER row.add(grid) return row
def pick_icon(self, button): chooser = Gtk.FileChooserDialog( title=_("Choose an icon"), parent=self.dialog, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) chooser.add_shortcut_folder("/usr/share/pixmaps") chooser.add_shortcut_folder("/usr/share/icons") fn = get_icon_string(self.image) if fn: if GLib.path_is_absolute(fn): chooser.set_filename(fn) else: theme = Gtk.IconTheme.get_default() icon_info = theme.lookup_icon(fn, 64, 0) icon_info_fn = icon_info.get_filename( ) if icon_info != None else None if icon_info_fn: chooser.set_filename(icon_info_fn) filter = Gtk.FileFilter() filter.add_pixbuf_formats() chooser.set_filter(filter) preview = Gtk.Image() chooser.set_preview_widget(preview) chooser.connect("update-preview", self.update_icon_preview_cb, preview) response = chooser.run() if response == Gtk.ResponseType.ACCEPT: set_icon_string(self.image, chooser.get_filename()) chooser.destroy()
def set_icon_string(image, icon): if GLib.path_is_absolute(icon): image._file = icon pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon, 64, 64) if pixbuf is not None: image.set_from_pixbuf(pixbuf) else: image._icon_name = strip_extensions(icon) image.set_from_icon_name (strip_extensions (icon), Gtk.IconSize.BUTTON)
def set_icon_string(image, icon): if GLib.path_is_absolute(icon): image._file = icon pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon, 64, 64) if pixbuf is not None: image.set_from_pixbuf(pixbuf) else: image._icon_name = strip_extensions(icon) image.set_from_icon_name(strip_extensions(icon), Gtk.IconSize.BUTTON)
def __init__(self, app): Gtk.ListBoxRow.__init__(self) self.app = app widget = SettingsWidget() grid = Gtk.Grid() grid.set_column_spacing(15) widget.pack_start(grid, True, True, 0) screen = Gdk.Screen.get_default() icon_theme = Gtk.IconTheme.get_for_screen(screen) if self.app.icon: try: if GLib.path_is_absolute(self.app.icon): shown_icon = GdkPixbuf.Pixbuf.new_from_file_at_scale(self.app.icon, 24, 24, True) img = Gtk.Image.new_from_pixbuf(shown_icon) else: pixbuf = icon_theme.load_icon(self.app.icon, 24, Gtk.IconLookupFlags.FORCE_SIZE) img = Gtk.Image.new_from_pixbuf(pixbuf) except: img = Gtk.Image.new_from_gicon(Gio.ThemedIcon.new(DEFAULT_ICON), Gtk.IconSize.LARGE_TOOLBAR) else: img = Gtk.Image.new_from_gicon(Gio.ThemedIcon.new(DEFAULT_ICON), Gtk.IconSize.LARGE_TOOLBAR) grid.attach(img, 0, 0, 1, 1) self.desc_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.desc_box.props.hexpand = True self.desc_box.props.halign = Gtk.Align.START self.name_label = Gtk.Label() name_markup = GLib.markup_escape_text(self.app.name) self.name_label.set_markup("<b>{}</b>".format(name_markup)) self.name_label.props.xalign = 0.0 self.desc_box.add(self.name_label) self.comment_label = Gtk.Label() comment_markup = GLib.markup_escape_text(self.app.comment) self.comment_label.set_markup("<small>{}</small>".format(comment_markup)) self.comment_label.props.xalign = 0.0 self.comment_label.set_ellipsize(Pango.EllipsizeMode.END) self.comment_label.set_max_width_chars(40) self.desc_box.add(self.comment_label) grid.attach_next_to(self.desc_box, img, Gtk.PositionType.RIGHT, 1, 1) self.desc_box.set_sensitive(app.enabled) self.delay_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.delay_box.props.hexpand = False self.delay_box.set_margin_right(15) label = Gtk.Label(_("Delay")) self.delay_box.pack_start(label, False, False, 0) self.delay_time_label = Gtk.Label() delay_time_markup = GLib.markup_escape_text(self.app.delay) self.delay_time_label.set_markup(delay_time_markup) self.delay_time_label.get_style_context().add_class("dim-label") self.delay_box.pack_start(self.delay_time_label, False, False, 0) grid.attach_next_to(self.delay_box, self.desc_box, Gtk.PositionType.RIGHT, 1, 1) self.delay_box.set_sensitive(app.enabled) switch_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) switch_box.set_margin_top(5) switch_box.set_margin_bottom(5) switch = Gtk.Switch() switch.set_active(self.app.enabled) switch.connect("notify::active", self.on_switch_activated) switch_box.add(switch) grid.attach_next_to(switch_box, self.delay_box, Gtk.PositionType.RIGHT, 1, 1) self.add(widget)
def _on_destination_changed(self, combobox): path = combobox.get_active_text() self.set_response_sensitive(Gtk.ResponseType.OK, GLib.path_is_absolute(path))
def _on_file_loaded(self, torrent): self.fileview.set_torrent_file(torrent) self.set_response_sensitive(Gtk.ResponseType.OK, GLib.path_is_absolute(self.destination_combo.get_active_text()))
def set_icon_string(image, icon): if GLib.path_is_absolute(icon): set_icon_file(image, icon) else: image.props.icon_name = strip_extensions(icon)
def __init__(self, app): Gtk.ListBoxRow.__init__(self) self.app = app widget = SettingsWidget() grid = Gtk.Grid() grid.set_column_spacing(15) widget.pack_start(grid, True, True, 0) screen = Gdk.Screen.get_default() icon_theme = Gtk.IconTheme.get_for_screen(screen) if self.app.icon: try: if GLib.path_is_absolute(self.app.icon): shown_icon = GdkPixbuf.Pixbuf.new_from_file_at_scale( self.app.icon, 24, 24, True) img = Gtk.Image.new_from_pixbuf(shown_icon) else: pixbuf = icon_theme.load_icon( self.app.icon, 24, Gtk.IconLookupFlags.FORCE_SIZE) img = Gtk.Image.new_from_pixbuf(pixbuf) except: img = Gtk.Image.new_from_gicon( Gio.ThemedIcon.new(DEFAULT_ICON), Gtk.IconSize.LARGE_TOOLBAR) else: img = Gtk.Image.new_from_gicon(Gio.ThemedIcon.new(DEFAULT_ICON), Gtk.IconSize.LARGE_TOOLBAR) grid.attach(img, 0, 0, 1, 1) self.desc_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.desc_box.props.hexpand = True self.desc_box.props.halign = Gtk.Align.START self.name_label = Gtk.Label() self.name_label.set_markup("<b>%s</b>" % self.app.name) self.name_label.props.xalign = 0.0 self.desc_box.add(self.name_label) self.comment_label = Gtk.Label() self.comment_label.set_markup("<small>%s</small>" % self.app.comment) self.comment_label.props.xalign = 0.0 self.comment_label.set_ellipsize(Pango.EllipsizeMode.END) self.comment_label.set_max_width_chars(40) self.desc_box.add(self.comment_label) grid.attach_next_to(self.desc_box, img, Gtk.PositionType.RIGHT, 1, 1) self.desc_box.set_sensitive(app.enabled) self.delay_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.delay_box.props.hexpand = False self.delay_box.set_margin_right(15) label = Gtk.Label(_("Delay")) self.delay_box.pack_start(label, False, False, 0) self.delay_time_label = Gtk.Label() self.delay_time_label.set_markup("%s" % self.app.delay) self.delay_time_label.get_style_context().add_class("dim-label") self.delay_box.pack_start(self.delay_time_label, False, False, 0) grid.attach_next_to(self.delay_box, self.desc_box, Gtk.PositionType.RIGHT, 1, 1) self.delay_box.set_sensitive(app.enabled) switch_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) switch_box.set_margin_top(5) switch_box.set_margin_bottom(5) switch = Gtk.Switch() switch.set_active(self.app.enabled) switch.connect("notify::active", self.on_switch_activated) switch_box.add(switch) grid.attach_next_to(switch_box, self.delay_box, Gtk.PositionType.RIGHT, 1, 1) self.add(widget)
def _on_file_loaded(self, torrent): self.fileview.set_torrent_file(torrent) self.set_response_sensitive( Gtk.ResponseType.OK, GLib.path_is_absolute(self.destination_combo.get_active_text()))
def __init__(self, app): Gtk.ListBoxRow.__init__(self) self.app = app widget = SettingsWidget() grid = Gtk.Grid() grid.set_column_spacing(15) widget.pack_start(grid, True, True, 0) screen = Gdk.Screen.get_default() icon_theme = Gtk.IconTheme.get_for_screen(screen) if self.app.icon: try: if GLib.path_is_absolute(self.app.icon): pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( self.app.icon, 24, 24, True) img = Gtk.Image.new_from_pixbuf(pixbuf) else: img = Gtk.Image.new_from_icon_name( self.app.icon, Gtk.IconSize.LARGE_TOOLBAR) except: img = Gtk.Image.new_from_icon_name(DEFAULT_ICON, Gtk.IconSize.LARGE_TOOLBAR) else: img = Gtk.Image.new_from_icon_name(DEFAULT_ICON, Gtk.IconSize.LARGE_TOOLBAR) valid, w, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) img.set_pixel_size(w) grid.attach(img, 0, 0, 1, 1) self.desc_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.desc_box.props.hexpand = True self.desc_box.props.halign = Gtk.Align.START self.name_label = Gtk.Label() name_markup = GLib.markup_escape_text(self.app.name) self.name_label.set_markup("<b>{}</b>".format(name_markup)) self.name_label.props.xalign = 0.0 self.desc_box.add(self.name_label) self.comment_label = Gtk.Label() comment_markup = GLib.markup_escape_text(self.app.comment) self.comment_label.set_markup( "<small>{}</small>".format(comment_markup)) self.comment_label.props.xalign = 0.0 self.comment_label.set_ellipsize(Pango.EllipsizeMode.END) self.desc_box.add(self.comment_label) grid.attach_next_to(self.desc_box, img, Gtk.PositionType.RIGHT, 1, 1) self.desc_box.set_sensitive(app.enabled) self.delay_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) DELAY_GROUP.add_widget(self.delay_box) self.delay_box.props.hexpand = False self.delay_box.set_margin_right(15) delay_time_markup = GLib.markup_escape_text(self.app.delay) self.delay_label = Gtk.Label(_("Delay")) self.delay_label.set_no_show_all(True) self.delay_box.pack_start(self.delay_label, False, False, 0) self.delay_time_label = Gtk.Label() self.delay_time_label.set_no_show_all(True) self.delay_time_label.set_markup(_("%s s") % delay_time_markup) self.delay_time_label.get_style_context().add_class("dim-label") self.delay_box.pack_start(self.delay_time_label, False, False, 0) grid.attach_next_to(self.delay_box, self.desc_box, Gtk.PositionType.RIGHT, 1, 1) self.delay_box.set_sensitive(app.enabled) self.delay_label.set_visible(delay_time_markup != "0") self.delay_time_label.set_visible(delay_time_markup != "0") switch_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) switch_box.set_margin_top(5) switch_box.set_margin_bottom(5) switch = Gtk.Switch() switch.set_active(self.app.enabled) switch.connect("notify::active", self.on_switch_activated) switch_box.add(switch) grid.attach_next_to(switch_box, self.delay_box, Gtk.PositionType.RIGHT, 1, 1) self.add(widget)
def set_icon_string(image, icon): if GLib.path_is_absolute(icon): image.props.file = icon else: image.props.icon_name = strip_extensions(icon)