diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2009-05-10 19:40:47 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2009-05-10 19:40:47 +0200 |
commit | 4bc9b503fa6070e491062d35967d20b37e9c94e0 (patch) | |
tree | 9d0d647a4a006db8adf18240418f72b80b4bd0bd /ui/ui_pygtk.py | |
parent | 91e7bba27adccc2d9815afed104b678366ecb62a (diff) | |
download | todolist-4bc9b503fa6070e491062d35967d20b37e9c94e0.tar.gz todolist-4bc9b503fa6070e491062d35967d20b37e9c94e0.tar.xz todolist-4bc9b503fa6070e491062d35967d20b37e9c94e0.zip |
add/remove support
change db layout to version 0.4, with removed column
only display items, that are not removed
created events for add, remove buttons
remove, __delitem__, contains in itemList as proxy to itemList.data
added default constructor (if nothing is set) for item to create a new
Diffstat (limited to '')
-rw-r--r-- | ui/ui_pygtk.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/ui/ui_pygtk.py b/ui/ui_pygtk.py index d41d34d..9c86382 100644 --- a/ui/ui_pygtk.py +++ b/ui/ui_pygtk.py @@ -8,6 +8,8 @@ import gtk.glade import gobject import item import time +import inspect +import os from license import version, gpl_3 class ui_pygtk: @@ -15,7 +17,8 @@ class ui_pygtk: self.itemList = itemList # load ui from glade file - glade = gtk.glade.XML ("todolist.glade") + 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.edit_dialog = glade.get_widget('edit_dialog') @@ -29,7 +32,9 @@ class ui_pygtk: "on_menu_quit_clicked" : gtk.main_quit, "on_main_window_destroy" : gtk.main_quit, "on_treeview_row_activated" : self.item_double_clicked_callback, - "on_edit_clicked" : self.edit_clicked_callback} + "on_edit_clicked" : self.edit_clicked_callback, + "on_remove_clicked" : self.remove_clicked_callback, + "on_add_clicked" : self.add_clicked_callback} glade.signal_autoconnect(dic) # fill the treeview with data @@ -130,6 +135,23 @@ class ui_pygtk: 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]) + self.itemList.remove(item) + 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]) + self.itemList.append(new_item) + return + ######################################################### # helper methods ######################################################### |