From: <cl...@us...> - 2002-06-11 17:18:32
|
Update of /cvsroot/todo-manager/todo-manager In directory usw-pr-cvs1:/tmp/cvs-serv12633 Modified Files: Tag: dev-bronze tdm_calendar.py Log Message: * Buttons that allow the user to change the current year and month * A bunch of small improvemets Index: tdm_calendar.py =================================================================== RCS file: /cvsroot/todo-manager/todo-manager/Attic/tdm_calendar.py,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -d -r1.1.2.11 -r1.1.2.12 --- tdm_calendar.py 24 May 2002 15:40:08 -0000 1.1.2.11 +++ tdm_calendar.py 11 Jun 2002 17:18:24 -0000 1.1.2.12 @@ -10,27 +10,29 @@ from Tkinter import * from calendar import monthrange +from controls import ThinButton import time -# Class Calendar -# -# Create a calendar in a frame for a given month. -# -# Initialising -# 1. Initialise by calling Calendar(year,month,command) -# 2. The initial displayed month is defined by the mounth and date. -# 3. The command will be run when the user selects a day. -# -# Operation -# 1. Any day can be selected with the mouse and the user inputed function will run. -# 2. The calendar date can be advanced a given time in mounths and years by calling IncTime(year,month). -# 3. The calendar date can be changed to any mounth with function ChangeTime(year,month). -# 4. The current calendar date can be obtained with function GetDate(). -# The integers year and month will be returned. +""" +Create a calendar in a frame for a given month. + +Initialising + 1. Initialise by calling Calendar(year,month,command) + 2. The initial displayed month is defined by the mounth and date. + 3. The command will be run when the user selects a day. + +Operation + 1. Any day can be selected with the mouse and the user inputed function will run. + 2. The calendar date can be advanced a given time in months and years by calling + IncTime(year,month). + 3. The calendar date can be changed to any month with function SetDate(year, month, day). + 4. The current calendar date can be obtained with function GetDate(). + The integers year and month will be returned. +""" class Calendar(Frame): def __init__(self,master,command=None,**kw): - Frame.__init__(self, master, kw) + Frame.__init__(self, master) # To preserve some things if kw.has_key("background"): @@ -39,19 +41,41 @@ self.__bgcolor = kw['bg'] else: self.__bgcolor = None - self.Weekday={1:'S',2:'M',3:'T',4:'W',5:'T',6:'F',7:'S'} - self.__LeftClickDateCommand=command + # Create the year and month selection buttons + frame = Frame(self, bd=0) + ThinButton(frame, text='<', command=lambda s=self: s.IncTime(-1)).pack(side=LEFT) + self._yearLabel = Label(frame, width=10, bd=2, relief=RAISED) + self._yearLabel.pack(side=LEFT) + ThinButton(frame, text='>', command=lambda s=self: s.IncTime(1)).pack(side=LEFT) + frame.grid(row=0, column=0, sticky=W) + + frame = Frame(self, bd=0) + ThinButton(frame, text='<', command=lambda s=self: s.IncTime(0, -1)).pack(side=LEFT) + self._monthLabel = Label(frame, width=10, bd=2, relief=RAISED) + self._monthLabel.pack(side=LEFT) + ThinButton(frame, text='>', command=lambda s=self: s.IncTime(0, 1)).pack(side=LEFT) + frame.grid(row=0, column=1, sticky=E) + + self._dateframe = Frame(self, kw) + # Create the day header - for i in range(1, 8): - Label(self,text=self.Weekday[i],fg='blue',bg=self.__bgcolor).grid(row=0,column=i) + c = 1 + for t in ('S', 'M', 'T', 'W', 'T', 'F', 'S'): + Label(self._dateframe,text=t,fg='blue',bg=self.__bgcolor).grid(row=0,column=c) + c = c + 1 self.SetCurrentDate() + self._dateframe.grid(row=1, column=0, columnspan=2, sticky=NSEW) + def Draw(self): + self._yearLabel['text'] = self.year + self._monthLabel['text'] = self.month + # Delete all of the old buttons - children = self.winfo_children() + children = self._dateframe.winfo_children() for i in range(len(children)): if i>7: children[i].destroy() @@ -75,15 +99,16 @@ elif i == 1 or i == 7: fg = 'gray40' # The weekend should be gray - Button(self,text=str(DayCount),bd=bd,width=1,height=1,relief=SOLID, + Button(self._dateframe,text=str(DayCount),bd=bd,width=1,height=1,relief=SOLID, fg=fg,bg=self.__bgcolor, command= lambda s=self, p=DayCount: s.SelDay(p)).grid(row=j, column=i, sticky=NSEW) else: # Required to make sure there are the right number of rows - Label(self,text='',bd=0,width=1,height=1,relief=FLAT,bg=self.__bgcolor).grid( - row=j,column=i) + Label(self._dateframe,text='',bd=0,width=1,height=1,relief=FLAT, + bg=self.__bgcolor).grid(row=j,column=i) + i=i+1 # Returns the day the user has selected with the mouse @@ -95,27 +120,31 @@ self.Draw() # Enter new year and month so that the calendar can be redrawn - def ChangeTime(self,year,month,day): + def SetDate(self, year, month, day): self.year=year + + # Value checking + if month > 12 or month < 1: + month = month % 12 + if month == 0: + month = 1 + self.month=month self.day=day self.Draw() # Enter no of years and/or months that the calendar must either advance (+ values) or go # back in time (- values). - def IncTime(self,year,month): + def IncTime(self, year=0, month=0): self.year=self.year+year self.month=self.month+month - if self.month>12 or self.month<0: + if self.month>12 or self.month<1: self.year=self.year+self.month/12 self.month=self.month%12 if self.month==0 and month <0: self.month=12 self.year=self.year-1 - if self.month==0 and month >0: - self.month=12 - self.year=self.year-1 self.Draw() @@ -130,4 +159,5 @@ self.year = temptime[0] self.month = temptime[1] self.day = temptime[2] + self.Draw() |