Python gi.repository.Gio 模块,ThemedIcon() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用gi.repository.Gio.ThemedIcon()

项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def generate_left_box(self):
        left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        remove_icon = Gio.ThemedIcon(name="user-trash-symbolic")
        remove_image = Gtk.Image.new_from_gicon(
            remove_icon, Gtk.IconSize.BUTTON)
        self.remove_button.set_tooltip_text(_("Remove selected accounts"))
        self.remove_button.set_image(remove_image)
        self.remove_button.set_sensitive(False)

        add_icon = Gio.ThemedIcon(name="list-add-symbolic")
        add_image = Gtk.Image.new_from_gicon(add_icon, Gtk.IconSize.BUTTON)
        self.add_button.set_tooltip_text(_("Add a new account"))
        self.add_button.set_image(add_image)

        lock_icon = Gio.ThemedIcon(name="changes-prevent-symbolic")
        lock_image = Gtk.Image.new_from_gicon(lock_icon, Gtk.IconSize.BUTTON)
        self.lock_button.set_tooltip_text(_("Lock the Application"))
        self.lock_button.set_image(lock_image)
        settings.connect('changed', self.bind_status)
        left_box.add(self.remove_button)
        left_box.add(self.add_button)
        left_box.add(self.lock_button)
        return left_box
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def generate_right_box(self):
        count = self.app.db.count()
        right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        select_icon = Gio.ThemedIcon(name="object-select-symbolic")
        select_image = Gtk.Image.new_from_gicon(
            select_icon, Gtk.IconSize.BUTTON)
        self.select_button.set_tooltip_text(_("Selection mode"))
        self.select_button.set_image(select_image)

        search_icon = Gio.ThemedIcon(name="system-search-symbolic")
        search_image = Gtk.Image.new_from_gicon(
            search_icon, Gtk.IconSize.BUTTON)
        self.search_button.set_tooltip_text(_("Search"))
        self.search_button.set_image(search_image)
        self.search_button.set_visible(count > 0)

        self.cancel_button.set_label(_("Cancel"))

        right_box.add(self.search_button)
        right_box.add(self.select_button)
        right_box.add(self.cancel_button)
        return right_box
项目:ubuntu-cleaner    作者:gerardpuig    | 项目源码 | 文件源码
def get_from_app(app, size=DEFAULT_SIZE):
    try:
        gicon = app.get_icon()
        pixbuf = None

        if gicon:
            if isinstance(gicon, Gio.ThemedIcon):
                return get_from_list(gicon.get_names(), size=size)
            elif isinstance(gicon, Gio.FileIcon):
                file = app.get_icon().get_file().get_path()
                return get_from_file(file, size)
        if not pixbuf:
            return get_from_name('application-x-executable', size=size)
    except Exception, e:
        log.error('get_from_app failed: %s' % e)
        return get_from_name(size=size)
项目:nautilus-folder-icons    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def get_default_icon(directory):
    """Use Gio to get the default icon."""
    attributes = ["metadata::custom-icon",
                  "metadata::custom-icon-name",
                  "standard::icon"]

    gfile = Gio.File.new_for_path(directory)
    ginfo = gfile.query_info("standard::icon,metadata::*",
                             Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)

    for attribute in attributes:
        if ginfo.has_attribute(attribute):
            attribute_type = ginfo.get_attribute_type(attribute)
            if attribute_type == Gio.FileAttributeType.STRING:
                value = ginfo.get_attribute_string(attribute)
                if value is not None:
                    return uriparse(value)
            elif attribute_type == Gio.FileAttributeType.OBJECT:
                # This return a Gio.ThemedIcon object
                value = ginfo.get_attribute_object(attribute)
                icon_names = value.props.names
                if icon_names:
                    return icon_names[0]
    return "folder"
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def generate_popover(self, box):
        settings_icon = Gio.ThemedIcon(name="open-menu-symbolic")
        settings_image = Gtk.Image.new_from_gicon(
            settings_icon, Gtk.IconSize.BUTTON)
        self.settings_button.set_tooltip_text(_("Settings"))
        self.settings_button.set_image(settings_image)
        self.settings_button.connect("clicked", self.toggle_popover)

        self.popover = Gtk.Popover.new_from_model(
            self.settings_button, self.app.menu)
        self.popover.props.width_request = 200
        box.add(self.settings_button)
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def generate_header_bar(self):
        """
            Generate the header bar box
        """
        self.hb.props.title = _("Add a new account")
        left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        cancel_button = Gtk.Button.new_with_label(_("Cancel"))
        cancel_button.connect("clicked", self.close_window)
        cancel_button.get_style_context().add_class("destructive-action")
        left_box.add(cancel_button)

        self.apply_button = Gtk.Button.new_with_label(_("Add"))
        self.apply_button.get_style_context().add_class("suggested-action")
        self.apply_button.connect("clicked", self.add_account)
        self.apply_button.set_sensitive(False)

        qr_button = Gtk.Button()
        qr_icon = Gio.ThemedIcon(name="qrscanner-symbolic")
        qr_image = Gtk.Image.new_from_gicon(qr_icon, Gtk.IconSize.BUTTON)
        qr_button.set_tooltip_text(_("Scan a QR code"))
        qr_button.set_image(qr_image)
        qr_button.connect("clicked", self.on_qr_scan)

        right_box.add(qr_button)
        right_box.add(self.apply_button)

        self.hb.pack_start(left_box)
        self.hb.pack_end(right_box)
        self.set_titlebar(self.hb)
项目:efibootmgr-gui    作者:Elinvention    | 项目源码 | 文件源码
def btn_with_icon(icon):
    btn = Gtk.Button()
    icon = Gio.ThemedIcon(name=icon)
    image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
    btn.add(image)
    return btn
项目:MTodo    作者:mortezaipo    | 项目源码 | 文件源码
def __init__(self, name: str, icon_name: str):
        """Initialize Button class"""
        self._name = name
        self._icon_name = icon_name
        self._icon = Gio.ThemedIcon(name=icon_name)
        self._widget = Gtk.Button()
        self._widget.add(Gtk.Image.new_from_gicon(self._icon, Gtk.IconSize.BUTTON))
        self._widget.set_name(self._name)
项目:nautilus-folder-icons    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def _build_header_bar(self):
        """Setup window headerbar."""
        # Header bar
        headerbar = Gtk.HeaderBar()
        headerbar_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                      spacing=3)

        title = Gtk.Label()
        title.set_text(_("Icon Chooser"))
        title.get_style_context().add_class("title")
        headerbar_container.pack_start(title, False, False, 0)

        subtitle = Gtk.Label()
        subtitle.get_style_context().add_class("subtitle")
        subtitle_text = ", ".join(self._folders)
        subtitle.set_text(subtitle_text)
        subtitle.set_ellipsize(Pango.EllipsizeMode.END)
        subtitle.set_tooltip_text(subtitle_text)
        subtitle.props.max_width_chars = 30
        headerbar_container.pack_start(subtitle, False, False, 0)

        headerbar.set_custom_title(headerbar_container)
        headerbar.set_show_close_button(False)

        # Search Button
        self._search_btn = Gtk.ToggleButton()
        search_icn = Gio.ThemedIcon(name="system-search-symbolic")
        search_img = Gtk.Image.new_from_gicon(search_icn, Gtk.IconSize.BUTTON)
        self._search_btn.set_image(search_img)

        # Cancel Button
        cancel_button = Gtk.Button()
        cancel_button.set_label(_("Cancel"))
        cancel_button.connect("clicked", self.close_window)

        headerbar.pack_start(cancel_button)
        headerbar.pack_end(self._search_btn)
        self.set_titlebar(headerbar)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def generate_widget(self, item):
        """ Generates gtk widget for specified menutitem """
        if isinstance(item, Separator) and item.label:
            widget = Gtk.Button.new_with_label(item.label)
            widget.set_relief(Gtk.ReliefStyle.NONE)
            widget.set_name("osd-menu-separator")
            return widget
        elif isinstance(item, Separator):
            widget = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
            widget.set_name("osd-menu-separator")
            return widget
        else:
            widget = Gtk.Button.new_with_label(item.label)
            widget.set_relief(Gtk.ReliefStyle.NONE)
            if hasattr(widget.get_children()[0], "set_xalign"):
                widget.get_children()[0].set_xalign(0)
            else:
                widget.get_children()[0].set_halign(Gtk.Align.START)
            if isinstance(item, Submenu):
                item.callback = self.show_submenu
                label1 = widget.get_children()[0]
                label2 = Gtk.Label(_(">>"))
                label2.set_property("margin-left", 30)
                box = Gtk.Box(Gtk.Orientation.HORIZONTAL)
                widget.remove(label1)
                box.pack_start(label1, True, True, 1)
                box.pack_start(label2, False, True, 1)
                widget.add(box)
                widget.set_name("osd-menu-item")
            elif item.id is None:
                widget.set_name("osd-menu-dummy")
            else:
                widget.set_name("osd-menu-item")

            if isinstance(item.icon, Gio.FileIcon):
                icon_file = item.icon.get_file().get_path()
                has_colors = True
            elif isinstance(item.icon, Gio.ThemedIcon):
                icon = Gtk.IconTheme.get_default().choose_icon(
                    item.icon.get_names(), 64, 0)
                icon_file = icon.get_filename() if icon else None
                has_colors = True
            else:
                icon_file, has_colors = find_icon(item.icon, self.PREFER_BW_ICONS)

            if icon_file:
                icon = MenuIcon(icon_file, has_colors)
                label = widget.get_children()[0]
                for c in [] + widget.get_children():
                    widget.remove(c)
                box = Gtk.Box()
                box.pack_start(icon,  False, True, 0)
                box.pack_start(label, True, True, 10)
                widget.add(box)

            return widget