From 4bc9b503fa6070e491062d35967d20b37e9c94e0 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sun, 10 May 2009 19:40:47 +0200 Subject: 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 --- ui/todolist.glade | 6 ++++-- ui/ui_pygtk.py | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/todolist.glade b/ui/todolist.glade index 1b1a732..ee8c46c 100644 --- a/ui/todolist.glade +++ b/ui/todolist.glade @@ -1,6 +1,6 @@ - + ToDo @@ -141,6 +141,7 @@ gtk-add True 0 + @@ -151,6 +152,7 @@ gtk-remove True 0 + 1 @@ -270,7 +272,7 @@ True - + True True 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 ######################################################### -- cgit v1.2.3