wx.DateTime instance getting clobbered

I'm using wxPython - GTK/2.4.2 and getting a wx.DateTime instance overwritten with garbage for reasons I don't understand.

I have a Frame containing a RowColSizer that contains 7 TextCtrl's (one for each day of the week) and one CalendarCtrl. There is also a label just above each TextCtrl containing the week day and date. I use self.current to hold what date the user wants. self.current is used to set the CalendarCtrl's date, and It is initially set to wx.DateTime_Now(). Each TextCtrl has the EVT_LEFT_DOWN event bound to a method called self.OnFocus(). The CalendarCtrl has the EVT_CALENDAR_SEL_CHANGED event bound to self.OnDaySel(). self.OnDaySel() simply gets the date selected on the CalendarCtrl and calls self.setDate() which changes the labels above each TextCtrl to reflect the proper dates. Here is self.OnDaySel().

    def OnDaySel(self, event):
        self.current = event.GetDate()
        newWeek = self.current.GetWeekOfYear()
        if newWeek != self.week:
            self.setDate()
            self.week = newWeek

self.OnFocus() changes the CalendarCtrl to reflect the day that was selected with the TextCtrl's and look like this.

    def OnFocus(self, event):
        day = self.dayIDs.index(event.GetId())
        self.current.SetToWeekDayInSameWeek(day,
            flags=self.current.Sunday_First)
        self.clnd.SetDate(self.current)

OK, now the problem. I can left click on the TextCtrl's OK, and I can click on a day in the CalendarCtrl OK. But if I then go back and click on a TextCtrl, self.current gets set to 'Tue Jan 13 09:58:22 1970', even if I check it before anything else is done in self.OnFocus().

I've tried everthing I can think of to track down this problem, but have hit a wall. If anyone can spot what I did wrong, I would appreciate being pointed in the right direction.

Thanks,
Gary

Gary Jaffe wrote:

OK, now the problem. I can left click on the TextCtrl's OK, and I can click on a day in the CalendarCtrl OK. But if I then go back and click on a TextCtrl, self.current gets set to 'Tue Jan 13 09:58:22 1970', even if I check it before anything else is done in self.OnFocus().

I've tried everthing I can think of to track down this problem, but have hit a wall. If anyone can spot what I did wrong, I would appreciate being pointed in the right direction.

Please try to duplicate it in a small-as-possible sample app.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Gary Jaffe wrote:

OK, now the problem. I can left click on the TextCtrl's OK, and I can click on a day in the CalendarCtrl OK. But if I then go back and click on a TextCtrl, self.current gets set to 'Tue Jan 13 09:58:22 1970', even if I check it before anything else is done in self.OnFocus().

I've tried everthing I can think of to track down this problem, but have hit a wall. If anyone can spot what I did wrong, I would appreciate being pointed in the right direction.

Please try to duplicate it in a small-as-possible sample app.

Here is the small-as-possible sample app that demonstrates the problem I am having.

···

-----------------------------------------------------------
#!/usr/bin/env python

import wx
import wx.calendar as cal

class schedFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)
        vBox = wx.BoxSizer(wx.VERTICAL)
        self.current = wx.DateTime_Now()

        text = wx.TextCtrl(self, -1, '', size=(120, 190),
            style=wx.TE_MULTILINE)
        wx.EVT_LEFT_DOWN(text, self.OnFocus)
        vBox.Add(text, 1, 0)

        clnd = cal.CalendarCtrl(self, -1,
            self.current, style=
            cal.CAL_SEQUENTIAL_MONTH_SELECTION)
        cal.EVT_CALENDAR_SEL_CHANGED(self, clnd.GetId(),
            self.OnDaySel)
        vBox.Add(clnd, 1, wx.EXPAND)

        self.SetSizer(vBox)
        self.SetAutoLayout(1)
        vBox.Fit(self)

    def OnDaySel(self, event):
        print "In OnDaySel at beginning: self.current = ", \
            self.current

##### Without this next line the problem goes away #####
        self.current = event.GetDate()
               print "In OnDaySel at end: self.current = ", \
            self.current

    def OnFocus(self, event):
        print "In OnFocus: self.current = ", self.current

class MainLoop(wx.App):
    def OnInit(self):
        frame = schedFrame(None, -1, "Sched")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MainLoop(0)
app.MainLoop()
-----------------------------------------------------------------------------

When I run this and click on a day in the calendar, then click in the TextCtrl, self.current gets clobbered by the time it is printed in self.OnFocus(). I see I can eliminate the problem by getting rid of the line <self.current = event.GetDate()> above. I'm not sure that's the way to get the date of the CalendarCtrl, but this is how I saw it done in the wxCalendarCtrl.py demo.

Gary

I tried your program on WinXP wxPython 2.5.2.7 Python 2.3.4, and it
seems to work as I would expect.

Left clicking on 9/28 --> textctrl, then 9/6 --> textctrl:
In OnFocus: self.current = 09/15/04 18:26:45
In OnDaySel at beginning: self.current = 09/15/04 18:26:45
In OnDaySel at end: self.current = 09/28/04 00:00:00
In OnFocus: self.current = 09/28/04 00:00:00
In OnFocus: self.current = 09/28/04 00:00:00
In OnDaySel at beginning: self.current = 09/28/04 00:00:00
In OnDaySel at end: self.current = 09/06/04 00:00:00
In OnFocus: self.current = 09/06/04 00:00:00

Donnal Walter
Arkansas Children's Hospital

···

--- Gary Jaffe <gfjaffe@yahoo.com> wrote:

When I run this and click on a day in the calendar, then click in
the TextCtrl, self.current gets clobbered by the time it is
printed in self.OnFocus(). I see I can eliminate the problem by
getting rid of the line <self.current = event.GetDate()> above.
I'm not sure that's the way to get the date of the CalendarCtrl,
but this is how I saw it done in the wxCalendarCtrl.py demo.

Donnal Walter wrote:

When I run this and click on a day in the calendar, then click in
the TextCtrl, self.current gets clobbered by the time it is
printed in self.OnFocus(). I see I can eliminate the problem by
getting rid of the line <self.current = event.GetDate()> above.
I'm not sure that's the way to get the date of the CalendarCtrl,
but this is how I saw it done in the wxCalendarCtrl.py demo.

I tried your program on WinXP wxPython 2.5.2.7 Python 2.3.4, and it
seems to work as I would expect.

Left clicking on 9/28 --> textctrl, then 9/6 --> textctrl:
In OnFocus: self.current = 09/15/04 18:26:45
In OnDaySel at beginning: self.current = 09/15/04 18:26:45
In OnDaySel at end: self.current = 09/28/04 00:00:00
In OnFocus: self.current = 09/28/04 00:00:00
In OnDaySel at beginning: self.current = 09/28/04 00:00:00
In OnDaySel at end: self.current = 09/06/04 00:00:00
In OnFocus: self.current = 09/06/04 00:00:00

Donnal Walter
Arkansas Children's Hospital

Thanks for checking it out on your platform. On mine (Libranet Linux GTK wxPython 2.4.2.4 Python 2.3.3) I get

Left clicking on 9/28 --> textctrl
In OnDaySel at beginning: self.current = Wed Sep 15 22:44:33 2004
In OnDaySel at end: self.current = Tue Sep 28 00:00:00 2004
In OnFocus: self.current = Tue Jan 13 05:53:17 1970

Gary

···

--- Gary Jaffe <gfjaffe@yahoo.com> wrote: