mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 00:14:09 -04:00
appindicator: Make the appindicator the root of the app
This reorganizes the ownership of the main window under the control of the appindicator. It also adds some additional flags in prefs to allow for disabling the opening of the main window on startup, and removes a bunch of cruft from main.
This commit is contained in:
parent
69151a450b
commit
83483aa7a3
@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
import queue
|
|
||||||
|
|
||||||
import g13gui.ui as ui
|
import g13gui.ui as ui
|
||||||
from g13gui.model.prefsstore import PreferencesStore
|
from g13gui.model.prefsstore import PreferencesStore
|
||||||
@ -18,11 +17,6 @@ if __name__ == '__main__':
|
|||||||
manager = Manager(prefs)
|
manager = Manager(prefs)
|
||||||
manager.start()
|
manager.start()
|
||||||
|
|
||||||
queue = queue.Queue()
|
indicator = ui.AppIndicator(prefs)
|
||||||
|
|
||||||
win = ui.MainWindow(queue, prefs)
|
|
||||||
win.show_all()
|
|
||||||
|
|
||||||
indicator = ui.AppIndicator(prefs, win)
|
|
||||||
|
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from builtins import property
|
||||||
|
|
||||||
from g13gui.common import VERSION
|
from g13gui.common import VERSION
|
||||||
from g13gui.model.bindingprofile import BindingProfile
|
from g13gui.model.bindingprofile import BindingProfile
|
||||||
from g13gui.observer.subject import Subject
|
from g13gui.observer.subject import Subject
|
||||||
@ -15,12 +17,21 @@ class Preferences(Subject):
|
|||||||
def __init__(self, dict=None):
|
def __init__(self, dict=None):
|
||||||
self._profiles = {}
|
self._profiles = {}
|
||||||
self._selectedProfile = None
|
self._selectedProfile = None
|
||||||
|
self._showWindowOnStart = True
|
||||||
|
|
||||||
if dict:
|
if dict:
|
||||||
self.loadFromDict(dict)
|
self.loadFromDict(dict)
|
||||||
else:
|
else:
|
||||||
self.initDefaultProfile()
|
self.initDefaultProfile()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def showWindowOnStart(self):
|
||||||
|
return self._showWindowOnStart
|
||||||
|
|
||||||
|
@showWindowOnStart.setter
|
||||||
|
def showWindowOnStart(self, value):
|
||||||
|
self.setProperty('showWindowOnStart', value)
|
||||||
|
|
||||||
def profiles(self, profileName=None):
|
def profiles(self, profileName=None):
|
||||||
if profileName:
|
if profileName:
|
||||||
return self._profiles[profileName]
|
return self._profiles[profileName]
|
||||||
@ -85,6 +96,7 @@ class Preferences(Subject):
|
|||||||
def saveToDict(self):
|
def saveToDict(self):
|
||||||
return {
|
return {
|
||||||
'version': VERSION,
|
'version': VERSION,
|
||||||
|
'showWindowOnStart': self._showWindowOnStart,
|
||||||
'profiles': dict([(name, profile.saveToDict()) for name, profile in self._profiles.items()]),
|
'profiles': dict([(name, profile.saveToDict()) for name, profile in self._profiles.items()]),
|
||||||
'selectedProfile': self._selectedProfile
|
'selectedProfile': self._selectedProfile
|
||||||
}
|
}
|
||||||
@ -100,6 +112,7 @@ class Preferences(Subject):
|
|||||||
self._addProfile(name, BindingProfile(profile))
|
self._addProfile(name, BindingProfile(profile))
|
||||||
|
|
||||||
self._setSelectedProfile(dict['selectedProfile'])
|
self._setSelectedProfile(dict['selectedProfile'])
|
||||||
|
self._showWindowOnStart = dict['showWindowOnStart']
|
||||||
|
|
||||||
except (Exception) as err:
|
except (Exception) as err:
|
||||||
print('Unable to initialize from dict: %s' % err)
|
print('Unable to initialize from dict: %s' % err)
|
||||||
|
@ -3,6 +3,7 @@ import gi
|
|||||||
from g13gui.common import PROGNAME
|
from g13gui.common import PROGNAME
|
||||||
from g13gui.observer.gtkobserver import GtkObserver
|
from g13gui.observer.gtkobserver import GtkObserver
|
||||||
from g13gui.observer.subject import ChangeType
|
from g13gui.observer.subject import ChangeType
|
||||||
|
from g13gui.ui.mainwindow import MainWindow
|
||||||
|
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
gi.require_version('AppIndicator3', '0.1')
|
gi.require_version('AppIndicator3', '0.1')
|
||||||
@ -11,13 +12,13 @@ from gi.repository import AppIndicator3 as indicator
|
|||||||
|
|
||||||
|
|
||||||
class AppIndicator(GtkObserver):
|
class AppIndicator(GtkObserver):
|
||||||
def __init__(self, prefs, mainWindow):
|
def __init__(self, prefs):
|
||||||
GtkObserver.__init__(self)
|
GtkObserver.__init__(self)
|
||||||
|
|
||||||
self._initIndicator()
|
self._initIndicator()
|
||||||
|
|
||||||
self._prefs = prefs
|
self._prefs = prefs
|
||||||
self._mainWindow = mainWindow
|
self._mainWindow = None
|
||||||
self._menu = Gtk.Menu()
|
self._menu = Gtk.Menu()
|
||||||
self._menuItems = []
|
self._menuItems = []
|
||||||
self._indicator.set_menu(self._menu)
|
self._indicator.set_menu(self._menu)
|
||||||
@ -27,6 +28,9 @@ class AppIndicator(GtkObserver):
|
|||||||
self.changeTrigger(self.onSelectedProfileChanged,
|
self.changeTrigger(self.onSelectedProfileChanged,
|
||||||
keys={'selectedProfile'})
|
keys={'selectedProfile'})
|
||||||
|
|
||||||
|
if self._prefs.showWindowOnStart:
|
||||||
|
self.showMainWindow(None)
|
||||||
|
|
||||||
self._rebuildMenu()
|
self._rebuildMenu()
|
||||||
|
|
||||||
def _initIndicator(self):
|
def _initIndicator(self):
|
||||||
@ -77,7 +81,13 @@ class AppIndicator(GtkObserver):
|
|||||||
self._menu.show_all()
|
self._menu.show_all()
|
||||||
self._rebuilding = False
|
self._rebuilding = False
|
||||||
|
|
||||||
|
def onMainWindowHidden(self, win):
|
||||||
|
del self._mainWindow
|
||||||
|
self._mainWindow = None
|
||||||
|
|
||||||
def showMainWindow(self, menuItem):
|
def showMainWindow(self, menuItem):
|
||||||
|
self._mainWindow = MainWindow(self._prefs)
|
||||||
|
self._mainWindow.connect('hide', self.onMainWindowHidden)
|
||||||
self._mainWindow.show_all()
|
self._mainWindow.show_all()
|
||||||
|
|
||||||
def changeProfile(self, menuItem):
|
def changeProfile(self, menuItem):
|
||||||
|
@ -29,6 +29,11 @@ class G13Button(Gtk.MenuButton, GtkObserver):
|
|||||||
self.set_can_default(False)
|
self.set_can_default(False)
|
||||||
self.updateProfileRegistration()
|
self.updateProfileRegistration()
|
||||||
|
|
||||||
|
self.connect('show', self.onShown)
|
||||||
|
|
||||||
|
def onShown(self, widget):
|
||||||
|
self.updateBindingDisplay()
|
||||||
|
|
||||||
def onSelectedProfileChanged(self, subject, changeType, key, data):
|
def onSelectedProfileChanged(self, subject, changeType, key, data):
|
||||||
self.updateProfileRegistration()
|
self.updateProfileRegistration()
|
||||||
self.updateBindingDisplay()
|
self.updateBindingDisplay()
|
||||||
|
@ -12,7 +12,7 @@ from gi.repository import Gtk, Gdk, GObject
|
|||||||
|
|
||||||
|
|
||||||
class MainWindow(Gtk.Window, GtkObserver):
|
class MainWindow(Gtk.Window, GtkObserver):
|
||||||
def __init__(self, workerQueue, prefs):
|
def __init__(self, prefs):
|
||||||
Gtk.Window.__init__(self)
|
Gtk.Window.__init__(self)
|
||||||
GtkObserver.__init__(self)
|
GtkObserver.__init__(self)
|
||||||
|
|
||||||
@ -22,7 +22,6 @@ class MainWindow(Gtk.Window, GtkObserver):
|
|||||||
geometry.max_height = 480
|
geometry.max_height = 480
|
||||||
self.set_geometry_hints(None, geometry, Gdk.WindowHints.MAX_SIZE)
|
self.set_geometry_hints(None, geometry, Gdk.WindowHints.MAX_SIZE)
|
||||||
|
|
||||||
self._workerQueue = workerQueue
|
|
||||||
self._prefs = prefs
|
self._prefs = prefs
|
||||||
self._prefs.registerObserver(self, 'selectedProfile')
|
self._prefs.registerObserver(self, 'selectedProfile')
|
||||||
self._prefs.selectedProfile().registerObserver(self)
|
self._prefs.selectedProfile().registerObserver(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user