From a5c1c9260fb01204112f8b8868170d15dd05019c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 23 Jun 2009 04:28:43 +0200 Subject: added priorities with possibility to define different colors colors does not work correctly --- ui/todolist.glade | 162 ++++++++++++++++++++++++++++++------------------------ ui/ui_pygtk.py | 55 +++++++++++++----- 2 files changed, 131 insertions(+), 86 deletions(-) (limited to 'ui') diff --git a/ui/todolist.glade b/ui/todolist.glade index 0548f2c..9d08682 100644 --- a/ui/todolist.glade +++ b/ui/todolist.glade @@ -1,6 +1,6 @@ - + ToDo @@ -119,7 +119,6 @@ True True - True @@ -209,69 +208,54 @@ 7 7 - + True - - - True - True - - - - - True - True - True - Select... - 0 - - - - False - False - 1 - - + 0 + 0 + Title: - 1 - 2 - 2 - 3 - GTK_FILL + GTK_FILL + - + True 0 0 - Due: + Priority: - 2 - 3 + 1 + 2 GTK_FILL - + True - - - - True - True - - + 0 + 0 + Description: + + + 3 + 4 + GTK_FILL + GTK_FILL + + + + + True + True 1 2 - 1 - 2 - GTK_FILL + @@ -296,54 +280,73 @@ - + True - True + Low +Normal +High + + + True + True + False + Normal + + 1 2 - - - - - - True - 0 - 0 - Description: - - - 3 - 4 - GTK_FILL + 1 + 2 GTK_FILL - + True 0 0 - Priority: + Due: - 1 - 2 + 2 + 3 GTK_FILL - + True - 0 - 0 - Title: + + + True + True + + + + + True + True + True + Select... + 0 + + + + False + False + 1 + + - GTK_FILL - + 1 + 2 + 2 + 3 + GTK_FILL @@ -401,6 +404,21 @@ True + + + True + + + True + True + True + Today + 0 + + + + + 250 @@ -410,6 +428,8 @@ False False + 4 + 1 @@ -466,7 +486,7 @@ 4 - 1 + 2 diff --git a/ui/ui_pygtk.py b/ui/ui_pygtk.py index 7f257f1..f9941ff 100644 --- a/ui/ui_pygtk.py +++ b/ui/ui_pygtk.py @@ -41,7 +41,8 @@ class ui_pygtk: "on_edit_clicked" : self.edit_clicked_callback, "on_remove_clicked" : self.remove_clicked_callback, "on_add_clicked" : self.add_clicked_callback, - "on_select_date_clicked" : self.select_date_clicked_callback + "on_select_date_clicked" : self.select_date_clicked_callback, + "on_show_today_clicked" : self.show_today_clicked_callback } glade.signal_autoconnect(dic) @@ -52,12 +53,22 @@ 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())) + cellRenderer = gtk.CellRendererText() + column = gtk.TreeViewColumn('Todo', cellRenderer) + column.set_cell_data_func(cellRenderer, (lambda column, cell, model, iter, userdata=None: cell.set_property('markup', ("%s\n%s" % (gobject.markup_escape_text(model.get_value(iter, 0).getTitle()), gobject.markup_escape_text(model.get_value(iter, 0).getDescription()))).strip())), None) + column.set_reorderable(True) + column.set_resizable(True) + #column.set_sort_column_id(id) + self.main_window.todolist.append_column(column) + for column in ([['Id', 'getId'], ['ToDo', 'getTitle'], ['...', 'getDescription'], ['Erstellt am', ['getCreatedAt', + (lambda x: time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(x)))]], + ['Bis', ['getDue', (lambda x: time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(x)))]] ]): self.main_window.todolist.append_column(self.create_column(len(self.main_window.todolist.get_columns())+1, column[0], column[1], liststore)) @@ -90,9 +101,11 @@ class ui_pygtk: def item_data_callback(self, column, cell, model, iter, userdata=None): # method to get the data from the item object for one column data='' + rowdata = model.get_value(iter, 0) + if (userdata == None): # try to convert the object to string - data = model.get_value(iter, 0) + data = rowdata.__str__() else: if type(userdata) is type([]): data = getattr(model.get_value(iter, 0), userdata[0])() @@ -105,12 +118,14 @@ class ui_pygtk: # set the data as cell content if isinstance(cell, gtk.CellRendererText) : - cell.set_property('text', data) + cell.set_property('markup', gobject.markup_escape_text(data.__str__())) + + # set backround color + if rowdata.getPriority().getColor() is not None: + cell.set_property('foreground-gdk', gtk.gdk.Color(red=rowdata.getPriority().getColor(), blue=0, green=0)) elif isinstance(cell, gtk.CellRendererToggle) : cell.set_property('active', data) - else: - return data - + def about_clicked_callback(self, widget, data=None): # show the about dialog about_window = gtk.AboutDialog() @@ -164,6 +179,14 @@ class ui_pygtk: self.main_window.todolist.get_model().row_inserted(self.main_window.todolist.get_model().get_path(iter), iter) return + def select_date(self, date): + # select the given date in the calendar control in the date select dialog + 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]) + 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 @@ -171,11 +194,7 @@ class ui_pygtk: 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]) + self.select_date(date) if self.date_select_dialog.run(): date = self.date_select_dialog.calendar.get_date() @@ -188,7 +207,13 @@ class ui_pygtk: '%d.%m.%Y %H:%M', date)) self.date_select_dialog.hide() return - + + def show_today_clicked_callback(self, widget, data=None): + # show today in the calendar control in the date select dialog + self.select_date(time.localtime()) + return + + ######################################################### # helper methods ######################################################### @@ -212,11 +237,11 @@ class ui_pygtk: if (successfull): item.title = self.edit_dialog.title_field.get_text() - item.priority = self.edit_dialog.priority_field.get_text() + item.setPriority(name=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')) + item.due = int(time.strftime('%s', time.strptime(self.edit_dialog.due_field.get_text(), '%d.%m.%Y %H:%M'))) except: item.due = -1 -- cgit v1.2.3