diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2009-05-08 22:38:50 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2009-05-08 22:38:50 +0200 |
commit | 91e7bba27adccc2d9815afed104b678366ecb62a (patch) | |
tree | ae704380d018728901db555bbbcadfb478826af0 /ui | |
parent | 570ca6350777acc69429300bea4cc8f8eb97267e (diff) | |
download | todolist-91e7bba27adccc2d9815afed104b678366ecb62a.tar.gz todolist-91e7bba27adccc2d9815afed104b678366ecb62a.tar.xz todolist-91e7bba27adccc2d9815afed104b678366ecb62a.zip |
gui redesign in glade, database layout 0.3
complete redesign of the gui with glade-3
gui loading with gtk.glade.XML
move to db layout 0.3 with completed column
Diffstat (limited to 'ui')
-rw-r--r-- | ui/todolist.glade | 448 | ||||
-rw-r--r-- | ui/ui_pygtk.py | 187 |
2 files changed, 532 insertions, 103 deletions
diff --git a/ui/todolist.glade b/ui/todolist.glade new file mode 100644 index 0000000..1b1a732 --- /dev/null +++ b/ui/todolist.glade @@ -0,0 +1,448 @@ +<?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 --> +<glade-interface> + <widget class="GtkWindow" id="main_window"> + <property name="title" translatable="yes">ToDo</property> + <signal name="destroy" handler="on_main_window_destroy"/> + <child> + <widget class="GtkVBox" id="vbox1"> + <property name="visible">True</property> + <child> + <widget class="GtkMenuBar" id="menubar1"> + <property name="visible">True</property> + <child> + <widget class="GtkMenuItem" id="menuitem1"> + <property name="visible">True</property> + <property name="label" translatable="yes">_File</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu1"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem5"> + <property name="visible">True</property> + <property name="label" translatable="yes">gtk-quit</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + <signal name="activate" handler="on_menu_quit_clicked"/> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem2"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Edit</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu2"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem6"> + <property name="visible">True</property> + <property name="label" translatable="yes">gtk-cut</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem7"> + <property name="visible">True</property> + <property name="label" translatable="yes">gtk-copy</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem8"> + <property name="visible">True</property> + <property name="label" translatable="yes">gtk-paste</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem9"> + <property name="visible">True</property> + <property name="label" translatable="yes">gtk-delete</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem3"> + <property name="visible">True</property> + <property name="label" translatable="yes">_View</property> + <property name="use_underline">True</property> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem4"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Help</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu3"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="imagemenuitem10"> + <property name="visible">True</property> + <property name="label" translatable="yes">gtk-about</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + <signal name="activate" handler="on_menu_about_clicked"/> + </widget> + </child> + </widget> + </child> + </widget> + </child> + </widget> + <packing> + <property name="expand">False</property> + </packing> + </child> + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <child> + <widget class="GtkTreeView" id="todolist"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="rules_hint">True</property> + <signal name="row_activated" handler="on_treeview_row_activated"/> + </widget> + </child> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <widget class="GtkHButtonBox" id="hbuttonbox1"> + <property name="visible">True</property> + <property name="spacing">7</property> + <property name="layout_style">GTK_BUTTONBOX_SPREAD</property> + <child> + <widget class="GtkButton" id="button1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-add</property> + <property name="use_stock">True</property> + <property name="response_id">0</property> + </widget> + </child> + <child> + <widget class="GtkButton" id="button2"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-remove</property> + <property name="use_stock">True</property> + <property name="response_id">0</property> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <widget class="GtkButton" id="button8"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-edit</property> + <property name="use_stock">True</property> + <property name="response_id">0</property> + <signal name="clicked" handler="on_edit_clicked"/> + </widget> + <packing> + <property name="position">2</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="padding">7</property> + <property name="position">2</property> + </packing> + </child> + <child> + <widget class="GtkStatusbar" id="statusbar1"> + <property name="visible">True</property> + <property name="spacing">2</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="position">3</property> + </packing> + </child> + </widget> + </child> + </widget> + <widget class="GtkDialog" id="date_select_dialog"> + <property name="border_width">5</property> + <property name="resizable">False</property> + <property name="modal">True</property> + <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property> + <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> + <child internal-child="vbox"> + <widget class="GtkVBox" id="dialog-vbox2"> + <property name="visible">True</property> + <property name="spacing">2</property> + <child> + <widget class="GtkCalendar" id="calendar1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="year">2009</property> + <property name="month">4</property> + <property name="day">5</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child internal-child="action_area"> + <widget class="GtkHButtonBox" id="dialog-action_area2"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_END</property> + <child> + <widget class="GtkButton" id="button6"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-cancel</property> + <property name="use_stock">True</property> + <property name="response_id">1</property> + </widget> + </child> + <child> + <widget class="GtkButton" id="button7"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-ok</property> + <property name="use_stock">True</property> + <property name="response_id">0</property> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="pack_type">GTK_PACK_END</property> + </packing> + </child> + </widget> + </child> + </widget> + <widget class="GtkDialog" id="edit_dialog"> + <property name="border_width">5</property> + <property name="title" translatable="yes">Edit</property> + <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property> + <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> + <child internal-child="vbox"> + <widget class="GtkVBox" id="dialog-vbox1"> + <property name="visible">True</property> + <property name="spacing">2</property> + <child> + <widget class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="n_rows">4</property> + <property name="n_columns">2</property> + <property name="column_spacing">7</property> + <property name="row_spacing">7</property> + <child> + <widget class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <child> + <widget class="GtkEntry" id="entry2"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </widget> + </child> + <child> + <widget class="GtkButton" id="button5"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">Select...</property> + <property name="response_id">0</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label4"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="yalign">0</property> + <property name="label" translatable="yes">Due:</property> + </widget> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkComboBoxEntry" id="comboboxentry1"> + <property name="visible">True</property> + <property name="items" translatable="yes"></property> + <child internal-child="entry"> + <widget class="GtkEntry" id="priority_field"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </widget> + </child> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow2"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="shadow_type">GTK_SHADOW_IN</property> + <child> + <widget class="GtkTextView" id="description_field"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </widget> + </child> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="title_field"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="yalign">0</property> + <property name="label" translatable="yes">Description:</property> + </widget> + <packing> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="yalign">0</property> + <property name="label" translatable="yes">Priority:</property> + </widget> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="yalign">0</property> + <property name="label" translatable="yes">Title:</property> + </widget> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + </widget> + <packing> + <property name="padding">7</property> + <property name="position">1</property> + </packing> + </child> + <child internal-child="action_area"> + <widget class="GtkHButtonBox" id="dialog-action_area1"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_END</property> + <child> + <widget class="GtkButton" id="button3"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-cancel</property> + <property name="use_stock">True</property> + <property name="response_id">0</property> + </widget> + </child> + <child> + <widget class="GtkButton" id="button4"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="label" translatable="yes">gtk-ok</property> + <property name="use_stock">True</property> + <property name="response_id">1</property> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="pack_type">GTK_PACK_END</property> + </packing> + </child> + </widget> + </child> + </widget> +</glade-interface> diff --git a/ui/ui_pygtk.py b/ui/ui_pygtk.py index ad16173..d41d34d 100644 --- a/ui/ui_pygtk.py +++ b/ui/ui_pygtk.py @@ -4,67 +4,57 @@ import pygtk pygtk.require('2.0') import gtk +import gtk.glade import gobject import item -from license import version, gpl_3 import time +from license import version, gpl_3 class ui_pygtk: def __init__(self, itemList): self.itemList = itemList - # create ui - # main window - self.main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.main_window.connect('destroy', self.destroy_callback) - - self.main_window.set_title('ToDo') - self.main_window.set_size_request(10, 10) - self.main_window.resize(100, 100) - self.main_window.move(10, 10) - - # todolist scroll window - todo_scroll = gtk.ScrolledWindow() - todo_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - + # load ui from glade file + glade = gtk.glade.XML ("todolist.glade") + self.main_window = glade.get_widget('main_window') + + 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.desc_field = glade.get_widget('description_field') + self.main_window.todolist = glade.get_widget('todolist') + + # connect the defined signales + dic = {"on_menu_about_clicked" : self.about_clicked_callback, + "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} + glade.signal_autoconnect(dic) + + # fill the treeview with data liststore = gtk.ListStore(object) for items in self.itemList: liststore.append([items]) - todolist = gtk.TreeView(liststore) - - for i, column in enumerate ([['Id', 'getId'], - ['ToDo', 'getTitle'], - ['...', 'getDescription'], - ['Erstellt am', ['getCreatedAt', - (lambda x: time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(x)))]] - ]): - todolist.append_column(self.create_column(i, column[0], column[1], liststore)) - - todo_scroll.add(todolist) + self.main_window.todolist.set_model(liststore) + self.main_window.todolist.append_column(self.create_column(0, 'Finished', 'getCompleted', liststore, gtk.CellRendererToggle())) + for column in ([['Id', 'getId'], + ['ToDo', 'getTitle'], + ['...', 'getDescription'], + ['Erstellt am', ['getCreatedAt', + (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)) - # statusbar - statusbar = gtk.Statusbar() - - # join elemnts - # main content box - main_content_box = gtk.VBox(False, 1) - main_content_box.pack_start(self.get_main_menu(), False, True, 0) - main_content_box.pack_start(todo_scroll, True, True, 0) - main_content_box.pack_start(statusbar, False, False, 0) - - self.main_window.add(main_content_box) - # start ui self.main_window.show_all() gtk.main() return - ######################################################### - # create gui - ######################################################### - def create_column(self, id, title, data, treemodel, cellRenderer=gtk.CellRendererText()): + # abstract mmethod to create a column for the data + # from the item objects in the treeview column = gtk.TreeViewColumn(title, cellRenderer) column.set_cell_data_func(cellRenderer, self.item_data_callback, data) @@ -78,64 +68,12 @@ class ui_pygtk: [iter1, iter2])))) return column - def get_main_menu(self): - if 'mainmenu' not in self.__dict__: - quit_action = gtk.Action('Quit', '_Quit', 'Exit Todolist', gtk.STOCK_QUIT) - quit_action.connect('activate', self.destroy_callback) - - settings_action = gtk.Action('Settings', '_Settings', 'Settings', gtk.STOCK_PREFERENCES) - settings_action.set_property('sensitive', False) - #settings_action.connect('activate', self.show_settings) - - #delete_action = gtk.Action('Delete', '_Delete', 'Delete a post', - # gtk.STOCK_DELETE) - #delete_action.connect('activate', self.delete_tweet) - - about_action = gtk.Action('About', '_About', 'About Todolist', gtk.STOCK_ABOUT) - about_action.connect('activate', self.about_click_callback) - - file_action = gtk.Action('File', '_File', 'File', None) - edit_action = gtk.Action('Edit', '_Edit', 'Edit', None) - help_action = gtk.Action('Help', '_Help', 'Help', None) - - action_group = gtk.ActionGroup('MainMenu') - action_group.add_action_with_accel(quit_action, None) # None = default - action_group.add_action(settings_action) - action_group.add_action(file_action) - action_group.add_action(edit_action) - action_group.add_action(help_action) - action_group.add_action(about_action) - - # definition of the UI - uimanager = gtk.UIManager() - uimanager.insert_action_group(action_group, 0) - uimanager.add_ui_from_string(''' - <ui> - <menubar name="MainMenu"> - <menu action="File"> - <menuitem action="Quit" /> - </menu> - <menu action="Edit"> - <separator /> - <menuitem action="Settings" /> - </menu> - <menu action="Help"> - <menuitem action="About" /> - </menu> - </menubar> - </ui> - ''') - - self.main_window.add_accel_group(uimanager.get_accel_group()) - self.main_menu = uimanager.get_widget('/MainMenu') - - return self.main_menu - ######################################################### # callbacks ######################################################### def item_data_callback(self, column, cell, model, iter, userdata=None): + # method to get the data from the item object for one column data='' if (userdata == None): # try to convert the object to string @@ -151,18 +89,15 @@ class ui_pygtk: data = getattr(model.get_value(iter, 0), userdata)() # set the data as cell content - if cell is not None: + if isinstance(cell, gtk.CellRendererText) : cell.set_property('text', data) + elif isinstance(cell, gtk.CellRendererToggle) : + cell.set_property('active', data) else: return data - def destroy_callback(self, widget, data=None): - gtk.main_quit() - return - - def about_click_callback(self, widget, data=None): - """Show the about dialog.""" - + def about_clicked_callback(self, widget, data=None): + # show the about dialog about_window = gtk.AboutDialog() about_window.set_name('Todolist') about_window.set_version(version) @@ -172,3 +107,49 @@ class ui_pygtk: about_window.run() about_window.hide() return + + 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) + + 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): + sort = list(model.get_sort_column_id()) + model.set_sort_column_id(0, gtk.SORT_ASCENDING) + apply(model.set_sort_column_id, sort) + return + + ######################################################### + # helper methods + ######################################################### + + def edit_item(self, item): + # helper method to edit item + self.edit_dialog.title_field.set_text(item.getTitle()) + self.edit_dialog.priority_field.set_text(item.getPriority().__str__()) + + 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): + 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()) + + return successfull |