summaryrefslogtreecommitdiffstats
path: root/ui/ui_pygtk.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-05-20 14:35:02 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2009-05-20 14:35:02 +0200
commite1b6d1a619aa8f75510d5b1812fe68459fb01578 (patch)
tree6ba790734eb4068cf0b1fe25dd743f7fcf9fd252 /ui/ui_pygtk.py
parent40204e2d53fb9212a00bff4cb56cf0d0c11da70f (diff)
downloadtodolist-e1b6d1a619aa8f75510d5b1812fe68459fb01578.tar.gz
todolist-e1b6d1a619aa8f75510d5b1812fe68459fb01578.tar.xz
todolist-e1b6d1a619aa8f75510d5b1812fe68459fb01578.zip
added date/time functionality
named date and time input fields save date/time default date/time to -1
Diffstat (limited to '')
-rw-r--r--ui/ui_pygtk.py80
1 files changed, 64 insertions, 16 deletions
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