[Banshee-List] DBus API: ShuffleMode and RepeatMode



Hello everybody,

this is somewhat of a bug report. I've created a python script that listens
for LIRC commands in order to skip/pause etc. songs (using DBus) using my
remote. This works flawlessly, so kudos from me for the great DBus api!

What doesn't work is setting the repeat or shuffle modes. To be more
precise: they are set correctly (the behaviour changes), however the UI
isn't updated accordingly (all buttons/checks stay at the same position)

I haven't looked at the code but I believe this is due to a missing event
invocation; as there are multiple ways in the UI to change the shuffle &
repeat modes (using the menu or the buttons), there must be a central way of
updating all these widgets, and it seems logical to use events & listeners
for this purpose.

it would be nice to see this updated.

As a treat for you people, here's the code I've used: (you need pyLirc
ofcourse)

#!/usr/bin/env python
import syslog,os,dbus,pylirc,signal,select,sys

def daemonize():
	"""Become a Linux/UNIX daemon"""
	os.chdir('/')
	if os.fork(): os._exit(0)
	os.setsid()
	sys.stdin  = sys.__stdin__  = open('/dev/null','r')
	sys.stdout = sys.__stdout__ = open('/dev/null','w')
	sys.stdout = sys.__stderr__ = os.dup(sys.stdout.fileno())

class lirc():

	def __init__(self):
		#logging & sigterms:		
		self.log = syslog.openlog("banshee-control[%d]" % os.getpid())
		signal.signal(signal.SIGINT,  lambda *args: quit())
		signal.signal(signal.SIGQUIT, lambda *args: quit())	
		
		#LIRC socket creation:
		self.lirc_sock = pylirc.init("banshee_control")
		while not pylirc.blocking(1): pass
		
		self.ready = True
		self.bus = None
		
		self.run()
		
	def quit():
		self.ready = False
		
	def run(self):
		while self.ready:
			try:
				commands = pylirc.nextcode()
			except:
				self.ready = False
				print "Reading next LIRC code failed, closing banshee-control..."
			if commands:
				for command in commands:
					self.parse_command(command)
		pylirc.exit()	
	
	def parse_command(self, command):
		if not self.bus: self.connect_dbus()
		try:	
			if command=="next":
				self.playback.Next(False)
			elif command=="previous":
				self.playback.Previous(False)
			elif command=="pp":
				self.engine.TogglePlaying()
			elif command=="stop":
				self.engine.Close()
			elif command=="repeatmode":
				rm = self.playback.GetRepeatMode()
				rm = (rm + 1) if rm < 2 else 0
				self.playback.SetRepeatMode(rm)
			elif command=="shufflemode":
				sm = int(not self.playback.GetShuffleMode())
				self.playback.SetShuffleMode(sm)
			##elif command=="pause": #I dont use these!
			##	self.banshee.Pause()
			##elif command=="play":
			##	self.banshee.Play()	
		except dbus.exceptions.DBusException: #try reconnecting:
			self.connect_dbus()
			self.parse_command(command)	
	
	def setup_dbus(self):
		self.bus = dbus.SessionBus()
		self.connect_dbus()
		
	def connect_dbus(self):
		if not self.bus:
			self.setup_dbus()
		else:
			self.engine = self.bus.get_object("org.bansheeproject.Banshee",
"/org/bansheeproject/Banshee/PlayerEngine")
			self.playback = self.bus.get_object("org.bansheeproject.Banshee",
"/org/bansheeproject/Banshee/PlaybackController")
		

if __name__=='__main__':
	daemonize()
	lirc()

-- 
View this message in context: http://www.nabble.com/DBus-API%3A-ShuffleMode-and-RepeatMode-tp22773116p22773116.html
Sent from the Banshee mailing list archive at Nabble.com.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]