diff options
-rw-r--r-- | item.py | 2 | ||||
-rw-r--r-- | ui/todolist.glade | 12 | ||||
-rw-r--r-- | ui/ui_pygtk.py | 80 |
3 files changed, 71 insertions, 23 deletions
@@ -28,7 +28,7 @@ class item: self.description = '' self.completed = 0 self.removed = 0 - self.due = 0 + self.due = -1 def setId(self, id): if self.id == -1: 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 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> -<!--Generated with glade3 3.4.5 on Wed May 20 00:19:39 2009 --> +<!--Generated with glade3 3.4.5 on Wed May 20 13:13:43 2009 --> <glade-interface> <widget class="GtkWindow" id="main_window"> <property name="title" translatable="yes">ToDo</property> @@ -425,10 +425,10 @@ <property name="visible">True</property> <property name="spacing">3</property> <child> - <widget class="GtkSpinButton" id="spinbutton1"> + <widget class="GtkSpinButton" id="hour_field"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="adjustment">12 0 23 1 10 10</property> + <property name="adjustment">12 0 23 1 10 0</property> <property name="wrap">True</property> </widget> <packing> @@ -449,10 +449,10 @@ </packing> </child> <child> - <widget class="GtkSpinButton" id="spinbutton2"> + <widget class="GtkSpinButton" id="minute_field"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="adjustment">0 0 59 5 15 15</property> + <property name="adjustment">0 0 59 5 15 0</property> <property name="wrap">True</property> </widget> <packing> @@ -485,7 +485,7 @@ <property name="receives_default">True</property> <property name="label" translatable="yes">gtk-cancel</property> <property name="use_stock">True</property> - <property name="response_id">1</property> + <property name="response_id">0</property> </widget> </child> <child> 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 |