]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupControl.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?
11 import wx
.lib
.popupctl
as pop
12 import wx
.calendar
as cal
14 class TestDateControl(pop
.wxPopupControl
):
15 def __init__(self
,*_args
,**_kwargs
):
16 apply(pop
.wxPopupControl
.__init
__,(self
,) + _args
,_kwargs
)
18 self
.win
= wx
.Window(self
,-1,pos
= (0,0),style
= 0)
19 self
.cal
= cal
.CalendarCtrl(self
.win
,-1,pos
= (0,0))
21 bz
= self
.cal
.GetBestSize()
24 # This method is needed to set the contents that will be displayed
26 self
.SetPopupContent(self
.win
)
28 # Event registration for date selection
29 self
.cal
.Bind(cal
.EVT_CALENDAR_DAY
, self
.OnCalSelected
)
31 # Method called when a day is selected in the calendar
32 def OnCalSelected(self
,evt
):
34 date
= self
.cal
.GetDate()
36 # Format the date that was selected for the text part of the control
37 self
.SetValue('%02d/%02d/%04d' % (date
.GetDay(),
42 # Method overridden from wxPopupControl
43 # This method is called just before the popup is displayed
44 # Use this method to format any controls in the popup
45 def FormatContent(self
):
46 # I parse the value in the text part to resemble the correct date in
47 # the calendar control
48 txtValue
= self
.GetValue()
49 dmy
= txtValue
.split('/')
53 date
= self
.cal
.GetDate()
61 self
.cal
.SetDate(wx
.DateTimeFromDMY(d
,m
,y
))
65 self
.cal
.SetDate(wx
.DateTime_Today())
68 #---------------------------------------------------------------------------
70 class TestPanel(wx
.Panel
):
71 def __init__(self
, parent
, log
):
73 wx
.Panel
.__init
__(self
, parent
, -1)
74 date
= TestDateControl(self
, -1, pos
= (30,30), size
= (100,22))
76 #----------------------------------------------------------------------
78 def runTest(frame
, nb
, log
):
79 win
= TestPanel(nb
, log
)
82 #----------------------------------------------------------------------
84 overview
= """<html><body>
85 <h2><center>wxPopupControl</center></h2>
87 wxPopupControl is a class that can display a value and has a button
88 that will popup another window similar to how a wxComboBox works. The
89 popup window can contain whatever is needed to edit the value. This
90 example uses a wxCalendarCtrl.
92 <p>Currently a wxDialog is used for the popup. Eventually a
93 wxPopupWindow should be used...
99 if __name__
== '__main__':
102 run
.main(['', os
.path
.basename(sys
.argv
[0])])