]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test7.py
2 #----------------------------------------------------------------------------
4 # Purpose: A minimal wxPython program that is a bit smarter than test1.
8 # Created: A long time ago, in a galaxy far, far away...
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
15 ## import all of the wxPython GUI package
16 from wxPython
.wx
import *
19 #---------------------------------------------------------------------------
21 ## Create a new frame class, derived from the wxPython Frame.
22 class MyFrame(wxFrame
):
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))
29 # Associate some events with methods of this class
30 EVT_SIZE(self
, self
.OnSize
)
31 EVT_MOVE(self
, self
.OnMove
)
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:",
38 wxDLG_PNT(panel
, wxPoint(4, 14)), wxDefaultSize
)
39 self
.sizeCtrl
= wxTextCtrl(panel
, -1, "",
40 wxDLG_PNT(panel
, wxPoint(24, 4)),
41 wxDLG_SZE(panel
, wxSize(36, -1)),
44 self
.posCtrl
= wxTextCtrl(panel
, -1, "",
45 wxDLG_PNT(panel
, wxPoint(24, 14)),
46 wxDLG_SZE(panel
, wxSize(36, -1)),
50 # This method is called automatically when the CLOSE event is
52 def OnCloseWindow(self
, event
):
53 # tell the window to kill itself
57 # This method is called by the System when the window is resized,
58 # because of the association above.
59 def OnSize(self
, event
):
60 size
= event
.GetSize()
61 self
.sizeCtrl
.SetValue("%s, %s" % (size
.width
, size
.height
))
63 # tell the event system to continue looking for an event handler,
64 # so the default handler will get called.
67 # This method is called by the System when the window is moved,
68 # because of the association above.
69 def OnMove(self
, event
):
70 pos
= event
.GetPosition()
71 self
.posCtrl
.SetValue("%s, %s" % (pos
.x
, pos
.y
))
75 #---------------------------------------------------------------------------
77 # Every wxWindows application must have a class derived from wxApp
80 # wxWindows calls this method to initialize the application
83 # Create an instance of our customized Frame class
84 frame
= MyFrame(NULL
, -1, "This is a test")
87 # Tell wxWindows that this is our main window
88 self
.SetTopWindow(frame
)
90 # Return a success flag
93 #---------------------------------------------------------------------------
96 app
= MyApp(0) # Create an instance of the application class
97 app
.MainLoop() # Tell it to start processing events
100 #----------------------------------------------------------------------------