Move SVG generation to the Drawing

This means we can just call refresh() from the parent after the orientation
has changed.
pull/145/head
Peter Hutterer 2019-07-16 21:06:32 +10:00
parent 9903bd851d
commit 09a66642ae
2 changed files with 10 additions and 7 deletions

View File

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

View File

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