views:

163

answers:

2

I am making a python tree visualizer using wxPython. It would be used like so:

show_tree([ 'A node with no children', ('A node with children', 'A child node', ('A child node with children', 'Another child')) ])

It worked fine but it shows a root with a value of "Tree". I made it so that it would create multiple roots but then learned that I wasn't allowed to do that. I reverted to the original code but used changed it from this: self.tree = wx.TreeCtrl(self) to this: self.tree = wx.TreeCtrl(self, style=wx.TR_HIDE_ROOT). It worked but it didn't show the little arrows on the side so you wouldn't know which nodes had children. Is there any way to hide the root node but keep the arrows. Note: I am on a Mac using Python version 2.5 and wxPython version 2.8.4.0.

A: 

Could wxTR_LINES_AT_ROOT be what you're looking for?

From wxWidgets documentation:

wxTR_LINES_AT_ROOT
  Use this style to show lines between root nodes.
  Only applicable if wxTR_HIDE_ROOT is set
  and wxTR_NO_LINES is not set.

disclaimer: this is for WX in c++, not python but it should be equivalent

Dashogun
A: 

Note: When I posted this I did not realize you were able to apply multiple styles to trees.
After trying everything, I realized that it was a combination of TR_HIDE_ROOT and TR_HAS_BUTTONS that does the trick of hiding the root while still showing arrows on the left side that allow you to collapse and hide nodes with children. This is the code I ended up using:

self.tree = wx.TreeCtrl(self, style=wx.TR_HAS_BUTTONS + wx.TR_HIDE_ROOT)
None