summaryrefslogtreecommitdiffstats
path: root/ui/ui_pygtk.py
diff options
context:
space:
mode:
Diffstat (limited to 'ui/ui_pygtk.py')
-rw-r--r--ui/ui_pygtk.py134
1 files changed, 87 insertions, 47 deletions
diff --git a/ui/ui_pygtk.py b/ui/ui_pygtk.py
index 4dd4b53..ad16173 100644
--- a/ui/ui_pygtk.py
+++ b/ui/ui_pygtk.py
@@ -5,18 +5,58 @@ import pygtk
pygtk.require('2.0')
import gtk
import gobject
-
+import item
from license import version, gpl_3
+import time
class ui_pygtk:
def __init__(self, itemList):
self.itemList = itemList
# create ui
- self.get_main_window(100, 100, 10, 10)
+ # 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)
+
+ 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)
+
+ # 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.get_main_window().show_all()
+ self.main_window.show_all()
gtk.main()
return
@@ -24,28 +64,20 @@ class ui_pygtk:
# create gui
#########################################################
- def get_main_window(self, initial_width=None, initial_height=None,
- initial_pos_x=None, initial_pos_y=None):
- if 'main_window' not in self.__dict__:
- 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) # very small minimal size
- self.main_window.resize(initial_width, initial_height)
- self.main_window.move(initial_pos_x, initial_pos_y)
-
- self.main_window.add(self.get_main_content_box())
- return self.main_window
-
- def get_main_content_box(self):
- if 'main_content_box' not in self.__dict__:
- self.main_content_box = gtk.VBox(False, 1)
- self.main_content_box.pack_start(self.get_main_menu(), False, True, 0)
- self.main_content_box.pack_start(self.get_todo_list(), True, True, 0)
- self.main_content_box.pack_start(self.get_statusbar(), False, False, 0)
- return self.main_content_box
-
+ def create_column(self, id, title, data, treemodel, cellRenderer=gtk.CellRendererText()):
+ column = gtk.TreeViewColumn(title, cellRenderer)
+
+ column.set_cell_data_func(cellRenderer, self.item_data_callback, data)
+ column.set_reorderable(True)
+ column.set_resizable(True)
+ column.set_sort_column_id(id)
+
+ treemodel.set_sort_func(id, (lambda model, iter1, iter2, userdata=None:
+ apply(cmp,
+ map((lambda x: self.item_data_callback(column, None, model, x, data)),
+ [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)
@@ -66,17 +98,17 @@ class ui_pygtk:
edit_action = gtk.Action('Edit', '_Edit', 'Edit', None)
help_action = gtk.Action('Help', '_Help', 'Help', None)
- self.action_group = gtk.ActionGroup('MainMenu')
- self.action_group.add_action_with_accel(quit_action, None) # None = default
- self.action_group.add_action(settings_action)
- self.action_group.add_action(file_action)
- self.action_group.add_action(edit_action)
- self.action_group.add_action(help_action)
- self.action_group.add_action(about_action)
+ 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(self.action_group, 0)
+ uimanager.insert_action_group(action_group, 0)
uimanager.add_ui_from_string('''
<ui>
<menubar name="MainMenu">
@@ -98,24 +130,32 @@ class ui_pygtk:
self.main_menu = uimanager.get_widget('/MainMenu')
return self.main_menu
-
- def get_todo_list(self):
- if 'todo_list' not in self.__dict__:
- self.todo_list = gtk.ScrolledWindow()
- self.todo_list.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
-
- return self.todo_list
-
- def get_statusbar(self):
- if 'statusbar' not in self.__dict__:
- self.statusbar = gtk.Statusbar()
- self.statusbar.show()
- return self.statusbar
#########################################################
# callbacks
#########################################################
-
+
+ def item_data_callback(self, column, cell, model, iter, userdata=None):
+ data=''
+ if (userdata == None):
+ # try to convert the object to string
+ data = model.get_value(iter, 0)
+ else:
+ if type(userdata) is type([]):
+ data = getattr(model.get_value(iter, 0), userdata[0])()
+
+ # modify data with the given functions
+ for i in xrange (1, len(userdata)):
+ data = userdata[i](data)
+ else:
+ data = getattr(model.get_value(iter, 0), userdata)()
+
+ # set the data as cell content
+ if cell is not None:
+ cell.set_property('text', data)
+ else:
+ return data
+
def destroy_callback(self, widget, data=None):
gtk.main_quit()
return