[Sugar-devel] [PATCH] add activity counter to metadata

Walter Bender walter at sugarlabs.org
Thu Jan 12 12:39:46 EST 2012


From: Walter Bender <walter.bender at gmail.com>

This patch adds/updates a new metadata field to instances of Sugar Activities.
Specifically, it maintains a count of how many times an activity instance has
be accessed. The mechanism used is to increment a counter each time an activity
is launched. (The counter is initialized to 1 on first launch.) This is part
of the "Activity-specific metadata" Feature described here [1].

[1] http://wiki.sugarlabs.org/go/Features/Activity_specific_metadata_in_Journal

---
 src/sugar/activity/widgets.py |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/sugar/activity/widgets.py b/src/sugar/activity/widgets.py
index 2a106e9..15eface 100644
--- a/src/sugar/activity/widgets.py
+++ b/src/sugar/activity/widgets.py
@@ -332,7 +332,16 @@ class ActivityToolbar(gtk.Toolbar):
         self.insert(self.stop, -1)
         self.stop.show()
 
+        if activity.metadata:
+            # activity count is the number of times this instance
+            # has been accessed
+            if 'activity count' in activity.metadata:
+                count = int(activity.metadata['activity count'])
+                count += 1
+            else:
+                count = 1
+            activity.metadata['activity count'] = str(count)
+
 
 class EditToolbar(gtk.Toolbar):
     """Provides the standard edit toolbar for Activities.
-- 
1.7.7.5



More information about the Sugar-devel mailing list