diff --git a/tuhigui/data/ui/DrawingPerspective.ui b/tuhigui/data/ui/DrawingPerspective.ui
index 3acee45..70289d4 100644
--- a/tuhigui/data/ui/DrawingPerspective.ui
+++ b/tuhigui/data/ui/DrawingPerspective.ui
@@ -11,81 +11,6 @@
False
vertical
top
-
-
-
- False
- True
- 0
-
-
True
diff --git a/tuhigui/data/ui/MainWindow.ui b/tuhigui/data/ui/MainWindow.ui
index 4a50908..1dd52ee 100644
--- a/tuhigui/data/ui/MainWindow.ui
+++ b/tuhigui/data/ui/MainWindow.ui
@@ -11,6 +11,16 @@
True
False
True
+
+
+ True
+ False
+ 10
+
+
+ 1
+
+
@@ -31,6 +41,18 @@
end
+
+
+ True
+ False
+ 10
+ battery-missing-symbolic
+
+
+ end
+ 2
+
+
diff --git a/tuhigui/drawingperspective.py b/tuhigui/drawingperspective.py
index f3fbc4a..f5d3188 100644
--- a/tuhigui/drawingperspective.py
+++ b/tuhigui/drawingperspective.py
@@ -55,10 +55,7 @@ def relative_time(seconds):
class DrawingPerspective(Gtk.Stack):
__gtype_name__ = "DrawingPerspective"
- image_battery = Gtk.Template.Child()
flowbox_drawings = Gtk.Template.Child()
- spinner_sync = Gtk.Template.Child()
- label_last_sync = Gtk.Template.Child()
overlay_undo = Gtk.Template.Child()
notification_delete_undo = Gtk.Template.Child()
notification_delete_close = Gtk.Template.Child()
@@ -66,9 +63,6 @@ class DrawingPerspective(Gtk.Stack):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.known_drawings = []
- self.last_sync_time = 0
- self._sync_label_timer = GObject.timeout_add_seconds(60, self._update_sync_label)
- self._update_sync_label()
Config.instance().connect('notify::orientation', self._on_orientation_changed)
def _on_orientation_changed(self, config, pspec):
@@ -124,9 +118,6 @@ class DrawingPerspective(Gtk.Stack):
device.connect('notify::connected', self._on_connected)
device.connect('notify::listening', self._on_listening_stopped)
- device.connect('notify::sync-state', self._on_sync_state)
- device.connect('notify::battery-percent', self._on_battery_changed)
- device.connect('notify::battery-state', self._on_battery_changed)
# This is a bit convoluted. We need to cache all drawings
# because Tuhi doesn't have guaranteed storage. So any json that
@@ -138,8 +129,6 @@ class DrawingPerspective(Gtk.Stack):
device.connect('notify::drawings-available', self._cache_drawings)
Config.instance().connect('notify::drawings', self._update_drawings)
- self._on_battery_changed(device, None)
-
self._update_drawings(Config.instance(), None)
# We always want to sync on startup
@@ -150,41 +139,6 @@ class DrawingPerspective(Gtk.Stack):
def name(self):
return "drawing_perspective"
- def _on_battery_changed(self, device, pspec):
- if device.battery_percent > 80:
- fill = 'full'
- elif device.battery_percent > 40:
- fill = 'good'
- elif device.battery_percent > 10:
- fill = 'low'
- else:
- fill = 'caution'
-
- if device.battery_state == 1:
- state = '-charging'
- elif device.battery_state == 0: # unknown
- fill = 'missing'
- state = ''
- else:
- state = ''
- batt_icon_name = f'battery-{fill}{state}-symbolic'
- _, isize = self.image_battery.get_icon_name()
- self.image_battery.set_from_icon_name(batt_icon_name, isize)
- self.image_battery.set_tooltip_text(f'{device.battery_percent}%')
-
- def _on_sync_state(self, device, pspec):
- if device.sync_state:
- self.spinner_sync.start()
- else:
- self.spinner_sync.stop()
- self.last_sync_time = time.time()
- self._update_sync_label()
-
- def _update_sync_label(self):
- now = time.time()
- self.label_last_sync.set_text(f'{relative_time(now - self.last_sync_time)}')
- return True
-
def _on_connected(self, device, pspec):
# Turns out we don't really care about whether the device is
# connected or not, it has little effect on how we work here
diff --git a/tuhigui/window.py b/tuhigui/window.py
index c07ca07..3f318d2 100644
--- a/tuhigui/window.py
+++ b/tuhigui/window.py
@@ -124,6 +124,8 @@ class MainWindow(Gtk.ApplicationWindow):
stack_perspectives = Gtk.Template.Child()
headerbar = Gtk.Template.Child()
menubutton1 = Gtk.Template.Child()
+ spinner_sync = Gtk.Template.Child()
+ image_battery = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
@@ -164,9 +166,46 @@ class MainWindow(Gtk.ApplicationWindow):
dialog.connect('response', self._on_setup_dialog_closed)
dialog.show()
else:
- dp.device = self._tuhi.devices[0]
+ device = self._tuhi.devices[0]
+ self._init_device(device)
+ dp.device = device
self.headerbar.set_title(f'Tuhi - {dp.device.name}')
+ def _init_device(self, device):
+ device.connect('notify::sync-state', self._on_sync_state)
+ device.connect('notify::battery-percent', self._on_battery_changed)
+ device.connect('notify::battery-state', self._on_battery_changed)
+ self._on_battery_changed(device, None)
+
+
+ def _on_battery_changed(self, device, pspec):
+ if device.battery_percent > 80:
+ fill = 'full'
+ elif device.battery_percent > 40:
+ fill = 'good'
+ elif device.battery_percent > 10:
+ fill = 'low'
+ else:
+ fill = 'caution'
+
+ if device.battery_state == 1:
+ state = '-charging'
+ elif device.battery_state == 0: # unknown
+ fill = 'missing'
+ state = ''
+ else:
+ state = ''
+ batt_icon_name = f'battery-{fill}{state}-symbolic'
+ _, isize = self.image_battery.get_icon_name()
+ self.image_battery.set_from_icon_name(batt_icon_name, isize)
+ self.image_battery.set_tooltip_text(f'{device.battery_percent}%')
+
+ def _on_sync_state(self, device, pspec):
+ if device.sync_state:
+ self.spinner_sync.start()
+ else:
+ self.spinner_sync.stop()
+
def _on_setup_dialog_closed(self, dialog, response):
device = dialog.device
dialog.destroy()
@@ -180,6 +219,7 @@ class MainWindow(Gtk.ApplicationWindow):
dp = self._get_child('drawing_perspective')
dp.device = device
+ self._init_device(device)
self.stack_perspectives.set_visible_child_name(dp.name)
def _add_perspective(self, perspective):