def __init__(self, applet): self.applet = applet self.button = PanelButton() self.button.connect('toggled', self.on_toggle) self.applet.add(self.button) self.applet.setup_menu_from_file( runtime.data_dir, "Hamster_Applet.xml", None, [ ("about", self.on_about), ("overview", self.show_overview), ("preferences", self.show_preferences), ("help", self.on_help_clicked), ]) # load window of activity switcher and todays view self._gui = load_ui_file("applet.ui") self.window = self._gui.get_object('hamster-window') # on close don't destroy the popup, just hide it instead self.window.connect("delete_event", lambda *args: self.__show_toggle(False)) self.window.connect("window-state-event", self.on_window_state_changed) self.new_name = widgets.ActivityEntry() self.new_name.connect("value-entered", self.on_switch_activity_clicked) self.new_name.set_property("secondary-icon-name", "help-contents") self.new_name.connect("icon-press", self.on_more_info_button_clicked) widgets.add_hint(self.new_name, _("Activity")) self.get_widget("new_name_box").add(self.new_name) self.new_name.connect("changed", self.on_activity_text_changed) self.new_tags = widgets.TagsEntry() self.new_tags.connect("tags_selected", self.on_switch_activity_clicked) widgets.add_hint(self.new_tags, _("Tags")) self.get_widget("new_tags_box").add(self.new_tags) self.tag_box = widgets.TagBox(interactive=False) self.get_widget("tag_box").add(self.tag_box) self.treeview = widgets.FactTree() self.treeview.connect("key-press-event", self.on_todays_keys) self.treeview.connect("edit-clicked", self._open_edit_activity) self.treeview.connect("row-activated", self.on_today_row_activated) self.get_widget("today_box").add(self.treeview) # DBus Setup try: dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) # Set up connection to the screensaver self.dbusIdleListener = idle.DbusIdleListener() self.dbusIdleListener.connect('idle-changed', self.on_idle_changed) except dbus.DBusException, e: logging.error("Can't init dbus: %s" % e)
def __init__(self, parent=None, fact_date=None, fact_id=None): gtk.Object.__init__(self) self._gui = load_ui_file("edit_activity.ui") self.window = self.get_widget('custom_fact_window') self.parent, self.fact_id = parent, fact_id start_date, end_date = None, None #TODO - should somehow hint that time is not welcome here self.new_name = widgets.ActivityEntry() self.get_widget("activity_box").add(self.new_name) self.new_tags = widgets.TagsEntry() self.get_widget("tags_box").add(self.new_tags) day_start = conf.get("day_start_minutes") self.day_start = dt.time(day_start / 60, day_start % 60) if fact_id: fact = runtime.storage.get_fact(fact_id) label = fact.activity if fact.category != _("Unsorted"): label += "@%s" % fact.category self.new_name.set_text(label) self.new_tags.set_text(", ".join(fact.tags)) start_date = fact.start_time end_date = fact.end_time buf = gtk.TextBuffer() buf.set_text(fact.description or "") self.get_widget('description').set_buffer(buf) self.get_widget("save_button").set_label("gtk-save") self.window.set_title(_("Update activity")) else: self.get_widget("delete_button").set_sensitive(False) # if there is previous activity with end time - attach to it # otherwise let's start at 8am (unless it is today - in that case # we will assume that the user wants to start from this moment) fact_date = fact_date or dt.date.today() last_activity = runtime.storage.get_facts(fact_date) if last_activity and last_activity[-1].end_time: start_date = last_activity[-1].end_time if fact_date != dt.date.today(): end_date = start_date + dt.timedelta(minutes=30) else: if fact_date == dt.date.today(): start_date = dt.datetime.now() else: start_date = dt.datetime(fact_date.year, fact_date.month, fact_date.day, 8) if not end_date: self.get_widget("in_progress").set_active(True) if (dt.datetime.now() - start_date).days == 0: end_date = dt.datetime.now() start_date = start_date or dt.datetime.now() end_date = end_date or start_date + dt.timedelta(minutes=30) self.start_date = widgets.DateInput(start_date) self.get_widget("start_date_placeholder").add(self.start_date) self.start_time = widgets.TimeInput(start_date) self.get_widget("start_time_placeholder").add(self.start_time) self.end_time = widgets.TimeInput(end_date, start_date) self.get_widget("end_time_placeholder").add(self.end_time) self.set_end_date_label(end_date) self.dayline = widgets.DayLine() self.dayline.connect("on-time-chosen", self.update_time) self._gui.get_object("day_preview").add(self.dayline) self.on_in_progress_toggled(self.get_widget("in_progress")) self.start_date.connect("date-entered", self.on_start_date_entered) self.start_time.connect("time-entered", self.on_start_time_entered) self.new_name.connect("changed", self.on_new_name_changed) self.end_time.connect("time-entered", self.on_end_time_entered) self._gui.connect_signals(self) self.window.show_all()