]>
Commit | Line | Data |
---|---|---|
af309447 RD |
1 | #!/bin/env python |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: test7.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 | ||
14 | ||
15 | ## import all of the wxPython GUI package | |
16 | from wxPython.wx import * | |
17 | ||
18 | ||
19 | #--------------------------------------------------------------------------- | |
20 | ||
21 | ## Create a new frame class, derived from the wxPython Frame. | |
22 | class MyFrame(wxFrame): | |
23 | ||
24 | def __init__(self, parent, id, title): | |
25 | # First, call the base class' __init__ method to create the frame | |
26 | wxFrame.__init__(self, parent, id, title, | |
27 | wxPoint(100, 100), wxSize(160, 100)) | |
28 | ||
29 | # Associate some events with methods of this class | |
30 | EVT_SIZE(self, self.OnSize) | |
31 | EVT_MOVE(self, self.OnMove) | |
32 | ||
33 | # Add a panel and some controls to display the size and position | |
34 | panel = wxPanel(self, -1) | |
35 | wxStaticText(panel, -1, "Size:", | |
36 | wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize) | |
37 | wxStaticText(panel, -1, "Pos:", | |
1e4a197e RD |
38 | wxDLG_PNT(panel, wxPoint(4, 18)), wxDefaultSize) |
39 | wxStaticText(panel, -1, "ScreenPos:", | |
40 | wxDLG_PNT(panel, wxPoint(4, 32)), wxDefaultSize) | |
af309447 | 41 | self.sizeCtrl = wxTextCtrl(panel, -1, "", |
1e4a197e | 42 | wxDLG_PNT(panel, wxPoint(36, 4)), |
af309447 RD |
43 | wxDLG_SZE(panel, wxSize(36, -1)), |
44 | wxTE_READONLY) | |
45 | ||
46 | self.posCtrl = wxTextCtrl(panel, -1, "", | |
1e4a197e | 47 | wxDLG_PNT(panel, wxPoint(36, 18)), |
af309447 RD |
48 | wxDLG_SZE(panel, wxSize(36, -1)), |
49 | wxTE_READONLY) | |
50 | ||
1e4a197e RD |
51 | self.sposCtrl = wxTextCtrl(panel, -1, "", |
52 | wxDLG_PNT(panel, wxPoint(36, 32)), | |
53 | wxDLG_SZE(panel, wxSize(36, -1)), | |
54 | wxTE_READONLY) | |
55 | ||
56 | panel.Fit() | |
57 | self.Fit() | |
af309447 RD |
58 | |
59 | # This method is called automatically when the CLOSE event is | |
60 | # sent to this window | |
61 | def OnCloseWindow(self, event): | |
62 | # tell the window to kill itself | |
63 | self.Destroy() | |
64 | ||
65 | ||
66 | # This method is called by the System when the window is resized, | |
67 | # because of the association above. | |
68 | def OnSize(self, event): | |
69 | size = event.GetSize() | |
70 | self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height)) | |
1e4a197e RD |
71 | p = self.ClientToScreen((0,0)) |
72 | self.sposCtrl.SetValue("%s, %s" % (p.x, p.y)) | |
af309447 RD |
73 | |
74 | # tell the event system to continue looking for an event handler, | |
75 | # so the default handler will get called. | |
76 | event.Skip() | |
77 | ||
78 | # This method is called by the System when the window is moved, | |
79 | # because of the association above. | |
80 | def OnMove(self, event): | |
81 | pos = event.GetPosition() | |
82 | self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y)) | |
1e4a197e RD |
83 | p = self.ClientToScreen((0,0)) |
84 | self.sposCtrl.SetValue("%s, %s" % (p.x, p.y)) | |
af309447 RD |
85 | |
86 | ||
87 | ||
88 | #--------------------------------------------------------------------------- | |
89 | ||
90 | # Every wxWindows application must have a class derived from wxApp | |
91 | class MyApp(wxApp): | |
92 | ||
93 | # wxWindows calls this method to initialize the application | |
94 | def OnInit(self): | |
95 | ||
96 | # Create an instance of our customized Frame class | |
97 | frame = MyFrame(NULL, -1, "This is a test") | |
98 | frame.Show(true) | |
99 | ||
100 | # Tell wxWindows that this is our main window | |
101 | self.SetTopWindow(frame) | |
102 | ||
103 | # Return a success flag | |
104 | return true | |
105 | ||
106 | #--------------------------------------------------------------------------- | |
107 | ||
108 | ||
109 | app = MyApp(0) # Create an instance of the application class | |
110 | app.MainLoop() # Tell it to start processing events | |
111 | ||
112 | ||
113 | #---------------------------------------------------------------------------- | |
114 | # | |
115 | ||
116 | ||
117 | ||
118 | ||
119 | ||
120 | ||
121 | ||
122 | ||
123 |