hamster-applet r615 - trunk/hamster
- From: tbaugis svn gnome org
- To: svn-commits-list gnome org
- Subject: hamster-applet r615 - trunk/hamster
- Date: Thu, 30 Oct 2008 08:08:27 +0000 (UTC)
Author: tbaugis
Date: Thu Oct 30 08:08:27 2008
New Revision: 615
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=615&view=rev
Log:
now it is possible to specify category when adding activity in
"activity category" manner.
if category is not there, it get's created.
if category is not specified, will pick first entry that matches
also, now we resurrect activities, if they have been called out,
but are living in the gray world of deleted activities.
fixes bug 554411 and bug 558273
Modified:
trunk/hamster/add_custom_fact.py
trunk/hamster/applet.py
trunk/hamster/db.py
Modified: trunk/hamster/add_custom_fact.py
==============================================================================
--- trunk/hamster/add_custom_fact.py (original)
+++ trunk/hamster/add_custom_fact.py Thu Oct 30 08:08:27 2008
@@ -41,26 +41,7 @@
self.glade = gtk.glade.XML(os.path.join(SHARED_DATA_DIR, GLADE_FILE))
self.window = self.get_widget('custom_fact_window')
- # set up drop down menu
- self.activity_list = self.glade.get_widget('activity-list')
- self.activity_list.set_model(gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT))
- category_cell = CategoryCell()
- self.activity_list.pack_start(category_cell, False)
- self.activity_list.add_attribute(category_cell, 'text', 1)
- self.activity_list.set_text_column(0)
-
- # set up autocompletition
- self.activities = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
- completion = gtk.EntryCompletion()
- completion.set_model(self.activities)
- completion.set_text_column(0)
- completion.set_minimum_key_length(1)
- category_cell = CategoryCell()
- completion.pack_start(category_cell, False)
- completion.add_attribute(category_cell, 'text', 1)
-
- self.activity_list.child.set_completion(completion)
-
+ self.set_dropdown()
self.hours = gtk.ListStore(gobject.TYPE_STRING)
@@ -107,29 +88,84 @@
self.glade.signal_autoconnect(self)
+
+ def set_dropdown(self):
+ # set up drop down menu
+ self.activity_list = self.glade.get_widget('activity-list')
+ self.activity_list.set_model(gtk.ListStore(gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING))
+
+ self.activity_list.clear()
+ activity_cell = gtk.CellRendererText()
+ self.activity_list.pack_start(activity_cell, True)
+ self.activity_list.add_attribute(activity_cell, 'text', 0)
+ category_cell = CategoryCell()
+ self.activity_list.pack_start(category_cell, False)
+ self.activity_list.add_attribute(category_cell, 'text', 1)
+ self.activity_list.set_property("text-column", 2)
+
+
+ # set up autocompletition
+ self.activities = gtk.ListStore(gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING)
+ completion = gtk.EntryCompletion()
+ completion.set_model(self.activities)
+
+ activity_cell = gtk.CellRendererText()
+ completion.pack_start(activity_cell, True)
+ completion.add_attribute(activity_cell, 'text', 0)
+ completion.set_property("text-column", 2)
+
+ category_cell = CategoryCell()
+ completion.pack_start(category_cell, False)
+ completion.add_attribute(category_cell, 'text', 1)
+
+ def match_func(completion, key, iter):
+ model = completion.get_model()
+ text = model.get_value(iter, 2)
+ if text and text.startswith(key):
+ return True
+ return False
+
+ completion.set_match_func(match_func)
+ completion.set_minimum_key_length(1)
+ completion.set_inline_completion(True)
+
+ self.activity_list.child.set_completion(completion)
+
+
def refresh_menu(self):
- all_activities = storage.get_autocomplete_activities()
+ #first populate the autocomplete - contains all entries in lowercase
self.activities.clear()
+ all_activities = storage.get_autocomplete_activities()
for activity in all_activities:
- self.activities.append([activity['name'], activity['category']])
+ activity_category = "%s %s" % (activity['name'], activity['category'])
+ self.activities.append([activity['name'],
+ activity['category'],
+ activity_category])
- activity_list = self.get_widget('activity-list')
- store = activity_list.get_model()
+
+ #now populate the menu - contains only categorized entries
+ store = self.activity_list.get_model()
store.clear()
#populate fresh list from DB
- activities = storage.get_sorted_activities()
- prev_item = None
+ categorized_activities = storage.get_sorted_activities()
- today = datetime.date.today()
- for activity in activities:
- item = store.append([activity['name'], activity['category'], activity['id']])
+ for activity in categorized_activities:
+ activity_category = "%s %s" % (activity['name'], activity['category'])
+ item = store.append([activity['name'],
+ activity['category'],
+ activity_category])
+ # finally add TODO tasks from evolution to both lists
tasks = hamster.eds.get_eds_tasks()
for activity in tasks:
- item = store.append([activity['name'], -1])
-
+ self.activities.append([activity['name']])
+ store.append([activity['name'], -1])
return True
Modified: trunk/hamster/applet.py
==============================================================================
--- trunk/hamster/applet.py (original)
+++ trunk/hamster/applet.py Thu Oct 30 08:08:27 2008
@@ -182,29 +182,7 @@
self.glade = gtk.glade.XML(os.path.join(SHARED_DATA_DIR, "menu.glade"))
self.window = self.glade.get_widget('hamster-window')
-
-
- # set up drop down menu
- self.activity_list = self.glade.get_widget('activity-list')
- self.activity_list.set_model(gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT))
- category_cell = CategoryCell()
- self.activity_list.pack_start(category_cell, False)
- self.activity_list.add_attribute(category_cell, 'text', 1)
- self.activity_list.set_text_column(0)
-
- # set up autocompletition
- self.activities = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
- completion = gtk.EntryCompletion()
- completion.set_model(self.activities)
- completion.set_text_column(0)
- completion.set_minimum_key_length(1)
- completion.set_inline_completion(True)
-
- category_cell = CategoryCell()
- completion.pack_start(category_cell, False)
- completion.add_attribute(category_cell, 'text', 1)
-
- self.activity_list.child.set_completion(completion)
+ self.set_dropdown()
# init today's tree
self.treeview = self.glade.get_widget('today')
@@ -287,6 +265,56 @@
dispatcher.add_handler('gconf_notify_interval_changed', self.on_notify_interval_changed)
self.on_notify_interval_changed(None, self.config.get_notify_interval())
+
+ def set_dropdown(self):
+ # set up drop down menu
+ self.activity_list = self.glade.get_widget('activity-list')
+ self.activity_list.set_model(gtk.ListStore(gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING))
+
+ self.activity_list.clear()
+ activity_cell = gtk.CellRendererText()
+ self.activity_list.pack_start(activity_cell, True)
+ self.activity_list.add_attribute(activity_cell, 'text', 0)
+ category_cell = CategoryCell()
+ self.activity_list.pack_start(category_cell, False)
+ self.activity_list.add_attribute(category_cell, 'text', 1)
+
+ self.activity_list.set_property("text-column", 2)
+
+
+ # set up autocompletition
+ self.activities = gtk.ListStore(gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING)
+ completion = gtk.EntryCompletion()
+ completion.set_model(self.activities)
+
+ activity_cell = gtk.CellRendererText()
+ completion.pack_start(activity_cell, True)
+ completion.add_attribute(activity_cell, 'text', 0)
+ completion.set_property("text-column", 2)
+
+ category_cell = CategoryCell()
+ completion.pack_start(category_cell, False)
+ completion.add_attribute(category_cell, 'text', 1)
+
+
+ def match_func(completion, key, iter):
+ model = completion.get_model()
+ text = model.get_value(iter, 2)
+ if text and text.startswith(key):
+ return True
+ return False
+
+ completion.set_match_func(match_func)
+ completion.set_minimum_key_length(1)
+ completion.set_inline_completion(True)
+
+ self.activity_list.child.set_completion(completion)
+
+
def on_today_release_event(self, tree, event):
pointer = event.window.get_pointer() # x, y, flags
path = tree.get_path_at_pos(pointer[0], pointer[1]) #column, innerx, innery
@@ -390,7 +418,10 @@
self.activities.clear()
all_activities = storage.get_autocomplete_activities()
for activity in all_activities:
- self.activities.append([activity['name'], activity['category']])
+ activity_category = "%s %s" % (activity['name'], activity['category'])
+ self.activities.append([activity['name'],
+ activity['category'],
+ activity_category])
#now populate the menu - contains only categorized entries
@@ -401,7 +432,10 @@
categorized_activities = storage.get_sorted_activities()
for activity in categorized_activities:
- item = store.append([activity['name'], activity['category'], activity['id']])
+ activity_category = "%s %s" % (activity['name'], activity['category'])
+ item = store.append([activity['name'],
+ activity['category'],
+ activity_category])
# finally add TODO tasks from evolution to both lists
tasks = hamster.eds.get_eds_tasks()
Modified: trunk/hamster/db.py
==============================================================================
--- trunk/hamster/db.py (original)
+++ trunk/hamster/db.py Thu Oct 30 08:08:27 2008
@@ -95,16 +95,55 @@
- def __get_activity_by_name(self, name):
+ def __get_activity_by_name(self, name, category_id = None):
"""get most recent, preferably not deleted activity by it's name"""
+
+ if category_id:
+ query = """
+ SELECT id, deleted from activities
+ WHERE lower(name) = lower(?)
+ AND category_id = ?
+ ORDER BY deleted, id desc
+ LIMIT 1
+ """
+
+ res = self.fetchone(query, (name, category_id))
+ else:
+ query = """
+ SELECT id, deleted from activities
+ WHERE lower(name) = lower(?)
+ ORDER BY deleted, id desc
+ LIMIT 1
+ """
+
+ res = self.fetchone(query, (name,))
+
+ if res:
+ # if the activity was marked as deleted, ressurect on first call
+ # and put in the unsorted category
+ if res['deleted']:
+ update = """
+ UPDATE activities
+ SET deleted = null, category_id = -1
+ WHERE id = ?
+ """
+ self.execute(update, (res['id'], ))
+
+ return res['id']
+
+ return None
+
+ def __get_category_by_name(self, name):
+ """returns category by it's name"""
+
query = """
- SELECT id from activities
+ SELECT id from categories
WHERE lower(name) = lower(?)
- ORDER BY deleted, id desc
+ ORDER BY id desc
LIMIT 1
"""
-
- res = self.fetchone(query, (name,))
+
+ res = self.fetchone(query, (name, ))
if res:
return res['id']
@@ -152,10 +191,20 @@
start_time = start_time or datetime.datetime.now()
# try to lookup activity by it's name in db. active ones have priority
- activity_id = self.__get_activity_by_name(activity_name)
+ category_id = None
+ if activity_name.find("@") > 0:
+ #at symbol marks category
+ activity_name, category_name = activity_name.split("@")
+
+ if category_name:
+ category_id = self.__get_category_by_name(category_name)
+ if not category_id:
+ category_id = self.__insert_category(category_name)
+
+ activity_id = self.__get_activity_by_name(activity_name, category_id)
if not activity_id:
- activity_id = self.__insert_activity(activity_name)
+ activity_id = self.__insert_activity(activity_name, category_id)
# now fetch facts for the specified day and check if we have to
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]