ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Here's my situation: I've written a python-based amarok script to make a libnotify popup whenever the track changes.
I've written this script because the current "standard" libnotify script is a bash script that doesn't handle things such as parentheses and slashes well, and additionally I wanted to do some more advanced imaging to the cover image.
To make a long story short, I also use WICD (which too is based on python) to connect to wireless networks.
It seems that WICD and Amarok are fighting in that whenever I reconnect to a wireless network, amarok stutters if it's playing. I have, however verified that my script is causing this--no stutter if I stop it from running. Therefore, I have concluded that it is python causing the issue.
To that end, my script uses sys.stdin.readline() (it was using raw_input()) to talk to amarok (which sends commands to scripts via stdin), if it matters, but I'm looking to solve this. I can provide the script if necessary.
#!/usr/bin/env python
import sys, threading, pydcop, pynotify, Image, ImageDraw
from cgi import escape
amarok = pydcop.anyAppCalled("amarok")
pynotify.init("Amarok pynotify")
def readloop():
while True:
cmd = sys.stdin.readline()
title = escape(amarok.player.title())
artist = escape(amarok.player.artist())
album = escape(amarok.player.album())
cover = amarok.player.coverImage()
coverImg = Image.open(cover)
coverImg.thumbnail((64, 64), Image.ANTIALIAS)
coverDraw = ImageDraw.Draw(coverImg)
coverDraw.rectangle([(0, 0), (coverImg.size[0]-1, coverImg.size[1]-1)], outline=(0))
cover = "/tmp/amarok-notify.png"
coverImg.save(cover)
cover = "file://" + cover
if cmd == "configure":
amarok.playlist.popupMessage("This script does not have any configuration options")
elif cmd == "engineStateChange: playing\n":
n = pynotify.Notification("Amarok Playing", "<b>" + title + "</b> by <b>" + artist + "</b> on <b>" + album + "</b>", cover)
n.show()
elif cmd == "engineStateChange: paused\n":
n = pynotify.Notification("Amarok Paused", "<b>" + title + "</b> by <b>" + artist + "</b> on <b>" + album + "</b>", cover)
n.show()
if __name__ == "__main__":
t = threading.Thread(target=readloop)
t.start()
After some more experimentation, it seems more likely that it was the awn icon script, not the python script, but I digress... for completeness, here's my script. I added the bit for threading on the end in an attempt to alleviate the issue. Didn't really work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.