]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/DialogUnits.py
Added a demo showing how to use wxPostEvent
[wxWidgets.git] / utils / wxPython / demo / DialogUnits.py
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
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:",
38 wxDLG_PNT(panel, wxPoint(4, 16)), wxDefaultSize)
39 self.sizeCtrl = wxTextCtrl(panel, -1, "",
40 wxDLG_PNT(panel, wxPoint(24, 4)),
41 wxDLG_SZE(panel, wxSize(36, -1)),
42 wxTE_READONLY)
43
44 self.posCtrl = wxTextCtrl(panel, -1, "",
45 wxDLG_PNT(panel, wxPoint(24, 16)),
46 wxDLG_SZE(panel, wxSize(36, -1)),
47 wxTE_READONLY)
48
49 #print wxDLG_PNT(panel, wxPoint(24, 4)), wxDLG_SZE(panel, wxSize(36, -1))
50 #print wxDLG_PNT(panel, wxPoint(24, 16)),wxDLG_SZE(panel, wxSize(36, -1))
51
52
53 # This method is called automatically when the CLOSE event is
54 # sent to this window
55 def OnCloseWindow(self, event):
56 # tell the window to kill itself
57 self.Destroy()
58
59
60 # This method is called by the System when the window is resized,
61 # because of the association above.
62 def OnSize(self, event):
63 size = event.GetSize()
64 self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
65
66 # tell the event system to continue looking for an event handler,
67 # so the default handler will get called.
68 event.Skip()
69
70 # This method is called by the System when the window is moved,
71 # because of the association above.
72 def OnMove(self, event):
73 pos = event.GetPosition()
74 self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
75
76
77
78 #---------------------------------------------------------------------------
79 # if running standalone
80
81 if __name__ == "__main__":
82 # Every wxWindows application must have a class derived from wxApp
83 class MyApp(wxApp):
84
85 # wxWindows calls this method to initialize the application
86 def OnInit(self):
87
88 # Create an instance of our customized Frame class
89 frame = MyFrame(NULL, -1, "This is a test")
90 frame.Show(true)
91
92 # Tell wxWindows that this is our main window
93 self.SetTopWindow(frame)
94
95 # Return a success flag
96 return true
97
98
99 app = MyApp(0) # Create an instance of the application class
100 app.MainLoop() # Tell it to start processing events
101
102
103 #---------------------------------------------------------------------------
104 # if running as part of the Demo Framework...
105
106 def runTest(frame, nb, log):
107 win = MyFrame(frame, -1, "This is a test")
108 frame.otherWin = win
109 win.Show(true)
110
111
112 overview = """\
113 A simple example that shows how to use Dialog Units.
114 """
115
116 #----------------------------------------------------------------------------
117 #
118
119
120
121
122
123
124
125
126