Traceback (most recent call last):
File "Calendar.py", line 150, in ?
Events(dirname(__file__)).pause()
File "Calendar.py", line 68, in __init__
adesklets.Events_handler.__init__(self)
File "usr/lib/python2.4/site-packages/adesklets/events_handler.py", line 159, in __init__
File "usr/lib/python2.4/site-packages/adesklets/events_handler.py", line 296, in _alarm
File "Calendar.py", line 103, in alarm
self._display()
File "Calendar.py", line 121, in _display
adesklets.context_set_image(0)
File "/usr/lib/python2.4/commands.py", line 374, in context_set_image
File "usr/lib/python2.4/site-packages/adesklets/commands_handler.py", line 103, in out
adesklets.error_handler.ADESKLETSError: adesklets command error - syntax error
"""
Calendar.py - darkliquid <darkliquid@darkliquid.co.uk>, 2005
Simple, adesklets calendar script:
Basically, this should simply grab the output
of the calendar.month9) function and display
on the screen using the fonts defined from the
config file. Eventually, I plan to add more
functionality to this so that different fonts
for various parts can be altered and then who knows?
"""
import adesklets
from os import getenv, spawnlp, P_NOWAIT
from os.path import join, dirname
class Config(adesklets.ConfigFile):
"""
This is calendar.py desklet configuration file;
"""
cfg_default = { 'heading_font': 'Vera',
'heading_font_size': 14,
'heading_color': 'FFFFFF',
'heading_opacity': 255,
'date_font': 'Vera',
'date_font_size': 12,
'date_past_color': 'BBBBBB',
'date_past_opacity': 100,
'date_color': 'FFFFFF',
'date_opacity': 255 }
def __init__(self,id,filename):
adesklets.ConfigFile.__init__(self,id,filename)
def color(self,string):
return [eval('0x%s' % string[i*2:i*2+2]) for i in range(len(string)/2)]
#------------------------------------------------------------------------------
class CalendarDesklet:
"""
Class that generates a calendar on the desktop
"""
import calendar
import datetime
def __init__(self, config):
self.config=config
def __call__(self):
now = self.datetime.date.today()
return self.calendar.month(now.year,now.month)
#------------------------------------------------------------------------------
class Events(adesklets.Events_handler):
"""
The usual Events handling class
"""
def __init__(self, basedir):
if len(basedir)==0:
self.basedir='.'
else:
self.basedir=basedir
adesklets.Events_handler.__init__(self)
def __del__(self):
adesklets.Events_handler.__del__(self)
def ready(self):
# Do initialisation stuff here
# Get the config file
self.config=Config(adesklets.get_id(),
join(self.basedir,'config.txt'))
# Send the config data to the Calendar class
self.calendar_desklet = CalendarDesklet(self.config)
# Load fonts
self._heading_font = adesklets.load_font(
'%s/%d' % (self.config['heading_font'],
self.config['heading_font_size']))
if self.config['date_font']:
self._date_font = adesklets.load_font(
'%s/%d' % (self.config['date_font'],
self.config['date_font_size']))
else:
self._date_font = self._heading_font
# Set up window properties
adesklets.window_set_transparency(True)
adesklets.menu_add_separator()
adesklets.menu_add_item('Configure')
adesklets.window_show()
def alarm(self):
"""
Refresh the display as needed
"""
self.block()
self._display()
return max(60,60)
def menu_fire(self, delayed, menu_id, item):
if item=='Configure':
editor=getenv('EDITOR')
if editor:
self._execute('xterm -e %s ' % editor +
join(self.basedir,'config.txt'))
def _display(self):
"""
The main drawing routine
"""
# Get text dimensions
cal = self.calendar_desklet()
adesklets.context_set_font(self._heading_font)
w,h = adesklets.get_text_size(cal)
adesklets.context_set_image(0)
# Set up a buffer
buffer = adesklets.create_image(w,h)
adesklets.context_set_image(buffer)
adesklets.context_set_blend(False)
adesklets.context_set_color(0,0,0,0)
adesklets.image_fill_rectangle(0,0,w,h)
adesklets.context_set_blend(True)
# Draw text onto buffer
adesklets.context_set_font(self._heading_font)
adesklets.context_set_color(*(self.config.color(
self.config['heading_color']) + [255]))
adesklets.text_draw(0,0,y,cal)
# Resize window if need be and put everything on foreground
if w!= adesklets.image_get_width() or h!= adesklets.image_get_height():
adesklets.window_resize(w,h)
adesklets.context_set_image(0)
adesklets.context_set_blend(False)
adesklets.blend_image_onto_image(buffer,1,0,0,w,h,0,0,w,h)
adesklets.free_image(buffer)
def _execute(self,command):
spawnlp(P_NOWAIT, command.split()[0], *command.split())
#------------------------------------------------------------------------------
# Start running
Events(dirname(__file__)).pause()
w,h = adesklets.get_text_size(cal)
1) get_text_size February 2005 2) Mo Tu We Th Fr Sa Su 3) 1 2 3 4 5 6 4) 7 8 9 10 11 12 13 5) 14 15 16 17 18 19 20 6) 21 22 23 24 25 26 27 7) 28
export ADESKLETS_LOG=$HOME/adesklets_log/log
ADESKLETS_ID=0 python calendar.py
adesklets :
"""
Calendar.py - darkliquid <darkliquid@darkliquid.co.uk>, 2005
Simple, adesklets calendar script:
Basically, this should simply grab the output
of the calendar.month() function and display
on the screen using the fonts defined from the
config file. Eventually, I plan to add more
functionality to this so that different fonts
for various parts can be altered and then who knows?
"""
import adesklets
from os import getenv, spawnlp, P_NOWAIT
from os.path import join, dirname
class Config(adesklets.ConfigFile):
"""
This is calendar.py desklet configuration file;
"""
cfg_default = { 'heading_font': 'Vera',
'heading_font_size': 14,
'heading_color': 'FFAFAF',
'heading_opacity': 255,
'day_font': 'Vera',
'day_font_size': 12,
'day_colour': 'AFFFAF',
'date_font': 'Vera',
'date_font_size': 12,
'date_past_colour': 'BBBBBB',
'date_past_opacity': 100,
'date_color': 'FFFFFF',
'date_opacity': 255,
'cell_padding': 2 }
def __init__(self,id,filename):
adesklets.ConfigFile.__init__(self,id,filename)
def color(self,string):
return [eval('0x%s' % string[i*2:i*2+2]) for i in range(len(string)/2)]
#------------------------------------------------------------------------------
class CalendarDesklet:
"""
Class that generates a calendar on the desktop
"""
import calendar
import datetime
def __init__(self, config):
self.config=config
def __call__(self):
"""
This function grabs the calendar as produced by the calendar
module and processes it into a more palatable form for later
manipulation
"""
now = self.datetime.date.today()
cal = self.calendar.month(now.year,now.month)
cal_list = cal.splitlines()
new_cal = []
temp_list = []
for row in xrange(0,7):
if (row==0):
new_cal.append(cal_list[row:row+1][0].strip())
else:
for col in xrange(0,21,3):
temp_list.append(cal_list[row:row+1][0][col:col+3].strip())
new_cal.append(temp_list)
temp_list=[]
return new_cal
#------------------------------------------------------------------------------
class Events(adesklets.Events_handler):
"""
The usual Events handling class
"""
def __init__(self, basedir):
if len(basedir)==0:
self.basedir='.'
else:
self.basedir=basedir
adesklets.Events_handler.__init__(self)
def __del__(self):
adesklets.Events_handler.__del__(self)
def ready(self):
# Do initialisation stuff here
# Get the config file
self.config=Config(adesklets.get_id(),
join(self.basedir,'config.txt'))
# Send the config data to the Calendar class
self.calendar_desklet = CalendarDesklet(self.config)
# Load fonts
self._heading_font = adesklets.load_font(
'%s/%d' % (self.config['heading_font'],
self.config['heading_font_size']))
if self.config['date_font']:
self._date_font = adesklets.load_font(
'%s/%d' % (self.config['date_font'],
self.config['date_font_size']))
else:
self._date_font = self._heading_font
# Set up window properties
adesklets.window_set_transparency(True)
adesklets.menu_add_separator()
adesklets.menu_add_item('Configure')
adesklets.window_show()
def alarm(self):
"""
Refresh the display as needed
"""
self.block()
self._display()
return max(60,60)
def menu_fire(self, delayed, menu_id, item):
if item=='Configure':
editor=getenv('EDITOR')
if editor:
self._execute('xterm -e %s ' % editor +
join(self.basedir,'config.txt'))
def cellsize(self, cal):
"""
This function determines the minimum required cell size to display
the characters within a cell without overlapping into other cells.
It determines this by finding the maximum widths and heights in the
list of cell data (ie: day numbers or days names). It then takes the
maximum of the final max width and height and returns that (we want
square cells, right?)
"""
old_w = 0
old_h = 0
w = 0
h = 0
adesklets.context_set_font(self._heading_font)
for row in xrange(1,7):
for col in xrange(0,7):
if (len(cal[row:row+1][0][col:col+1][0]) > 0):
old_w,old_h = adesklets.get_text_size(cal[row:row+1][0][col:col+1][0])
w=max(w,old_w)
h=max(h,old_h)
return max(w,h)
def _display(self):
"""
The main drawing routine
"""
# Get cell dimensions
cal = self.calendar_desklet()
cellsize = self.cellsize(cal)
adesklets.context_set_image(0)
# Calc calendar dimensions
calsize = (cellsize * 7)
print calsize
# Set up a buffer
buffer = adesklets.create_image(calsize,calsize)
adesklets.context_set_image(buffer)
adesklets.context_set_blend(False)
adesklets.context_set_color(0,0,0,0)
adesklets.image_fill_rectangle(0,0,calsize,calsize)
adesklets.context_set_blend(True)
# Draw text onto buffer
adesklets.context_set_font(self._heading_font)
adesklets.context_set_color(*(self.config.color(
self.config['heading_color']) + [255]))
# This bit draws the header
headersize = adesklets.get_text_size(cal[0:1][0])
header_position = (calsize / 2) - (headersize[0] / 2)
adesklets.text_draw(header_position,0,cal[0:1][0])
# This draws the rest
for row in xrange(1,7):
for col in xrange(0,7):
if (len(cal[row:row+1][0][col:col+1][0]) > 0):
adesklets.text_draw((col*cellsize),(row*cellsize),cal[row:row+1][0][col:col+1][0])
# Resize window and put everything on foreground
adesklets.window_resize(calsize,calsize)
adesklets.context_set_image(0)
adesklets.context_set_blend(False)
adesklets.blend_image_onto_image(buffer,1,0,0,calsize,calsize,0,0,calsize,calsize)
adesklets.free_image(buffer)
def _execute(self,command):
spawnlp(P_NOWAIT, command.split()[0], *command.split())
#------------------------------------------------------------------------------
# Start running
Events(dirname(__file__)).pause()
lstFoo = []
for strBar in lstBaz:
lstFoo.append(strBar.strip())
lstFoo = [x.strip() for x in lstBaz]
#!/usr/bin/env python
#!/usr/bin/env python