Exemplo n.º 1
0
 def _display_caption(self):
     if self.config['caption_font']:
         # Sweep buffer caption clean
         #
         adesklets.context_set_image(self._buffer_caption)
         adesklets.context_set_color(0,0,0,0)
         adesklets.image_fill_rectangle(0,0,
                                        self._window_width,
                                        self._caption_height)
         
         if self._active in range(len(self.icons)) and \
                len(self.icons[self._active][0])>0:
             # Compute final text position
             #
             width, height = adesklets.get_text_size(
                 self.icons[self._active][0])
             pos = self._position(self._active, -1, False)
             x = (pos[0]+pos[2]/2)-width/2
             if x+width>self._window_width: x=self._window_width-x
             if x<0: x=0
             
             # If turned on, performs the caption fade-in
             #
             if self.config['caption_fade_in']:
                 # Sweep window buffer space
                 #
                 adesklets.context_set_image(0)
                 adesklets.blend_image_onto_image(self._buffer_caption,1,
                                                  0,0,
                                                  self._window_width,
                                                  self._caption_height,
                                                  0,adesklets.echo('$y'),
                                                  self._window_width,
                                                  self._caption_height)
                 
                 # Set variables and execute the fade in
                 #
                 adesklets.set('text',self.icons[self._active][0])
                 adesklets.set('x',x)
                 adesklets.set('width',width)
                 adesklets.set('height',height) 
                 adesklets.play(*self._fadein)
                 
             # Force final result, regardless the previous state
             #
             adesklets.context_set_image(self._buffer_caption)
             adesklets.context_set_color(*self._caption_color)
             adesklets.text_draw(x,0,self.icons[self._active][0])
         
         # Render final result on caption buffer
         #
         adesklets.context_set_image(0)    
         adesklets.blend_image_onto_image(self._buffer_caption,1,
                                          0,0,
                                          self._window_width,
                                          self._caption_height,
                                          0,adesklets.echo('$y'),
                                          self._window_width,
                                          self._caption_height)
Exemplo n.º 2
0
    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()