Sunday, December 20, 2009

Bending Gtk.TreeView to my Will

Today I made some progress in bending the Gtk.Treeview to my will, and making a proper easy and fun Quidget, called DictionaryGrid. Notice that key? is a column of checkboxes, and price is a column of spinner controls formatted with two decimal digits. This is done automatically by the DictionaryGrid.

The code for creating this grid is easy and fun, as the behavior is controlled simply through choosing the right name for keys:
    dicts = [{"ID": 0, "key?": True, "price":0.00,"tags" : "aaa bbb ccc","_foo":"bar"},
{"ID": 1, "key?": False, "price":2.00,"tags" : "bbb ccc ddd","_foo":"bar"},
{"ID": 2, "key?": True, "price":3.00,"tags" : "ccc ddd eee","_foo":"bar"},
{"ID": 3, "key?": False, "price":4.00,"tags" : "ddd eee fff","_foo":"bar"},
{"ID": 4, "key?": True, "price":5.00,"tags" : "eee fff ggg","_foo":"bar"}]
#create and show a test window
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.set_title("DictionaryGrid Test Window")
win.connect("destroy",gtk.main_quit)
win.show()

#create a top level container
vbox = gtk.VBox(False, False)
vbox.show()
win.add(vbox)

#create a test widget with test database values
grid = DictionaryGrid(dicts)



My accomplishments today were:
  • Started implementing the "conventions" system. A key of "id", will be automatically set to an integer column, for proper sorting.
  • A key of "price" will automatically be formatted as currency, and will also be presented in a spinner control. I will change the id columns to use the spinner as well, so that all numerical columns will automatically use spinners.
Due to specifying types, the persistence of any edits are broken at the moment. My next step will be to ensure proper conversion to the necessary types for the ListStore. This may have the strange effect of changing the type in the dictionary that backs the store. I'm not sure what the right thing to do there is. I like that if you hand a the DictionaryGrid a string that represents the number, the DictionaryGrid does the right thing. However, handing back a different type seems unexpected. Perhaps the DictionaryGrid should remember if the original type was a string, and if so, convert back to that before it stores the value back into the dictionary.


About Quidgets
Quickly + Widgets = Quidgets
There is a Launchpad Project for Quidgets
The most up to date changes are in the Quidgets Trunk Branch
You can install Quidgets from the my PPA

2 comments: