[hamster-applet] tags entry monitors tag changes itself



commit 43337885bd9f2ed7a79c7c97a4c9e0eb38b22649
Author: Toms Bauģis <toms baugis gmail com>
Date:   Tue Nov 24 11:23:29 2009 +0000

    tags entry monitors tag changes itself

 hamster/applet.py       |    1 -
 hamster/db.py           |    9 +++------
 hamster/standalone.py   |    1 -
 hamster/storage.py      |    6 +++++-
 hamster/widgets/tags.py |   13 ++++++++-----
 5 files changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/hamster/applet.py b/hamster/applet.py
index fffac16..409fe4b 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -235,7 +235,6 @@ class HamsterApplet(object):
         self.new_name.connect("changed", self.on_activity_text_changed)
 
         self.new_tags = widgets.TagsEntry()
-        self.new_tags.set_entries([tag["name"] for tag in runtime.storage.get_tags(autocomplete = True)])
         widgets.add_hint(self.new_tags, _("Tags or Description"))
         self.get_widget("new_tags_box").add(self.new_tags)
         
diff --git a/hamster/db.py b/hamster/db.py
index 833a312..098dad6 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -107,11 +107,9 @@ class Storage(storage.Storage):
 
             self.execute([statement] * len(add), [(tag,) for tag in add])
 
-            return self.__get_tag_ids(list(add)) # all done, recurse
+            return self.__get_tag_ids(tags)[0], True # all done, recurse
         else:
-            return db_tags
-
-        print db_tags
+            return db_tags, False
 
     def __get_category_list(self):
         return self.fetchall("SELECT * FROM categories ORDER BY category_order")
@@ -419,12 +417,11 @@ class Storage(storage.Storage):
         
         # TODO - untangle descriptions - allow just one place where to enter them
         activity.description = ", ".join(descriptions) # somebody will file bug on "why tags can't be seven words"
-        tags = self.__get_tag_ids(tags) #this will create any missing tags too
+        tags = self.get_tag_ids(tags) #this will create any missing tags too
         
         if category_name:
             activity.category_name = category_name
         if description:
-            print "over ride %s" % description
             activity.description = description #override
         
         start_time = activity.start_time or start_time or datetime.datetime.now()
diff --git a/hamster/standalone.py b/hamster/standalone.py
index a4a29e6..a9d2220 100755
--- a/hamster/standalone.py
+++ b/hamster/standalone.py
@@ -51,7 +51,6 @@ class MainWindow(object):
 
 
         self.new_tags = widgets.TagsEntry()
-        self.new_tags.set_entries([tag["name"] for tag in runtime.storage.get_tags(autocomplete = True)])
         
         widgets.add_hint(self.new_tags, _("Tags or Description"))
         self.get_widget("new_tags_box").add(self.new_tags)
diff --git a/hamster/storage.py b/hamster/storage.py
index 9071dc0..e9db2ac 100644
--- a/hamster/storage.py
+++ b/hamster/storage.py
@@ -36,7 +36,11 @@ class Storage(object):
         return self.__get_tags(autocomplete)
         
     def get_tag_ids(self, tags):
-        self.__get_tag_ids(tags)        
+        tags, new_added = self.__get_tag_ids(tags)
+        if new_added:
+            self.dispatch('new_tags_added', ())
+        return tags
+
 
 
     def get_fact(self, id):
diff --git a/hamster/widgets/tags.py b/hamster/widgets/tags.py
index 35834aa..316a743 100644
--- a/hamster/widgets/tags.py
+++ b/hamster/widgets/tags.py
@@ -32,7 +32,7 @@ class TagsEntry(gtk.Entry):
 
     def __init__(self):
         gtk.Entry.__init__(self)
-        self.tags = []
+        self.tags = None
         self.filter = None # currently applied filter string
         self.filter_tags = [] #filtered tags
         
@@ -56,12 +56,14 @@ class TagsEntry(gtk.Entry):
         self.connect("key-press-event", self._on_key_press_event)
         self.connect("key-release-event", self._on_key_release_event)
         self.connect("focus-out-event", self._on_focus_out_event)
+
+        runtime.dispatcher.add_handler('new_tags_added', self.refresh_tags)
         self.show()
         self.populate_suggestions()
 
-    def set_entries(self, tags):
-        self.tags = tags
-        
+    def refresh_tags(self, event, data):
+        self.tags = None
+
     def get_tags(self):
         # splits the string by comma and filters out blanks
         return [tag.strip() for tag in self.get_text().split(",") if tag.strip()]
@@ -115,6 +117,8 @@ class TagsEntry(gtk.Entry):
         self.categories = None
 
     def populate_suggestions(self):
+        self.tags = self.tags or [tag["name"] for tag in runtime.storage.get_tags(autocomplete = True)]
+
         cursor_tag = self.get_cursor_tag()
             
         self.filter = cursor_tag
@@ -183,7 +187,6 @@ class TagsEntry(gtk.Entry):
         self.set_position(cursor + len(new_tag)-len(old_tag)) # put the cursor back
 
     def _on_key_press_event(self, entry, event):
-
         if event.keyval == gtk.keysyms.Tab:
             if self.popup.get_property("visible"):
                 #we have to replace



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