]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/PopupControl.py
1 # 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7 # o Is it just me or are the graphics for the control not lining up right?
9 # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
11 # o wxPopupControl -> PopupControl
15 import wx
.lib
.popupctl
as pop
16 import wx
.calendar
as cal
18 class TestDateControl(pop
.PopupControl
):
19 def __init__(self
,*_args
,**_kwargs
):
20 apply(pop
.PopupControl
.__init
__,(self
,) + _args
,_kwargs
)
22 self
.win
= wx
.Window(self
,-1,pos
= (0,0),style
= 0)
23 self
.cal
= cal
.CalendarCtrl(self
.win
,-1,pos
= (0,0))
25 bz
= self
.cal
.GetBestSize()
28 # This method is needed to set the contents that will be displayed
30 self
.SetPopupContent(self
.win
)
32 # Event registration for date selection
33 self
.cal
.Bind(cal
.EVT_CALENDAR_DAY
, self
.OnCalSelected
)
35 # Method called when a day is selected in the calendar
36 def OnCalSelected(self
,evt
):
38 date
= self
.cal
.GetDate()
40 # Format the date that was selected for the text part of the control
41 self
.SetValue('%02d/%02d/%04d' % (date
.GetDay(),
46 # Method overridden from PopupControl
47 # This method is called just before the popup is displayed
48 # Use this method to format any controls in the popup
49 def FormatContent(self
):
50 # I parse the value in the text part to resemble the correct date in
51 # the calendar control
52 txtValue
= self
.GetValue()
53 dmy
= txtValue
.split('/')
57 date
= self
.cal
.GetDate()
65 self
.cal
.SetDate(wx
.DateTimeFromDMY(d
,m
,y
))
69 self
.cal
.SetDate(wx
.DateTime_Today())
72 #---------------------------------------------------------------------------
74 class TestPanel(wx
.Panel
):
75 def __init__(self
, parent
, log
):
77 wx
.Panel
.__init
__(self
, parent
, -1)
78 date
= TestDateControl(self
, -1, pos
= (30,30), size
= (100,22))
80 #----------------------------------------------------------------------
82 def runTest(frame
, nb
, log
):
83 win
= TestPanel(nb
, log
)
86 #----------------------------------------------------------------------
88 overview
= """<html><body>
89 <h2><center>PopupControl</center></h2>
91 PopupControl is a class that can display a value and has a button
92 that will popup another window similar to how a wxComboBox works. The
93 popup window can contain whatever is needed to edit the value. This
94 example uses a wxCalendarCtrl.
96 <p>Currently a wxDialog is used for the popup. Eventually a
97 wxPopupWindow should be used...
103 if __name__
== '__main__':
106 run
.main(['', os
.path
.basename(sys
.argv
[0])])