diff options
-rw-r--r-- | item.py | 21 | ||||
-rw-r--r-- | itemList.py | 11 | ||||
-rw-r--r-- | storage/sqlite.py | 24 | ||||
-rw-r--r-- | ui/todolist.glade | 6 | ||||
-rw-r--r-- | ui/ui_pygtk.py | 26 |
5 files changed, 73 insertions, 15 deletions
@@ -1,22 +1,32 @@ # -*- coding: utf-8 -*- +import time class item: readOnly = ['id'] - def __init__(self, title=None, created=None, priority=None, description=None, completed=None, row=None): + def __init__(self, title=None, created=None, priority=None, description=None, completed=None, removed=None, row=None): + self.__dict__['id'] = -1 + if title != None: - self.__dict__['id'] = -1 self.title = title self.created = created self.priority = priority self.description = description self.completed = completed - else: + self.removed = removed + elif row != None: id = row[0] - + row.__delitem__(0) apply(self.__init__, row) self.__dict__['id'] = id + else: + self.title = '' + self.created = time.time() + self.priority = '' + self.description = '' + self.completed = 0 + self.removed = 0 def setId(self, id): if self.id == -1: @@ -40,6 +50,9 @@ class item: def getCompleted(self): return self.completed + def getRemoved(self): + return self.removed + def __setattr__(self, name, value): if name not in item.readOnly: if name not in self.__dict__ or self.__dict__[name] != value: diff --git a/itemList.py b/itemList.py index 6252946..7dc2944 100644 --- a/itemList.py +++ b/itemList.py @@ -14,6 +14,17 @@ class itemList: def __setitem__(self, idx, item): self.data[idx] = item + def __delitem__(self, key): + self.date[key].removed = True + self.data.__delitem__(key) + + def remove(self, item): + item.removed = True + self.data.remove(item) + + def __contians__(self, item): + return (item in self.data) + def append(self, item): item.observer = self self.data.append(item) diff --git a/storage/sqlite.py b/storage/sqlite.py index bfdae42..7a8e1d8 100644 --- a/storage/sqlite.py +++ b/storage/sqlite.py @@ -6,7 +6,7 @@ from item import item from pysqlite2 import dbapi2 as sqliteBackend class sqlite(storageBase): - dbVersion = '0.3' + dbVersion = '0.4' def __init__(self): self.con = sqliteBackend.connect(self.getConfigDir() + '/data.sqlite') @@ -34,7 +34,9 @@ class sqlite(storageBase): title TEXT(255), createdAt INTEGER, priority INTEGER, - desc BLOB + desc BLOB, + completed INTEGER(1) DEFAULT (0), + removed INTEGER(1) DEFAULT (0) )''') self.cur.execute('drop table if exists control') @@ -61,6 +63,12 @@ class sqlite(storageBase): self.con.commit() updateFrom = ('0.3',) + if updateFrom == ('0.3',): + self.cur.execute('''alter table todo + add removed INTEGER(1) DEFAULT (0)''') + self.con.commit() + updateFrom = ('0.4',) + self.cur.execute("update control set value = ? where setting = 'db-version'", updateFrom) self.con.commit() @@ -69,7 +77,7 @@ class sqlite(storageBase): def load(self): items = itemList(self) - todos = self.cur.execute('select * from todo').fetchall() + todos = self.cur.execute('select * from todo where removed=0').fetchall() for todo in todos: items += item(row=list(todo)) @@ -77,11 +85,13 @@ class sqlite(storageBase): def notifyChange(self, sender): if sender.getId() >= 0: - self.cur.execute('update todo set title=?, createdAt=?, priority=?, desc=?, completed=? where id=?', - (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getDescription(), sender.getCompleted(), sender.getId())) + self.cur.execute('update todo set title=?, createdAt=?, priority=?, desc=?, completed=?, removed=? where id=?', + (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), + sender.getDescription(), sender.getCompleted(), sender.getRemoved(), sender.getId())) self.con.commit() else: - self.cur.execute('insert into todo (title, createdAt, priority, desc, completed) VALUES (?, ?, ?, ?, ?)', - (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getDescription(), sender.getCompleted())) + self.cur.execute('insert into todo (title, createdAt, priority, desc, completed, removed) VALUES (?, ?, ?, ?, ?, ?)', + (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), + sender.getDescription(), sender.getCompleted(), sender.getRemoved())) self.con.commit() sender.setId(self.cur.execute('select last_insert_rowid()').fetchone()[0]) 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 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> -<!--Generated with glade3 3.4.5 on Fri May 8 22:04:24 2009 --> +<!--Generated with glade3 3.4.5 on Sat May 9 23:38:34 2009 --> <glade-interface> <widget class="GtkWindow" id="main_window"> <property name="title" translatable="yes">ToDo</property> @@ -141,6 +141,7 @@ <property name="label" translatable="yes">gtk-add</property> <property name="use_stock">True</property> <property name="response_id">0</property> + <signal name="clicked" handler="on_add_clicked"/> </widget> </child> <child> @@ -151,6 +152,7 @@ <property name="label" translatable="yes">gtk-remove</property> <property name="use_stock">True</property> <property name="response_id">0</property> + <signal name="clicked" handler="on_remove_clicked"/> </widget> <packing> <property name="position">1</property> @@ -270,7 +272,7 @@ <widget class="GtkHBox" id="hbox1"> <property name="visible">True</property> <child> - <widget class="GtkEntry" id="entry2"> + <widget class="GtkEntry" id="entry1"> <property name="visible">True</property> <property name="can_focus">True</property> </widget> 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 ######################################################### |