Hook up synchronizing the drawings
And drop the rotate/sync button while we're there. The rotate button because it's not hooked up anyway. The sync button because that is not how we work: we just always listen while we're running, any drawing will "immediately" be synched from the device.
This commit is contained in:
parent
d97c5eaaac
commit
71849d926d
|
@ -2,11 +2,6 @@
|
||||||
<!-- Generated with glade 3.22.1 -->
|
<!-- Generated with glade 3.22.1 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkImage" id="image_rotate">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="icon_name">object-rotate-right</property>
|
|
||||||
</object>
|
|
||||||
<template class="DrawingPerspective" parent="GtkStack">
|
<template class="DrawingPerspective" parent="GtkStack">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
@ -62,35 +57,6 @@
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkButton">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">True</property>
|
|
||||||
<property name="image">image_rotate</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="btn_sync">
|
|
||||||
<property name="label" translatable="yes">Sync!</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">True</property>
|
|
||||||
<property name="margin_left">10</property>
|
|
||||||
<property name="margin_right">20</property>
|
|
||||||
<signal name="clicked" handler="_on_sync_button_clicked" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">4</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
@ -123,6 +89,21 @@
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="label_sync">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Press button on device to synchronize drawings</property>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="size" value="20000"/>
|
||||||
|
</attributes>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="name">page0</property>
|
<property name="name">page0</property>
|
||||||
|
|
|
@ -30,9 +30,14 @@ class DrawingPerspective(Gtk.Stack):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.known_drawings = []
|
||||||
|
|
||||||
def _init_drawings(self):
|
def _update_drawings(self, device, pspec):
|
||||||
for ts in self.device.drawings_available:
|
for ts in self.device.drawings_available:
|
||||||
|
if ts in self.known_drawings:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.known_drawings.append(ts)
|
||||||
js = json.loads(self.device.json(ts))
|
js = json.loads(self.device.json(ts))
|
||||||
svg = JsonSvg(js)
|
svg = JsonSvg(js)
|
||||||
drawing = Drawing(svg)
|
drawing = Drawing(svg)
|
||||||
|
@ -47,6 +52,11 @@ class DrawingPerspective(Gtk.Stack):
|
||||||
self._device = device
|
self._device = device
|
||||||
self.label_devicename.set_text(f'{device.name} - {device.address}')
|
self.label_devicename.set_text(f'{device.name} - {device.address}')
|
||||||
|
|
||||||
|
device.connect('notify::connected', self._on_connected)
|
||||||
|
device.connect('notify::listening', self._on_listening_stopped)
|
||||||
|
self.device.connect('notify::drawings-available',
|
||||||
|
self._update_drawings)
|
||||||
|
|
||||||
# icon name is something like battery-020-charging, or battery-040
|
# icon name is something like battery-020-charging, or battery-040
|
||||||
# in 20-step increments
|
# in 20-step increments
|
||||||
if device.battery_state == 1:
|
if device.battery_state == 1:
|
||||||
|
@ -57,13 +67,18 @@ class DrawingPerspective(Gtk.Stack):
|
||||||
batt_icon_name = f'battery-{percent}{state}'
|
batt_icon_name = f'battery-{percent}{state}'
|
||||||
_, isize = self.image_battery.get_icon_name()
|
_, isize = self.image_battery.get_icon_name()
|
||||||
self.image_battery.set_from_icon_name(batt_icon_name, isize)
|
self.image_battery.set_from_icon_name(batt_icon_name, isize)
|
||||||
self._init_drawings()
|
self._update_drawings(self.device, None)
|
||||||
|
|
||||||
|
# We always want to sync on startup
|
||||||
|
device.start_listening()
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def name(self):
|
def name(self):
|
||||||
return "drawing_perspective"
|
return "drawing_perspective"
|
||||||
|
|
||||||
@Gtk.Template.Callback("_on_sync_button_clicked")
|
def _on_connected(self, device, pspec):
|
||||||
def _on_quit_button_clicked(self, button):
|
pass
|
||||||
button.set_label('Stop')
|
|
||||||
print('sync now')
|
def _on_listening_stopped(self, device, pspec):
|
||||||
|
# We never want to stop listening
|
||||||
|
device.start_listening()
|
||||||
|
|
Loading…
Reference in New Issue