]>
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 #----------------------------------------------------------------------------
17 #---------------------------------------------------------------------------
19 # Create a new frame class, derived from the wxPython Frame.
20 class MyFrame(wx
.Frame
):
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))
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
)
31 # Add a panel and some controls to display the size and position
32 panel
= wx
.Panel(self
, -1)
34 wx
.StaticText(panel
, -1, "Size:",
35 wx
.DLG_PNT(panel
, (4, 4)), wx
.DefaultSize
38 wx
.StaticText(panel
, -1, "Pos:",
39 wx
.DLG_PNT(panel
, (4, 16)), wx
.DefaultSize
42 self
.sizeCtrl
= wx
.TextCtrl(panel
, -1, "",
43 wx
.DLG_PNT(panel
, (24, 4)),
44 wx
.DLG_SZE(panel
, (36, -1)),
47 self
.posCtrl
= wx
.TextCtrl(panel
, -1, "",
48 wx
.DLG_PNT(panel
, (24, 16)),
49 wx
.DLG_SZE(panel
, (36, -1)),
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))
55 # This method is called automatically when the CLOSE event is
57 def OnCloseWindow(self
, event
):
58 # tell the window to kill itself
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
))
67 # tell the event system to continue looking for an event handler,
68 # so the default handler will get called.
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
))
79 #---------------------------------------------------------------------------
80 # if running standalone
82 if __name__
== "__main__":
83 # Every wxWindows application must have a class derived from wxApp
86 # wxWindows calls this method to initialize the application
89 # Create an instance of our customized Frame class
90 frame
= MyFrame(None, -1, "This is a test")
93 # Tell wxWindows that this is our main window
94 self
.SetTopWindow(frame
)
96 # Return a success flag
100 app
= MyApp(0) # Create an instance of the application class
101 app
.MainLoop() # Tell it to start processing events
104 #---------------------------------------------------------------------------
105 # if running as part of the Demo Framework...
107 def runTest(frame
, nb
, log
):
108 win
= MyFrame(frame
, -1, "This is a test")
114 A simple example that shows how to use Dialog Units.
117 #----------------------------------------------------------------------------