From cc5966dab27a67f61b910f1273b307da31e0f10b Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 6 May 2024 19:11:18 -0500 Subject: [PATCH] Added status icon for system trays --- src/core/widgets/webkit/webkit_ui.py | 1 - src/core/window.py | 7 ++- src/libs/status_icon.py | 67 ++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/libs/status_icon.py diff --git a/src/core/widgets/webkit/webkit_ui.py b/src/core/widgets/webkit/webkit_ui.py index 9b55997..263e491 100644 --- a/src/core/widgets/webkit/webkit_ui.py +++ b/src/core/widgets/webkit/webkit_ui.py @@ -13,7 +13,6 @@ from libs.settings.other.webkit_ui_settings import WebkitUISettings from libs.dto.event import Event - class WebkitUI(WebKit2.WebView): def __init__(self): super(WebkitUI, self).__init__() diff --git a/src/core/window.py b/src/core/window.py index a6dac07..f1f8997 100644 --- a/src/core/window.py +++ b/src/core/window.py @@ -11,6 +11,7 @@ from gi.repository import Gdk from gi.repository import GLib # Application imports +from libs.status_icon import StatusIcon from core.controllers.base_controller import BaseController @@ -27,7 +28,8 @@ class Window(Gtk.ApplicationWindow): super(Window, self).__init__() settings_manager.set_main_window(self) - self._controller = None + self._status_icon = None + self._controller = None self._setup_styling() self._setup_signals() @@ -65,7 +67,8 @@ class Window(Gtk.ApplicationWindow): if settings_manager.is_debug(): self.set_interactive_debugging(True) - self._controller = BaseController(args, unknownargs) + self._controller = BaseController(args, unknownargs) + self._status_icon = StatusIcon() if not self._controller: raise ControllerStartException("BaseController exited and doesn't exist...") diff --git a/src/libs/status_icon.py b/src/libs/status_icon.py new file mode 100644 index 0000000..2769a05 --- /dev/null +++ b/src/libs/status_icon.py @@ -0,0 +1,67 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +gi.require_version('AppIndicator3', '0.1') +from gi.repository import Gtk +from gi.repository import GLib +from gi.repository import AppIndicator3 + +# Application imports + + + +class StatusIcon(): + """ StatusIcon for Application to go to Status Tray. """ + + def __init__(self): + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + + def _setup_styling(self): + ... + + def _setup_signals(self): + ... + + def _subscribe_to_events(self): + ... + + def _load_widgets(self): + status_menu = Gtk.Menu() + icon_theme = Gtk.IconTheme.get_default() + check_menu_item = Gtk.CheckMenuItem.new_with_label("Update icon") + quit_menu_item = Gtk.MenuItem.new_with_label("Quit") + + # Create StatusNotifierItem + self.indicator = AppIndicator3.Indicator.new( + f"{APP_NAME}-statusicon", + "gtk-info", + AppIndicator3.IndicatorCategory.APPLICATION_STATUS) + self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) + + check_menu_item.connect("activate", self.check_menu_item_cb) + quit_menu_item.connect("activate", self.quit_menu_item_cb) + icon_theme.connect('changed', self.icon_theme_changed_cb) + + self.indicator.set_menu(status_menu) + status_menu.append(check_menu_item) + status_menu.append(quit_menu_item) + status_menu.show_all() + + def update_icon(self, icon_name): + self.indicator.set_icon(icon_name) + + def check_menu_item_cb(self, widget, data = None): + icon_name = "parole" if widget.get_active() else "gtk-info" + self.update_icon(icon_name) + + def icon_theme_changed_cb(self, theme): + self.update_icon("gtk-info") + + def quit_menu_item_cb(self, widget, data = None): + event_system.emit("tear-down")