-
Notifications
You must be signed in to change notification settings - Fork 21
/
MultiFrame.py
executable file
·64 lines (47 loc) · 1.61 KB
/
MultiFrame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
A demo of how to do really simple communication between multiple frames
"""
import wx
import random
class MsgFrame(wx.Frame):
""" This window displays a simple message """
def __init__(self, frame_num):
wx.Frame.__init__(self, None, -1, title="Frame # %i" %frame_num, size=(400, 100))
self.frame_num = frame_num
self.message = wx.StaticText(self, label = "A non-message")
s = wx.BoxSizer(wx.VERTICAL)
s.Add((1, 1), 1)
s.Add(self.message, 0, wx.ALIGN_CENTER)
s.Add((1, 1), 1)
self.SetSizer(s)
self.Bind(wx.EVT_LEFT_DOWN, self.OnClick)
def SetMessage(self, message):
self.message.Label = message
self.Layout()
self.Refresh()
self.Update()
def OnClick(self, evt):
pos = evt.Position
App = wx.GetApp()
App.SetMessage("Mouse clicked in frame: %i at position: (%i, %i)" %(
self.frame_num, pos[0], pos[1]), self.frame_num + 1)
class DemoApp(wx.App):
def OnInit(self):
# build the frames:
self.frames = []
for i in range(5):
frame = MsgFrame(frame_num=i)
frame.Move((30 + i * 100, 30 + i * 100))
frame.Show()
self.frames.append(frame)
return True
def SetMessage(self, message, frame_num):
""" set a message on the given frame_number """
try:
self.frames[frame_num].SetMessage(message)
except IndexError:
self.frames[0].SetMessage(message)
if __name__ == "__main__":
app = DemoApp(False)
app.MainLoop()