def __init__(self, parent=None, fact_id=None, base_fact=None): gobject.GObject.__init__(self) self._gui = load_ui_file("edit_activity.ui") self.window = self.get_widget('custom_fact_window') self.window.set_size_request(600, 200) self.parent = parent # None if creating a new fact, instead of editing one self.fact_id = fact_id self.activity = widgets.ActivityEntry() self.activity.connect("changed", self.on_activity_changed) self.get_widget("activity_box").add(self.activity) self.day_start = conf.day_start self.dayline = widgets.DayLine() self._gui.get_object("day_preview").add(self.dayline) self.description_box = self.get_widget('description') self.description_buffer = self.description_box.get_buffer() self.description_buffer.connect("changed", self.on_description_changed) self.save_button = self.get_widget("save_button") self.activity.grab_focus() if fact_id: # editing fact = runtime.storage.get_fact(fact_id) self.date = fact.date original_fact = fact self.window.set_title(_("Update activity")) else: self.date = hamster_today() self.get_widget("delete_button").set_sensitive(False) if base_fact: # start a clone now. original_fact = base_fact.copy(start_time=hamster_now(), end_time=None) else: original_fact = None if original_fact: stripped_fact = original_fact.copy() stripped_fact.description = None label = stripped_fact.serialized(prepend_date=False) with self.activity.handler_block(self.activity.checker): self.activity.set_text(label) time_len = len(label) - len(stripped_fact.serialized_name()) self.activity.select_region(0, time_len - 1) self.description_buffer.set_text(original_fact.description) self.activity.original_fact = original_fact self._gui.connect_signals(self) self.validate_fields() self.window.show_all()
def __init__(self, parent=None, fact_id=None, base_fact=None): gobject.GObject.__init__(self) self._gui = load_ui_file("edit_activity.ui") self.window = self.get_widget('custom_fact_window') self.window.set_size_request(600, 200) self.parent = parent # None if creating a new fact, instead of editing one self.fact_id = fact_id self.activity = widgets.ActivityEntry() self.activity.connect("changed", self.on_activity_changed) self.get_widget("activity_box").add(self.activity) self.day_start = conf.day_start self.dayline = widgets.DayLine() self._gui.get_object("day_preview").add(self.dayline) self.activity.grab_focus() if fact_id: # editing fact = runtime.storage.get_fact(fact_id) self.date = fact.date original_fact = fact self.get_widget("save_button").set_label("gtk-save") self.window.set_title(_("Update activity")) else: self.date = hamster_today() self.get_widget("delete_button").set_sensitive(False) if base_fact: # cloning original_fact = base_fact.copy() # start running now. # Do not try to pass end_time=None to copy(), above; # it would be discarded. original_fact.start_time = dt.datetime.now() original_fact.end_time = None else: original_fact = None if original_fact: label = original_fact.serialized(prepend_date=False) with self.activity.handler_block(self.activity.checker): self.activity.set_text(label) time_len = len(label) - len(original_fact.serialized_name()) self.activity.select_region(time_len, -1) buf = gtk.TextBuffer() buf.set_text(original_fact.description or "") self.get_widget('description').set_buffer(buf) self.activity.original_fact = original_fact self._gui.connect_signals(self) self.validate_fields() self.window.show_all()
def __init__(self, parent=None, fact_date=None, fact_id=None): gobject.GObject.__init__(self) self._gui = load_ui_file("edit_activity.ui") self.window = self.get_widget('custom_fact_window') self.window.set_size_request(600, 200) self.parent = parent self.fact_id = fact_id self.activity = widgets.ActivityEntry() self.activity.connect("changed", self.on_activity_changed) self.get_widget("activity_box").add(self.activity) self.day_start = conf.day_start self.date = fact_date if not self.date: self.date = datetime_to_hamsterday(dt.datetime.now()) self.dayline = widgets.DayLine() self._gui.get_object("day_preview").add(self.dayline) self.activity.grab_focus() if fact_id: fact = runtime.storage.get_fact(fact_id) self.activity.original_fact = fact label = fact.serialized(prepend_date=False) with self.activity.handler_block(self.activity.checker): self.activity.set_text(label) self.activity.select_region(len(label) - len(fact.serialized_name()), -1) 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) self._gui.connect_signals(self) self.validate_fields() self.window.show_all()
def __init__(self, action, fact_id=None): Controller.__init__(self) self._date = None # for the date property self._gui = load_ui_file("edit_activity.ui") self.window = self.get_widget('custom_fact_window') self.window.set_size_request(600, 200) self.action = action self.fact_id = fact_id self.category_entry = widgets.CategoryEntry( widget=self.get_widget('category')) self.activity_entry = widgets.ActivityEntry( widget=self.get_widget('activity'), category_widget=self.category_entry) self.cmdline = widgets.CmdLineEntry( parent=self.get_widget("cmdline box")) self.cmdline.connect("focus_in_event", self.on_cmdline_focus_in_event) self.cmdline.connect("focus_out_event", self.on_cmdline_focus_out_event) self.dayline = widgets.DayLine() self._gui.get_object("day_preview").add(self.dayline) self.description_box = self.get_widget('description') self.description_buffer = self.description_box.get_buffer() self.end_date = widgets.Calendar( widget=self.get_widget("end date"), expander=self.get_widget("end date expander")) self.end_time = widgets.TimeInput( parent=self.get_widget("end time box")) self.start_date = widgets.Calendar( widget=self.get_widget("start date"), expander=self.get_widget("start date expander")) self.start_time = widgets.TimeInput( parent=self.get_widget("start time box")) self.tags_entry = widgets.TagsEntry() self.get_widget("tags box").add(self.tags_entry) self.save_button = self.get_widget("save_button") # this will set self.master_is_cmdline self.cmdline.grab_focus() title = _("Update activity") if action == "edit" else _("Add activity") self.window.set_title(title) self.get_widget("delete_button").set_sensitive(action == "edit") if action == "edit": self.fact = runtime.storage.get_fact(fact_id) elif action == "clone": base_fact = runtime.storage.get_fact(fact_id) self.fact = base_fact.copy(start_time=dt.datetime.now(), end_time=None) else: self.fact = Fact(start_time=dt.datetime.now()) original_fact = self.fact # TODO: should use hday, not date. self.date = self.fact.date self.update_fields() self.update_cmdline(select=True) self.cmdline.original_fact = original_fact # This signal should be emitted only after a manual modification, # not at init time when cmdline might not always be fully parsable. self.cmdline.connect("changed", self.on_cmdline_changed) self.description_buffer.connect("changed", self.on_description_changed) self.start_time.connect("changed", self.on_start_time_changed) self.start_date.connect("day-selected", self.on_start_date_changed) self.start_date.expander.connect("activate", self.on_start_date_expander_activated) self.end_time.connect("changed", self.on_end_time_changed) self.end_date.connect("day-selected", self.on_end_date_changed) self.end_date.expander.connect("activate", self.on_end_date_expander_activated) self.activity_entry.connect("changed", self.on_activity_changed) self.category_entry.connect("changed", self.on_category_changed) self.tags_entry.connect("changed", self.on_tags_changed) self._gui.connect_signals(self) self.validate_fields() self.window.show_all()
def __init__(self, parent=None, fact_id=None, base_fact=None): gobject.GObject.__init__(self) self._gui = load_ui_file("edit_activity.ui") self.window = self.get_widget('custom_fact_window') self.window.set_size_request(600, 200) self.parent = parent # None if creating a new fact, instead of editing one self.fact_id = fact_id self.category_entry = widgets.CategoryEntry( widget=self.get_widget('category')) self.activity_entry = widgets.ActivityEntry( widget=self.get_widget('activity'), category_widget=self.category_entry) self.cmdline = widgets.CmdLineEntry() self.get_widget("command line box").add(self.cmdline) self.cmdline.connect("focus_in_event", self.on_cmdline_focus_in_event) self.cmdline.connect("focus_out_event", self.on_cmdline_focus_out_event) self.dayline = widgets.DayLine() self._gui.get_object("day_preview").add(self.dayline) self.description_box = self.get_widget('description') self.description_buffer = self.description_box.get_buffer() self.end_date = widgets.Calendar( widget=self.get_widget("end date"), expander=self.get_widget("end date expander")) self.end_time = widgets.TimeInput() self.get_widget("end time box").add(self.end_time) self.start_date = widgets.Calendar( widget=self.get_widget("start date"), expander=self.get_widget("start date expander")) self.start_time = widgets.TimeInput() self.get_widget("start time box").add(self.start_time) self.tags_entry = widgets.TagsEntry() self.get_widget("tags box").add(self.tags_entry) self.save_button = self.get_widget("save_button") # this will set self.master_is_cmdline self.cmdline.grab_focus() if fact_id: # editing self.fact = runtime.storage.get_fact(fact_id) self.date = self.fact.date self.window.set_title(_("Update activity")) else: self.window.set_title(_("Add activity")) self.date = hamster_today() self.get_widget("delete_button").set_sensitive(False) if base_fact: # start a clone now. self.fact = base_fact.copy(start_time=hamster_now(), end_time=None) else: self.fact = Fact(start_time=hamster_now()) original_fact = self.fact self.update_fields() self.update_cmdline(select=True) self.cmdline.original_fact = original_fact # This signal should be emitted only after a manual modification, # not at init time when cmdline might not always be fully parsable. self.cmdline.connect("changed", self.on_cmdline_changed) self.description_buffer.connect("changed", self.on_description_changed) self.start_time.connect("changed", self.on_start_time_changed) self.start_date.connect("day-selected", self.on_start_date_changed) self.start_date.expander.connect("activate", self.on_start_date_expander_activated) self.end_time.connect("changed", self.on_end_time_changed) self.end_date.connect("day-selected", self.on_end_date_changed) self.end_date.expander.connect("activate", self.on_end_date_expander_activated) self.activity_entry.connect("changed", self.on_activity_changed) self.category_entry.connect("changed", self.on_category_changed) self.tags_entry.connect("changed", self.on_tags_changed) self._gui.connect_signals(self) self.validate_fields() self.window.show_all()