Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 19/03/2006, à 23:11

tonyo

adesklet au premier plan

Salut,

j'aimerais placer un desklet adesklet au premier plan, c'est-à-dire au-dessus d'un panel gnome. Malheureusement, je ne vois pas comment faire...
Il semble que cette option ne soit pas dans les options générales de config des desklets, mais je suis prêt à trifouiller un peu le code du desklet en question pour l'adapter (je l'ai déjà adapté à ce que je souhaitais...)

Source du desklet en question :

#!/usr/bin/env python
"""
--------------------------------------------------------------------------------
Copyright (C) 2005 Mike Pirnat <exilejedi@users.sourceforge.net>

Released under the GPL, version 2.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies of the Software and its documentation and acknowledgment shall be
given in the documentation and software packages that this Software was
used.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.   
--------------------------------------------------------------------------------

This is a simple little desklet that displays a text-based digital clock.

The font, font size, font color, and time format are configurable.

The font color is specified as an HTML-style hexadecimal value, eg "#FFFFFF" for
white, "#00FF00" for green, etc.

The most useful formatting strings for the time display are:

    %H  Hour (24-hour clock) as a decimal number [00,23].
    %I  Hour (12-hour clock) as a decimal number [01,12].
    %M  Minute as a decimal number [00,59].
    %p  Locale's equivalent of either AM or PM.
    %S  Second as a decimal number [00,61].

Though the complete lineup of Python strformat() formatting strings is available
if you happen to want additional options.  For a complete list, refer to:
    
    http://docs.python.org/lib/module-time.html

Like the other demo adesklets packages, you can just run this script from its
final location on your disk to start it.
"""

import adesklets
import time
import datetime					# modifs tonyo

from os import getenv, system
from os.path import join, dirname

class Config(adesklets.ConfigFile):
    """
    This is the asimpleclock.py desklet configuration file.  Each instance of
    the desklet gets a separate Python dictionary that holds its 
    configuration.  You can adjust the font, font color, font size, and output
    format as you see fit.

    Valid fonts are:
        * Vera
        * Whatever you have installed
       
    Font color is an HTML-style hexadecimal number, eg "#FF0000" for red.

    Font size is a plain old integer.

    The format string can use any of the normal Python time formatting strings.
    The most useful are:

        %H  Hour (24-hour clock) as a decimal number [00,23].
        %I  Hour (12-hour clock) as a decimal number [01,12].
        %M  Minute as a decimal number [00,59].
        %p  Locale's equivalent of either AM or PM.
        %S  Second as a decimal number [00,61].
       
    The complete list is here: http://docs.python.org/lib/module-time.html
    """
    cfg_default = {
        'color'     : '#00FF00',
        'font'      : 'Vera',
        'font_size' : 16,
        'format'    : '%H:%M:%S',
        'formatdate'    : '%d/%m/%y',		# modifs tonyo
    }


class Events(adesklets.Events_handler):
    """
    This is the main event handler and display routine for asimpleclock.py.
    All the heavy lifting gets done here, even though we should eventually
    move the display logic out into a separate class to allow fancy overrides,
    "themes", and the like.

    That day is sadly not today.
    """

    sizeX = 200 
    sizeY = 25

    def __init__(self, basedir):
        """
        Constructor.  Set up the bare essentials.
        """
        if len(basedir) == 0:
            self.basedir = '.'
        else:
            self.basedir = basedir
        self.delay  = 1
        self.buffer = None
        self.id     = None
        self.red    = None
        self.green  = None
        self.blue   = None
        self.font_size = None
        self.orig_font_size = None
        self.first_time = True
        self.config = None
        self.prev_time = None
        self.prev_date = None			# modifs tonyo
        adesklets.Events_handler.__init__(self)

    def __del__(self):
        """
        Destructor.  Tidy up after ourselves.
        """
        adesklets.Events_handler.__del__(self)

    def ready(self):
        """
        We're ready to start handling events, so let's make sure we take care
        of the "real initialization"--setting up our configuration, initializing
        the buffer and window, etc.
        """
        # The "real initialization" takes place here
        self.id = adesklets.get_id()
        self._get_config()

        # Per example, use a buffer image to avoid flicker
        self.buffer = self._new_buffer(self.sizeX, self.sizeY)

        # Set up the window
        adesklets.window_resize(self.sizeX, self.sizeY)
        adesklets.window_set_transparency(True)
        adesklets.menu_add_separator()
        adesklets.menu_add_item('Configure')
        adesklets.window_show()

    def alarm(self):
        """
        When the alarm goes off, this is what we do.
        """
        self.block()
        self.display()
        self.unblock()
        return self.delay

    def menu_fire(self, delayed, menu_id, item):
        """
        Handle menu events.
        """
        if item == 'Configure':
            editor = getenv('EDITOR')
            if editor:
                system('xterm -e %s %s/config.txt &' % (editor, self.basedir))

    def display(self):
        """
        The clock display logic happens here.

        One day, this should be broken out into a separate class to allow for
        nifty overrides, "theming", etc.  But not today.
        """
       
        # Reset the whole buffer image in transparent black
        self._setup_buffer(self.buffer)

        # Get the time
        cur_time = self._get_current_time()
	cur_date = self._get_current_date()		# modifs tonyo

        # Per Sylvain's suggestion, if the output hasn't changed,
        # don't redraw the desklet
        if cur_time == self.prev_time:
            return
        self.prev_time = cur_time
        self.prev_date = cur_date			# modifs tonyo
        font = '%s/%s' % (self.font, self.font_size)
        adesklets.load_font(font)
        adesklets.context_set_color(self.red,self.green,self.blue,200)

        # Draw text strings
        adesklets.context_set_font(0)
        text_x, text_y = adesklets.get_text_size(cur_time)
        adesklets.text_draw(0,12,cur_time)		# modifs tonyo
        adesklets.text_draw(0,0,cur_date)		# modifs tonyo
        adesklets.free_font(0)

        # Do we need to resize the window/buffer?
        if self.first_time or self.font_size != self.orig_font_size:
            self.first_time = False
            new_x = text_x + 5				# modifs tonyo
            new_y = text_y + 10				# modifs tonyo
            self.buffer = self._new_buffer(new_x, new_y)
            adesklets.window_resize(new_x, new_y)

        # Get final buffer size, in case we had to resize
        adesklets.context_set_image(self.buffer)
        buf_x = adesklets.image_get_width()
        buf_y = adesklets.image_get_height()

        # Copy everything from the buffer image to the real foreground image
        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 _get_current_time(self):
        """
        Get the current time in the desired format.
        """
        return time.strftime(self.format, time.localtime(time.time()))

###############						# modifs tonyo
    def _get_current_date(self):			# modifs tonyo
	return time.strftime(self.formatdate)		# modifs tonyo
###############						# modifs tonyo

    def _new_buffer(self, x, y):
        """
        Create a new buffer in the event that we need one (eg, if the format
        tells us to display the name of the day, or the name of the month, the
        old buffer may not be the right size once the day/month changes.
        """
        if self.buffer:
            adesklets.free_image(self.buffer)
        buffer = adesklets.create_image(x,y)
        #self._setup_buffer(buffer)
        return buffer

    def _setup_buffer(self, buffer):
        """
        Set up a new buffer.
        """
        adesklets.context_set_image(buffer)
        x = adesklets.image_get_width()
        y = adesklets.image_get_height()
        adesklets.context_set_color(0,0,0,0)
        adesklets.context_set_blend(False)
        adesklets.image_fill_rectangle(0,0,x,y)
        adesklets.context_set_blend(True)

    def _get_config(self):
        """
        Read configuration info from the configuration file.
        """
        if self.config is None:
            self.config = Config(adesklets.get_id(),
                    join(self.basedir,'config.txt'))
        config = self.config
        
        color = config.get('color')
        (self.red, self.green, self.blue) = self._parse_color(color)
        self.format = config.get('format')
        self.formatdate = config.get('formatdate')		# modifs tonyo
        self.font = config.get('font')
        self.font_size = config.get('font_size')
        if self.first_time or self.orig_font_size != self.font_size:
            self.orig_font_size = self.font_size

    def _parse_color(self, color):
        """
        Parse an HTML-style hexadecimal color value into respective decimal RGB
        values.
        """
        def hex_color_to_int(color):
            return eval('0x%s' % color)
        color = color[1:] # remove "#" from start of color
        red = hex_color_to_int(color[:2])
        green = hex_color_to_int(color[2:4])
        blue = hex_color_to_int(color[4:])
        return (red, green, blue)

# Let's get this party started!
Events(dirname(__file__)).pause()

merci d'avance pour vos indications
tonyo

Hors ligne

#2 Le 07/05/2006, à 15:37

manoudriton

Re : adesklet au premier plan

passer un desklet au premier plan me serait très utile aussi, je m'étonne de ne trouver aucune aide sur internet (et pourtant je cherche (mal ?)) pour une action qui me parrait aussi indispensable !

Alors toutes les belles captures d'écran des magnifiques bureaux qu'on trouve , et où on apperçoit des jolies barres d'outils, sur ces bureaux la , les deklets ne pourraient pas se trouvaient au premier plan ? Les barres d'outils ne servent que lorsqu'aucune fenêtre n'est ouverte ? Je ne comprends pas !

Hors ligne