3
# CalendarScreenlet (c) robgig1088 2007
15
class CalendarScreenlet (screenlets.Screenlet):
16
"""A simple Calendar Screenlet."""
18
# default meta-info for Screenlets
19
__name__ = 'CalendarScreenlet'
21
__author__ = 'RYX (initial version by robgig1088)'
22
__website__ = 'http://www.screenlets.org/screenlets'
26
def __init__(self, **keyword_args):
28
screenlets.Screenlet.__init__(self, width=200, height=200,
29
uses_theme=True, **keyword_args)
31
self.theme_name = "ryx"
32
# add default menu items
33
self.add_default_menuitems()
35
# attribute-"setter", handles setting of attributes
36
#def __setattr__(self, name, value):
37
# # call Screenlet.__setattr__ in baseclass (ESSENTIAL!!!!)
38
# screenlets.Screenlet.__setattr__(self, name, value)
40
def get_date_info(self, old_cuse = [0]):
42
day = datetime.datetime.now().strftime("%d")
44
month_num = datetime.datetime.now().strftime("%m")
46
year = datetime.datetime.now().strftime("%Y")
48
month_name = datetime.datetime.now().strftime("%B")
49
#make a date (1st of month)
50
when = datetime.date(int(year), int(month_num), int(1))
51
# get the first day of the month (mon, tues, etc..)
52
first_day = when.strftime("%A")
53
# find number of days in the month
54
if month_num in (1, 3, 5, 7, 8, 10, 12):
62
#find the first day of the month
63
start_day = int(when.strftime("%u"))
64
if start_day == 7: # and do calculations on it...
66
start_day = start_day + 1
67
# return the whole stuff
68
return [day, month_num, year, month_name,
69
days_in_month, first_day, start_day]
71
def on_draw(self, ctx):
73
date = self.get_date_info()
75
ctx.scale(self.scale, self.scale)
76
# draw bg (if theme available)
77
ctx.set_operator(cairo.OPERATOR_OVER)
80
self.theme.render(ctx, 'date-bg')
81
#self.theme.render(ctx, 'date-border')
84
p_layout = ctx.create_layout()
85
p_fdesc = pango.FontDescription("Free Sans 5")
86
p_layout.set_font_description(p_fdesc)
88
p_layout.set_width((self.width) * pango.SCALE)
89
p_layout.set_markup('<b>' + date[3] + '</b>')
90
ctx.set_source_rgba(1, 1, 1, 0.8)
91
ctx.show_layout(p_layout)
94
p_layout.set_markup('<b>' + date[2] + '</b>')
95
ctx.set_source_rgba(1, 1, 1, 0.8)
96
ctx.show_layout(p_layout)
100
#draw the header background
101
self.theme.render(ctx, 'header-bg')
103
p_layout.set_markup('<b>' + "S M T W T F S" + \
105
ctx.set_source_rgba(1, 1, 1, 0.8)
106
ctx.show_layout(p_layout)
111
for x in range(date[4] + 1):
113
ctx.translate(5 + (day-1)*13, 29 + 12*(row - 1))
114
if str(int(x)+1) == str(date[0]) or \
115
"0"+str(int(x)+1) == str(date[0]):
116
self.theme.render(ctx, 'day-bg')
119
p_layout.set_markup('<b>' + " 0"+str(x+1) + '</b>')
121
p_layout.set_markup('<b>' + " "+str(x+1) + '</b>')
122
ctx.set_source_rgba(1, 1, 1, 0.8)
123
ctx.show_layout(p_layout)
130
def on_draw_shape(self,ctx):
131
ctx.scale(self.scale, self.scale)
133
self.theme.render(ctx, 'date-bg')
136
# If the program is run directly or passed as an argument to the python
137
# interpreter then create a Screenlet instance and show it
138
if __name__ == "__main__":
139
import screenlets.session
140
screenlets.session.create_session(CalendarScreenlet)