I'm having trouble laying out a gui with a wxListBox. Why doesn't the
wxListBox show up in the following gui ?
If I change the following line to:
panelSizer.Add(btnBox, 1, wxEXPAND)
which is a box sizer holding two buttons immediately above the wxListBox ,
the wxListBox shows up but the buttons do not ?
Also whenever I print out the sizer minimum size, the wxListBox never seems
to contribute to it - even if I set the wxListBox's minimum size in it's
constructor.
Win 2000, wxPython 2.4.0.6
What am I missing here ?
Many thanks,
Rick Lawson
···
=====================================================================================================================================
Code follows, start with a -g option to pop up the gui:
#!/bin/python
import sys, os
from wxPython.wx import *
import getopt
import pydoc
def MsgBox (window, string):
dlg=wxMessageDialog(window, string, 'wxPyDoc', wxOK)
dlg.ShowModal()
dlg.Destroy()
class PyDocPanel(wxPanel):
def __init__(self, parent, id, pos=wxDefaultPosition,
size=wxDefaultSize, style=wxTAB_TRAVERSAL, name='panel'):
# init the parent class
wxPanel.__init__(self, parent, id, pos, size, style, name)
# create the panel sizer
panelSizer = wxBoxSizer(wxVERTICAL)
#panelSizer.AddGrowableCol(0)
self.SetSizer(panelSizer)
# create the status text
txtStatus = wxStaticText(self, -1, 'http://')
panelSizer.Add(txtStatus, 0, wxEXPAND | wxALL, 3)
# create search input
ID_TXT_SEARCH = wxNewId()
txtSearch = wxTextCtrl(self, ID_TXT_SEARCH)
panelSizer.Add(txtSearch, 0, wxEXPAND | wxALL, 3)
# create search buttons
btnBox = wxBoxSizer(wxHORIZONTAL)
ID_BTN_START = wxNewId()
btnStart = wxButton(self, ID_BTN_START, 'Start Search')
btnBox.Add(btnStart, 1, wxALL | wxALIGN_CENTER | wxEXPAND, 2)
ID_BTN_STOP = wxNewId()
btnStop = wxButton(self, ID_BTN_STOP, 'Stop Search')
btnBox.Add(btnStop, 1, wxALL | wxALIGN_CENTER | wxEXPAND, 2)
panelSizer.Add(btnBox, 0, wxEXPAND)
# create search results list box
ID_LST_SEARCH = wxNewId()
panelSizer.Add(wxStaticText(self, -1, 'Search Results ...'), -1,
wxTOP, 3)
lstSearch = wxListBox(self, ID_LST_SEARCH)
panelSizer.Add(lstSearch, 1, wxEXPAND)
# create the go to topic btn
ID_BTN_TOPIC = wxNewId()
btnTopic = wxButton(self, ID_BTN_TOPIC, 'View Topic')
panelSizer.Add(btnTopic, 0, wxEXPAND | wxALL, 3)
# create launch doc buttons
# Python Docs
ID_BTN_PYTHON = wxNewId()
btnPython = wxButton(self, ID_BTN_PYTHON, 'Python Docs')
panelSizer.Add(btnPython, 0, wxEXPAND | wxALL, 1)
# wxWindow Docs
ID_BTN_WXWINDOWS = wxNewId()
btnWxWindows = wxButton(self, ID_BTN_WXWINDOWS, 'wxWindows Docs')
panelSizer.Add(btnWxWindows, 0, wxEXPAND | wxALL, 1)
# wxPython Demo
ID_BTN_WXPYTHON = wxNewId()
btnWxPython = wxButton(self, ID_BTN_WXPYTHON, 'wxPython Demo')
panelSizer.Add(btnWxPython, 0, wxEXPAND | wxALL, 1)
self.Layout()
class main_window(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, -1, title, size=(200,400))
self.panel = PyDocPanel(self, -1)
if __name__=='__main__':
# Process the command line.
# We pass all options other than -g onto the pydoc module
# for the -g option we intercept it and start the wxPython gui instead
of Tkinter
optlist, args = getopt.getopt(sys.argv, 'gk:p:w:')
if ('-g','') not in optlist:
app = wxPySimpleApp()
win = main_window(None, -1, 'wxPyDoc')
win.Show(1)
app.MainLoop()
else:
print 'delegate to pydoc'
pydoc.cli()