From e1b6d1a619aa8f75510d5b1812fe68459fb01578 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 20 May 2009 14:35:02 +0200 Subject: added date/time functionality named date and time input fields save date/time default date/time to -1 --- ui/todolist.glade | 12 ++++----- ui/ui_pygtk.py | 80 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 70 insertions(+), 22 deletions(-) (limited to 'ui') diff --git a/ui/todolist.glade b/ui/todolist.glade index 26adac2..0548f2c 100644 --- a/ui/todolist.glade +++ b/ui/todolist.glade @@ -1,6 +1,6 @@ - + ToDo @@ -425,10 +425,10 @@ True 3 - + True True - 12 0 23 1 10 10 + 12 0 23 1 10 0 True @@ -449,10 +449,10 @@ - + True True - 0 0 59 5 15 15 + 0 0 59 5 15 0 True @@ -485,7 +485,7 @@ True gtk-cancel True - 1 + 0 diff --git a/ui/ui_pygtk.py b/ui/ui_pygtk.py index 9c86382..7f257f1 100644 --- a/ui/ui_pygtk.py +++ b/ui/ui_pygtk.py @@ -20,13 +20,19 @@ class ui_pygtk: c=inspect.currentframe() glade = gtk.glade.XML (os.path.dirname(c.f_code.co_filename) + "/todolist.glade") self.main_window = glade.get_widget('main_window') + self.main_window.todolist = glade.get_widget('todolist') self.edit_dialog = glade.get_widget('edit_dialog') self.edit_dialog.title_field = glade.get_widget('title_field') self.edit_dialog.priority_field = glade.get_widget('priority_field') + self.edit_dialog.due_field = glade.get_widget('due_field') self.edit_dialog.desc_field = glade.get_widget('description_field') - self.main_window.todolist = glade.get_widget('todolist') + self.date_select_dialog = glade.get_widget('date_select_dialog') + self.date_select_dialog.calendar = glade.get_widget('calendar') + self.date_select_dialog.hour_field = glade.get_widget('hour_field') + self.date_select_dialog.minute_field = glade.get_widget('minute_field') + # connect the defined signales dic = {"on_menu_about_clicked" : self.about_clicked_callback, "on_menu_quit_clicked" : gtk.main_quit, @@ -34,7 +40,9 @@ class ui_pygtk: "on_treeview_row_activated" : self.item_double_clicked_callback, "on_edit_clicked" : self.edit_clicked_callback, "on_remove_clicked" : self.remove_clicked_callback, - "on_add_clicked" : self.add_clicked_callback} + "on_add_clicked" : self.add_clicked_callback, + "on_select_date_clicked" : self.select_date_clicked_callback + } glade.signal_autoconnect(dic) # fill the treeview with data @@ -44,6 +52,8 @@ class ui_pygtk: self.main_window.todolist.set_model(liststore) self.main_window.todolist.append_column(self.create_column(0, 'Finished', 'getCompleted', liststore, gtk.CellRendererToggle())) + # magic column + # self.main_window.todolist.append_column(self.create_column(1, 'Todo', 'getCompleted', liststore, gtk.CellRendererText())) for column in ([['Id', 'getId'], ['ToDo', 'getTitle'], ['...', 'getDescription'], @@ -116,40 +126,67 @@ class ui_pygtk: def edit_clicked_callback(self, widget, data=None): # edit btn click treeview = self.main_window.todolist - if (treeview.get_selection().count_selected_rows() == 1): - item = treeview.get_model().get_value(treeview.get_selection().get_selected()[1], 0) + path = treeview.get_model().get_path(treeview.get_selection().get_selected()[1]) + self.item_double_clicked_callback(treeview, path, 0) - if self.edit_item(item): - sort = list(treeview.get_model().get_sort_column_id()) - treeview.get_model().set_sort_column_id(0, gtk.SORT_ASCENDING) - apply( treeview.get_model(), sort) - def item_double_clicked_callback(self, treeview, path, view_column, user_data=None): # dbl click on treeview row to edit item model = treeview.get_model() item = model.get_value(model.get_iter(path), 0) if self.edit_item(item): + treeview.get_model().row_changed(path, model.get_iter(path)) sort = list(model.get_sort_column_id()) - model.set_sort_column_id(0, gtk.SORT_ASCENDING) - apply(model.set_sort_column_id, sort) + if sort[0]: + model.set_sort_column_id(0, gtk.SORT_ASCENDING) + apply(model.set_sort_column_id, sort) return def remove_clicked_callback(self, widget, data=None): # remove the selected element treeview = self.main_window.todolist if (treeview.get_selection().count_selected_rows() == 1): - item = treeview.get_model().get_value(treeview.get_selection().get_selected()[1], 0) - self.main_window.todolist.get_model().remove(treeview.get_selection().get_selected()[1]) + iter = treeview.get_selection().get_selected()[1] + path = treeview.get_model().get_path(iter) + + item = treeview.get_model().get_value(iter, 0) + self.main_window.todolist.get_model().remove(iter) self.itemList.remove(item) + treeview.get_model().row_deleted(path) return def add_clicked_callback(self, widget, data=None): # add a new element new_item = item.item() if self.edit_item(new_item): - self.main_window.todolist.get_model().append([new_item]) + iter = self.main_window.todolist.get_model().append([new_item]) self.itemList.append(new_item) + self.main_window.todolist.get_model().row_inserted(self.main_window.todolist.get_model().get_path(iter), iter) + return + + def select_date_clicked_callback(self, widget, data=None): + # display the dialog to select a date after clicked on the + # button in the edit dialog + try: + date = time.strptime(self.edit_dialog.due_field.get_text(), '%d.%m.%Y %H:%M') + except: + date = time.localtime() + + self.date_select_dialog.calendar.select_month(date[1] - 1, date[0]) + self.date_select_dialog.calendar.select_day(date[2]) + self.date_select_dialog.hour_field.set_value(date[3]) + self.date_select_dialog.minute_field.set_value(date[4]) + + if self.date_select_dialog.run(): + date = self.date_select_dialog.calendar.get_date() + date = (date[0], date[1] + 1, date[2], + int(self.date_select_dialog.hour_field.get_value()), + int(self.date_select_dialog.minute_field.get_value()), + 0, 0, 0, 0) + + self.edit_dialog.due_field.set_text(time.strftime( + '%d.%m.%Y %H:%M', date)) + self.date_select_dialog.hide() return ######################################################### @@ -161,17 +198,28 @@ class ui_pygtk: self.edit_dialog.title_field.set_text(item.getTitle()) self.edit_dialog.priority_field.set_text(item.getPriority().__str__()) + if item.getDue() != -1: + self.edit_dialog.due_field.set_text(time.strftime('%d.%m.%Y %H:%M', time.localtime(item.getDue()))) + else: + self.edit_dialog.due_field.set_text('') + text_buffer = gtk.TextBuffer() if item.getDescription() != None: text_buffer.set_text(item.getDescription()) self.edit_dialog.desc_field.set_buffer(text_buffer) successfull = self.edit_dialog.run() - self.edit_dialog.hide() - if (successfull): + if (successfull): item.title = self.edit_dialog.title_field.get_text() item.priority = self.edit_dialog.priority_field.get_text() item.description = text_buffer.get_text(text_buffer.get_start_iter(), text_buffer.get_end_iter()) + try: + item.due = time.strftime('%s', time.strptime(self.edit_dialog.due_field.get_text(), '%d.%m.%Y %H:%M')) + except: + item.due = -1 + + + self.edit_dialog.hide() return successfull -- cgit v1.2.3