Python gi.repository.Gtk 模块,StatusIcon() 实例源码

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

项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        StatusIcon.__init__(self, *args, **kwargs)

        if not self._is_forced():
            if IS_UNITY:
                # Unity fakes SysTray support but actually hides all icons...
                raise NotImplementedError
            if IS_GNOME:
                # Gnome got broken as well
                raise NotImplementedError

        self._tray = Gtk.StatusIcon()

        self._tray.connect("activate", self._on_click)
        self._tray.connect("popup-menu", self._on_rclick)
        self._tray.connect("notify::embedded", self._on_embedded_change)

        self._tray.set_visible(True)
        self._tray.set_name("syncthing-gtk")
        self._tray.set_title(self.TRAY_TITLE)

        # self._tray.is_embedded() must be called asynchronously
        # See: http://stackoverflow.com/a/6365904/277882
        GLib.idle_add(self._on_embedded_change)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        StatusIcon.__init__(self, *args, **kwargs)

        self._arguments  = (args, kwargs)
        self._status_fb  = None
        self._status_gtk = None
        self.set("si-syncthing-unknown", "")

        # Do not ever force-show indicators when they do not think they'll work
        if "force" in self._arguments[1]:
            del self._arguments[1]["force"]

        try:
            # Try loading GTK native status icon
            self._status_gtk = StatusIconGTK3(*args, **kwargs)
            self._status_gtk.connect(b"clicked",        self._on_click)
            self._status_gtk.connect(b"notify::active", self._on_notify_active_gtk)
            self._on_notify_active_gtk()

            log.info("Using backend StatusIconGTK3 (primary)")
        except NotImplementedError:
            # Directly load fallback implementation
            self._load_fallback()
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def _load_fallback(self):
        status_icon_backends = [StatusIconAppIndicator, StatusIconDummy]

        if not self._status_fb:
            for StatusIconBackend in status_icon_backends:
                try:
                    self._status_fb = StatusIconBackend(*self._arguments[0], **self._arguments[1])
                    self._status_fb.connect(b"clicked",        self._on_click)
                    self._status_fb.connect(b"notify::active", self._on_notify_active_fb)
                    self._on_notify_active_fb()

                    log.warning("StatusIcon: Using backend %s (fallback)" % StatusIconBackend.__name__)
                    break
                except NotImplementedError:
                    continue

            # At least the dummy backend should have been loaded at this point...
            assert self._status_fb

        # Update fallback icon
        self.set(self._icon, self._text)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def get_status_icon(*args, **kwargs):
    # Try selecting backend based on environment variable
    if "STATUS_BACKEND" in os.environ:
        kwargs["force"] = True

        status_icon_backend_name = "StatusIcon%s" % (os.environ.get("STATUS_BACKEND"))
        if status_icon_backend_name in globals():
            try:
                status_icon = globals()[status_icon_backend_name](*args, **kwargs)
                log.info("StatusIcon: Using requested backend %s" % (status_icon_backend_name))
                return status_icon
            except NotImplementedError:
                log.error("StatusIcon: Requested backend %s is not supported" % (status_icon_backend_name))
        else:
            log.error("StatusIcon: Requested backend %s does not exist" % (status_icon_backend_name))

        return StatusIconDummy(*args, **kwargs)

    # Use proxy backend to determine the correct backend while the application is running
    return StatusIconProxy(*args, **kwargs)
项目:revolt    作者:aperezdc    | 项目源码 | 文件源码
def __init__(self, delegate, context_menu, app):
        super().__init__(delegate)
        self._status = Status.DISCONNECTED
        self._contextmenu = context_menu
        self._size = 16
        self._flipflop = True
        self._blinkmilliseconds = 500
        self._icondata = {}
        self.__load_icons(self._size, app)
        self._icon = Gtk.StatusIcon()
        self._icon.set_visible(True)
        self._icon.set_property("has-tooltip", True)
        self._icon.set_property("title", "Revolt")
        self._icon.connect("activate", self.__on_activate)
        self._icon.connect("popup-menu", self.__on_popup_menu)
        self._icon.connect("size-changed", self.__on_icon_size_change)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        StatusIcon.__init__(self, *args, **kwargs)

        # Pretty unlikely that this will be visible...
        self.set_property("active", False)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def set(self, icon=None, text=None):
        StatusIcon.set(self, icon, text)

        self._get_icon(icon)
        self._get_text(text)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def set(self, icon=None, text=None):
        StatusIcon.set(self, icon, text)

        self._tray.set_from_icon_name(self._get_icon(icon))
        self._tray.set_tooltip_text(self._get_text(text))
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def _set_visible(self, active):
        StatusIcon._set_visible(self, active)

        self._tray.set_visible(active)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def _set_visible(self, active):
        StatusIcon._set_visible(self, active)

        self._tray.set_status(self._status_active if active else self._status_passive)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def set(self, icon=None, text=None):
        StatusIcon.set(self, icon, text)

        self._tray.set_icon_full(self._get_icon(icon), self._get_text(text))
项目:pomodoroTasks2    作者:liloman    | 项目源码 | 文件源码
def __init__(self, rc = '~/.task'):
        self.tw = TaskWarrior(data_location=rc, create=True)
        self.status_icon = Gtk.StatusIcon()
        self.status_icon.set_from_file("images/iconStarted-0.png")
        self.status_icon.connect("popup-menu", self.right_click_event)
        self.status_icon.connect("activate", self.left_click_event)
        # systray daemon
        name = dbus.service.BusName(self.bus_name, bus=dbus.SessionBus(),do_not_queue=True, replace_existing=False, allow_replacement=False )
        dbus.service.Object.__init__(self, name, '/systray')
        # client for daemon
        bus = dbus.SessionBus(private = True)
        daemon_client = bus.get_object('org.liloman.pomodoro', "/daemon")
        self.interface = dbus.Interface(daemon_client, "org.liloman.pomodoroInterface")
项目:testindicator    作者:logileifs    | 项目源码 | 文件源码
def __init__(self, **kwargs):
        self.indicator = gtk.StatusIcon()
        self.indicator.set_from_stock(gtk.STOCK_ABOUT)
        self.indicator.connect('popup-menu', self.on_right_click)
        self.indicator.set_tooltip_text('testindicator')
项目:battray    作者:Carpetsmoker    | 项目源码 | 文件源码
def __init__(self, interval=None, configfile=None, platform=None, datadir=None):
        self.configfile, self.datadir, self.default_config = find_config(configfile, datadir)

        if platform:
            self.platform = getattr(platforms, platform, None)
            if self.platform is None:
                logging.error("No such platform: `{}'".format(platform))
                sys.exit(1)
        else:
            self.platform = platforms.find()
        self.data = self.played = self.notified = {}

        self.icon = Gtk.StatusIcon()
        self.icon.set_name('Battray')

        self.menu = Gtk.Menu()
        refresh = Gtk.MenuItem.new_with_label('Refresh')
        refresh.connect('activate', self.cb_update)
        self.menu.append(refresh)

        about = Gtk.MenuItem.new_with_label('About')
        about.connect('activate', self.cb_about)
        self.menu.append(about)

        quit = Gtk.MenuItem.new_with_label('Quit')
        quit.connect('activate', self.cb_destroy)
        self.menu.append(quit)

        self.icon.connect('activate', self.cb_update)
        self.icon.connect('popup-menu', self.cb_popup_menu)
        self.icon.set_visible(True)

        self.update_status()
        GLib.timeout_add_seconds(interval or 15, self.update_status)
项目:battray    作者:Carpetsmoker    | 项目源码 | 文件源码
def cb_popup_menu(self, widget, button, time, data=None):
        self.menu.show_all()
        self.menu.popup(None, None, Gtk.StatusIcon.position_menu, self.icon, button, time)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def init_status_icon(self):
        def on_status_icon_popup_menu(status_icon, event_button, event_time):
            menu.popup(None, None,
                    lambda a,b: Gtk.StatusIcon.position_menu(menu, status_icon),
                    None, event_button, event_time)

        def on_status_icon_activate(status_icon):
            if self.window.props.visible:
                self.window.hide()
            else:
                self.window.present()

        if not self.profile or not self.profile['use-status-icon']:
            self.status_icon = None
            return

        menu = Gtk.Menu()
        show_item = Gtk.MenuItem.new_with_label(_('Show App'))
        show_item.connect('activate', lambda item: self.window.present())
        menu.append(show_item)

        sep_item = Gtk.SeparatorMenuItem()
        menu.append(sep_item)

        pause_upload_item = Gtk.MenuItem.new_with_label(
                _('Pause Upload Tasks'))
        pause_upload_item.connect('activate',
                lambda item: self.upload_page.pause_tasks())
        menu.append(pause_upload_item)

        pause_download_item = Gtk.MenuItem.new_with_label(
                _('Pause Download Tasks'))
        pause_download_item.connect('activate',
                lambda item: self.download_page.pause_tasks())
        menu.append(pause_download_item)

        sep_item = Gtk.SeparatorMenuItem()
        menu.append(sep_item)

        quit_item = Gtk.MenuItem.new_with_label(_('Quit'))
        quit_item.connect('activate', lambda item: self.quit())
        menu.append(quit_item)

        menu.show_all()
        self.status_menu = menu

        if 'AppIndicator' in globals():
            self.status_icon = AppIndicator.Indicator.new(Config.NAME,
                    Config.NAME,
                    AppIndicator.IndicatorCategory.APPLICATION_STATUS)
            self.status_icon.set_menu(menu)
            self.status_icon.set_status(AppIndicator.IndicatorStatus.ACTIVE)
        else:
            self.status_icon = Gtk.StatusIcon()
            self.status_icon.set_from_icon_name(Config.NAME)
            # left click
            self.status_icon.connect('activate', on_status_icon_activate)
            # right click
            self.status_icon.connect('popup_menu', on_status_icon_popup_menu)

    # Open API
项目:revolt    作者:aperezdc    | 项目源码 | 文件源码
def __init__(self, delegate, context_menu, app, failure_callback):
        super().__init__(delegate)

        import gi
        gi.require_version("StatusNotifier", "1.0")
        from gi.repository import StatusNotifier

        if hasattr(StatusNotifier.Icon, "ATTENTION_ICON"):
            self.SNI_ATTENTION_ICON = StatusNotifier.Icon.ATTENTION_ICON
            self.SNI_ACTIVE_ICON = StatusNotifier.Icon.ICON
        else:
            self.SNI_ATTENTION_ICON = StatusNotifier.Icon.STATUS_NOTIFIER_ATTENTION_ICON
            self.SNI_ACTIVE_ICON = StatusNotifier.Icon.STATUS_NOTIFIER_ICON
        self.SNI_ATTENTION = StatusNotifier.Status.NEEDS_ATTENTION
        self.SNI_ACTIVE = StatusNotifier.Status.ACTIVE

        theme = Gtk.IconTheme.get_default()
        self._offline_icon_pixbuf = theme.load_icon(app.get_application_id(),
                                                    self.ICON_PIXBUF_SIZE,
                                                    Gtk.IconLookupFlags.FORCE_SVG |
                                                    Gtk.IconLookupFlags.FORCE_SYMBOLIC)
        self._attention_icon_pixbuf = theme.load_icon(app.get_application_id() + "-status-blink",
                                                      self.ICON_PIXBUF_SIZE,
                                                      Gtk.IconLookupFlags.FORCE_SVG |
                                                      Gtk.IconLookupFlags.FORCE_SYMBOLIC)
        self._online_icon_pixbuf = theme.load_icon(app.get_application_id() + "-status-online",
                                                   self.ICON_PIXBUF_SIZE,
                                                   Gtk.IconLookupFlags.FORCE_SVG |
                                                   Gtk.IconLookupFlags.FORCE_SYMBOLIC)

        self._failure_callback = failure_callback
        self._sni = StatusNotifier.Item.new_from_pixbuf(app.get_application_id(),
                                                        StatusNotifier.Category.COMMUNICATIONS,
                                                        self._offline_icon_pixbuf)
        if not self._sni.set_context_menu(context_menu):
            # TODO: No DbusMenu support built into StatusIcon, we need to handle the
            #  "context-menu" signal ourselves. For now, fallback to use GtkStatusIcon
            raise RuntimeError("StatusNotifier does not support DbusMenu, falling back to GtkStatusIcon")

        self._sni.connect("registration-failed", self.__on_registration_failed)
        self._sni.connect("activate", self.__on_activate)
        self._sni.set_from_pixbuf(self.SNI_ATTENTION_ICON, self._attention_icon_pixbuf)
        self._sni.set_title("Revolt")
        self._sni.set_status(self.SNI_ACTIVE)
        self._sni.set_item_is_menu(False)
        self._sni.freeze_tooltip()
        self._sni.set_tooltip_title("Revolt")
        self._sni.thaw_tooltip()
        self._sni.register()