[wxPython-users] Another sizer question

Grzegorz Makarewicz mak at trisoft.com.pl
Sun Nov 11 09:18:03 PST 2007


eShopping wrote:
> apologies for asking another sizer question - I think I get the hang
> of them, don't use wxPython for a while then get stuck again.  Anyway,
> I am trying to plot a matplotlib graph in the same window as some text
> controls using a box sizer.  The matplotlib window works fine as a
> standalone window but when I add it to the "main" window, (a) it does
> not appear and (b) I can't use the text controls.  Hopefully, this is
> simple fix for someone more knowledgeable but I am struggling.
>
> Thanks in advance
>
> Alun Griffiths
> ===========================================================
> import wx
> import matplotlib
> import numpy
>
> # uncomment the following to use wx rather than wxagg
> #matplotlib.use('WX')
> #from matplotlib.backends.backend_wx import FigureCanvasWx as
> FigureCanvas
>
> # comment out the following to use wx rather than wxagg
> matplotlib.use('WXAgg')
> from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as
> FigureCanvas
> from matplotlib.figure import Figure
>
>
>
> # ==================
> # Define main window
> # ==================
>
> class TopFrame(wx.Frame):
>     """Frame class that acts as top level window"""
>
>     # Constructor for main window
>
>     def __init__(self):
>
>         # Create a Frame instance
>
>         wx.Frame.__init__(self, None, title="Example matplotlib window")
>
>         # Create panel to hold sizer
>
>         panel = wx.Panel(self)
>
>         # Create a sizer to hold the tree and image widgets
>
>         box=wx.BoxSizer(wx.HORIZONTAL)
>
>
>         # Define data items
>
>         giipLabel  = wx.StaticText(self, wx.ID_ANY, "GIIP (Bscf)")
>         giipText   = wx.TextCtrl(self, value="50.0", size=(75,-1))
>
>         presLabel  = wx.StaticText(self, wx.ID_ANY, "initial pressure
> (psia)")
>         presText   = wx.TextCtrl(self, value="3000.0", size=(75,-1))
>
>         tresLabel  = wx.StaticText(self, wx.ID_ANY, "initial
> temperature (deg F)")
>         tresText   = wx.TextCtrl(self, value="150.0", size=(75,-1))
>
>         sgLabel    = wx.StaticText(self, wx.ID_ANY, "gas gravity (rel.
> air)")
>         sgText     = wx.TextCtrl(self, value="0.60", size=(75,-1))
>
>         qmaxLabel  = wx.StaticText(self, wx.ID_ANY, "plateau rate
> (MMscfd)")
>         qmaxText   = wx.TextCtrl(self, value="25.0", size=(75,-1))
>
>         nwLabel    = wx.StaticText(self, wx.ID_ANY, "number of wells")
>         nwSpinner  = wx.SpinCtrl(self, wx.ID_ANY, size=(50,-1), min=1,
> max=20, name="nwSpinner")
>
>
>         # Define sizers
>
>         lhsSizer = wx.FlexGridSizer(cols = 3, hgap = 5, vgap = 5)
>         lhsSizer.AddGrowableCol(2)      # Allow only data input fields
> to grow
>
>
>         # Add widgets to sizers
>
>         lhsSizer.Add(giipLabel, 0, wx.ALIGN_CENTER_VERTICAL)
>         lhsSizer.Add((10,10), 1)
>         lhsSizer.Add(giipText)
>         lhsSizer.Add(presLabel, 0, wx.ALIGN_CENTER_VERTICAL)
>         lhsSizer.Add((10,10), 1)
>         lhsSizer.Add(presText)
>         lhsSizer.Add(tresLabel, 0, wx.ALIGN_CENTER_VERTICAL)
>         lhsSizer.Add((10,10), 1)
>         lhsSizer.Add(tresText)
>         lhsSizer.Add(sgLabel, 0, wx.ALIGN_CENTER_VERTICAL)
>         lhsSizer.Add((10,10), 1)
>         lhsSizer.Add(sgText)
>         lhsSizer.Add(qmaxLabel, 0, wx.ALIGN_CENTER_VERTICAL)
>         lhsSizer.Add((10,10), 1)
>         lhsSizer.Add(qmaxText)
>         lhsSizer.Add(nwLabel, 0, wx.ALIGN_CENTER_VERTICAL)
>         lhsSizer.Add((10,10), 1)
>         lhsSizer.Add(nwSpinner)
>
>         box.Add(lhsSizer, 0)
>
>         # Load the plot window and add to sizer
stop :) - as far U have added some items to sizer - but self.plot doesnt
define minimum size nor anything what deals with frame size :) -
consider - min size for this item is 0
>
>         self.plot = PlotFrame(self)
>
>         box.Add(self.plot, 1)
>
>         # Add the sizer to the panel
>
>         panel.SetSizerAndFit(box)
nice but - plot window isnt shown - just because sizer reduces its size to 0


mak





More information about the wxpython-users mailing list