def test_category(self): # plain activity name activity = stuff.Fact("just a simple case@hamster") self.assertEquals(activity.activity, "just a simple case") self.assertEquals(activity.category, "hamster") assert activity.start_time is None assert activity.end_time is None assert activity.description is None
def on_today_row_activated(self, tree, path, column): fact = tree.get_selected_fact() fact = stuff.Fact(fact.activity, category = fact.category, description = fact.description, tags = ", ".join(fact.tags)) if fact.activity: runtime.storage.add_fact(fact)
def test_description(self): # plain activity name activity = stuff.Fact("case, with added description") self.assertEquals(activity.activity, "case") self.assertEquals(activity.description, "with added description") assert activity.category is None assert activity.start_time is None assert activity.end_time is None assert activity.category is None
def test_full(self): # plain activity name activity = stuff.Fact( "1225-1325 case@cat, description #ta non-tag #tag #bag") self.assertEquals(activity.start_time.strftime("%H:%M"), "12:25") self.assertEquals(activity.end_time.strftime("%H:%M"), "13:25") self.assertEquals(activity.activity, "case") self.assertEquals(activity.category, "cat") self.assertEquals(activity.description, "description #ta non-tag") self.assertEquals(set(activity.tags), set(["bag", "tag"]))
def test_tags(self): # plain activity name activity = stuff.Fact( "case, with added #de description #and, #some #tags") self.assertEquals(activity.activity, "case") self.assertEquals(activity.description, "with added #de description") self.assertEquals(set(activity.tags), set(["and", "some", "tags"])) assert activity.category is None assert activity.start_time is None assert activity.end_time is None
def test_with_start_and_end_time(self): # with time activity = stuff.Fact("12:35-14:25 with start-end time") self.assertEquals(activity.activity, "with start-end time") self.assertEquals(activity.start_time.strftime("%H:%M"), "12:35") self.assertEquals(activity.end_time.strftime("%H:%M"), "14:25") #rest must be empty assert activity.category is None assert activity.description is None
def on_switch_activity_clicked(self, widget): activity, temporary = self.new_name.get_value() fact = stuff.Fact(activity, tags = self.new_tags.get_text().decode("utf8", "replace")) if not fact.activity: return runtime.storage.add_fact(fact, temporary) self.new_name.set_text("") self.new_tags.set_text("")
def AddFact(self, fact, start_time, end_time, temporary = False): start_time = dt.datetime.utcfromtimestamp(start_time) if start_time else None end_time = dt.datetime.utcfromtimestamp(end_time) if end_time else None fact = stuff.Fact(fact, start_time = start_time, end_time = end_time) start_time = fact.start_time or dt.datetime.now().replace(second = 0, microsecond = 0) self.start_transaction() result = self.__add_fact(fact.serialized_name(), start_time, end_time, temporary) self.end_transaction() if result: self.FactsChanged() return result or 0
def on_workspace_changed(self, screen, previous_workspace): if not previous_workspace: # wnck has a slight hiccup on init and after that calls # workspace changed event with blank previous state that should be # ignored return if not self.workspace_tracking: return # default to not doing anything current_workspace = screen.get_active_workspace() # rely on workspace numbers as names change prev = previous_workspace.get_number() new = current_workspace.get_number() # on switch, update our mapping between spaces and activities self.workspace_activities[prev] = self.last_activity activity = None if "name" in self.workspace_tracking: # first try to look up activity by desktop name mapping = conf.get("workspace_mapping") fact = None if new < len(mapping): fact = stuff.Fact(mapping[new]) if fact.activity: category_id = None if fact.category: category_id = runtime.storage.get_category_id(fact.category) activity = runtime.storage.get_activity_by_name(fact.activity, category_id, resurrect = False) if activity: # we need dict below activity = dict(name = activity.name, category = activity.category, description = fact.description, tags = fact.tags) if not activity and "memory" in self.workspace_tracking: # now see if maybe we have any memory of the new workspace # (as in - user was here and tracking Y) # if the new workspace is in our dict, switch to the specified activity if new in self.workspace_activities and self.workspace_activities[new]: activity = self.workspace_activities[new] if not activity: return # check if maybe there is no need to switch, as field match: if self.last_activity and \ self.last_activity.name.lower() == activity.name.lower() and \ (self.last_activity.category or "").lower() == (activity.category or "").lower() and \ ", ".join(self.last_activity.tags).lower() == ", ".join(activity.tags).lower(): return # ok, switch fact = stuff.Fact(activity.name, tags = ", ".join(activity.tags), category = activity.category, description = activity.description); runtime.storage.add_fact(fact)