Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
two windows sticking together.
both in different styles.
both with fixed x,y relation
'''
import wx
from threading import Timer
class Frame1 (wx.Frame):
def __init__(self, parent = None, id = -1, title = "", size = wx.Size(367, 304)):
style = wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BOX | wx.SYSTEM_MENU)
wx.Frame.__init__(self, parent, id, title, size = size, style = style)
panel = wx.Panel (self)
vbox_main = wx.BoxSizer (wx.VERTICAL)
panel.SetSizer (vbox_main)
self.win1 = wx.Window (panel)
vbox_main.Add (self.win1, 1, wx.ALL | wx.EXPAND)
self.SetBackgroundColour ((255,255,255))
self.txt1 = wx.StaticText (panel)
self.Show ()
class Frame2 (wx.Frame):
def __init__(self, parent = None, id = -1, title = "", size = wx.Size(367, 304), style = wx.MINIMIZE_BOX | wx.STAY_ON_TOP):
wx.Frame.__init__(self, parent, id, title, size = size, style = style)
panel = wx.Panel (self)
vbox_main = wx.BoxSizer (wx.VERTICAL)
panel.SetSizer (vbox_main)
self.win2 = wx.Window (panel)
vbox_main.Add (self.win2, 1, wx.ALL | wx.EXPAND)
self.SetBackgroundColour ((255,255,255))
self.txt2 = wx.StaticText (panel)
self.Show ()
def resize_frame():
oldsize = F1.GetSize ()
pos = F1.GetPosition()
# minimum and maximum size of the window
wHight = oldsize.GetHeight ()
if wHight > 529:
wHight = 529
if wHight < 200:
wHight = 200
# x/y relation = 1.2 / 1
newsize = (wHight*1.2, wHight)
F1.SetSize (newsize)
F2.SetSize (newsize)
# stick window2 to the end of window1
F2.Move ((pos[0], pos[1]+wHight))
F1.txt1.SetLabel (''.join ((" Position: ", str (pos), "\n Size: ", str (newsize))))
F2.txt2.SetLabel (''.join ((" Position: ", str ((pos[0], pos[1]+wHight)))))
# after 100ms call resize_frame()
t = Timer (0.1, resize_frame); t.start()
def main():
size = F1.GetSize ()
pos = F1.GetPosition()
wHight = size.GetHeight ()
# stick window2 to the end of window1
F2.Move ((pos[0],pos[1]+wHight))
F1.win1.SetFocus ()
# after 100ms call resize_frame()
t = Timer (0.1, resize_frame); t.start()
if __name__ == '__main__':
app = wx.PySimpleApp ()
F1 = Frame1 ()
F2 = Frame2 ()
main()
app.MainLoop ()