示例#1
0
    def renderFlag(self):
        
        lKbdLayout = KbdLayout()
        #self.logfile.write("\nEntering renderFlag")
        try:
            lCurLayout = lKbdLayout.getCurrentLayout()
        except:
            print "\nsome error occured in KbdLayout\n";
        print lCurLayout+", Prev: "+self._layout
        if lCurLayout == self._layout:
            return

        self._layout = lCurLayout

        # Find Flag image for the current layout

        # Load the image files for the flags
        lFound = False
        for lFlag, lLayout in self.config['layouts']:
            if lCurLayout == lLayout:
                self._flag = adesklets.load_image(
                                        join(self._basedir,"img/"+lFlag))
                #print lFlag+" img: "+str(self._flag)
                lFound = True
                break
        
        
 
        adesklets.context_set_image(self._flag)
        self.flagWidth  = adesklets.image_get_width()
        self.flagHeight = adesklets.image_get_height()
        adesklets.context_set_image(0)
        adesklets.blend_image_onto_image(self._flag, 1, 0, 0,
                        self.flagWidth,self.flagHeight,
                        0, 0, self.config['width'],self.config['height'])
示例#2
0
    def loadSkin(self, skinName):
        # load images from a given skin at adeskclock/skins/<skinName>

        # load clock face
        self.clockFace = \
                adesklets.load_image(self.basedir + self.SKINS_SUBDIR +
                self.config['skin'] + '/' + self.CLOCK_FACE_IMAGE)
        adesklets.context_set_image(self.clockFace)
        self.faceWidth = adesklets.image_get_width()
        self.faceHeight = adesklets.image_get_height()

        # hour hand
        self.hourHand = \
                adesklets.load_image(self.basedir + self.SKINS_SUBDIR +
                self.config['skin'] + '/' + self.HOUR_HAND_IMAGE)
        adesklets.context_set_image(self.hourHand)
        self.hourWidth = adesklets.image_get_width()
        self.hourHeight = adesklets.image_get_height()

        # minute hand
        self.minuteHand = \
                adesklets.load_image(self.basedir + self.SKINS_SUBDIR +
                self.config['skin'] + '/' + self.MINUTE_HAND_IMAGE)
        adesklets.context_set_image(self.minuteHand)
        self.minuteWidth = adesklets.image_get_width()
        self.minuteHeight = adesklets.image_get_height()

        # second hand
        self.secondHand = \
                adesklets.load_image(self.basedir + self.SKINS_SUBDIR +
                self.config['skin'] + '/' + self.SECOND_HAND_IMAGE)
        adesklets.context_set_image(self.secondHand)
        self.secondWidth = adesklets.image_get_width()
        self.secondHeight = adesklets.image_get_height()

        # force full refresh
        self.renderBackground()
        self.renderForeground()

        # DEBUGGING
        print adesklets.images_info()
        print self.buffer
        self.quit()
        '''
示例#3
0
    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)
示例#4
0
	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)
示例#5
0
文件: yab.py 项目: rangalo/desklets
    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()