Rename Config.load() to Config.instance() for better clarity
This commit is contained in:
parent
09a66642ae
commit
1743a93873
|
@ -122,7 +122,7 @@ class Config(GObject.Object):
|
|||
self.notify('drawings')
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
def instance(cls):
|
||||
if cls._config_obj is None:
|
||||
cls._config_obj = Config()
|
||||
return cls._config_obj
|
||||
|
|
|
@ -98,4 +98,4 @@ class Drawing(Gtk.Box):
|
|||
|
||||
@Gtk.Template.Callback('_on_delete_button_clicked')
|
||||
def _on_delete_button_clicked(self, button):
|
||||
Config.load().delete_drawing(self.timestamp)
|
||||
Config.instance().delete_drawing(self.timestamp)
|
||||
|
|
|
@ -65,20 +65,18 @@ class DrawingPerspective(Gtk.Stack):
|
|||
self.last_sync_time = 0
|
||||
self._sync_label_timer = GObject.timeout_add_seconds(60, self._update_sync_label)
|
||||
self._update_sync_label()
|
||||
Config.load().connect('notify::orientation', self._on_orientation_changed)
|
||||
Config.instance().connect('notify::orientation', self._on_orientation_changed)
|
||||
|
||||
def _on_orientation_changed(self, config, pspec):
|
||||
# When the orientation changes, we just re-generate all SVGs. This
|
||||
# isn't something that should happen very often anyway so meh.
|
||||
self.known_drawings = []
|
||||
|
||||
self.flowbox_drawings.foreach(lambda child: child.get_child().refresh())
|
||||
|
||||
def _cache_drawings(self, device, pspec):
|
||||
# The config backend filters duplicates anyway, so don't care here
|
||||
for ts in self.device.drawings_available:
|
||||
json_string = self.device.json(ts)
|
||||
Config.load().add_drawing(ts, json_string)
|
||||
Config.instance().add_drawing(ts, json_string)
|
||||
|
||||
def _update_drawings(self, config, pspec):
|
||||
for js in config.drawings:
|
||||
|
@ -134,11 +132,11 @@ class DrawingPerspective(Gtk.Stack):
|
|||
# json itself (once cached) that we then actually use for SVG
|
||||
# generation.
|
||||
device.connect('notify::drawings-available', self._cache_drawings)
|
||||
Config.load().connect('notify::drawings', self._update_drawings)
|
||||
Config.instance().connect('notify::drawings', self._update_drawings)
|
||||
|
||||
self._on_battery_changed(device, None)
|
||||
|
||||
self._update_drawings(Config.load(), None)
|
||||
self._update_drawings(Config.instance(), None)
|
||||
|
||||
# We always want to sync on startup
|
||||
logger.debug(f'{device.name} - starting to listen')
|
||||
|
@ -200,5 +198,5 @@ class DrawingPerspective(Gtk.Stack):
|
|||
|
||||
@Gtk.Template.Callback('_on_undo_clicked')
|
||||
def _on_undo_clicked(self, button):
|
||||
Config.load().undelete_drawing(button.deleted_drawing)
|
||||
Config.instance().undelete_drawing(button.deleted_drawing)
|
||||
self.overlay_undo.set_reveal_child(False)
|
||||
|
|
|
@ -32,7 +32,7 @@ class JsonSvg(GObject.Object):
|
|||
|
||||
self.timestamp = json['timestamp']
|
||||
self.filename = os.path.join(DATA_PATH, f'{self.timestamp}.svg')
|
||||
self.orientation = Config.load().orientation
|
||||
self.orientation = Config.instance().orientation
|
||||
self._convert()
|
||||
|
||||
def _convert(self):
|
||||
|
|
|
@ -73,7 +73,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
action = Gio.SimpleAction.new_stateful('orientation', GLib.VariantType('s'),
|
||||
GLib.Variant('s', 'landscape'))
|
||||
action.connect('activate', self._on_orientation_changed)
|
||||
action.set_state(GLib.Variant.new_string(Config.load().orientation))
|
||||
action.set_state(GLib.Variant.new_string(Config.instance().orientation))
|
||||
self.add_action(action)
|
||||
|
||||
builder = Gtk.Builder.new_from_string(MENU_XML, -1)
|
||||
|
@ -135,4 +135,4 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
|
||||
def _on_orientation_changed(self, action, label):
|
||||
action.set_state(label)
|
||||
Config.load().orientation = label.get_string() # this is a GVariant
|
||||
Config.instance().orientation = label.get_string() # this is a GVariant
|
||||
|
|
Loading…
Reference in New Issue