How to make Multi-line leafs in wxTreeCtrl ?

I'm about to port a toy project (a sort of outliner program) from
Tkinter to wxPython. (And learn wxPython in the process.) The main
part of it is a tree widget, which must have multi-line leafs. The idea
is that the contents of the leafs will be between couple of words and
couple of lines long, and I want to see all of it, without scrolling
horizontally.

Can I achieve this with wxTreeCtrl ? (I looked at the SplitTree demo,
but thats not good enough as I want the text to appear in the tree and not
as seperate widgets.)

Alternatively, is there a way to make a widget like this? I had several
ideas, of which the most promising was to use wxOGL. However, I'm not
sure wxOGL has everything I need. I would have to:
- Create text on the canvas. It needs to be wrapped (that is, I set the
  upper-left coordinates, and the width of the text, and rest should be
  automatic, the text should be broken into multiple lines as
  necessary).
- Edit the text. (In-place, not in a seperate
  widget. Basically I would need something like wxTextCtrl on the
  canvas. I think this could be done by re-inventing wxTextCtrl as a
  wxOGL wxShape, provided I have a basic set of features, like the
  above-mentioned line-wrapping.)
- Move the text efficiently. (I think wxShape's Move method will do,
  although I didn't test the performance.)

I looked at the demo, and it had some text in a wxDividedShape which did
the sort of word-wrapping I was thinking about, however if the height of
the wxDividedShape wasn't big enough, only the first couple of lines
were visible.
How could I set the height so that all of the text is visible?
(It looked like the text wasn't a seperate object, but an
attribute of the DividedShape's Region. That seems a bit strange, as if
I couldn't get at the text object, only through the wxShapeRegion's api.
For example I found a method that returned the Region's size, but not
one which would return the text's size.)
I also tried wxTextShape, but couldn't get that to word-wrap.

Thanks in advance,
Abel Daniel

Abel Daniel wrote:

I'm about to port a toy project (a sort of outliner program) from
Tkinter to wxPython. (And learn wxPython in the process.) The main
part of it is a tree widget, which must have multi-line leafs. The idea
is that the contents of the leafs will be between couple of words and
couple of lines long, and I want to see all of it, without scrolling
horizontally.

Can I achieve this with wxTreeCtrl ?

Unfortunatly not. Only a single line of text can be used.

(I looked at the SplitTree demo,
but thats not good enough as I want the text to appear in the tree and not
as seperate widgets.)

Alternatively, is there a way to make a widget like this? I had several
ideas, of which the most promising was to use wxOGL. However, I'm not
sure wxOGL has everything I need.

Until we have a better canvas type of widget then the only other alternative is to do it at a lower level and handle all the drawing and the keyboard/mouse events yourself.

I would have to:
- Create text on the canvas. It needs to be wrapped (that is, I set the
  upper-left coordinates, and the width of the text, and rest should be
  automatic, the text should be broken into multiple lines as
  necessary).

You'll probably have to derive your own Shape class to do this. OGL shapes always expect their size to be set by someone else and don't have the concept of best size or anything, and I expect that if a Shape changes it's own size that you'll need to ensure that the affected region of the canvas gets refreshed. You should be able to derive a WrappedTextShape from wxShape and overload OnDraw(self, dc) to do the drawing

- Edit the text. (In-place, not in a seperate
  widget. Basically I would need something like wxTextCtrl on the
  canvas. I think this could be done by re-inventing wxTextCtrl as a
  wxOGL wxShape, provided I have a basic set of features, like the
  above-mentioned line-wrapping.)

The easiest way to do this is to create a wxTextCtrl on the canvas at the same location and size as the Shape when the user wishes to edit the text. (After a double click or something.) When done editing (after a certain key or clicking elsewhere on the canvas) then update the Shape and then Destroy the wxTextCtrl.

- Move the text efficiently. (I think wxShape's Move method will do,
  although I didn't test the performance.)

Shouldn't be a problem.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!