[pygtk] How do I add Scrollbar in a TreeViewModel?

Paolo Bacci paolobacci at gmail.com
Wed Jun 4 02:38:26 WST 2008


Hi, it's my first email here and I want to add a scrollbar to my treeview
widget but i'm not being successful

I tried instantiating one Hscrollbar and one Vscrollbar(I need these 2
scrollbar) to add in the window but it said that only one widget could be
added and treeview is already there.

My code:

> import pygtk
> pygtk.require('2.0')
> import gtk
> class TreeView:
>
>     # close the window and quit
>     def delete_event(self, widget, event, data=3DNone):
>         gtk.main_quit()
>         return False
>
>     def begin(self, tagHTML):
>         # Create a new window
>
>         self.window =3D gtk.Window(gtk.WINDOW_TOPLEVEL)
>
>         self.window.set_title("DOM HTML View")
>
>         self.window.set_size_request(900, 500)
>
>         self.window.connect("delete_event", self.delete_event)
>
>         # create a TreeStore with one string column to use as the model
>         self.treestore =3D gtk.TreeStore(str)
>
>         self.tooltips =3D gtk.Tooltips()
>
>         createTree(self, tagHTML, None)
>
>         self.hscrollbar =3D gtk.HScrollbar(None)
>
>         self.vscrollbar =3D gtk.VScrollbar(None)
>
>         # create the TreeView using treestore
>         self.treeview =3D gtk.TreeView(self.treestore)
>
>         # create the TreeViewColumn to display the data
>         self.tvcolumn =3D gtk.TreeViewColumn('')
>
>         # add tvcolumn to treeview
>         self.treeview.append_column(self.tvcolumn)
>
>         # create a CellRendererText to render the data
>         self.cell =3D 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.treeview.set_search_column(0)
>
>         # Allow sorting on the column
>         self.tvcolumn.set_sort_column_id(0)
>
>         # Allow drag and drop reordering of rows
>         self.treeview.set_reorderable(True)
>
>         self.window.add(self.treeview)
>
>         self.window.show_all()
>
>         gtk.main()
>
> def createTree(self, tag, tParent):
>     try:
>         parent =3D self.treestore.append(tParent, [tag.sTagName])
>     except AttributeError:
>         print 'Error getting Attribute from object', tag
>         return 0
>     for i in xrange(tag.lTagChildren.__len__()):
>         nextTag =3D tag.lTagChildren[i]
>         createTree(self, nextTag, parent)
>

How do I add scrollbar to my tree model?
Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080603/9623dedf/at=
tachment.htm


More information about the pygtk mailing list