[gnome-clocks] Add a can-select property



commit 629ec5a44eb971699b54dd6c6dde1c658f3e7b4e
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Aug 26 15:56:14 2012 +0200

    Add a can-select property
    
    Add a can-select property to World and Alarms and use its change
    notification to update the select button sensitivity

 gnomeclocks/app.py    |   12 +++++++++---
 gnomeclocks/clocks.py |    9 ++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index fb07453..c4f1503 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -302,8 +302,10 @@ class ClocksToolbar(Gtk.Toolbar):
         for view in views:
             button = ClockButton(view.label)
             self.buttonBox.pack_start(button, False, False, 0)
-            button.connect('toggled', self._on_toggled, view)
+            button.connect("toggled", self._on_toggled, view)
             self.viewsButtons[view] = button
+            if view.hasSelectionMode:
+                view.connect("notify::can-select", self._on_can_select_changed)
             if view == views[0]:
                 self.current_view = view
                 button.set_active(True)
@@ -321,7 +323,7 @@ class ClocksToolbar(Gtk.Toolbar):
         image.set_from_gicon(icon, Gtk.IconSize.MENU)
         self.selectButton.add(image)
         self.selectButton.set_size_request(32, 32)
-        self.selectButton.set_sensitive(self.current_view.can_select())
+        self.selectButton.set_sensitive(self.current_view.can_select)
         self.selectButton.connect('clicked', self._on_selection_mode, True)
         self.rightBox = box = Gtk.Box()
         box.pack_end(self.selectButton, False, False, 0)
@@ -368,7 +370,7 @@ class ClocksToolbar(Gtk.Toolbar):
             self.selectButton.get_children()[0].show_all()
             self.selectButton.show_all()
             self.selectButton.set_relief(Gtk.ReliefStyle.NORMAL)
-            self.selectButton.set_sensitive(view.can_select())
+            self.selectButton.set_sensitive(view.can_select)
         else:
             width = self.selectButton.get_allocation().width
             self.selectButton.set_relief(Gtk.ReliefStyle.NONE)
@@ -378,6 +380,10 @@ class ClocksToolbar(Gtk.Toolbar):
 
         self.emit("view-clock", view)
 
+    def _on_can_select_changed(self, view, pspec):
+        if view == self.current_view:
+            self.selectButton.set_sensitive(view.can_select)
+
     def _on_selection_mode(self, button, selection_mode):
         self.selection_toolbar.set_visible(selection_mode)
         self.set_visible(not selection_mode)
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index ba56322..9da3751 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -56,9 +56,6 @@ class Clock(Gtk.EventBox):
     def open_new_dialog(self):
         pass
 
-    def can_select(self):
-        pass
-
     def get_selection(self):
         pass
 
@@ -113,6 +110,7 @@ class World(Clock):
     def set_selection_mode(self, active):
         self.iconview.set_selection_mode(active)
 
+    @GObject.Property(type=bool, default=False)
     def can_select(self):
         return len(self.liststore) != 0
 
@@ -147,6 +145,7 @@ class World(Clock):
                                            "<b>" + name + "</b>",
                                            d])
         d.set_iter(self.liststore, view_iter)
+        self.notify("can-select")
 
     def delete_clocks(self, clocks):
         for d in clocks:
@@ -155,6 +154,7 @@ class World(Clock):
         self.iconview.unselect_all()
         self.liststore.clear()
         self.load_clocks()
+        self.notify("can-select")
 
     def update_empty_view(self):
         if len(self.liststore) == 0:
@@ -240,6 +240,7 @@ class Alarm(Clock):
     def set_selection_mode(self, active):
         self.iconview.set_selection_mode(active)
 
+    @GObject.Property(type=bool, default=False)
     def can_select(self):
         return len(self.liststore) != 0
 
@@ -294,6 +295,7 @@ class Alarm(Clock):
                                            widget,
                                            alert,
                                            alarm])
+        self.notify("can-select")
 
     def edit_alarm(self, old_vevent, alarm):
         handler = ICSHandler()
@@ -308,6 +310,7 @@ class Alarm(Clock):
         self.iconview.unselect_all()
         self.liststore.clear()
         self.load_alarms()
+        self.notify("can-select")
 
     def open_new_dialog(self):
         window = AlarmDialog(self, self.get_toplevel())



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