Move SVG generation to the Drawing
This means we can just call refresh() from the parent after the orientation has changed.
This commit is contained in:
parent
9903bd851d
commit
09a66642ae
|
@ -13,6 +13,7 @@
|
||||||
from gi.repository import GObject, Gtk
|
from gi.repository import GObject, Gtk
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
from .svg import JsonSvg
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
@ -44,9 +45,10 @@ class Drawing(Gtk.Box):
|
||||||
image_completed = Gtk.Template.Child()
|
image_completed = Gtk.Template.Child()
|
||||||
btn_download = Gtk.Template.Child()
|
btn_download = Gtk.Template.Child()
|
||||||
|
|
||||||
def __init__(self, svg, *args, **kwargs):
|
def __init__(self, json_data, *args, **kwargs):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.svg = svg
|
self.json_data = json_data
|
||||||
|
self.svg = svg = JsonSvg(json_data)
|
||||||
day = relative_date(svg.timestamp)
|
day = relative_date(svg.timestamp)
|
||||||
hour = time.strftime('%H:%M', time.localtime(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.image_completed.set_visible(False)
|
||||||
self.timestamp = svg.timestamp
|
self.timestamp = svg.timestamp
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.svg = svg = JsonSvg(self.json_data)
|
||||||
|
self.image_svg.set_from_file(svg.filename)
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def name(self):
|
def name(self):
|
||||||
return "drawing"
|
return "drawing"
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
from gi.repository import GObject, Gtk
|
from gi.repository import GObject, Gtk
|
||||||
from .drawing import Drawing
|
from .drawing import Drawing
|
||||||
from .svg import JsonSvg
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
@ -73,8 +72,7 @@ class DrawingPerspective(Gtk.Stack):
|
||||||
# isn't something that should happen very often anyway so meh.
|
# isn't something that should happen very often anyway so meh.
|
||||||
self.known_drawings = []
|
self.known_drawings = []
|
||||||
|
|
||||||
self.flowbox_drawings.foreach(lambda child: self.flowbox_drawings.remove(child))
|
self.flowbox_drawings.foreach(lambda child: child.get_child().refresh())
|
||||||
self._update_drawings(Config.load(), None)
|
|
||||||
|
|
||||||
def _cache_drawings(self, device, pspec):
|
def _cache_drawings(self, device, pspec):
|
||||||
# The config backend filters duplicates anyway, so don't care here
|
# The config backend filters duplicates anyway, so don't care here
|
||||||
|
@ -89,8 +87,7 @@ class DrawingPerspective(Gtk.Stack):
|
||||||
|
|
||||||
self.known_drawings.append(js)
|
self.known_drawings.append(js)
|
||||||
|
|
||||||
svg = JsonSvg(js)
|
drawing = Drawing(js)
|
||||||
drawing = Drawing(svg)
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in New Issue