mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 00:14:09 -04:00
saving: Re-add preferences saving to disk
At this point, functionality is nearly the same as what we had before I started the migration away from g13d. We can now save prefs to disk! The next trick is to make sure that the backlighting works, and I think we can call that the next version, and maybe tag it for a alpha release.
This commit is contained in:
parent
83483aa7a3
commit
5cc4e81dd5
@ -1,10 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
|
import threading
|
||||||
|
|
||||||
from g13gui.model.prefs import Preferences
|
from g13gui.model.prefs import Preferences
|
||||||
from g13gui.common import PROFILES_CONFIG_PATH
|
from g13gui.common import PROFILES_CONFIG_PATH
|
||||||
|
|
||||||
|
|
||||||
class PreferencesStore(object):
|
class PreferencesStore(object):
|
||||||
|
SaveLock = threading.Lock()
|
||||||
|
|
||||||
def getPrefs():
|
def getPrefs():
|
||||||
try:
|
try:
|
||||||
with open(PROFILES_CONFIG_PATH, 'r') as f:
|
with open(PROFILES_CONFIG_PATH, 'r') as f:
|
||||||
@ -17,8 +20,9 @@ class PreferencesStore(object):
|
|||||||
return Preferences()
|
return Preferences()
|
||||||
|
|
||||||
def storePrefs(prefs):
|
def storePrefs(prefs):
|
||||||
prefsDict = prefs.saveToDict()
|
with PreferencesStore.SaveLock:
|
||||||
|
prefsDict = prefs.saveToDict()
|
||||||
|
|
||||||
with open(PROFILES_CONFIG_PATH, 'w') as f:
|
with open(PROFILES_CONFIG_PATH, 'w') as f:
|
||||||
f.write(json.dumps(prefsDict, default=str))
|
f.write(json.dumps(prefsDict, default=str))
|
||||||
f.flush()
|
f.flush()
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
import threading
|
||||||
|
|
||||||
import g13gui.ui as ui
|
import g13gui.ui as ui
|
||||||
|
|
||||||
from g13gui.observer.gtkobserver import GtkObserver
|
from g13gui.observer.gtkobserver import GtkObserver
|
||||||
|
from g13gui.model.prefsstore import PreferencesStore
|
||||||
|
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
gi.require_version('Gdk', '3.0')
|
gi.require_version('Gdk', '3.0')
|
||||||
@ -44,9 +46,20 @@ class MainWindow(Gtk.Window, GtkObserver):
|
|||||||
|
|
||||||
self.setupG13ButtonGrid()
|
self.setupG13ButtonGrid()
|
||||||
|
|
||||||
|
def _updateProfileRegistration(self):
|
||||||
|
self._lastProfileName.removeObserver(self)
|
||||||
|
self._lastProfileName = self._prefs.selectedProfile()
|
||||||
|
self._lastProfileName.registerObserver(self)
|
||||||
|
|
||||||
def onChangeTrigger(self, subject, changeType, key, data=None):
|
def onChangeTrigger(self, subject, changeType, key, data=None):
|
||||||
print('Subject changed! Need to save!')
|
if key == 'selectedProfile':
|
||||||
pass
|
self._updateProfileRegistration(self)
|
||||||
|
elif key == 'profile':
|
||||||
|
pass
|
||||||
|
|
||||||
|
t = threading.Thread(
|
||||||
|
target=PreferencesStore.storePrefs, args=(self._prefs,))
|
||||||
|
t.start()
|
||||||
|
|
||||||
def setupHeaderBar(self):
|
def setupHeaderBar(self):
|
||||||
self._headerBar = Gtk.HeaderBar()
|
self._headerBar = Gtk.HeaderBar()
|
||||||
@ -72,42 +85,8 @@ class MainWindow(Gtk.Window, GtkObserver):
|
|||||||
editProfileButton.set_popover(editProfilePopover)
|
editProfileButton.set_popover(editProfilePopover)
|
||||||
self._headerBar.add(editProfileButton)
|
self._headerBar.add(editProfileButton)
|
||||||
|
|
||||||
self._uploadButton = Gtk.Button.new_from_icon_name(
|
|
||||||
"document-send-symbolic", 1)
|
|
||||||
self._uploadButton.connect("clicked", self.uploadClicked)
|
|
||||||
self._headerBar.add(self._uploadButton)
|
|
||||||
|
|
||||||
Gtk.Window.set_titlebar(self, self._headerBar)
|
Gtk.Window.set_titlebar(self, self._headerBar)
|
||||||
|
|
||||||
@GObject.Signal(name='daemon-connection-changed', arg_types=(bool,))
|
|
||||||
def daemonConnectionChanged(self, connected):
|
|
||||||
self._connected = connected
|
|
||||||
if connected:
|
|
||||||
self._uploadButton.set_state_flags(Gtk.StateFlags.NORMAL, True)
|
|
||||||
self._infoBar.hide()
|
|
||||||
self._doUpload()
|
|
||||||
else:
|
|
||||||
self._uploadButton.set_state_flags(Gtk.StateFlags.INSENSITIVE,
|
|
||||||
True)
|
|
||||||
self._infoBar.set_message_type(Gtk.MessageType.WARNING)
|
|
||||||
self._infoBarLabel.set_text(
|
|
||||||
'The G13 user space driver is not running. '
|
|
||||||
'Attempting to reconnect.')
|
|
||||||
self._infoBar.show()
|
|
||||||
|
|
||||||
@GObject.Signal(name='uploading', arg_types=(float,))
|
|
||||||
def uploadStatusChanged(self, percentage):
|
|
||||||
if percentage < 1.0:
|
|
||||||
self._infoBar.set_message_type(Gtk.MessageType.INFO)
|
|
||||||
self._infoBarLabel.set_text('Uploading to the G13...')
|
|
||||||
self._infoBar.show()
|
|
||||||
else:
|
|
||||||
self._infoBar.hide()
|
|
||||||
|
|
||||||
def uploadClicked(self, widget):
|
|
||||||
self._doUpload()
|
|
||||||
self._doSave()
|
|
||||||
|
|
||||||
def setupG13ButtonGrid(self):
|
def setupG13ButtonGrid(self):
|
||||||
self._mButtons = Gtk.ButtonBox(
|
self._mButtons = Gtk.ButtonBox(
|
||||||
spacing=3,
|
spacing=3,
|
||||||
|
Loading…
Reference in New Issue
Block a user