mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 00:14:09 -04:00
g13gui: Migrate preferences storage to a single class
Helps deal with separations of concerns.
This commit is contained in:
parent
d9e391e90a
commit
fce850f786
@ -9,6 +9,7 @@ import traceback
|
|||||||
import xdg.BaseDirectory as basedir
|
import xdg.BaseDirectory as basedir
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from g13gui.model import PreferencesStore
|
||||||
from g13gui.common import PROFILES_CONFIG_PATH
|
from g13gui.common import PROFILES_CONFIG_PATH
|
||||||
from g13gui.common import VERSION
|
from g13gui.common import VERSION
|
||||||
|
|
||||||
@ -31,13 +32,11 @@ class UploadTask():
|
|||||||
|
|
||||||
|
|
||||||
class SaveTask():
|
class SaveTask():
|
||||||
def __init__(self, prefsDict):
|
def __init__(self, prefs):
|
||||||
self._prefsDict = prefsDict
|
self._prefs = prefs
|
||||||
|
|
||||||
def run(self, outfp, infp, callback):
|
def run(self, outfp, infp, callback):
|
||||||
with open(PROFILES_CONFIG_PATH, 'w') as f:
|
PreferencesStore.storePrefs(self._prefs)
|
||||||
f.write(json.dumps(self._prefsDict, default=str))
|
|
||||||
f.flush()
|
|
||||||
|
|
||||||
|
|
||||||
G13D_IN_FIFO = "/run/g13d/in"
|
G13D_IN_FIFO = "/run/g13d/in"
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import queue
|
|
||||||
import gi
|
import gi
|
||||||
|
import json
|
||||||
|
import queue
|
||||||
|
|
||||||
import g13gui.model as model
|
import g13gui.model as model
|
||||||
import g13gui.ui as ui
|
import g13gui.ui as ui
|
||||||
|
|
||||||
from g13gui.g13d import G13DWorker
|
from g13gui.g13d import G13DWorker
|
||||||
|
from g13gui.common import PROFILES_CONFIG_PATH
|
||||||
|
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, GObject
|
from gi.repository import Gtk, GObject
|
||||||
|
|
||||||
|
|
||||||
VERSION = '0.1.0'
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
prefs = model.Preferences()
|
prefs = model.PreferencesStore.getPrefs()
|
||||||
queue = queue.Queue()
|
queue = queue.Queue()
|
||||||
|
|
||||||
win = ui.MainWindow(queue, prefs)
|
win = ui.MainWindow(queue, prefs)
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
from g13gui.model.bindingprofile import BindingProfile
|
from g13gui.model.bindingprofile import BindingProfile
|
||||||
from g13gui.model.prefs import Preferences
|
from g13gui.model.prefs import Preferences
|
||||||
|
from g13gui.model.prefsstore import PreferencesStore
|
||||||
|
22
g13gui/g13gui/model/prefsstore.py
Normal file
22
g13gui/g13gui/model/prefsstore.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
import g13gui.model as model
|
||||||
|
from g13gui.common import PROFILES_CONFIG_PATH
|
||||||
|
|
||||||
|
|
||||||
|
class PreferencesStore(object):
|
||||||
|
def getPrefs():
|
||||||
|
try:
|
||||||
|
with open(PROFILES_CONFIG_PATH, 'r') as f:
|
||||||
|
data = f.read()
|
||||||
|
prefsDict = json.loads(data)
|
||||||
|
return model.Preferences(prefsDict)
|
||||||
|
except:
|
||||||
|
return model.Preferences()
|
||||||
|
|
||||||
|
def storePrefs(prefs):
|
||||||
|
prefsDict = prefs.saveToDict()
|
||||||
|
|
||||||
|
with open(PROFILES_CONFIG_PATH, 'w') as f:
|
||||||
|
f.write(json.dumps(prefsDict, default=str))
|
||||||
|
f.flush()
|
Loading…
Reference in New Issue
Block a user