From: Alex T. <al...@tw...> - 2007-10-03 21:48:46
|
hwg wrote: > I'm using the Calendar component to enter dates into a text field. > (Thanks to the example Calendar Dialog provided by Alex Tweedly on his > home page). > > I just want to change the functionality a bit, and I'm not sure how to > do it. > > When the Calendar pops up, it is always sitting at today's date. I > would like it to be sitting at whatever date was already in the text > box. How do I change the "current date" on the Calendar programatically? > Certainly not the only way, possibly not the best way, but you can do something very like this ..... I made modifications to caldialog.py I think to the same version as is on the web site) - here's notes and the relevant section that I changed 1. add the import of datetime 2. added year, month and day parameters to the __init__ 3. set the date as soon as the custom dialog is created (i.e. before it is displayed) and then you'll need to make changes to the calling code to extract the date from the text box and pass it in ... import wx import datetime class CalDialog(model.CustomDialog): def __init__(self, parent, txt='', y=2006, m=1, d=1): model.CustomDialog.__init__(self, parent) self.components.Calendar1.PySetDate(datetime.date(y,m,d)) def on_Calendar1_mouseDoubleClick(self, event): self.EndModal(wx.ID_OK) def on_btnOK_mouseClick(self, event): print "in ok click" event.Skip() def calDialog(parent, y=2006, m=1, d=2): dlg = CalDialog(parent, y=y, m=m, d=d) result = dlg.showModal() -- Alex Tweedly mailto:al...@tw... www.tweedly.net |