[gnome-clocks] Bind the empty view to the model
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Bind the empty view to the model
- Date: Tue, 21 Aug 2012 16:33:12 +0000 (UTC)
commit 814a7365805c0c0b38b1bf07b5053e209f5e03a9
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Aug 21 18:11:22 2012 +0200
Bind the empty view to the model
Make the empty view implicitely updated when items are added or removed
from the tree model
gnomeclocks/clocks.py | 118 +++++++++++++++++++++++++------------------------
1 files changed, 60 insertions(+), 58 deletions(-)
---
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index 7d5cb28..0fb02ac 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -67,19 +67,23 @@ class World(Clock):
def __init__(self):
Clock.__init__(self, _("World"), True, True)
+ self.empty_view = EmptyPlaceholder(
+ "document-open-recent-symbolic",
+ _("Select <b>New</b> to add a world clock"))
+ self.add(self.empty_view)
+
self.liststore = Gtk.ListStore(bool,
Pixbuf,
str,
GObject.TYPE_PYOBJECT)
- self.iconview = SelectableIconView(self.liststore, 0, 1, 2)
- self.empty_view = EmptyPlaceholder(
- "document-open-recent-symbolic",
- _("Select <b>New</b> to add a world clock"))
+ self.iconview = SelectableIconView(self.liststore, 0, 1, 2)
self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.add(self.iconview)
+ self.liststore.connect("row-inserted", self._on_item_inserted)
+ self.liststore.connect("row-deleted", self._on_item_deleted)
self.iconview.connect("item-activated", self._on_item_activated)
self.iconview.connect("selection-changed", self._on_selection_changed)
@@ -87,8 +91,11 @@ class World(Clock):
self.load_clocks()
self.show_all()
- def set_selection_mode(self, active):
- self.iconview.set_selection_mode(active)
+ def _on_item_inserted(self, model, path, treeiter):
+ self.update_empty_view()
+
+ def _on_item_deleted(self, model, path):
+ self.update_empty_view()
def _on_item_activated(self, iconview, path):
d = self.liststore[path][3]
@@ -97,17 +104,16 @@ class World(Clock):
def _on_selection_changed(self, iconview):
self.emit("selection-changed")
+ def set_selection_mode(self, active):
+ self.iconview.set_selection_mode(active)
+
def get_selection(self):
return self.iconview.get_selection()
def load_clocks(self):
self.clocks = worldclockstorage.load_clocks()
- if len(self.clocks) == 0:
- self.load_empty_clocks_view()
- else:
- for clock in self.clocks:
- self.add_clock_widget(clock)
- self.load_clocks_view()
+ for clock in self.clocks:
+ self.add_clock_widget(clock)
def add_clock(self, location):
location_id = location.id + "---" + location.location.get_code()
@@ -116,8 +122,6 @@ class World(Clock):
self.add_clock_widget(location)
self.show_all()
worldclockstorage.save_clocks(self.clocks)
- if len(self.clocks) > 0:
- self.load_clocks_view()
def add_clock_widget(self, location):
d = DigitalClock(location)
@@ -130,22 +134,18 @@ class World(Clock):
def delete_clock(self, d):
self.clocks.remove(d.location)
self.iconview.unselect_all()
- if len(self.clocks) == 0:
- self.load_empty_clocks_view()
-
- def load_clocks_view(self):
- if self.empty_view in self.get_children():
- self.remove(self.empty_view)
- if self.scrolledwindow not in self.get_children():
- self.add(self.scrolledwindow)
- self.show_all()
- def load_empty_clocks_view(self):
- if self.scrolledwindow in self.get_children():
- self.remove(self.scrolledwindow)
- if self.empty_view not in self.get_children():
- self.add(self.empty_view)
- self.show_all()
+ def update_empty_view(self):
+ if len(self.liststore) == 0:
+ if self.scrolledwindow in self.get_children():
+ self.remove(self.scrolledwindow)
+ self.add(self.empty_view)
+ self.show_all()
+ else:
+ if self.empty_view in self.get_children():
+ self.remove(self.empty_view)
+ self.add(self.scrolledwindow)
+ self.show_all()
def open_new_dialog(self):
parent = self.get_parent().get_parent().get_parent()
@@ -164,20 +164,24 @@ class Alarm(Clock):
def __init__(self):
Clock.__init__(self, _("Alarm"), True, True)
+ self.empty_view = EmptyPlaceholder(
+ "alarm-symbolic",
+ _("Select <b>New</b> to add an alarm"))
+ self.add(self.empty_view)
+
self.liststore = Gtk.ListStore(bool,
Pixbuf,
str,
GObject.TYPE_PYOBJECT,
GObject.TYPE_PYOBJECT)
- self.iconview = SelectableIconView(self.liststore, 0, 1, 2)
- self.empty_view = EmptyPlaceholder(
- "alarm-symbolic",
- _("Select <b>New</b> to add an alarm"))
+ self.iconview = SelectableIconView(self.liststore, 0, 1, 2)
self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.add(self.iconview)
+ self.liststore.connect("row-inserted", self._on_item_inserted)
+ self.liststore.connect("row-deleted", self._on_item_deleted)
self.iconview.connect("item-activated", self._on_item_activated)
self.iconview.connect("selection-changed", self._on_selection_changed)
@@ -185,8 +189,11 @@ class Alarm(Clock):
self.load_alarms()
self.show_all()
- def set_selection_mode(self, active):
- self.iconview.set_selection_mode(active)
+ def _on_item_inserted(self, model, path, treeiter):
+ self.update_empty_view()
+
+ def _on_item_deleted(self, model, path):
+ self.update_empty_view()
def _on_item_activated(self, iconview, path):
alarm = self.liststore[path][-1]
@@ -195,34 +202,31 @@ class Alarm(Clock):
def _on_selection_changed(self, iconview):
self.emit("selection-changed")
+ def set_selection_mode(self, active):
+ self.iconview.set_selection_mode(active)
+
def get_selection(self):
return self.iconview.get_selection()
def load_alarms(self):
handler = ICSHandler()
vevents = handler.load_vevents()
- if vevents:
- for vevent in vevents:
- alarm = AlarmItem()
- alarm.new_from_vevent(vevent)
- self.add_alarm_widget(alarm)
- self.load_alarms_view()
+ for vevent in vevents:
+ alarm = AlarmItem()
+ alarm.new_from_vevent(vevent)
+ self.add_alarm_widget(alarm)
+
+ def update_empty_view(self):
+ if len(self.liststore) == 0:
+ if self.scrolledwindow in self.get_children():
+ self.remove(self.scrolledwindow)
+ self.add(self.empty_view)
+ self.show_all()
else:
- self.load_empty_alarms_view()
-
- def load_alarms_view(self):
- if self.empty_view in self.get_children():
- self.remove(self.empty_view)
- if self.scrolledwindow not in self.get_children():
- self.add(self.scrolledwindow)
- self.show_all()
-
- def load_empty_alarms_view(self):
- if self.scrolledwindow in self.get_children():
- self.remove(self.scrolledwindow)
- if self.empty_view not in self.get_children():
- self.add(self.empty_view)
- self.show_all()
+ if self.empty_view in self.get_children():
+ self.remove(self.empty_view)
+ self.add(self.scrolledwindow)
+ self.show_all()
def add_alarm(self, alarm):
handler = ICSHandler()
@@ -230,8 +234,6 @@ class Alarm(Clock):
self.add_alarm_widget(alarm)
self.show_all()
vevents = handler.load_vevents()
- if vevents:
- self.load_alarms_view()
def add_alarm_widget(self, alarm):
name = alarm.get_alarm_name()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]