gui: move the battery and sync spinner to the titlebar

We have the real estate there anyway, might as well make use of it
pull/145/head
Peter Hutterer 2019-07-18 17:30:41 +10:00
parent 900d0302cd
commit 1224711328
4 changed files with 63 additions and 122 deletions

View File

@ -11,81 +11,6 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="baseline_position">top</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkSpinner" id="spinner_sync">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="label" translatable="yes">last synchronized:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_last_sync">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_battery">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="icon_name">battery-missing-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkOverlay">
<property name="visible">True</property>

View File

@ -11,6 +11,16 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkSpinner" id="spinner_sync">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="title">
<placeholder/>
</child>
@ -31,6 +41,18 @@
<property name="pack_type">end</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_battery">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">10</property>
<property name="icon_name">battery-missing-symbolic</property>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child>

View File

@ -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

View File

@ -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):