|Subject:||Re: [wxPython-users] How to handle word-wrapping static text?|
|From:||Erik Westra ("ewe...@gmail.com)|
|Date:||Dec 22, 2004 4:15:20 pm|
I might be missing something here, but wouldn't HTMLWindow do the job? Needs a bit of html wrapped around (and maybe inserted in) the text, but that's simple enough.
I've done that in a couple of places, but an HTML window doesn't satisfy the requirement of taking up exactly the height of its contents -- it uses a scrolling window and just takes the same size regardless of the amount of text to be displayed, which works sometimes (when you have nothing below the text to display, or can have a fixed-size window), but looks terribly unprofessional in many cases. Let me give you an example of the type of problem I'm up against.
In my system, I often get messages returned by some remote part of the system (possibly from a background thread, possibly even from a program running on a different computer), and these messages must be displayed by the GUI. These messages might be as short as "The operation completed successfully", or they might include a more detailed description of why an operation failed, which can extend to maybe five or ten lines of text.
At present, I'm making use of wx.MessageBox to display these messages, and including embedded newline characters in the text to force the wx.MessageBox to word-wrap the text so that it looks good. This works well, in that the wx.MessageBox automatically adjusts its height according to how many lines of text are in the message to be dissplayed -- but, as I said earlier, I've now discovered that what looks good on one platform looks awful on another, and I'd have to somehow adjust the embedded newlines according to which platform we're running on.
Of course, I also tried using a wx.lib.dialogs.ScrolledMessageDialog to achieve this (which is the equivalent of what you've suggested above), but because the window is a fixed size it looks terribly unprofessional when a one-line message is shown in a large scrollable window. It really doesn't do it for me, I'm afraid.
Of course, this example is only one place where I hit up against this problem. More generally, I've got to create my own windows with complicated layouts, that really do need to make use of a static text control of some sort that automatically word-wraps, and then adjusts its height so that the sizer can place the other controls correctly around it, allowing for whatever amount of text the control happens to be showing at the time. If there's some way of making an HTML window (or a ready-only wx.TextCtrl) do that, then that'll solve the problem -- but I haven't been able to figure out any way of making these controls behave in this way.
Thanks for the suggestion, though...