2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
import wx
|
|
|
|
import wx.lib.popupctl as pop
|
|
|
|
import wx.calendar as cal
|
|
|
|
|
2003-12-22 14:09:54 -05:00
|
|
|
class TestDateControl(pop.PopupControl):
|
2003-03-25 01:35:27 -05:00
|
|
|
def __init__(self,*_args,**_kwargs):
|
2003-12-22 14:09:54 -05:00
|
|
|
apply(pop.PopupControl.__init__,(self,) + _args,_kwargs)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.win = wx.Window(self,-1,pos = (0,0),style = 0)
|
|
|
|
self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0))
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
bz = self.cal.GetBestSize()
|
|
|
|
self.win.SetSize(bz)
|
|
|
|
|
|
|
|
# This method is needed to set the contents that will be displayed
|
|
|
|
# in the popup
|
|
|
|
self.SetPopupContent(self.win)
|
|
|
|
|
|
|
|
# Event registration for date selection
|
2003-12-08 20:23:28 -05:00
|
|
|
self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
# Method called when a day is selected in the calendar
|
|
|
|
def OnCalSelected(self,evt):
|
|
|
|
self.PopDown()
|
|
|
|
date = self.cal.GetDate()
|
|
|
|
|
|
|
|
# Format the date that was selected for the text part of the control
|
|
|
|
self.SetValue('%02d/%02d/%04d' % (date.GetDay(),
|
|
|
|
date.GetMonth()+1,
|
|
|
|
date.GetYear()))
|
|
|
|
evt.Skip()
|
|
|
|
|
2003-12-22 14:09:54 -05:00
|
|
|
# Method overridden from PopupControl
|
2003-03-25 01:35:27 -05:00
|
|
|
# This method is called just before the popup is displayed
|
|
|
|
# Use this method to format any controls in the popup
|
|
|
|
def FormatContent(self):
|
|
|
|
# I parse the value in the text part to resemble the correct date in
|
|
|
|
# the calendar control
|
|
|
|
txtValue = self.GetValue()
|
|
|
|
dmy = txtValue.split('/')
|
|
|
|
didSet = False
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
if len(dmy) == 3:
|
|
|
|
date = self.cal.GetDate()
|
|
|
|
d = int(dmy[0])
|
|
|
|
m = int(dmy[1]) - 1
|
|
|
|
y = int(dmy[2])
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
if d > 0 and d < 31:
|
|
|
|
if m >= 0 and m < 12:
|
|
|
|
if y > 1000:
|
2003-12-08 20:23:28 -05:00
|
|
|
self.cal.SetDate(wx.DateTimeFromDMY(d,m,y))
|
2003-03-25 01:35:27 -05:00
|
|
|
didSet = True
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
if not didSet:
|
2003-12-08 20:23:28 -05:00
|
|
|
self.cal.SetDate(wx.DateTime_Today())
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2003-03-25 01:35:27 -05:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2003-03-25 01:35:27 -05:00
|
|
|
date = TestDateControl(self, -1, pos = (30,30), size = (100,22))
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
overview = """<html><body>
|
2003-12-22 14:09:54 -05:00
|
|
|
<h2><center>PopupControl</center></h2>
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-22 14:09:54 -05:00
|
|
|
PopupControl is a class that can display a value and has a button
|
2004-01-12 22:17:17 -05:00
|
|
|
that will popup another window similar to how a wx.ComboBox works. The
|
2003-03-25 01:35:27 -05:00
|
|
|
popup window can contain whatever is needed to edit the value. This
|
2004-01-12 22:17:17 -05:00
|
|
|
example uses a wx.CalendarCtrl.
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
<p>Currently a wx.Dialog is used for the popup. Eventually a
|
|
|
|
wx.PopupWindow should be used...
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|