I'm trying to programmatically resize a window. I want to scale
the client area by a constant factor, so I'm trying to use
GetClientSize() to find the current size, scaling that, and then
using SetClientSize(). (Actually, the specific functions I'm
using are wxWindow.GetClientSizeTuple() and
wxWindowSetClientSizeWH()--not sure why the non-symmetric names,
but that's trivial.)
However, I find my height/width ratio constantly changing, by a
fairly large amount. It seems to me that one of those functions
is not adjusting for my toolbar. In order to verify this, I
created a very simple test app (code attached), that does nothing
except get its client size, then set its client size to the same
values. When I do this without a toolbar, all is fine, but when
I add a toolbar, then not only does my height shrink each
iteration, but my width *grows* each time! I printed out the
width and height through multiple iterations. Without the
toolbar, the client area (on a 500x300 window) was consistently
492 x 254. With the toolbar, I got this:
Client size is 492 226
Client size is 520 198
Client size is 548 170
Client size is 576 142
Client size is 604 114
Client size is 632 86
Client size is 660 58
It looks like the correction that should be being added to the
height, is being added to the width instead. However, I'm not
sure which of these functions is doing it, or whether this is in
wxPython code or wxWindows itself.
Any ideas where I should look? Should I submit a bug report?
And if so, to wxPython or wxWindows? Hm, I'm using wxPython
2.2.5, perhaps this has already been fixed? (Python is 2.0, OS
is Win95b, if it matters...)
Jeff Shannon
Technician/Programmer
Credit International
Code follows, hopefully not too badly mangled by linewrap:
------SizingTest.py-----------------------------------------------
from wxPython.wx import *
class MyFrame(wxFrame):
def __init__(self, *args, **kwargs):
wxFrame.__init__(self, *args, **kwargs)
mymenu = wxMenu()
mymenu.Append(20, "Rescale", "Rescale the window")
menubar = wxMenuBar()
menubar.Append(mymenu, "&Menu")
self.SetMenuBar(menubar)
# Commenting out the following three lines
# removes the problem
self.tb =
self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER|wxTB_FLAT)
self.tb.AddSimpleTool(20, wxBitmap('scaleup.bmp',
wxBITMAP_TYPE_BMP),
"Rescale", "Rescale the window")
self.tb.Realize()
EVT_MENU(self, 20, self.OnScale)
self.Show(1)
def OnScale(self, event):
x, y = self.GetClientSizeTuple()
print "Client size is", x, y
self.SetClientSizeWH(x, y)
class MyApp(wxApp):
def OnInit(self):
self.frame = MyFrame(NULL, -1, "Sizing Test",
wxPoint(50, 50), wxSize(500,300))
self.frame.Show(true)
self.SetTopWindow(self.frame)
return true
if __name__ == '__main__':
app = MyApp(0)
app.MainLoop()