def __render_day_cell(self, cell, col): # Set up a drawing buffer for the day cell buffer = adesklets.create_image(self._cellsize, self._cellsize) adesklets.context_set_image(buffer) adesklets.context_set_blend(False) adesklets.context_set_color(0,0,0,0) adesklets.image_fill_rectangle(0,0,self._cellsize,self._cellsize) adesklets.context_set_blend(True) # Draws the day cell background adesklets.context_set_color(*self._day_bg_color) adesklets.image_fill_rectangle(self._cell_padding, self._cell_padding, (self._cellsize - self._cell_padding), (self._cellsize - self._cell_padding)) # Draws the day cell border adesklets.context_set_color(*self._day_border_color) adesklets.image_draw_rectangle(self._cell_padding, self._cell_padding, (self._cellsize - self._cell_padding), (self._cellsize - self._cell_padding)) # Draws the day cell text adesklets.context_set_font(self._day_font) x, y = adesklets.get_text_size(cell) adesklets.context_set_color(*self._day_font_color) adesklets.text_draw(((self._cellsize / 2) - (x / 2)),((self._cellsize / 2) - (y / 2)),cell) # Blend day cell image into main buffer adesklets.context_set_image(self._buffer) adesklets.blend_image_onto_image(buffer,1,0,0,self._cellsize,self._cellsize, (col * self._cellsize),self._cellsize,self._cellsize,self._cellsize) adesklets.free_image(buffer)
def _blend_image(self): """ Blend the buffer image onto the foreground image """ buf_x = adesklets.image_get_width() buf_y = adesklets.image_get_height() adesklets.context_set_image(0) adesklets.context_set_blend(False) adesklets.blend_image_onto_image(self.buffer, 1, 0, 0, buf_x, buf_y, \ 0, 0, buf_x, buf_y) adesklets.context_set_blend(True)
def renderBackground(self): # draws the clock face to a background layer print 'background' # clear the canvas #adesklets.context_set_image(self.buffer) #adesklets.context_set_blend(False) #adesklets.context_set_color(0, 0, 0, 0) adesklets.image_fill_rectangle(0, 0, self.w, self.h) adesklets.context_set_blend(True) # render background to buffer # D'oh! Make sure it's self.buffer, not self.bugger ;) adesklets.context_set_image(1) adesklets.blend_image_onto_image(self.clockFace, 1, 0, 0, self.faceWidth, self.faceHeight, 0, 0, self.w, self.h)
def background_grab(self, delayed): """ Set up the bar background. We choosed to work directly on image #1 because the operation is always setting the same pixels, so there is no real flickering, just a delay. """ if self.config['bar_height']>0: # Compute rectangle dimensions # coords=[0,(self.config['icon_max_height']- self.config['bar_height'])/2, self._window_width,self.config['bar_height']] if self.config['caption_above']: coords[1]+=self._caption_height # Draw it # adesklets.context_set_blend(True) adesklets.context_set_image(1) if self.config['bar_background_1']: adesklets.context_set_color( *(self.config.color(self.config['bar_background_1'])+ [self.config['bar_opacity_1']])) if self.config['bar_background_2']: adesklets.context_set_color_range( adesklets.create_color_range()) adesklets.add_color_to_color_range(0) adesklets.context_set_color( *(self.config.color(self.config['bar_background_2'])+ [self.config['bar_opacity_2']])) adesklets.add_color_to_color_range(self._window_width) adesklets.image_fill_color_range_rectangle( *(coords+[self.config['bar_gradient_angle']])) adesklets.free_color_range(0) else: adesklets.image_fill_rectangle(*coords) if self.config['bar_foreground']: adesklets.context_set_color( *(self.config.color(self.config['bar_foreground']+'FF'))) adesklets.image_draw_rectangle(*coords) adesklets.context_set_blend(False)
def button_press(self, delayed, x, y, button): if button==1: active, scaling = self._get_active_and_scaling(x) if active in range(len(self.icons)): if self.config['click_effect']: if self.config['caption_font'] and \ self.config['caption_above']: y = self._caption_height else: y = 0 adesklets.context_set_image(self.icons[active][2]) image=adesklets.clone_image() adesklets.context_set_image(image) adesklets.apply_filter(self.config['click_effect']) adesklets.context_set_image(0) adesklets.blend_image_onto_image(image,1,\ 0,0,self.icons[active][3],self.icons[active][4], *map(lambda x: x[0]+x[1], zip([0,y,0,0],self._position(active,x)))) adesklets.free_image(image) sleep(max(self.config['click_effect_duration'],.01)) adesklets.context_set_blend(False) self._display_icons(x) self._execute(self.icons[active][1])
def display(self): """ The main drawing routine """ # Get cell dimensions self._cellsize = self.__getcellsize() adesklets.context_set_image(0) # Calc calendar dimensions self._calsize = (self._cellsize * 7) # Set up a buffer self._buffer = adesklets.create_image(self._calsize,self._calsize+self._cellsize) adesklets.context_set_image(self._buffer) adesklets.context_set_blend(False) adesklets.context_set_color(0,0,0,0) adesklets.image_fill_rectangle(0,0,self._calsize,self._calsize) adesklets.context_set_blend(True) # Draw heading self.__render_heading_cell(self._cal[0:1][0]) # Draw the days for col in xrange(0,7): self.__render_day_cell(self._cal[1:2][0][col:col+1],col) # This draws the rest for row in xrange(2,len(self._cal)): for col in xrange(0,7): if (len(self._cal[row:row+1][0][col:col+1][0]) > 0): self.__render_date_cell(self._cal[row:row+1][0][col:col+1][0], col, row) # Resize window and put everything on foreground adesklets.context_set_image(0) if self._calsize != adesklets.image_get_width() or self._calsize+self._cellsize != adesklets.image_get_height(): adesklets.window_resize(self._calsize,self._calsize+self._cellsize) adesklets.context_set_blend(False) adesklets.blend_image_onto_image(self._buffer,1,0,0,self._calsize,self._calsize+self._cellsize,0,0,self._calsize,self._calsize+self._cellsize) adesklets.free_image(self._buffer)
def ready(self): # Real initialisation take place here. # self.config=Config(adesklets.get_id(), join(self.basedir,'config.txt')) # Load all the icons, and retrieve size # for icon, caption, command in self.config['icons']: adesklets.context_set_image( adesklets.load_image(join(self.basedir,'icons',icon))) self.icons.append((caption, command, adesklets.context_get_image(), adesklets.image_get_width(), adesklets.image_get_height())) # Compute the window size # self._window_width=((self.config['icon_spacing']+ self.config['icon_min_width'])*len(self.icons)+ (self.config['icon_max_width']- self.config['icon_min_width'])+ self.config['icon_spacing']) self._window_height=self.config['icon_max_height'] # Set the icon buffer # self._buffer_icons=adesklets.create_image(self._window_width, self._window_height) # Load the caption font (if needed), adjusting # the window size appropriately # if self.config['caption_font']: adesklets.context_set_font( adesklets.load_font('%s/%s' % (self.config['caption_font'], str(self.config['caption_size'])))) dummy, self._caption_height = adesklets.get_text_size('x') self._window_height+=self._caption_height # Create the caption buffer # self._buffer_caption=adesklets.create_image(self._window_width, self._caption_height) # Compute and save final caption color once and for all # color_base=self.config.color(self.config['caption_color']) self._caption_color = color_base + [255] # Prepare the fade-in effect # if self.config['caption_fade_in']: adesklets.start_recording() time_step = (float(self.config['caption_fade_in_duration'])/ self.config['caption_fade_in_steps']) fade_step = int(250/self.config['caption_fade_in_steps']) for i in range(self.config['caption_fade_in_steps']): adesklets.time_gate((i+1)*time_step) adesklets.context_set_image('$buffer') adesklets.context_set_color(0,0,0,0) adesklets.image_fill_rectangle('$x',0, '$width','$height') adesklets.context_set_color(*(color_base+[fade_step*i+5])) adesklets.text_draw('$x',0,'$text') adesklets.context_set_image(0) adesklets.blend_image_onto_image('$buffer',1, '$x',0,'$width','$height', '$x','$y','$width','$height') self._fadein = adesklets.stop_recording() adesklets.play_set_abort_on_events(True) # Set the 'y' and 'buffer' variables once and for all # if self.config['caption_above']: adesklets.set('y',0) else: adesklets.set('y',self.config['icon_max_height']) adesklets.set('buffer',self._buffer_caption) else: self._caption_height=0 # Resize the window # adesklets.window_resize(self._window_width,self._window_height) adesklets.context_set_image(0) # Finish setting things up, then display the window # adesklets.context_set_blend(False) adesklets.window_set_transparency(True) adesklets.menu_add_separator() adesklets.menu_add_item('Configure') self._display_icons() adesklets.window_show()
def renderForeground(self): # draws the clock hands to a foreground layer # clear the canvas adesklets.context_set_image(self.buffer) adesklets.context_set_blend(False) adesklets.context_set_color(0, 0, 0, 0) adesklets.image_fill_rectangle(0, 0, self.w, self.h) adesklets.context_set_blend(True) # hands rotate around middle of the window #a = self.pivotX #b = self.pivotY a = self.w / 2 b = self.h / 2 """ Pivoting: Pivot vector p has origin at top-left corner of graphic (0,0) and points to pivot point (x increasing to the right, y increasing downwards). Rotation matrix for this coordinate system (angles defined from 3 o'clock increasing clockwise) given by R = | cos(theta) -sin(theta) | | sin(theta) cos(theta) | Therefore, new position r' translated by rotated p r' = r - Rp Or, rx' = rx - ( px*cos(theta) - py*sin(theta) ) py' = ry - ( px*sin(theta) + py*cos(theta) ) """ # hour hand ang = self.getHourAngle() sina = math.sin(ang) cosa = math.cos(ang) px = self.skinConfig['hourPivotX'] py = self.skinConfig['hourPivotY'] rx = a - (px*cosa - py*sina) ry = b - (px*sina + py*cosa) #adesklets.blend_image_onto_image_at_angle(self.hourHand, 1, # 0, 0, self.hourWidth, self.hourHeight, rx, ry, # self.hourWidth*cosa, self.hourWidth*sina) adesklets.blend_image_onto_image_at_angle(self.hourHand, 1, 0, 0, self.w, self.h, rx, ry, self.w*cosa, self.w*sina) # minute hand ang = self.getMinuteAngle() sina = math.sin(ang) cosa = math.cos(ang) px = self.skinConfig['minutePivotX'] py = self.skinConfig['minutePivotY'] rx = a - (px*cosa - py*sina) ry = b - (px*sina + py*cosa) #adesklets.blend_image_onto_image_at_angle(self.minuteHand, 1, # 0, 0, self.minuteWidth, self.minuteHeight, rx, ry, # self.minuteWidth*cosa, self.minuteWidth*sina) adesklets.blend_image_onto_image_at_angle(self.minuteHand, 1, 0, 0, self.w, self.h, rx, ry, self.w*cosa, self.w*sina) # second hand if (self.config['showSecondHand']): ang = self.getSecondAngle() sina = math.sin(ang) cosa = math.cos(ang) px = self.skinConfig['secondPivotX'] #print px py = self.skinConfig['secondPivotY'] #print py rx = a - (px*cosa - py*sina) #print rx ry = b - (px*sina + py*cosa) #print ry #adesklets.blend_image_onto_image_at_angle(self.secondHand, 1, # 0, 0, self.secondWidth, self.secondHeight, rx, ry, # self.secondWidth*cosa, self.secondWidth*sina) adesklets.blend_image_onto_image_at_angle(self.secondHand, 1, 0, 0, self.w, self.h, rx, ry, self.w*cosa, self.w*sina) # render buffer to screen adesklets.context_set_image(0) adesklets.context_set_blend(False) adesklets.blend_image_onto_image(self.buffer, 1, 0, 0, self.w, self.h, 0, 0, self.w, self.h) adesklets.context_set_blend(True)
def __render_date_cell(self, cell, col, row): # Set up a drawing buffer for the date buffer = adesklets.create_image(self._cellsize, self._cellsize) adesklets.context_set_image(buffer) adesklets.context_set_blend(False) adesklets.context_set_color(0,0,0,0) adesklets.image_fill_rectangle(0,0,self._cellsize,self._cellsize) adesklets.context_set_blend(True) # Draws the date cell background if (int(cell) == int(datetime.date.today().day)): adesklets.context_set_color(*self._date_today_bg_color) elif (int(cell) < int(datetime.date.today().day)): adesklets.context_set_color(*self._date_past_bg_color) else: adesklets.context_set_color(*self._date_bg_color) if self._month_offset<0 or self._year_offset<0: adesklets.context_set_color(*self._date_past_bg_color) elif self._month_offset>0 or self._year_offset>0: adesklets.context_set_color(*self._date_bg_color) adesklets.image_fill_rectangle(self._cell_padding, self._cell_padding, (self._cellsize - self._cell_padding), (self._cellsize - self._cell_padding)) # Draws the date cell border if (int(cell) == int(datetime.date.today().day)): adesklets.context_set_color(*self._date_today_border_color) elif (int(cell) < int(datetime.date.today().day)): adesklets.context_set_color(*self._date_past_border_color) else: adesklets.context_set_color(*self._date_border_color) if self._month_offset<0 or self._year_offset<0: adesklets.context_set_color(*self._date_past_border_color) elif self._month_offset>0 or self._year_offset>0: adesklets.context_set_color(*self._date_border_color) adesklets.image_draw_rectangle(self._cell_padding, self._cell_padding, (self._cellsize - self._cell_padding), (self._cellsize - self._cell_padding)) # Draws the date cell text if (int(cell) == int(datetime.date.today().day)): adesklets.context_set_font(self._date_today_font) adesklets.context_set_color(*self._date_today_font_color) elif (int(cell) < int(datetime.date.today().day)): adesklets.context_set_font(self._date_past_font) adesklets.context_set_color(*self._date_past_font_color) else: adesklets.context_set_font(self._date_font) adesklets.context_set_color(*self._date_font_color) if self._month_offset<0 or self._year_offset<0: adesklets.context_set_font(self._date_past_font) adesklets.context_set_color(*self._date_past_font_color) elif self._month_offset>0 or self._year_offset>0: adesklets.context_set_font(self._date_font) adesklets.context_set_color(*self._date_font_color) x, y = adesklets.get_text_size(cell) adesklets.text_draw(((self._cellsize / 2) - (x / 2)),((self._cellsize / 2) - (y / 2)),cell) # Blend date cell image into main buffer adesklets.context_set_image(self._buffer) adesklets.blend_image_onto_image(buffer,1,0,0,self._cellsize,self._cellsize, (col * self._cellsize),(row * self._cellsize),self._cellsize,self._cellsize) adesklets.free_image(buffer)