import wx;
class StickTogetherFrame(wx.Frame):
def __init__(self,
parent,
otherFrames,
id=-1,
title=wx.EmptyString,
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE,
name=wx.FrameNameStr):
wx.Frame.__init__(self, parent, id, title, pos, size, style, name);
wx.EVT_MOVE(self, self.onMove)
self.currentPos = self.GetPosition();
self.relatedFrames = otherFrames;
self.relatedFrames.append(self);
self.manualUpdate = True;
def onMove(self, event):
newPos = event.m_pos;
dX = newPos[0] - self.currentPos[0];
dY = newPos[1] - self.currentPos[1];
self.currentPos = newPos;
if self.manualUpdate:
self.updatePositions(dX, dY);
def updatePositions(self, deltaX, deltaY):
for frame in self.relatedFrames:
if frame.GetId() != self.GetId():
oldPos = frame.GetPosition();
newPos = (oldPos[0] + deltaX, oldPos[1] + deltaY);
frame.manualUpdate = False;
frame.SetPosition(newPos);
frame.manualUpdate = True;
if __name__ == "__main__":
app = wx.PySimpleApp()
allFrames = [];
frame1 = StickTogetherFrame(None, allFrames, wx.NewId(), pos = (0,0))
frame2 = StickTogetherFrame(None, allFrames, wx.NewId(), pos = (100,100));
frame1.Show();
frame2.Show();
app.MainLoop()
Comments