Added status icon for system trays

This commit is contained in:
itdominator 2024-05-06 19:11:18 -05:00
parent e82e4fb1eb
commit cc5966dab2
3 changed files with 72 additions and 3 deletions

View File

@ -13,7 +13,6 @@ from libs.settings.other.webkit_ui_settings import WebkitUISettings
from libs.dto.event import Event from libs.dto.event import Event
class WebkitUI(WebKit2.WebView): class WebkitUI(WebKit2.WebView):
def __init__(self): def __init__(self):
super(WebkitUI, self).__init__() super(WebkitUI, self).__init__()

View File

@ -11,6 +11,7 @@ from gi.repository import Gdk
from gi.repository import GLib from gi.repository import GLib
# Application imports # Application imports
from libs.status_icon import StatusIcon
from core.controllers.base_controller import BaseController from core.controllers.base_controller import BaseController
@ -27,7 +28,8 @@ class Window(Gtk.ApplicationWindow):
super(Window, self).__init__() super(Window, self).__init__()
settings_manager.set_main_window(self) settings_manager.set_main_window(self)
self._controller = None self._status_icon = None
self._controller = None
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
@ -65,7 +67,8 @@ class Window(Gtk.ApplicationWindow):
if settings_manager.is_debug(): if settings_manager.is_debug():
self.set_interactive_debugging(True) self.set_interactive_debugging(True)
self._controller = BaseController(args, unknownargs) self._controller = BaseController(args, unknownargs)
self._status_icon = StatusIcon()
if not self._controller: if not self._controller:
raise ControllerStartException("BaseController exited and doesn't exist...") raise ControllerStartException("BaseController exited and doesn't exist...")

67
src/libs/status_icon.py Normal file
View File

@ -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")