I have a program I am working on that has a few wxStaticText control
fields where the label information
will change based on user input. I am having trouble getting them to
resize properly (i.e. if the new label has more
text than the previous label, not all of it is being displayed. If
the label has less text, than the unused space is not being
reused by items below.)
I have written a small test program to try to figure out how my program
should work and I haven’t figured it out yet.
I am trying to get self.label_1 to resize based on when the user hits the
button.
Can someone give me some ideas with this…maybe point me at a web
site?
Here is the test code
#!/usr/bin/env python
generated by wxGlade 0.3.1 on Tue May 11 12:39:38 2004
from wxPython.wx import *
from wxPython.lib.scrolledpanel import wxScrolledPanel
class MyFrame(wxFrame):
def __init__(self, *args, **kwds):
# begin wxGlade:
MyFrame.init
kwds["style"] =
wxDEFAULT_FRAME_STYLE
wxFrame.__init__(self, *args,
**kwds)
self.status = TRUE
self.sizer_1 =
wxBoxSizer(wxVERTICAL)
self.sizer_2 =
wxBoxSizer(wxVERTICAL)
self.panel_1 =
wxScrolledPanel(self, -1, (-1,-1))
self.button_1 =
wxButton(self.panel_1, wxID_OK, “button_1”)
self.label_1 =
wxStaticText(self.panel_1, -1, “The Cat”)
self.label_2 =
wxStaticText(self.panel_1, -1, “The Dog”)
EVT_BUTTON(self.panel_1,
wxID_OK, self.OnButton)
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade:
MyFrame.__set_properties
self.SetTitle(“frame_1”)
# end wxGlade
def __do_layout(self):
# begin wxGlade:
MyFrame.__do_layout
self.sizer_1 =
wxBoxSizer(wxVERTICAL)
self.sizer_2 =
wxBoxSizer(wxVERTICAL)
self.sizer_2.Add(self.button_1, 1, 0, 0)
self.sizer_2.Add(self.label_1,
1, wxADJUST_MINSIZE|wxALL, 10)
self.sizer_2.Add(self.label_2,
1, wxADJUST_MINSIZE|wxALL, 10)
self.panel_1.SetAutoLayout(1)
self.panel_1.SetSizer(self.sizer_2)
self.sizer_2.Fit(self.panel_1)
self.sizer_2.SetSizeHints(self.panel_1)
self.panel_1.SetupScrolling(scroll_x = TRUE)
self.sizer_1.Add(self.panel_1,
1, wxEXPAND, 0)
self.SetAutoLayout(1)
self.SetSizer(self.sizer_1)
self.sizer_1.Fit(self)
self.sizer_1.SetSizeHints(self)
self.Layout()
# end wxGlade
def OnButton(self, event):
if self.status == TRUE :
self.status = FALSE
self.label_1.SetLabel(“The Cat\nate the food\nin the
bowl”)
else :
self.status = TRUE
self.label_1.SetLabel(“The Cat”)
w,h =
self.label_1.GetSizeTuple()
···
self.sizer_2.SetItemMinSize(self.label_1, w, h)
self.panel_1.Layout()
self.panel_1.Fit()
self.panel_1.GetAdjustedBestSize()
self.panel_1.Refresh(TRUE)
self.panel_1.SetupScrolling(scroll_x = TRUE)
end of class MyFrame
class MyApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
frame_1 = MyFrame(None, -1,
“”)
self.SetTopWindow(frame_1)
frame_1.Show(1)
return 1
end of class MyApp
if name == “main”:
app = MyApp(0)
app.MainLoop()