]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/env python | |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: test1.py | |
4 | # Purpose: A minimal wxPython program | |
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 | ||
34 | # This method is called automatically when the CLOSE event is | |
35 | # sent to this window | |
36 | def OnCloseWindow(self, event): | |
37 | # tell the window to kill itself | |
38 | self.Destroy() | |
39 | ||
40 | ||
41 | # This method is called by the System when the window is resized, | |
42 | # because of the association above. | |
43 | def OnSize(self, event): | |
44 | size = event.GetSize() | |
45 | print "size:", size.width, size.height | |
46 | ||
47 | # This method is called by the System when the window is moved, | |
48 | # because of the association above. | |
49 | def OnMove(self, event): | |
50 | pos = event.GetPosition() | |
51 | print "pos:", pos.x, pos.y | |
52 | ||
53 | ||
54 | ||
55 | #--------------------------------------------------------------------------- | |
56 | ||
57 | # Every wxWindows application must have a class derived from wxApp | |
58 | class MyApp(wxApp): | |
59 | ||
60 | # wxWindows calls this method to initialize the application | |
61 | def OnInit(self): | |
62 | ||
63 | # Create an instance of our customized Frame class | |
64 | frame = MyFrame(NULL, -1, "This is a test") | |
65 | frame.Show(true) | |
66 | ||
67 | # Tell wxWindows that this is our main window | |
68 | self.SetTopWindow(frame) | |
69 | ||
70 | # Return a success flag | |
71 | return true | |
72 | ||
73 | #--------------------------------------------------------------------------- | |
74 | ||
75 | ||
76 | app = MyApp(0) # Create an instance of the application class | |
77 | app.MainLoop() # Tell it to start processing events | |
78 | ||
79 | print 'done!' | |
80 | ||
81 | #---------------------------------------------------------------------------- | |
82 | # | |
83 |