]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/DialogUnits.py
Allow clearing the history, and saving the history on demand
[wxWidgets.git] / 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 wx
16
17 #---------------------------------------------------------------------------
18
19 # Create a new frame class, derived from the wxPython Frame.
20 class MyFrame(wx.Frame):
21
22 def __init__(self, parent, id, title):
23 # First, call the base class' __init__ method to create the frame
24 wx.Frame.__init__(self, parent, id, title, (100, 100), (160, 100))
25
26 # Associate some events with methods of this class
27 self.Bind(wx.EVT_SIZE, self.OnSize)
28 self.Bind(wx.EVT_MOVE, self.OnMove)
29 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
30
31 # Add a panel and some controls to display the size and position
32 panel = wx.Panel(self, -1)
33
34 wx.StaticText(panel, -1, "Size:",
35 wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize
36 )
37
38 wx.StaticText(panel, -1, "Pos:",
39 wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize
40 )
41
42 self.sizeCtrl = wx.TextCtrl(panel, -1, "",
43 wx.DLG_PNT(panel, (24, 4)),
44 wx.DLG_SZE(panel, (36, -1)),
45 wx.TE_READONLY)
46
47 self.posCtrl = wx.TextCtrl(panel, -1, "",
48 wx.DLG_PNT(panel, (24, 16)),
49 wx.DLG_SZE(panel, (36, -1)),
50 wx.TE_READONLY)
51
52 #print wx.DLG_PNT(panel, (24, 4)), wx.DLG_SZE(panel, (36, -1))
53 #print wx.DLG_PNT(panel, (24, 16)),wx.DLG_SZE(panel, (36, -1))
54
55 # This method is called automatically when the CLOSE event is
56 # sent to this window
57 def OnCloseWindow(self, event):
58 # tell the window to kill itself
59 self.Destroy()
60
61 # This method is called by the System when the window is resized,
62 # because of the association above.
63 def OnSize(self, event):
64 size = event.GetSize()
65 self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
66
67 # tell the event system to continue looking for an event handler,
68 # so the default handler will get called.
69 event.Skip()
70
71 # This method is called by the System when the window is moved,
72 # because of the association above.
73 def OnMove(self, event):
74 pos = event.GetPosition()
75 self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
76
77
78
79 #---------------------------------------------------------------------------
80 # if running standalone
81
82 if __name__ == "__main__":
83 # Every wxWindows application must have a class derived from wxApp
84 class MyApp(wx.App):
85
86 # wxWindows calls this method to initialize the application
87 def OnInit(self):
88
89 # Create an instance of our customized Frame class
90 frame = MyFrame(None, -1, "This is a test")
91 frame.Show(True)
92
93 # Tell wxWindows that this is our main window
94 self.SetTopWindow(frame)
95
96 # Return a success flag
97 return True
98
99
100 app = MyApp(0) # Create an instance of the application class
101 app.MainLoop() # Tell it to start processing events
102
103
104 #---------------------------------------------------------------------------
105 # if running as part of the Demo Framework...
106
107 def runTest(frame, nb, log):
108 win = MyFrame(frame, -1, "This is a test")
109 frame.otherWin = win
110 win.Show(True)
111
112
113 overview = """\
114 A simple example that shows how to use Dialog Units.
115 """
116
117 #----------------------------------------------------------------------------
118 #
119
120
121
122
123
124
125
126
127