]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupControl.py
1 from wxPython
.wx
import *
2 from wxPython
.lib
.popupctl
import wxPopupControl
3 from wxPython
.calendar
import *
5 class TestDateControl(wxPopupControl
):
6 def __init__(self
,*_args
,**_kwargs
):
7 apply(wxPopupControl
.__init
__,(self
,) + _args
,_kwargs
)
9 self
.win
= wxWindow(self
,-1,pos
= (0,0),style
= 0)
10 self
.cal
= wxCalendarCtrl(self
.win
,-1,pos
= (0,0))
12 bz
= self
.cal
.GetBestSize()
15 # This method is needed to set the contents that will be displayed
17 self
.SetPopupContent(self
.win
)
19 # Event registration for date selection
20 EVT_CALENDAR_DAY(self
.cal
,self
.cal
.GetId(),self
.OnCalSelected
)
22 # Method called when a day is selected in the calendar
23 def OnCalSelected(self
,evt
):
25 date
= self
.cal
.GetDate()
27 # Format the date that was selected for the text part of the control
28 self
.SetValue('%02d/%02d/%04d' % (date
.GetDay(),
33 # Method overridden from wxPopupControl
34 # This method is called just before the popup is displayed
35 # Use this method to format any controls in the popup
36 def FormatContent(self
):
37 # I parse the value in the text part to resemble the correct date in
38 # the calendar control
39 txtValue
= self
.GetValue()
40 dmy
= txtValue
.split('/')
43 date
= self
.cal
.GetDate()
50 self
.cal
.SetDate(wxDateTimeFromDMY(d
,m
,y
))
53 self
.cal
.SetDate(wxDateTime_Today())
56 #---------------------------------------------------------------------------
58 class TestPanel(wxPanel
):
59 def __init__(self
, parent
, log
):
61 wxPanel
.__init
__(self
, parent
, -1)
62 date
= TestDateControl(self
, -1, pos
= (30,30), size
= (100,22))
64 #----------------------------------------------------------------------
66 def runTest(frame
, nb
, log
):
67 win
= TestPanel(nb
, log
)
70 #----------------------------------------------------------------------
74 overview
= """<html><body>
75 <h2><center>wxPopupControl</center></h2>
77 wxPopupControl is a class that can display a value and has a button
78 that will popup another window similar to how a wxComboBox works. The
79 popup window can contain whatever is needed to edit the value. This
80 example uses a wxCalendarCtrl.
82 <p>Currently a wxDialog is used for the popup. Eventually a
83 wxPopupWindow should be used...
90 if __name__
== '__main__':
93 run
.main(['', os
.path
.basename(sys
.argv
[0])])