How to make Multi-line leafs in wxTreeCtrl ?

Think of the possibility of linking a short leaf description to the appearance of a multiline explanation when the leaf is selected. Don't burden a user with details unless he asks for them...This is often a good writing technique: a bold short explanation of the multiple lines. Actually in writing, the details are typically only on the leaves.

Want to edit the explanation node? Double click and open an edit area.
Think xml.

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Thursday, August 21, 2003 3:18 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] How to make Multi-line leafs in wxTreeCtrl
?

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!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org