]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: DialogUnits.py | |
4 | # Purpose: A minimal wxPython program that is a bit smarter than test1. | |
5 | # | |
6 | # Author: Robin Dunn | |
7 | # | |
8 | # Created: A long time ago, in a galaxy far, far away... | |
9 | # RCS-ID: $Id$ | |
10 | # Copyright: (c) 1998 by Total Control Software | |
11 | # Licence: wxWindows license | |
12 | #---------------------------------------------------------------------------- | |
13 | # Updated 11/9/2003 by Jeff Grimmett (grimmtooth@softhome.net) | |
14 | # | |
15 | # o Converted for V2.5 compatability | |
16 | # | |
17 | ||
18 | import wx | |
19 | ||
20 | #--------------------------------------------------------------------------- | |
21 | ||
22 | # Create a new frame class, derived from the wxPython Frame. | |
23 | class MyFrame(wx.Frame): | |
24 | ||
25 | def __init__(self, parent, id, title): | |
26 | # First, call the base class' __init__ method to create the frame | |
27 | wx.Frame.__init__(self, parent, id, title, (100, 100), (160, 100)) | |
28 | ||
29 | # Associate some events with methods of this class | |
30 | self.Bind(wx.EVT_SIZE, self.OnSize) | |
31 | self.Bind(wx.EVT_MOVE, self.OnMove) | |
32 | self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) | |
33 | ||
34 | # Add a panel and some controls to display the size and position | |
35 | panel = wx.Panel(self, -1) | |
36 | ||
37 | wx.StaticText(panel, -1, "Size:", | |
38 | wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize | |
39 | ) | |
40 | ||
41 | wx.StaticText(panel, -1, "Pos:", | |
42 | wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize | |
43 | ) | |
44 | ||
45 | self.sizeCtrl = wx.TextCtrl(panel, -1, "", | |
46 | wx.DLG_PNT(panel, (24, 4)), | |
47 | wx.DLG_SZE(panel, (36, -1)), | |
48 | wx.TE_READONLY) | |
49 | ||
50 | self.posCtrl = wx.TextCtrl(panel, -1, "", | |
51 | wx.DLG_PNT(panel, (24, 16)), | |
52 | wx.DLG_SZE(panel, (36, -1)), | |
53 | wx.TE_READONLY) | |
54 | ||
55 | #print wx.DLG_PNT(panel, (24, 4)), wx.DLG_SZE(panel, (36, -1)) | |
56 | #print wx.DLG_PNT(panel, (24, 16)),wx.DLG_SZE(panel, (36, -1)) | |
57 | ||
58 | # This method is called automatically when the CLOSE event is | |
59 | # sent to this window | |
60 | def OnCloseWindow(self, event): | |
61 | # tell the window to kill itself | |
62 | self.Destroy() | |
63 | ||
64 | # This method is called by the System when the window is resized, | |
65 | # because of the association above. | |
66 | def OnSize(self, event): | |
67 | size = event.GetSize() | |
68 | self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height)) | |
69 | ||
70 | # tell the event system to continue looking for an event handler, | |
71 | # so the default handler will get called. | |
72 | event.Skip() | |
73 | ||
74 | # This method is called by the System when the window is moved, | |
75 | # because of the association above. | |
76 | def OnMove(self, event): | |
77 | pos = event.GetPosition() | |
78 | self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y)) | |
79 | ||
80 | ||
81 | ||
82 | #--------------------------------------------------------------------------- | |
83 | # if running standalone | |
84 | ||
85 | if __name__ == "__main__": | |
86 | # Every wxWindows application must have a class derived from wxApp | |
87 | class MyApp(wx.App): | |
88 | ||
89 | # wxWindows calls this method to initialize the application | |
90 | def OnInit(self): | |
91 | ||
92 | # Create an instance of our customized Frame class | |
93 | frame = MyFrame(None, -1, "This is a test") | |
94 | frame.Show(True) | |
95 | ||
96 | # Tell wxWindows that this is our main window | |
97 | self.SetTopWindow(frame) | |
98 | ||
99 | # Return a success flag | |
100 | return True | |
101 | ||
102 | ||
103 | app = MyApp(0) # Create an instance of the application class | |
104 | app.MainLoop() # Tell it to start processing events | |
105 | ||
106 | ||
107 | #--------------------------------------------------------------------------- | |
108 | # if running as part of the Demo Framework... | |
109 | ||
110 | def runTest(frame, nb, log): | |
111 | win = MyFrame(frame, -1, "This is a test") | |
112 | frame.otherWin = win | |
113 | win.Show(True) | |
114 | ||
115 | ||
116 | overview = """\ | |
117 | A simple example that shows how to use Dialog Units. | |
118 | """ | |
119 | ||
120 | #---------------------------------------------------------------------------- | |
121 | # | |
122 | ||
123 | ||
124 | ||
125 | ||
126 | ||
127 | ||
128 | ||
129 | ||
130 |