This is my wx.Calender demo in wx.python
###########################################################################
# -*- coding: ISO-8859-1 -*-
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses>.
__author__ = "Mayank Johri"
__copyright__ = "2009"
__version__ = "0.0.1"
__date__ = "Oct 13 2009"
__license__ = "GNU 3 or latest."
###########################################################################
import re
import datetime
import calendar
import wx
import string
import wx.calendar as cal
import sys
import os
APPDIR = sys.path[0]
TBMENU_RESTORE = wx.NewId()
TBMENU_CLOSE = wx.NewId()
year = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
def thismonth():
""" Presently not using"""
calendar.setfirstweekday(0)
today = datetime.datetime.date(datetime.datetime.now())
current = re.split('-', str(today))
current_no = int(current[1])
current_month = year[current_no-1]
current_day = int(re.sub('\A0', '', current[2]))
current_yr = int(current[0])
myCal = '%s %s' %(current_month, current_yr)
myCal = myCal + '\n' + "M T W Th F Sa Su" + '\n'
month = calendar.monthcalendar(current_yr, current_no)
nweeks = len(month)
for w in range(0,nweeks):
week = month[w]
for x in xrange(0,7):
day = week[x]
if x == 5 or x == 6:
classtype = 'weekend'
else:
classtype = 'day'
if day == 0:
classtype = 'X'
myCal = myCal + str(classtype).ljust(3)
elif day == current_day:
myCal = myCal + str(day).ljust(3)
else:
myCal = myCal + str(day).ljust(3)
myCal = myCal + '\n'
return (myCal)
class MyTaskBarIcon(wx.TaskBarIcon):
def __init__(self, frame):
wx.TaskBarIcon.__init__(self)
self.frame = frame
icon = wx.Icon(os.path.join(APPDIR, 'clock.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarRightClick)
self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=1)
self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=2)
def OnTaskBarRightClick(self, event):
if not self.frame.IsShown():
self.frame.Show()
else: self.frame.Hide()
def CreatePopupMenu(self):
menu = wx.Menu()
menu.Append(1, 'Show/Hide')
menu.Append(2, 'Close')
return menu
def OnTaskBarClose(self, event):
self.Destroy()
self.frame.Destroy()
def OnTaskBarActivate(self, event):
if not self.frame.IsShown():
self.frame.Show()
else: self.frame.Hide()
def OnTaskBarDeactivate(self, event):
if self.frame.IsShown():
self.frame.Hide()
class MayaCalendar(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, title="Maya Calender, Ver: 0.0.1")
vbox = wx.BoxSizer(wx.VERTICAL)
calend = cal.CalendarCtrl(self, -1, wx.DateTime_Now(),
style = cal.CAL_SHOW_HOLIDAYS|cal.CAL_SEQUENTIAL_MONTH_SELECTION)
vbox.Add(calend, 0, wx.EXPAND | wx.ALL, 20)
self.Bind(cal.EVT_CALENDAR, self.OnCalSelected, id=calend.GetId())
self.SetSizerAndFit(vbox)
self.Show(True)
self.tskic = MyTaskBarIcon(self)
self.Centre()
def OnCalSelected(self, event):
date = event.GetDate()
dt = string.split(str(date), ' ')
s = ' '.join([str(s) for s in dt])
self.text.SetLabel(s)
class MyApp(wx.App):
def OnInit(self):
frame = MayaCalendar(None, -1, 'Maya Calender, Ver: 0.0.1')
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()