]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/DialogUnits.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 #----------------------------------------------------------------------------
13 # Updated 11/9/2003 by Jeff Grimmett (grimmtooth@softhome.net)
15 # o Converted for V2.5 compatability
20 #---------------------------------------------------------------------------
22 # Create a new frame class, derived from the wxPython Frame.
23 class MyFrame(wx
.Frame
):
25 def __init__(self
, parent
, id, title
):
26 # First, call the base class' __init__ method to create the frame
27 wx
.Frame
.__init
__(self
, parent
, id, title
, (100, 100), (160, 100))
29 # Associate some events with methods of this class
30 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
31 self
.Bind(wx
.EVT_MOVE
, self
.OnMove
)
32 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
34 # Add a panel and some controls to display the size and position
35 panel
= wx
.Panel(self
, -1)
37 wx
.StaticText(panel
, -1, "Size:",
38 wx
.DLG_PNT(panel
, (4, 4)), wx
.DefaultSize
41 wx
.StaticText(panel
, -1, "Pos:",
42 wx
.DLG_PNT(panel
, (4, 16)), wx
.DefaultSize
45 self
.sizeCtrl
= wx
.TextCtrl(panel
, -1, "",
46 wx
.DLG_PNT(panel
, (24, 4)),
47 wx
.DLG_SZE(panel
, (36, -1)),
50 self
.posCtrl
= wx
.TextCtrl(panel
, -1, "",
51 wx
.DLG_PNT(panel
, (24, 16)),
52 wx
.DLG_SZE(panel
, (36, -1)),
55 #print wx.DLG_PNT(panel, (24, 4)), wx.DLG_SZE(panel, (36, -1))
56 #print wx.DLG_PNT(panel, (24, 16)),wx.DLG_SZE(panel, (36, -1))
58 # This method is called automatically when the CLOSE event is
60 def OnCloseWindow(self
, event
):
61 # tell the window to kill itself
64 # This method is called by the System when the window is resized,
65 # because of the association above.
66 def OnSize(self
, event
):
67 size
= event
.GetSize()
68 self
.sizeCtrl
.SetValue("%s, %s" % (size
.width
, size
.height
))
70 # tell the event system to continue looking for an event handler,
71 # so the default handler will get called.
74 # This method is called by the System when the window is moved,
75 # because of the association above.
76 def OnMove(self
, event
):
77 pos
= event
.GetPosition()
78 self
.posCtrl
.SetValue("%s, %s" % (pos
.x
, pos
.y
))
82 #---------------------------------------------------------------------------
83 # if running standalone
85 if __name__
== "__main__":
86 # Every wxWindows application must have a class derived from wxApp
89 # wxWindows calls this method to initialize the application
92 # Create an instance of our customized Frame class
93 frame
= MyFrame(None, -1, "This is a test")
96 # Tell wxWindows that this is our main window
97 self
.SetTopWindow(frame
)
99 # Return a success flag
103 app
= MyApp(0) # Create an instance of the application class
104 app
.MainLoop() # Tell it to start processing events
107 #---------------------------------------------------------------------------
108 # if running as part of the Demo Framework...
110 def runTest(frame
, nb
, log
):
111 win
= MyFrame(frame
, -1, "This is a test")
117 A simple example that shows how to use Dialog Units.
120 #----------------------------------------------------------------------------