rozen, Monday 10 February 2014 à 04:30
|
|
Subscription date : 20 December 2009
Messages : 19
|
- The version of Cairo-Dock ('cairo-dock -v' in a terminal). 3.3.99.beta1
- Your GNU/Linux distribution (Debian, Ubuntu, Fedora, etc.). Mint 16
- Or you using OpenGL or not. Yes
- Your Window manager (Compiz, Metacity, Kwin, Openbox, etc.). ?
- Your Desktop Environment (Gnome, KDE, XFCE, etc.). XFCE
Hi,
I just upgraded my linux system from Mint 15 to Mint 16. My problem is that several crucial applets that I wrote in Python no longer work. The include a date applet, a clock, and a network monitor. They all are meant to be updated periodically, usually every second.
My applets appear in a separate dock located at the right edge of my screen. When I start the applets they appear, that is the correct initial values but they never seem to be updated. I use Python threading to recreated the the icons periodically and I use the dbus ReloadIcon to update the icon. Let me emphasize that the applets seemed to work fine before I updated my system which also updated the version of cairo-dock. I don't remember the version, it may have been 3.2.99. I am including the clock applet since it is the smallest one:
print "dprClock starting."
import os
import sys
import shutil
import time
import threading
import os, os.path
import sys
import copy
import Image, ImageDraw
import math
from datetime import datetime
from CDApplet import CDApplet
from CairoDock import CairoDock
reloadicon_command = "dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.ReloadIcon string:\"config-file=dprClock.conf\""
restart_command = " dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.ReloadModule string:dprClock # new icon -> reload (only the icon is reloaded)"
class dprClock(CDApplet):
def __init__(self):
CDApplet.__init__(self) self.create_template()
self.duration = 1 self.die = 0
self.dialog_active_time = 30 self.clock_image = Image.new('RGB', (64, 64), (100, 149, 237))
self.dbus = CairoDock().iface
def begin(self):
print "*** begin function: dprClock."
self.update()
self.t = threading.Thread(target=update_timer,
args=(self, self.duration))
self.t.start()
def end(self):
print "*** end function: dprClock"
self.die = 1
def update(self):
sys.stdout.flush()
self.update_clock()
def restart(self):
print "*** restart function: dprClock"
self.update()
def update_clock(self):
print >> self.f, "*** update clock: dprClock"
self.f.flush()
clock_template =self.clock_template.copy()
draw = ImageDraw.Draw(clock_template)
center = 32
time = datetime.time(datetime.now())
hr = time.hour % 12
min = time.minute
sec = int(math.floor(time.second))
hr_degrees = hr * (360 / 12)
min_degrees = min * 0.5 hr_degrees += min_degrees
psi = math.radians(hr_degrees)
hdx = math.floor(math.sin(psi) * 26 * 0.45)
hdy = math.floor(-math.cos(psi) * 26 * 0.45)
hr_box = (center, center, center+hdx, center+hdy) draw.line( hr_box, width=4, fill= 'white') psi = min * (math.pi / 30.0)
mdx = math.floor(math.sin(psi) * 26 * 0.8)
mdy = math.floor(-math.cos(psi) * 26 * 0.8)
min_box = (center, center, center+mdx, center+mdy) draw.line( min_box, width=3, fill='white') psi = sec * (math.pi / 30.0)
sdx = math.floor(math.sin(psi) * 26 * 0.9)
sdy = math.floor(-math.cos(psi) * 26 * 0.9)
sec_box = (center, center, center+sdx, center+sdy) draw.line( sec_box, width=2, fill = 'cyan') fn = os.path.expanduser('icon')
clock_template.save(fn, 'JPEG')
self.dbus.ReloadIcon('config-file=dprClock.conf') def create_template(self):
''' Create clock template with dots for hour markers. Done
once in __init__'''
clock_template = Image.new('RGB', (64, 64), '#b22222') draw = ImageDraw.Draw(clock_template)
center = 32
for spot in range(0, 60, 5):
psi = spot * (math.pi / 30.0)
spot_x = math.floor(math.sin(psi) * 27) + 34
spot_y = math.floor(-math.cos(psi) * 27) + 34
if ((spot % 15) == 0):
spot_x -= 3
spot_y -= 3
delta = 3
else:
spot_x -= 1
spot_y -= 1
delta = 2
box = (spot_x-delta, spot_y-delta, spot_x+delta, spot_y+delta)
draw.ellipse(box, fill = 'yellow')
self.clock_template = clock_template.copy()
def update_timer(c, duration):
'''This is the timer thread.'''
while 1:
print >> c.f, "timer loop"
c.f.flush()
if c.die: return
time.sleep(duration)
c.update()
return
def main():
pass
if __name__ == '__main__':
dprClock().run()
I seem to remember that in the past debugging print statements wrote to .xsession-errors. But that does not seem to be the case currently. Is there an easy way to capture my debugging messages. I tried running cairo-dock in a terminal but that was not very satisfactory and I didn't learn much.
Any suggestions would be very much appreciated,
Thanks in Advance,
Don |
fabounet, Monday 10 February 2014 à 13:59
|
|
Subscription date : 30 November 2007
Messages : 17118
|
Hi,
first, an applet doesn't need to access the dock directly
if you want to update your applet periodically, use a timer (for instance, use the timeout_add function from glib)
second, ReloadIcon and ReloadModule don't exist anymore; there is an unique Reload method
the Dock API has changed to be easier and more powerful, and you can find the info on the wiki  |
SQP, Monday 10 February 2014 à 20:03
|
|
Subscription date : 03 July 2010
Messages : 1081
|
fabounet : the Dock API has changed to be easier and more powerful, and you can find the info on the wiki :)
since you talk about that, I miss the old ActivateModule command. Add+Remove are too complicated for such a simple operation. It's needed to work easier on external applets. |
Guest, Tuesday 11 February 2014 à 05:55
|
|
|
Hi,
I was not able to get Reload to do update the Icon but self.icon.SetIcon(...) seemed to work.
I was not able to get the timeout_add function from glib work but pythons time.sleep(1) seemed to work.
Now I can't get any response in on_click() function. The icon enlarges and rotates but I don't seem to get into the on_click function.
Thanks for your responses,
Don |
fabounet, Monday 17 February 2014 à 13:55
|
|
Subscription date : 30 November 2007
Messages : 17118
|
I think that using sleep is not that good, because meanwhile your applet doesn't respond to events from the dock.
so using a glib timeout seems a better approach (and I think you can find some examples in our third-party applets)
@SQP: well, you can still define a wrapper around those functions, personnaly I like having a unified API
(but I agree with you that you need the wiki to know the syntax, that's the drawback) |
SQP, Monday 17 February 2014 à 15:50
|
|
Subscription date : 03 July 2010
Messages : 1081
|
of course I wrapped it, how the fuck can you work on external applets without that? It's the command I use the most.
but even if that sound more "unified", this method is still really needed. I don't know how to do it from bash, nor should I have to use complex arguments to do that. (find location of conf file??)
I need this ActivateModule or some sort of RebootModule method to really unload and reload external applets.
(and since I'm forced to do the "remove/add" method, I regularly have a violent dock crash with "glist: double list corrupted") |
|