[gnome-clocks] Use vertical spinbuttons for the timer
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Use vertical spinbuttons for the timer
- Date: Tue, 4 Sep 2012 20:46:46 +0000 (UTC)
commit 7e990eb18a2e9eb83454ab0e8988720ec8278c6b
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Sep 4 22:38:48 2012 +0200
Use vertical spinbuttons for the timer
gnomeclocks/timer.py | 6 ++--
gnomeclocks/widgets.py | 72 +++++++++--------------------------------------
2 files changed, 17 insertions(+), 61 deletions(-)
---
diff --git a/gnomeclocks/timer.py b/gnomeclocks/timer.py
index 1a25d71..a1c0c83 100644
--- a/gnomeclocks/timer.py
+++ b/gnomeclocks/timer.py
@@ -85,9 +85,9 @@ class TimerWelcomeScreen(Gtk.Grid):
self.set_valign(Gtk.Align.CENTER)
self.set_row_spacing(48)
- self.hours = Spinner(24)
- self.minutes = Spinner(59)
- self.seconds = Spinner(59)
+ self.hours = Spinner(0, 24)
+ self.minutes = Spinner(0, 59)
+ self.seconds = Spinner(0, 59)
self.hours.connect("value-changed", self._on_spinner_changed)
self.minutes.connect("value-changed", self._on_spinner_changed)
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index 26d3b21..5900e61 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -121,66 +121,22 @@ class DigitalClockDrawing(Gtk.DrawingArea):
return self.pixbuf
-class Spinner(Gtk.Box):
- MARKUP = "<span font_desc=\"64.0\">%02i</span>"
-
- __gsignals__ = {
- 'value-changed': (GObject.SignalFlags.RUN_LAST,
- None,
- ())
- }
-
- def __init__(self, max_value):
+class Spinner(Gtk.SpinButton):
+ def __init__(self, min_value, max_value):
super(Spinner, self).__init__()
- self.max_value = max_value
self.set_orientation(Gtk.Orientation.VERTICAL)
- iconUp = Gio.ThemedIcon.new_with_default_fallbacks("go-up-symbolic")
- iconDown = Gio.ThemedIcon.new_with_default_fallbacks(
- "go-down-symbolic")
- imageUp = Gtk.Image.new_from_gicon(iconUp, Gtk.IconSize.DND)
- imageDown = Gtk.Image.new_from_gicon(iconDown, Gtk.IconSize.DND)
-
- self.up = Gtk.Button()
- self.up.set_image(imageUp)
- self.up.set_relief(Gtk.ReliefStyle.NONE)
-
- self.value = Gtk.Label('')
- self.value.set_markup(Spinner.MARKUP % (0))
- self.value.set_alignment(0.5, 0.5)
-
- self.down = Gtk.Button()
- self.down.set_image(imageDown)
- self.down.set_relief(Gtk.ReliefStyle.NONE)
-
- self.pack_start(self.up, False, False, 0)
- self.pack_start(self.value, True, True, 0)
- self.pack_start(self.down, False, False, 0)
-
- self.up.connect('clicked', self._increase)
- self.down.connect('clicked', self._decrease)
-
- def get_value(self):
- return int(self.value.get_text())
-
- def set_value(self, newValue):
- self.value.set_markup(Spinner.MARKUP % (newValue))
- self.emit("value-changed")
-
- def _increase(self, widget):
- value = self.get_value()
- if value == self.max_value:
- value = 0
- else:
- value += 1
- self.set_value(value)
-
- def _decrease(self, widget):
- value = self.get_value()
- if value == 0:
- value = self.max_value
- else:
- value -= 1
- self.set_value(value)
+ self.set_numeric(True)
+ self.set_increments(1.0, 1.0)
+ self.set_wrap(True)
+ self.set_range(min_value, max_value)
+ attrs = Pango.parse_markup('<span font_desc=\"64.0\">00</span>', -1, "_")[1]
+ self.set_attributes(attrs)
+
+ self.connect('output', self._show_leading_zeros)
+
+ def _show_leading_zeros(self, spin_button):
+ spin_button.set_text('{:02d}'.format(spin_button.get_value_as_int()))
+ return True
class EmptyPlaceholder(Gtk.Box):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]