Home Forums Wiki Doc Install Extras Screenshots Source Code Projects Blog Users Groups Register
Glx-Dock / Cairo-Dock List of forums Applets | Applets A Suggestion about Periodically Updating Applets
The latest stable release is the *3.4.0* : How to install it here.
Note: We just switched from BZR to Git on Github! (only to host the code and your future pull requests)
Applets | Applets

Subjects Author Language Messages Last message
[Locked] A Suggestion about Periodically Updating Applets
rozen English 4

rozen, Saturday 08 September 2012 à 18:02

Subscription date : 20 December 2009
Messages : 19

I have been thinking about this posting for several days because I am not sure exactly how to put it. I am concerned that I might ask for something that upon careful consideration I really would not want.

The spot where I am coming from is:

(1) I really want to build any applets in Python. I have done my share of programming in the shell and in C.

(2) Most of the applets I want to construct require that the display be updated periodically. This seems to apply to a large group of applets like timers, calendars, moon phase applets, as well as system monitoring applets.

This requirement for periodic updates does not seem to be addressed well in Cairo-Dock as shown by the fact that the included Accessory Applet Calendar built its own update mechanism but it contained errors and did not function while the Moon Accessory Applet didn't even try.

In order to get a better understanding of the situation, I rewrote a simplified version of Calendar in Python. But trying to provide the updating mechanism when midnight occurs as well as, testing the date when a suspended system is restarted drove me into threads, which are confusing. While it appears to work, I am not sure it is a good implementation. I am attaching my implementation, NewCal.py for comment. Even then I was not able to invoke dbus via Python; I had to resort to os.system() to invoke a CLI command. (More on that with another post.)

I think that I was looking for something like the following. You provide the Python programmer the functions: begin, end, reload, and get_config. I think it would be helpful to add an "update" method supported with a periodic call. It would seem that it would be better to provide that at the CD level rather than requiring an "ad hoc" solution for each applet requiring it. A parameter in the applet configure file could specify the period in seconds or milliseconds with a value of zero meaning that no update function is desired.

I am running Cairo-Dock 3.0.0, on Mint 13 with Xfce

I would really appreciate hearing your thoughts,



import icon_template
import datetime
import os
import threading
from CDApplet import CDApplet
from CairoDock import CairoDock

"dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.ReloadIcon string:\"config-file=NewCal.conf\""

### Applet class ###
class NewCal(CDApplet):
def __init__(self):
# call high-level init
self.display_date ''
self.die = 0
.duration 10 # seconds

def end(self):
self.die = 1

    def begin
today datetime.date.today()
self.display_date != today:
self.display_date today

def update(self):
today datetime.date.today()
self.display_date != today:
self.display_date today

    def restart

def update_icon(selftoday):
YearMonthDay) = str(today).split('-')

Day[0] == '0':
# I don't want to see Days like "02"
Day Day[1]
icon_string icon_template.template % (MonthDay)
icon_file open('icon''w')
        print >> 

# Three trial alternatives: One. Works
        #cmd = icon_template.restart_command

        # Alternative two. Fails
        #dbus_iface = self.icon

        #Alternative three. Works.
cmd reloadicon_command

def update_timer(cduration):
'update_timer starting')
c.die: return

__name__ == '__main__':

matttbe, Sunday 09 September 2012 à 13:20

Subscription date : 24 January 2009
Messages : 12573

Yes, maybe it can be interesting to add this 'update' function to be able to use a cairo-dock-task.
I guess it's maybe too late to add it on the next version but it's not too late to start talking about this (possible) future feature

@fabounet: what do you think about that?

PS: @rozen: I think 'Twitter' applet is using threads and timers (from gobject) if you want another example

Eduardo Mucelli, Wednesday 12 September 2012 à 20:19

Subscription date : 05 August 2009
Messages : 285
I think it is better to use GObject's timeout_add function.

From the doc, "The gobject.timeout_add() function sets a function (specified by callback) to be called at regular intervals (specified by interval, with the default priority, gobject.PRIORITY_DEFAULT. Additional arguments to pass to callback can be specified after callback. The idle priority may be specified as a keyword-value pair with the keyword "priority"."

fabounet, Friday 14 September 2012 à 22:48

Subscription date : 30 November 2007
Messages : 17118
+1, if you want to make a periodic task, use a gobject timer, and if you want to use threads, it's relatively easy in Python (at least, more than in C )
so Cairo-Dock doesn't need to provide anything here, not like in C where it provide the CairoTask.

Applets | Applets

Subjects Author Language Messages Last message
[Locked] A Suggestion about Periodically Updating Applets
rozen English 4

Glx-Dock / Cairo-Dock List of forums Applets | Applets A Suggestion about Periodically Updating Applets Top

Online users :

Powered by ElementSpeak © 2007 Adrien Pilleboue, 2009-2013 Matthieu Baerts.
Dock based on CSS Dock Menu (Ndesign) with jQuery. Icons by zgegball
Cairo-Dock is a free software under GNU-GPL3 licence. First stable version created by Fabounet.
Many thanks to TuxFamily for the web Hosting and Mav for the domain name.