Fitting Contents Problem

I am having a little trouble in that my contents are not growing to fill the whole frame. I have a growable column and a growable row, but when the GUI is created, it just fits the initial contents of the widgets. This is a problem because the contents of some things change such that they will get wider, and the user needs to be able to drag things so that they can read all the contents. Has anyone run into this problem? I can send code if that will help, but I didn't want to clog people's inboxes.

Andrew Bouchard

Andrew Bouchard wrote:

I am having a little trouble in that my contents are not growing to fill the whole frame. I have a growable column and a growable row, but when the GUI is created, it just fits the initial contents of the widgets. This is a problem because the contents of some things change such that they will get wider, and the user needs to be able to drag things so that they can read all the contents. Has anyone run into this problem? I can send code if that will help, but I didn't want to clog people's inboxes.

http://wiki.wxpython.org/MakingSampleApps

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for the tip on making sample applications. It turns out that it did help with diagnosis, but I still can't find a solution. It would appear that there's something about the images that I am putting in that makes the fit not work, since as soon as I took it out everything worked great. I have attached a sample application that replicates the problem as well as the two images that it uses.

For reference, the project is an elevator simulation. Yes, it is for class, but the class is concerned with the development of the control logic, not the GUI. Thanks very much!

Andrew Bouchard

elevator_closed.jpg

elevator_open.jpg

SampleApp.py (3.82 KB)

Hello,

If by the 'fit not work' you mean all the extra space below your controls in the frame you can call

self.SetInitialSize()

at the end of the layout (where self is your frame) to set the initial 'best' size for the frame. Currently you are only sizing the panel and not the frame that is around the panel.

Cody

···

On Sep 1, 2008, at 5:06 PM, Andrew Bouchard wrote:

Thanks for the tip on making sample applications. It turns out that it did help with diagnosis, but I still can't find a solution. It would appear that there's something about the images that I am putting in that makes the fit not work, since as soon as I took it out everything worked great. I have attached a sample application that replicates the problem as well as the two images that it uses.

For reference, the project is an elevator simulation. Yes, it is for class, but the class is concerned with the development of the control logic, not the GUI. Thanks very much!

Andrew Bouchard
<elevator_closed.jpg><elevator_open.jpg># Elevator Simulator
# Written by Andrew Bouchard
# This program simulates the behavior of a simple elevator and was written for the Vanderbilt University fall 2008 class
# CS376 Hybrid and Embedded Systems taught by Xenofon Koutsoukos
# Date Started: 8/31/2008
# Last Updated: 9/1/2008

# Import needed libraries
import wx

print wx.version()

# This is the main GUI class
class Elevator(wx.Frame):
   def __init__(self, parent, id, title):

       # Initialize the frame
       wx.Frame.__init__(self, parent, id, title, size=(500, 800))

       # Declare fonts
       title = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD)
       subtitle = wx.Font(11, wx.DEFAULT, wx.NORMAL, wx.BOLD)

       # Define the panel and the sizer
       panel = wx.Panel(self, -1)
       sizer = wx.GridBagSizer(0, 0)

       # Create elevator images
       OpenImage = 'elevator_open.jpg'
       open = wx.Image(OpenImage, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
       ClosedImage = 'elevator_closed.jpg'
       closed = wx.Image(ClosedImage, wx.BITMAP_TYPE_ANY).ConvertToBitmap()

       # Declare the row for the gui widgets
       guirow = 0

       # Column Labels
       lblIncallsTitle = wx.StaticText(panel, -1, 'Internal calls')
       sizer.Add(lblIncallsTitle, (guirow, 0), flag=wx.ALL | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL, border=5)
       lblExcallsTitle = wx.StaticText(panel, -1, 'External calls')
       sizer.Add(lblExcallsTitle, (guirow, 2), (1, 2), wx.ALL | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL, 5)

       guirow = guirow+1

       # Second floor
       # Incall button
       self.cmdIncall2 = wx.ToggleButton(panel, 2, '2')
       sizer.Add(self.cmdIncall2, (guirow, 0), (1,1), flag=wx.ALL | wx.ALIGN_CENTER, border=5)
       # Elevator graphic
       self.floor2 = wx.StaticBitmap(self, -1, closed)
       sizer.Add(self.floor2, (guirow, 1), (1,1), flag=wx.ALL | wx.ALIGN_CENTER, border=5)
       # Excall up button
       self.cmdExcall2Up = wx.ToggleButton(panel, 12, 'Up')
       sizer.Add(self.cmdExcall2Up, (guirow, 2), (1,1), flag=wx.ALL > wx.ALIGN_CENTER, border=5)
       # Excall down button
       self.cmdExcall2Down = wx.ToggleButton(panel, 22, 'Down')
       sizer.Add(self.cmdExcall2Down, (guirow, 3), (1,1), flag=wx.ALL | wx.ALIGN_CENTER, border=5)

       guirow = guirow+1

       # First floor
       # Incall button
       self.cmdIncall1 = wx.ToggleButton(panel, 1, '1')
       sizer.Add(self.cmdIncall1, (guirow, 0), (1,1), flag=wx.ALL | wx.ALIGN_CENTER, border=5)
       # Elevator graphic
       self.floor1 = wx.StaticBitmap(self, -1, open)
       sizer.Add(self.floor1, (guirow, 1), (1,1), flag=wx.ALL | wx.ALIGN_CENTER, border=5)
       # Excall up button
       self.cmdExcall1Up = wx.ToggleButton(panel, 11, 'Up')
       sizer.Add(self.cmdExcall1Up, (guirow, 2), (1,1), flag=wx.ALL > wx.ALIGN_CENTER, border=5)
       # Excall down button
       self.cmdExcall1Down = wx.ToggleButton(panel, 21, 'Down')
       sizer.Add(self.cmdExcall1Down, (guirow, 3), (1,1), flag=wx.ALL | wx.ALIGN_CENTER, border=5)

       guirow = guirow+1

       # Step button
       cmdStep = wx.Button(panel, -1, 'Step')
       sizer.Add(cmdStep, (guirow, 0), (1,2), flag=wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border=5)
       # Reset button
       cmdReset = wx.Button(panel, -1, 'Reset')
       sizer.Add(cmdReset, (guirow, 2), (1,2), flag=wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border=5)

       sizer.AddGrowableCol(0)
       sizer.AddGrowableRow(guirow)
       panel.SetSizerAndFit(sizer)
       self.Centre()
       self.Show(True)

# Start the GUI
app = wx.App()
main = Elevator(None, -1, 'Elevator Simulation')
app.MainLoop()_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Andrew Bouchard wrote:

Thanks for the tip on making sample applications. It turns out that it did help with diagnosis, but I still can't find a solution. It would appear that there's something about the images that I am putting in that makes the fit not work, since as soon as I took it out everything worked great. I have attached a sample application that replicates the problem as well as the two images that it uses.

For reference, the project is an elevator simulation. Yes, it is for class, but the class is concerned with the development of the control logic, not the GUI. Thanks very much!

I'm not sure if this is the problem you are concerned with, but I see a common problem that people tend to do fairly often. Specifically, the code gives the panel a sizer and fits it, but then doesn't do anything to fit the frame to the needs of the sizer. I like to solve that by *not* using Fit on the panel (or SetSizerAndFit) and then putting the panel in a sizer assigned to the frame. Finally, calling Fit on the frame will go recursively down the child widgets and sizers and set the frame to be the best size to show it all. If you want the frame to not be sizable smaller than that then SetSizeHints will take care of that.

  ...
  panel.SetSizer(sizer)
  frm_sizer = wx.BoxSizer()
  frm_sizer.Add(panel, 1, wx.EXPAND)
  self.SetSizer(frm_sizer)
  self.Fit()
  ...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!