mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 00:14:09 -04:00
g13gui: Add in AppIndicator support
This allows us to quickly switch between profiles in a normal environment. It's kinda a hack until we have proper applet support, though this will require changes to g13d to be possible.
This commit is contained in:
parent
4bc6ec0db8
commit
fb2330568c
@ -4,6 +4,7 @@ import os
|
||||
import os.path
|
||||
import xdg.BaseDirectory as basedir
|
||||
|
||||
PROGNAME = 'g13gui'
|
||||
VERSION = '0.1.0'
|
||||
PROFILES_CONFIG_PATH = os.path.join(basedir.save_config_path('g13', 'g13gui'),
|
||||
'profiles.json')
|
||||
|
@ -18,9 +18,10 @@ if __name__ == '__main__':
|
||||
queue = queue.Queue()
|
||||
|
||||
win = ui.MainWindow(queue, prefs)
|
||||
win.connect("destroy", Gtk.main_quit)
|
||||
win.show_all()
|
||||
|
||||
indicator = ui.AppIndicator(prefs, win)
|
||||
|
||||
worker = G13DWorker(queue, win)
|
||||
worker.start()
|
||||
|
||||
|
@ -4,3 +4,4 @@ from g13gui.ui.g13buttonpopover import G13ButtonPopover
|
||||
from g13gui.ui.mainwindow import MainWindow
|
||||
from g13gui.ui.profilepopover import ProfilePopover
|
||||
from g13gui.ui.profilepopover import ProfilePopoverMode
|
||||
from g13gui.ui.appindicator import AppIndicator
|
||||
|
85
g13gui/g13gui/ui/appindicator.py
Normal file
85
g13gui/g13gui/ui/appindicator.py
Normal file
@ -0,0 +1,85 @@
|
||||
import gi
|
||||
|
||||
from g13gui.common import PROGNAME
|
||||
from g13gui.observer import GtkObserver
|
||||
from g13gui.observer import ChangeType
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('AppIndicator3', '0.1')
|
||||
from gi.repository import Gtk, GObject
|
||||
from gi.repository import AppIndicator3 as indicator
|
||||
|
||||
|
||||
class AppIndicator(GtkObserver):
|
||||
def __init__(self, prefs, mainWindow):
|
||||
GtkObserver.__init__(self)
|
||||
|
||||
self._initIndicator()
|
||||
|
||||
self._prefs = prefs
|
||||
self._prefs.registerObserver(self, {'profile'})
|
||||
self._mainWindow = mainWindow
|
||||
self._menu = Gtk.Menu()
|
||||
self._menuItems = []
|
||||
self._indicator.set_menu(self._menu)
|
||||
self._rebuilding = False
|
||||
|
||||
self._rebuildMenu()
|
||||
|
||||
def _initIndicator(self):
|
||||
self._indicator = indicator.Indicator.new(
|
||||
PROGNAME, "g13gui", indicator.IndicatorCategory.OTHER)
|
||||
self._indicator.set_status(indicator.IndicatorStatus.ACTIVE)
|
||||
|
||||
def _removeAllMenuItems(self):
|
||||
for item in self._menuItems:
|
||||
self._menu.remove(item)
|
||||
self._menuItems = []
|
||||
|
||||
def _attachMenuItem(self, item):
|
||||
self._menu.append(item)
|
||||
self._menuItems.append(item)
|
||||
|
||||
def _rebuildMenu(self):
|
||||
if self._rebuilding:
|
||||
return
|
||||
|
||||
self._rebuilding = True
|
||||
self._removeAllMenuItems()
|
||||
profileNames = sorted(self._prefs.profileNames())
|
||||
selectedProfile = self._prefs.selectedProfileName()
|
||||
|
||||
for name in profileNames:
|
||||
item = Gtk.CheckMenuItem(name)
|
||||
item.set_draw_as_radio(True)
|
||||
item.connect('activate', self.changeProfile)
|
||||
if name == selectedProfile:
|
||||
item.set_active(True)
|
||||
self._attachMenuItem(item)
|
||||
|
||||
sep = Gtk.SeparatorMenuItem()
|
||||
self._attachMenuItem(sep)
|
||||
|
||||
mainWindowItem = Gtk.MenuItem('Show g13 Configurator')
|
||||
mainWindowItem.connect('activate', self.showMainWindow)
|
||||
self._attachMenuItem(mainWindowItem)
|
||||
|
||||
sep = Gtk.SeparatorMenuItem()
|
||||
self._attachMenuItem(sep)
|
||||
|
||||
quitItem = Gtk.MenuItem('Quit')
|
||||
self._attachMenuItem(quitItem)
|
||||
quitItem.connect('activate', Gtk.main_quit)
|
||||
|
||||
self._menu.show_all()
|
||||
self._rebuilding = False
|
||||
|
||||
def showMainWindow(self, menuItem):
|
||||
self._mainWindow.show_all()
|
||||
|
||||
def changeProfile(self, menuItem):
|
||||
self._prefs.setSelectedProfile(menuItem.get_label())
|
||||
self._rebuildMenu()
|
||||
|
||||
def gtkSubjectChanged(self, subject, changeType, key, data=None):
|
||||
self._rebuildMenu()
|
Loading…
Reference in New Issue
Block a user