From 09a66642ae47bab6327b7d11b6104abdb21a2829 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 16 Jul 2019 21:06:32 +1000 Subject: [PATCH] Move SVG generation to the Drawing This means we can just call refresh() from the parent after the orientation has changed. --- tuhigui/drawing.py | 10 ++++++++-- tuhigui/drawingperspective.py | 7 ++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tuhigui/drawing.py b/tuhigui/drawing.py index 1bcc104..3d2c8a6 100644 --- a/tuhigui/drawing.py +++ b/tuhigui/drawing.py @@ -13,6 +13,7 @@ from gi.repository import GObject, Gtk from .config import Config +from .svg import JsonSvg import datetime import time @@ -44,9 +45,10 @@ class Drawing(Gtk.Box): image_completed = Gtk.Template.Child() btn_download = Gtk.Template.Child() - def __init__(self, svg, *args, **kwargs): + def __init__(self, json_data, *args, **kwargs): super().__init__() - self.svg = svg + self.json_data = json_data + self.svg = svg = JsonSvg(json_data) day = relative_date(svg.timestamp) hour = time.strftime('%H:%M', time.localtime(svg.timestamp)) @@ -55,6 +57,10 @@ class Drawing(Gtk.Box): self.image_completed.set_visible(False) self.timestamp = svg.timestamp + def refresh(self): + self.svg = svg = JsonSvg(self.json_data) + self.image_svg.set_from_file(svg.filename) + @GObject.Property def name(self): return "drawing" diff --git a/tuhigui/drawingperspective.py b/tuhigui/drawingperspective.py index 75a05d2..7210513 100644 --- a/tuhigui/drawingperspective.py +++ b/tuhigui/drawingperspective.py @@ -13,7 +13,6 @@ from gi.repository import GObject, Gtk from .drawing import Drawing -from .svg import JsonSvg from .config import Config import time @@ -73,8 +72,7 @@ class DrawingPerspective(Gtk.Stack): # isn't something that should happen very often anyway so meh. self.known_drawings = [] - self.flowbox_drawings.foreach(lambda child: self.flowbox_drawings.remove(child)) - self._update_drawings(Config.load(), None) + 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 @@ -89,8 +87,7 @@ class DrawingPerspective(Gtk.Stack): self.known_drawings.append(js) - svg = JsonSvg(js) - drawing = Drawing(svg) + drawing = Drawing(js) # We don't know which order we get drawings from the device, so # let's do a sorted insert here