LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-14-2008, 09:53 AM   #1
enigma_0Z
Member
 
Registered: Apr 2005
Distribution: Ubuntu, RHEL, Darwin
Posts: 73

Rep: Reputation: 15
Python: Stdin and python apps fighting?


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.
 
Old 07-15-2008, 07:33 AM   #2
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Quote:
Originally Posted by enigma_0Z View Post
Therefore, I have concluded that it is python causing the issue.
I highly doubt it's Python rather than the actual script itself. You should probably post your script so we can see if there is any obvious problems.
 
Old 07-15-2008, 09:45 AM   #3
enigma_0Z
Member
 
Registered: Apr 2005
Distribution: Ubuntu, RHEL, Darwin
Posts: 73

Original Poster
Rep: Reputation: 15
Script is as follows:

Code:
#!/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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Charming Python: Python elegance and warts, Part 2 LXer Syndicated Linux News 0 08-31-2007 09:40 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 08:54 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 12:05 PM
Distributing Python apps with Glade UI vharishankar Programming 0 11-27-2005 04:50 AM
python (karamba/superkaramba apps) JARofHERB Programming 3 11-10-2004 11:34 PM


All times are GMT -5. The time now is 02:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration