Hi Alex,
Even if I am not completely sure, I think I understand your problem.
You want a frame divided in two "regions". One contains your "working area" and
the other contains some controls like static text ctrls and buttons.
From your question I understood you want to group the text ctrls and the
buttons. In my opinion, you are using a wrong strategy, because you puts your
buttons and your text ctrls in the scrolled window, which leads to a complicate
resizing.
I propose here an another approach (with a demo code at the end).
1) I create a frame and put a dark blue panel in it.
2) In the panel, I place a green window (wxWindow), this is what I'm calling
the working area. In you case, it may be a scrolled window.
3) Then, I create a ToolsWindow (again a wxWindow). This windows contains two
buttons and two text ctrls. All these controls have a fixed size. The ToolWindow
represents a group of controls. It is red im my example.
4) Place the ToolsWindow on the panel.
5) Apply some constraints to the two ojects in the panel. This is the
critical part. The two objects are side by side and the ToolsWindow
must have some constant size due to its ctrls having well defined
sizes. The constraints depends on how the ToolsWindow is defined.
6) I add some events to show how the ctls are interacting each other.
The resut is a resizable frame, with a group of controls that
keep their sizes. The ToolsWindow is always visible.
There are other ways to do the job, eg wxSashWindow, look at the demo.
Hope that helps. Have fun.
Jean-Michel Fauth, Switzerland
ยทยทยท
#------------------------------------------------------------------
# groupctrls.py
# win98se, py 2.2.3, wxpy 2.4.0.7
#------------------------------------------------------------------
from wxPython.wx import *
#------------------------------------------------------------------
class ToolsWindow(wxWindow):
def __init__(self, parent, id, pos):
wxWindow.__init__(self, parent, id, pos, wxSize(200, 400), 0)
self.parent = parent
self.SetBackgroundColour(wxRED)
gap = 10
wi, he = self.GetSizeTuple()
self.statxt1 = wxStaticText(self, -1, "staticText1", wxPoint(gap, 8), \
wxSize(wi - 2 * gap, 14), wxST_NO_AUTORESIZE)
self.statxt1.SetBackgroundColour(wxWHITE)
self.statxt2 = wxStaticText(self, -1, "staticText2", wxPoint(gap, 40), \
wxSize(wi - 2 * gap, 14), wxST_NO_AUTORESIZE)
self.statxt2.SetBackgroundColour(wxWHITE)
but1 = wxButton(self, 1001, 'cyan', wxPoint(gap, 100), wxSize(100, 24))
EVT_BUTTON(self, 1001, self.OnClick1)
but2 = wxButton(self, 1002, 'white', wxPoint(gap, 130), wxSize(100, 24))
EVT_BUTTON(self, 1002, self.OnClick2)
def OnClick1(self, event):
self.parent.mg.SetBackgroundColour(wxCYAN)
self.parent.mg.Refresh()
def OnClick2(self, event):
self.parent.mg.SetBackgroundColour(wxWHITE)
self.parent.mg.Refresh()
#-------------------------------------------------------------------
class AColouredWindow(wxWindow):
def __init__(self, parent, id, pos, size, style):
print 'init'
style = wxSIMPLE_BORDER
wxWindow.__init__(self, parent, id, pos, size, style)
self.parent = parent
self.SetBackgroundColour(wxGREEN)
EVT_MOTION(self, self.OnMotion)
def OnMotion(self, event):
self.parent.tw.statxt1.SetLabel('mouse inside')
#-------------------------------------------------------------------
class MainPanel(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self, parent, -1, wxDefaultPosition, wxDefaultSize)
self.SetBackgroundColour(wxBLUE)
self.SetAutoLayout(true)
#ToolsWindows at the right of the main frame
self.tw = ToolsWindow(self, -1, wxPoint(-1, -1))
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 0)
lc.left.SameAs(self, wxRight, -self.tw.GetSizeTuple()[0] - 0)
lc.width.AsIs()
lc.height.SameAs(self, wxHeight, 0)
self.tw.SetConstraints(lc)
#something on the left part of the main frame
self.mg = AColouredWindow(self, -1, wxPoint(-1, -1), wxSize(-1, -1), wxNO_BORDER)
lc = wxLayoutConstraints()
gap = 20
lc.top.SameAs(self, wxTop, gap)
lc.left.SameAs(self, wxLeft, gap)
lc.right.LeftOf(self.tw, gap)
lc.bottom.SameAs(self, wxBottom, gap)
self.mg.SetConstraints(lc)
EVT_MOTION(self, self.OnMotion)
def OnMotion(self, event):
self.tw.statxt1.SetLabel("mouse outside")
#------------------------------------------------------------------
class MainFrame(wxFrame):
def __init__(self, parent, ID):
style = wxDEFAULT_FRAME_STYLE
wxFrame.__init__(self, parent, ID, 'groupedctrls', wxPoint(0,0), \
wxSize(760, 570), style)
self.CentreOnParent()
self.panel = MainPanel(self)
EVT_CLOSE(self, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
#------------------------------------------------------------------
class MainApp(wxApp):
def OnInit(self):
frame = MainFrame(None, -1)
frame.Show(True)
self.SetTopWindow(frame)
return true
#------------------------------------------------------------------
def main():
app = MainApp(0)
app.MainLoop()
#------------------------------------------------------------------
if __name__ == '__main__':
main()
#eof---------------------------------------------------------------