gui: use a GdkPixbuf to scale into the desired size

pull/145/head
Peter Hutterer 2019-07-19 11:17:19 +10:00
parent 66130b9b8b
commit c00580655e
2 changed files with 13 additions and 9 deletions

View File

@ -133,10 +133,10 @@
</child>
<child>
<object class="GtkImage" id="image_svg">
<property name="width_request">200</property>
<property name="height_request">200</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="stock">gtk-missing-image</property>
<style>
<class name="bg-paper"/>

View File

@ -12,7 +12,7 @@
#
from gettext import gettext as _
from gi.repository import GObject, Gtk
from gi.repository import GObject, Gtk, GdkPixbuf
from .config import Config
from .svg import JsonSvg
@ -54,13 +54,12 @@ class Drawing(Gtk.Box):
Config.instance().connect('notify::orientation', self._on_orientation_changed)
self.json_data = json_data
self.svg = svg = JsonSvg(json_data, orientation=self.orientation)
day = relative_date(svg.timestamp)
hour = time.strftime('%H:%M', time.localtime(svg.timestamp))
self.refresh() # sets self.svg
day = relative_date(self.svg.timestamp)
hour = time.strftime('%H:%M', time.localtime(self.svg.timestamp))
self.label_timestamp.set_text(f'{day} {hour}')
self.image_svg.set_from_file(svg.filename)
self.timestamp = svg.timestamp
self.timestamp = self.svg.timestamp
def _on_orientation_changed(self, config, pspec):
self.orientation = config.orientation
@ -68,7 +67,12 @@ class Drawing(Gtk.Box):
def refresh(self):
self.svg = svg = JsonSvg(self.json_data, self.orientation)
self.image_svg.set_from_file(svg.filename)
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename=svg.filename,
width=250,
height=250,
preserve_aspect_ratio=True)
self.image_svg.set_from_pixbuf(pixbuf)
@GObject.Property
def name(self):