[gnome-clocks] Make spinner emit a signal when the value changes



commit f767563522550e835ee66d8492ccee81df92f624
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Sep 4 09:30:28 2012 +0200

    Make spinner emit a signal when the value changes
    
    In this way it is generic and does not need to be aware of timer's
    internals

 gnomeclocks/timer.py   |   13 ++++++++++---
 gnomeclocks/widgets.py |   12 ++++++++----
 2 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/gnomeclocks/timer.py b/gnomeclocks/timer.py
index 193fc1c..1a25d71 100644
--- a/gnomeclocks/timer.py
+++ b/gnomeclocks/timer.py
@@ -85,9 +85,13 @@ class TimerWelcomeScreen(Gtk.Grid):
         self.set_valign(Gtk.Align.CENTER)
         self.set_row_spacing(48)
 
-        self.hours = Spinner(24, self)
-        self.minutes = Spinner(59, self)
-        self.seconds = Spinner(59, self)
+        self.hours = Spinner(24)
+        self.minutes = Spinner(59)
+        self.seconds = Spinner(59)
+
+        self.hours.connect("value-changed", self._on_spinner_changed)
+        self.minutes.connect("value-changed", self._on_spinner_changed)
+        self.seconds.connect("value-changed", self._on_spinner_changed)
 
         spinner = Gtk.Box()
         spinner.pack_start(self.hours, False, False, 0)
@@ -132,6 +136,9 @@ class TimerWelcomeScreen(Gtk.Grid):
             self.startButton.set_sensitive(True)
             self.startButton.get_style_context().add_class("clocks-go")
 
+    def _on_spinner_changed(self, spinner):
+        self.update_start_button_status()
+
     def _on_start_clicked(self, data):
         self.timer.start()
 
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index 2c564bc..26d3b21 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -124,10 +124,15 @@ class DigitalClockDrawing(Gtk.DrawingArea):
 class Spinner(Gtk.Box):
     MARKUP = "<span font_desc=\"64.0\">%02i</span>"
 
-    def __init__(self, max_value, timer_welcome_screen):
+    __gsignals__ = {
+        'value-changed': (GObject.SignalFlags.RUN_LAST,
+                          None,
+                          ())
+    }
+
+    def __init__(self, max_value):
         super(Spinner, self).__init__()
         self.max_value = max_value
-        self.timer_welcome_screen = timer_welcome_screen
         self.set_orientation(Gtk.Orientation.VERTICAL)
         iconUp = Gio.ThemedIcon.new_with_default_fallbacks("go-up-symbolic")
         iconDown = Gio.ThemedIcon.new_with_default_fallbacks(
@@ -159,6 +164,7 @@ class Spinner(Gtk.Box):
 
     def set_value(self, newValue):
         self.value.set_markup(Spinner.MARKUP % (newValue))
+        self.emit("value-changed")
 
     def _increase(self, widget):
         value = self.get_value()
@@ -167,7 +173,6 @@ class Spinner(Gtk.Box):
         else:
             value += 1
         self.set_value(value)
-        self.timer_welcome_screen.update_start_button_status()
 
     def _decrease(self, widget):
         value = self.get_value()
@@ -176,7 +181,6 @@ class Spinner(Gtk.Box):
         else:
             value -= 1
         self.set_value(value)
-        self.timer_welcome_screen.update_start_button_status()
 
 
 class EmptyPlaceholder(Gtk.Box):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]