예제 #1
0
def text_size(font, text):
    """Gets the height and width of text using font, in imlib2"""
    font_num = adesklets.load_font(font)
    adesklets.context_set_font(font_num)
    width, height = adesklets.get_text_size(text)
    adesklets.free_font(font_num)
    return width, height
예제 #2
0
    def _draw_time(self):
        """
        Draw the time onto the canvas
        """
        x_pos = 0
        y_pos = 0

        # run through the tuple and print each part of the time
        for display in self.displays:
            text = get_time(display['format'])
            if self.caps:
                text = text.upper()
            s_x_pos = display['x_pos']
            s_y_pos = display['y_pos']

            x_pos = eval(s_x_pos) if isinstance(s_x_pos, str) else s_x_pos
            y_pos = eval(s_y_pos) if isinstance(s_y_pos, str) else s_y_pos

            print text

            # sure this is gross and dumb, but it's easier.
            cur_font = adesklets.load_font(display['font'])
            adesklets.context_set_font(cur_font)
            adesklets.text_draw(x_pos, y_pos, text)
            adesklets.free_font(cur_font)
예제 #3
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()
예제 #4
0
	def __call__(self):
		""" Build todays calendar, set up fonts and stuff """

		self._month_offset = self.config['month_offset']
		if (self.config['month_offset_negative']):
			self._month_offset = self._month_offset * -1
		self._year_offset = self.config['year_offset']
		if (self.config['year_offset_negative']):
			self._year_offset = self._year_offset * -1
		self.update()

		# Load cell attributes
		self._heading_font = adesklets.load_font('%s/%d' % (self.config['heading_font'],
															self.config['heading_font_size']))

		self._heading_font_color = (self.config.color(self.config['heading_font_color']))
		self._heading_bg_color = (self.config.color(self.config['heading_bg_color']))
		self._heading_border_color = (self.config.color(self.config['heading_border_color']))

		self._day_font = adesklets.load_font('%s/%d' % (self.config['day_font'],
														self.config['day_font_size']))

		self._day_font_color = (self.config.color(self.config['day_font_color']))
		self._day_bg_color = (self.config.color(self.config['day_bg_color']))
		self._day_border_color = (self.config.color(self.config['day_border_color']))

		self._date_font = adesklets.load_font('%s/%d' % (self.config['date_font'],
														 self.config['date_font_size']))

		self._date_font_color = (self.config.color(self.config['date_font_color']))
		self._date_bg_color = (self.config.color(self.config['date_bg_color']))
		self._date_border_color = (self.config.color(self.config['date_border_color']))

		self._date_today_font = adesklets.load_font('%s/%d' % (self.config['date_today_font'],
														 self.config['date_today_font_size']))

		self._date_today_font_color = (self.config.color(self.config['date_today_font_color']))
		self._date_today_bg_color = (self.config.color(self.config['date_today_bg_color']))
		self._date_today_border_color = (self.config.color(self.config['date_today_border_color']))

		self._date_past_font = adesklets.load_font('%s/%d' % (self.config['date_past_font'],
														 self.config['date_past_font_size']))

		self._date_past_font_color = (self.config.color(self.config['date_past_font_color']))
		self._date_past_bg_color = (self.config.color(self.config['date_past_bg_color']))
		self._date_past_border_color = (self.config.color(self.config['date_past_border_color']))

		# Get other calendar attributes
		self._cell_padding = self.config['cell_padding']

		# Set up window properties
		adesklets.window_set_transparency(True)
		adesklets.menu_add_separator()
		adesklets.menu_add_item('Configure')
		if have_tkinter:
			adesklets.menu_add_separator()
			adesklets.menu_add_item('Add_DateNote')
			adesklets.menu_add_item('Edit_DateNote')
			adesklets.menu_add_item('Remove_DateNotes')
		adesklets.menu_add_separator()
		adesklets.menu_add_item('Prev_Month')
		adesklets.menu_add_item('Next_Month')
		adesklets.menu_add_item('Prev_Year')
		adesklets.menu_add_item('Next_Year')
		adesklets.window_show()