gui: hook up a zoom slider

The default size of the drawings is a bit small now, good for an overview but
not for identifying which drawing to use now. Add a zoom slider for that.
pull/145/head
Peter Hutterer 2019-07-19 16:41:17 +10:00
parent 097f66f33c
commit d06b92e9af
4 changed files with 100 additions and 6 deletions

View File

@ -2,6 +2,12 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="adjustment_zoom">
<property name="upper">15</property>
<property name="step_increment">1.0000000002235174</property>
<property name="page_increment">1</property>
<signal name="value-changed" handler="_on_zoom_changed" swapped="no"/>
</object>
<template class="MainWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="default_width">1000</property>
@ -25,6 +31,9 @@
<property name="can_focus">False</property>
<property name="margin_left">10</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="title">
<placeholder/>
@ -59,6 +68,55 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">zoom-out-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScale" id="scale_zoom">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment_zoom</property>
<property name="round_digits">0</property>
<property name="draw_value">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">zoom-in-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
<child>

View File

@ -38,6 +38,7 @@ class Drawing(Gtk.Box):
Config.instance().connect('notify::orientation', self._on_orientation_changed)
self.json_data = json_data
self._zoom = 0
self.refresh() # sets self.svg
self.timestamp = self.svg.timestamp
@ -47,18 +48,34 @@ class Drawing(Gtk.Box):
self.refresh()
def refresh(self):
self.svg = svg = JsonSvg(self.json_data, self.orientation)
self.svg = JsonSvg(self.json_data, self.orientation)
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename=self.svg.filename,
width=1000,
height=1000,
preserve_aspect_ratio=True)
self.redraw()
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)
def redraw(self):
pb = self.pixbuf.scale_simple(250 + (self.zoom * 50),
250 + (self.zoom * 50),
GdkPixbuf.InterpType.BILINEAR)
self.image_svg.set_from_pixbuf(pb)
@GObject.Property
def name(self):
return "drawing"
@GObject.Property
def zoom(self):
return self._zoom
@zoom.setter
def zoom(self, zoom):
if zoom == self._zoom:
return
self._zoom = zoom
self.redraw()
@Gtk.Template.Callback('_on_download_button_clicked')
def _on_download_button_clicked(self, button):
dialog = Gtk.FileChooserDialog(_('Please choose a file'),

View File

@ -101,6 +101,7 @@ class DrawingPerspective(Gtk.Stack):
super().__init__(*args, **kwargs)
self.known_drawings = {} # type {timestamp: Drawing()}
self.flowboxes = {}
self._zoom = 0
def _cache_drawings(self, device, pspec):
# The config backend filters duplicates anyway, so don't care here
@ -176,6 +177,19 @@ class DrawingPerspective(Gtk.Stack):
def name(self):
return "drawing_perspective"
@GObject.Property
def zoom(self):
return self._zoom
@zoom.setter
def zoom(self, zoom):
if zoom == self._zoom:
return
self._zoom = zoom
for ts, drawing in self.known_drawings.items():
drawing.zoom = zoom
def _on_connected(self, device, pspec):
# Turns out we don't really care about whether the device is
# connected or not, it has little effect on how we work here

View File

@ -237,3 +237,8 @@ class MainWindow(Gtk.ApplicationWindow):
def _on_orientation_changed(self, action, label):
action.set_state(label)
Config.instance().orientation = label.get_string() # this is a GVariant
@Gtk.Template.Callback('_on_zoom_changed')
def _on_zoom_changed(self, adjustment):
dp = self._get_child('drawing_perspective')
dp.zoom = int(adjustment.get_value())