Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/treeview.py
diff options
context:
space:
mode:
Diffstat (limited to 'treeview.py')
-rw-r--r--treeview.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/treeview.py b/treeview.py
new file mode 100644
index 0000000..2a8da2b
--- /dev/null
+++ b/treeview.py
@@ -0,0 +1,55 @@
+# [SNIPPET_NAME: Basic Tree View]
+# [SNIPPET_CATEGORIES: PyGTK]
+# [SNIPPET_DESCRIPTION: Create a basic tree view]
+# [SNIPPET_DOCS: http://www.pygtk.org/docs/pygtk/class-gtktreeview.html, http://www.pygtk.org/pygtk2tutorial/ch-TreeViewWidget.html]
+
+# example basictreeview.py
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+class TreeView(gtk.TreeView):
+
+ def __init__(self):
+
+ gtk.TreeView.__init__(self)
+
+ # create a TreeStore with one string column to use as the model
+ self.treestore = gtk.TreeStore(str)
+
+ # we'll add some data now - 4 rows with 3 child rows each
+ for parent in range(4):
+ piter = self.treestore.append(None, ['parent %i' % parent])
+ for child in range(3):
+ self.treestore.append(piter, ['child %i of parent %i' %
+ (child, parent)])
+
+ # create the TreeView using treestore
+ self.set_model(self.treestore)
+
+ # create the TreeViewColumn to display the data
+ self.tvcolumn = gtk.TreeViewColumn('Column 0')
+
+ # add tvcolumn to treeview
+ self.append_column(self.tvcolumn)
+
+ # create a CellRendererText to render the data
+ self.cell = gtk.CellRendererText()
+
+ # add the cell to the tvcolumn and allow it to expand
+ self.tvcolumn.pack_start(self.cell, True)
+
+ # set the cell "text" attribute to column 0 - retrieve text
+ # from that column in treestore
+ self.tvcolumn.add_attribute(self.cell, 'text', 0)
+
+ # make it searchable
+ self.set_search_column(0)
+
+ # Allow sorting on the column
+ self.tvcolumn.set_sort_column_id(0)
+
+ # Allow drag and drop reordering of rows
+ self.set_reorderable(True)
+ self.show_all()