[wxPython-users] can a pyplot exist on a wxPanel or does it need
to be in a wxFrame?
Christopher Barker
Chris.Barker at noaa.gov
Thu Mar 8 09:36:51 PST 2007
C M wrote:
> And so I'm thinking that the plotpanel perhaps needs a sizer? =
Exactly -- you need to give it a size and position somehow.
> For the layout I was envisioning, I wanted the plot panel to be =
> positioned sort of in the center of the window, with some borders,
> and so that is why I was trying to place it on a panel.
Like the enclosed code?
You don't need an additional panel for that. Sizers can provide a =
border, too. The line is:
MainSizer.Add(self.plotCanvas1, 1, wx.EXPAND|wx.ALL, 40)
So we're adding the plotCanvas to the sizer:
The "1" tells it to stretch in the direction of the sizer (wx.VERTICAL =
in this case), the wx.EXPAND flag tells it to EXPAND the the other =
direction, the wx.ALL tells it you want borders on all sides, and the 40 =
indicates that the borders should be 40 pixels wide.
If you want relative borders, you could do that by putting spacers in =
and assigning them appropriate relative stretch values (the second =
parameter).
> Perhaps if I put a sizer on a panel first, (so Panel > Sizer > =
> plotpanel) it will allow the plot to display properly.
One of the things to keep in mind is that there are 3 different =
hierarchies that are essentially independent:
The Python class-subclass hierarchy
The wx Window Parent-Child hierarchy
The Sizer hierarchy
an example is that you can have a Panel on a Panel on a Panel (the wx =
parent-child) all in one Python class, or each panel can be in its own =
class.
Then within one Panel, you can have a whole pile of nested sizers.
Personally, I try to NOT nest a lot Panels in one class -- it just gets =
confusing. I make a subclass for each layer.
Sizers, on the other hand. sometimes have to be nested to get the layout =
you want. The thing to remember is that Sizers are somewhat independent =
of the parent child relationship -- all they do is the layout -- they =
take the place of lot size and position calculations.
So -- determine your parent-child relationship based on functionality -- =
put controls that work together on a wx.Panel subclass. Then work out =
your layout with Sizers.
> I have to admit I've avoided looking into sizers because they for some =
> reason struck me as unintuitive.
Well, intuitive is in the eye of the intuiter (is that a word?). But =
they do take some work to wrap your brain around, and the syntax is =
uglier than it could be. The trickiest bit is that all the flags are a =
jumble of unrelated functionality.
That being said, I find that to some extent they do fit my brain. I tend =
to think of layout in terms of things like:
"I want a row of buttons along the bottom" -- a horizontal box sizer.
"I want a bunch of controls all lined up on rows and columns" -- a GridSizer
etc.
> Perhaps I should just suck it up and learn them.
Yes. It's worth it. The Wiki has some good stuff.
-Chris
-- =
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testPlotApp.py
Type: text/x-python
Size: 2860 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20070=
308/8de62dd8/testPlotApp.py
More information about the wxpython-users
mailing list