I had problems setting the day in the calendar widget (I was setting it
programmatically). So I made a bunch of changes which seemed to get it to
work. The point of the code I changed was not entirely clear to me, so I
may have done it some violence. I see no good reason for having 2 day
variables (3 if you include the select_day variable, which is set once and
never used in the original code).
I know your notes warned the calendar was a bit shakey. Since I really
needed a date/time widget, and since MS Windows can't do strptime(), it
would be great to have one.
There is also a sequencing problem, which I worked around. If you set the
day before the graphics have been displayed, self.st_pos is not set.
Here are the changes; I'm releasing them under GNU Public License:
bash-2.02$ diff -u calendar-0.py calendar.py # -0 is the original (v
2.1..113)
--- calendar-0.py Wed Dec 29 10:43:02 1999
+++ calendar.py Thu Jun 08 11:54:49 2000
@@ -213,7 +213,6 @@
x1 = self.x_st
y1 = self.y_st
- y1 = self.y_st
y2 = self.y_st + self.cheight
for i in range(8):
if self.hide_grid is FALSE:
@@ -308,21 +307,20 @@
dt = now()
self.month = dt.month
self.year = dt.year
- self.day = dt.day
+ self.set_day = dt.day
# set the current day
def SetCurrentDay(self):
self.SetNow()
- self.set_day = self.day
# get the date, day, month, year set in calendar
def GetDate(self):
- return self.day, self.month, self.year
+ return self.set_day, self.month, self.year
def GetDay(self):
- return self.day
+ return self.set_day
def GetMonth(self):
return self.month
@@ -373,17 +371,16 @@
def TestDay(self, key):
try:
- self.day = int(self.cal[key])
+ self.set_day = int(self.cal[key])
except:
return None
- if self.day == "":
+ if self.set_day == "":
return None
else:
evt = wxPyCommandEvent(2100, self.GetId())
- evt.click, evt.day, evt.month, evt.year = self.click, self.day,
sel
f.month, self.year
+ evt.click, evt.day, evt.month, evt.year = self.click,
self.set_day,
self.month, self.year
self.GetEventHandler().ProcessEvent(evt)
- self.set_day = self.day
return key
# find the clicked area rectangle
@@ -458,10 +455,13 @@
# set the day selection
def SetDay(self, day):
+ #print "calendar::SetDay", day
+ self.set_day = day
day = day + self.st_pos - 1
self.SelectDay(day)
def SelectDay(self, key):
+ #print "calendar::SelectDay with key ", key
sel_size = 1
self.DrawRect(self.sel_key, self.back_color, sel_size) # clear
larg
e selection
if self.hide_grid is FALSE:
@@ -469,8 +469,9 @@
self.DrawRect(key, self.sel_color, sel_size)
self.sel_key = key # store last used by
- self.select_day = None
···
-
+ self.set_day = key-self.st_pos+1
+ #print "calendar::SelectDay set day to ", self.set_day
+
def ClearDsp(self):
self.Clear()