diff options
Diffstat (limited to 'ui/ui_pygtk.py')
-rw-r--r-- | ui/ui_pygtk.py | 55 |
1 files changed, 40 insertions, 15 deletions
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', ("<b>%s</b>\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 |