ResolutionRow: add label to highlight the active resolution

Fixes #80, #81.
This commit is contained in:
Jente Hidskes
2017-08-16 23:22:48 +02:00
committed by Peter Hutterer
parent 2cec0e4e0e
commit f17e341dbe
2 changed files with 28 additions and 0 deletions

View File

@@ -58,6 +58,21 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="active_label">
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Active</property>
<property name="justify">right</property>
<property name="track_visited_links">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>

View File

@@ -29,6 +29,7 @@ class ResolutionRow(Gtk.ListBoxRow):
__gtype_name__ = "ResolutionRow"
dpi_label = GtkTemplate.Child()
active_label = GtkTemplate.Child()
revealer = GtkTemplate.Child()
scale = GtkTemplate.Child()
@@ -38,6 +39,7 @@ class ResolutionRow(Gtk.ListBoxRow):
self._resolution = None
self._resolution_handler = 0
self._active_handler = 0
self._scale_handler = self.scale.connect("value-changed",
self._on_scale_value_changed)
@@ -49,14 +51,19 @@ class ResolutionRow(Gtk.ListBoxRow):
def _init_values(self, resolution):
if self._resolution_handler > 0:
self._resolution.disconnect(self._resolution_handler)
if self._active_handler > 0:
self._resolution.disconnect(self._active_handler)
self._resolution = resolution
self._resolution_handler = resolution.connect("notify::resolution",
self._on_resolution_changed)
self._active_handler = resolution.connect("notify::is-active",
self._on_is_active_changed)
xres, __ = resolution.resolution
minres = resolution.minimum
maxres = resolution.maximum
self.dpi_label.set_text("{} DPI".format(xres))
self.active_label.set_visible(resolution.is_active)
with self.scale.handler_block(self._scale_handler):
self.scale.props.adjustment.configure(xres, minres, maxres, 50, 50, 0)
@@ -100,7 +107,13 @@ class ResolutionRow(Gtk.ListBoxRow):
xres, __ = resolution.resolution
self.scale.set_value(xres)
def _on_is_active_changed(self, resolution, pspec):
# The active resolution changed; update the visibility of the label.
self.active_label.set_visible(resolution.is_active)
def toggle_revealer(self):
"""Toggles the revealer to show or hide the configuration widgets."""
reveal = not self.revealer.get_reveal_child()
self.revealer.set_reveal_child(reveal)
if reveal:
self._resolution.set_active()