mirror of https://github.com/tuhiproject/tuhi.git
gui: group the list of drawings up by month
parent
2547f6b26d
commit
b7bf68326f
|
@ -4,6 +4,7 @@
|
||||||
<file preprocess="xml-stripblanks">AboutDialog.ui</file>
|
<file preprocess="xml-stripblanks">AboutDialog.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/Drawing.ui</file>
|
<file preprocess="xml-stripblanks">ui/Drawing.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/DrawingPerspective.ui</file>
|
<file preprocess="xml-stripblanks">ui/DrawingPerspective.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">ui/Flowbox.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/MainWindow.ui</file>
|
<file preprocess="xml-stripblanks">ui/MainWindow.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/SetupPerspective.ui</file>
|
<file preprocess="xml-stripblanks">ui/SetupPerspective.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/ErrorPerspective.ui</file>
|
<file preprocess="xml-stripblanks">ui/ErrorPerspective.ui</file>
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="shadow_type">in</property>
|
<property name="shadow_type">in</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkViewport">
|
<object class="GtkViewport" id="viewport">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkFlowBox" id="flowbox_drawings">
|
<object class="GtkBox" id="box_all_drawings">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="homogeneous">True</property>
|
<property name="orientation">vertical</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.22.1 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<template class="Flowbox" parent="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="label_date">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">start</property>
|
||||||
|
<property name="margin_left">10</property>
|
||||||
|
<property name="margin_top">10</property>
|
||||||
|
<property name="margin_bottom">10</property>
|
||||||
|
<property name="hexpand">False</property>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="weight" value="bold"/>
|
||||||
|
<attribute name="size" value="20000"/>
|
||||||
|
</attributes>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFlowBox" id="flowbox_drawings">
|
||||||
|
<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">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
|
@ -51,34 +51,19 @@ def relative_time(seconds):
|
||||||
return _('a long time ago')
|
return _('a long time ago')
|
||||||
|
|
||||||
|
|
||||||
@Gtk.Template(resource_path="/org/freedesktop/Tuhi/ui/DrawingPerspective.ui")
|
@Gtk.Template(resource_path="/org/freedesktop/Tuhi/ui/Flowbox.ui")
|
||||||
class DrawingPerspective(Gtk.Stack):
|
class Flowbox(Gtk.Box):
|
||||||
__gtype_name__ = "DrawingPerspective"
|
__gtype_name__ = "Flowbox"
|
||||||
|
|
||||||
|
label_date = Gtk.Template.Child()
|
||||||
flowbox_drawings = Gtk.Template.Child()
|
flowbox_drawings = Gtk.Template.Child()
|
||||||
overlay_undo = Gtk.Template.Child()
|
|
||||||
notification_delete_undo = Gtk.Template.Child()
|
|
||||||
notification_delete_close = Gtk.Template.Child()
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, timestruct, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.known_drawings = []
|
self.time = timestruct
|
||||||
|
self.label_date.set_text(time.strftime('%B %Y', self.time))
|
||||||
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.instance().add_drawing(ts, json_string)
|
|
||||||
|
|
||||||
def _update_drawings(self, config, pspec):
|
|
||||||
for js in config.drawings:
|
|
||||||
if js in self.known_drawings:
|
|
||||||
continue
|
|
||||||
|
|
||||||
self.known_drawings.append(js)
|
|
||||||
|
|
||||||
drawing = Drawing(js)
|
|
||||||
|
|
||||||
|
def insert(self, drawing):
|
||||||
# We don't know which order we get drawings from the device, so
|
# We don't know which order we get drawings from the device, so
|
||||||
# let's do a sorted insert here
|
# let's do a sorted insert here
|
||||||
index = 0
|
index = 0
|
||||||
|
@ -91,16 +76,74 @@ class DrawingPerspective(Gtk.Stack):
|
||||||
|
|
||||||
self.flowbox_drawings.insert(drawing, index)
|
self.flowbox_drawings.insert(drawing, index)
|
||||||
|
|
||||||
# Remove deleted ones
|
def delete(self, drawing):
|
||||||
deleted = [d for d in self.known_drawings if d not in config.drawings]
|
|
||||||
for d in deleted:
|
|
||||||
def delete_matching_child(child, drawing):
|
def delete_matching_child(child, drawing):
|
||||||
if child.get_child().timestamp == drawing['timestamp']:
|
if child.get_child() == drawing:
|
||||||
self.flowbox_drawings.remove(child)
|
self.flowbox_drawings.remove(child)
|
||||||
self.known_drawings.remove(drawing)
|
self.flowbox_drawings.foreach(delete_matching_child, drawing)
|
||||||
self.notification_delete_undo.deleted_drawing = drawing['timestamp']
|
|
||||||
|
@GObject.property
|
||||||
|
def is_empty(self):
|
||||||
|
return not self.flowbox_drawings.get_children()
|
||||||
|
|
||||||
|
|
||||||
|
@Gtk.Template(resource_path="/org/freedesktop/Tuhi/ui/DrawingPerspective.ui")
|
||||||
|
class DrawingPerspective(Gtk.Stack):
|
||||||
|
__gtype_name__ = "DrawingPerspective"
|
||||||
|
|
||||||
|
viewport = Gtk.Template.Child()
|
||||||
|
overlay_undo = Gtk.Template.Child()
|
||||||
|
notification_delete_undo = Gtk.Template.Child()
|
||||||
|
notification_delete_close = Gtk.Template.Child()
|
||||||
|
box_all_drawings = Gtk.Template.Child()
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.known_drawings = {} # type {timestamp: Drawing()}
|
||||||
|
self.flowboxes = {}
|
||||||
|
|
||||||
|
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.instance().add_drawing(ts, json_string)
|
||||||
|
|
||||||
|
def _update_drawings(self, config, pspec):
|
||||||
|
def _hash(drawing):
|
||||||
|
return time.strftime('Y%m', time.gmtime(drawing.timestamp))
|
||||||
|
|
||||||
|
for js in config.drawings:
|
||||||
|
ts = js['timestamp']
|
||||||
|
if ts in self.known_drawings:
|
||||||
|
continue
|
||||||
|
|
||||||
|
drawing = Drawing(js)
|
||||||
|
self.known_drawings[ts] = drawing
|
||||||
|
|
||||||
|
# Now pick the right monthly flowbox to insert into
|
||||||
|
key = _hash(drawing)
|
||||||
|
try:
|
||||||
|
fb = self.flowboxes[key]
|
||||||
|
except KeyError:
|
||||||
|
fb = Flowbox(time.gmtime(drawing.timestamp))
|
||||||
|
self.flowboxes[key] = fb
|
||||||
|
self.box_all_drawings.add(fb)
|
||||||
|
finally:
|
||||||
|
fb.insert(drawing)
|
||||||
|
|
||||||
|
# Remove deleted drawings
|
||||||
|
deleted = [ts for ts in self.known_drawings if ts not in
|
||||||
|
[ js['timestamp'] for js in config.drawings]]
|
||||||
|
for ts in deleted:
|
||||||
|
drawing = self.known_drawings[ts]
|
||||||
|
fb = self.flowboxes[_hash(drawing)]
|
||||||
|
fb.delete(drawing)
|
||||||
|
if fb.is_empty:
|
||||||
|
del self.flowboxes[_hash(drawing)]
|
||||||
|
self.box_all_drawings.remove(fb)
|
||||||
|
del self.known_drawings[ts]
|
||||||
|
self.notification_delete_undo.deleted_drawing = drawing.timestamp
|
||||||
self.overlay_undo.set_reveal_child(True)
|
self.overlay_undo.set_reveal_child(True)
|
||||||
self.flowbox_drawings.foreach(delete_matching_child, d)
|
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def device(self):
|
def device(self):
|
||||||
|
|
Loading…
Reference in New Issue