Hi, All:
I have a question about the program efficiency of using
wx.StaticText and directly using DrawText to present text.
what are the advantages of each method?
And another question is how bad it will be if using panels inside
panels and sizers inside sizer?
Efficiency isn’t much of a concern. It’s far more important to consider the resulting characteristics and usability of the results.
DrawText is used for composing bitmap images using one of a variety of available DCs in which a the bitmap can be composed using combinations of text, geometrical shapes and photographic bitmaps. Once the bitmap is generated it is essentially immutable. Changing it usually means recomposing the entire bitmap.
wx.StaticText, on the other hand is a control object which can be placed and moved around at either the programmer’s will or that of a sizer. It’s easy to redefine its label text string.
Positioning panels of fixed sizes directly inside other panels at particular locations is no different than positioning, say, StaticText controls on the parent panel. Positioning one type of control within a parent (container control) is done the same ways as positioning any other type of control there.
All sizers’ purpose is to automatically manage positioning of controls and well as other sizers. There usefulness is especially apparent when the Frame is resized by the user. Managing the control’s positions within the parent panel, or in general any container control, can be done much more flexibly using a Sizer. See:
Hi, All:
I have a question about the program efficiency of using
wx.StaticText and directly using DrawText to present text.
what are the advantages of each method?
Using wx.StaticText gives you a self-contained widget and all the functionality (and overhead) that being a widget implies. Drawing it yourself means that you need to deal with paint event handlers, positioning, fonts, alignment, and so on. OTOH, the native static text widget is also dealing with its own paint event handler, and so if you've got hundreds of static text widgets on a form then that means that there are hundreds of paint events being delivered and dealt with. So if you are drawing all the text on the form yourself then that could be done in just a single paint event handler. IOW, it is a balancing act between simplicity/convenience and efficiency/complexity.
And another question is how bad it will be if using panels inside
panels and sizers inside sizer?
I'm not exactly sure that you are asking here, but one trick that may apply is that you can add empty "spacers" to a sizer and then when handling the paint event you can use the sizer item for that spacer to get the rectangle where it is located so you know where to draw your text.