]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | #!/bin/env python |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: test1.py | |
4 | # Purpose: A minimal wxPython program | |
5 | # | |
6 | # Author: Robin Dunn | |
7 | # | |
af309447 | 8 | # Created: A long time ago, in a galaxy far, far away... |
7bf85405 RD |
9 | # RCS-ID: $Id$ |
10 | # Copyright: (c) 1998 by Total Control Software | |
11 | # Licence: wxWindows license | |
12 | #---------------------------------------------------------------------------- | |
13 | ||
14 | ||
af309447 | 15 | ## import all of the wxPython GUI package |
b8b8dda7 | 16 | from wxPython.wx import * |
7bf85405 RD |
17 | |
18 | ||
19 | #--------------------------------------------------------------------------- | |
20 | ||
af309447 | 21 | ## Create a new frame class, derived from the wxPython Frame. |
7bf85405 | 22 | class MyFrame(wxFrame): |
af309447 | 23 | |
7bf85405 | 24 | def __init__(self, parent, id, title): |
af309447 RD |
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) | |
7bf85405 | 32 | |
af309447 RD |
33 | |
34 | # This method is called automatically when the CLOSE event is | |
35 | # sent to this window | |
7bf85405 | 36 | def OnCloseWindow(self, event): |
af309447 | 37 | # tell the window to kill itself |
7bf85405 RD |
38 | self.Destroy() |
39 | ||
af309447 RD |
40 | |
41 | # This method is called by the System when the window is resized, | |
42 | # because of the association above. | |
7bf85405 RD |
43 | def OnSize(self, event): |
44 | size = event.GetSize() | |
45 | print "size:", size.width, size.height | |
46 | ||
af309447 RD |
47 | # This method is called by the System when the window is moved, |
48 | # because of the association above. | |
7bf85405 | 49 | def OnMove(self, event): |
7bf85405 RD |
50 | pos = event.GetPosition() |
51 | print "pos:", pos.x, pos.y | |
52 | ||
53 | ||
54 | ||
55 | #--------------------------------------------------------------------------- | |
56 | ||
af309447 | 57 | # Every wxWindows application must have a class derived from wxApp |
7bf85405 | 58 | class MyApp(wxApp): |
af309447 RD |
59 | |
60 | # wxWindows calls this method to initialize the application | |
7bf85405 | 61 | def OnInit(self): |
af309447 RD |
62 | |
63 | # Create an instance of our customized Frame class | |
7bf85405 RD |
64 | frame = MyFrame(NULL, -1, "This is a test") |
65 | frame.Show(true) | |
af309447 RD |
66 | |
67 | # Tell wxWindows that this is our main window | |
7bf85405 | 68 | self.SetTopWindow(frame) |
af309447 RD |
69 | |
70 | # Return a success flag | |
7bf85405 RD |
71 | return true |
72 | ||
73 | #--------------------------------------------------------------------------- | |
74 | ||
75 | ||
af309447 RD |
76 | app = MyApp(0) # Create an instance of the application class |
77 | app.MainLoop() # Tell it to start processing events | |
7bf85405 RD |
78 | |
79 | ||
80 | #---------------------------------------------------------------------------- | |
81 | # | |
af309447 | 82 |