Caligari
Caligari

Reputation: 1421

wxPython - blank frame in Ubuntu

I've written a basic application in wxPython. While it works fine under Windows, under Linux (Ubuntu 11.10), the frame will appear empty (except for a few small broken elements on the left hand side). There are no errors in the console. Just before running it, I installed wxPython as per http://wiki.wxpython.org/InstallingOnUbuntuOrDebian

Any ideas appreciated.

class MainWindow(wx.Frame):
def __init__(self, parent, title):
    self.dirname=''

    # A "-1" in the size parameter instructs wxWidgets to use the default size.
    wx.Frame.__init__(self, parent, title=title, size=(400,500),style=wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX))
    self.CreateStatusBar() # A Statusbar in the bottom of the window
    panel = wx.Panel(self, wx.ID_ANY)

    # Setting up the menus
    filemenu = wx.Menu()
    editmenu = wx.Menu()

    menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open an underway netCDF to load")
    menuAbout= filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
    menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
    menuConfig = editmenu.Append(wx.ID_EDIT, "&Config", "Edit Configuration")

    # Creating the menubar.
    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
    menuBar.Append(editmenu,"&Edit")
    self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

    #Sizer setup.
    sizer = wx.BoxSizer(wx.VERTICAL) #root sizer
    buttonSizer = wx.BoxSizer(wx.HORIZONTAL)

    #Buttons.
    self.buttonLoadData = wx.Button(panel, -1, "&Load Data")
    self.buttonAbort = wx.Button(panel, -1, "&Abort Load")
    self.buttonAbort.Enabled = False
    self.buttonLoadData.Enabled = False

    #Slider. Should probably be a floating point spin control.
    #self.sliderRate = wx.Slider(panel, -1, 5, 0, 100, wx.DefaultPosition, (380, -1), wx.SL_AUTOTICKS | wx.SL_LABELS)
    self.sliderRate = self.FloatSlider(panel, -1, 1000, 0, 5000, wx.DefaultPosition, (380, -1), wx.SL_AUTOTICKS | wx.SL_LABELS)

    #Log window.
    self.log = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY)


    # Events.
    self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
    self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
    self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
    self.Bind(wx.EVT_MENU, self.OnConfig, menuConfig)
    self.Bind(wx.EVT_BUTTON, self.OnLoadButton, self.buttonLoadData)
    self.Bind(wx.EVT_BUTTON, self.OnAbortButton, self.buttonAbort)
    self.Bind(wx.EVT_SLIDER, self.OnSlider)

    #Subscribe to messages from underlying simulator
    Publisher().subscribe(self.updateDisplay, "update")

    #Layout sizers
    buttonSizer.Add(self.buttonLoadData, 0, wx.ALL, 5)
    buttonSizer.Add(self.buttonAbort, 0, wx.ALL, 5)
    sizer.Add(buttonSizer, 0, wx.ALL, 5)
    sizer.Add(self.sliderRate, 0, wx.ALL, 5)
    sizer.Add(self.log, 1, wx.EXPAND, 5)

    panel.SetSizer(sizer)
    panel.Layout()

Upvotes: 1

Views: 727

Answers (1)

Andrey Sobolev
Andrey Sobolev

Reputation: 12713

You might have forgotten to add sizer.Fit(panel) in between of SetSizer and Layout to make sure wxPython calculates the layout properly. I do not know why it's working on Windows, but on Linux I wasn't able to make wxPython show frames correctly without Fit:

    panel.SetSizer(sizer)
    sizer.Fit(panel)
    panel.Layout()

This should do it.

Upvotes: 1

Related Questions