You are not logged in.

#1 2016-03-22 11:00

From: UK
Registered: 2015-12-14
Posts: 2,989

Qt alternative to using GLib

I am currently writing a "skin" for xmms2, and although everything is going to plan, I have realised I am using GLib for my xmms2 connection. I have a file like this :-

from gi.repository.GLib import io_add_watch, IO_OUT, IO_IN, source_remove

class GLibConnector:
	def __init__(self, xmms):
		self.in_id = None
		self.out_id = None

	def need_out(self, i):
		if self.xmms.want_ioout() and self.out_id is None:
			self.out_id = io_add_watch(self.xmms.get_fd(), IO_OUT, self.handle_out)

	def handle_in(self, source, cond):
		if cond == IO_IN:
			return self.xmms.ioin()

		return True

	def handle_out(self, source, cond):
		if cond == IO_OUT and self.xmms.want_ioout():
		if not self.xmms.want_ioout():
			self.out_id = None

		return not self.out_id is None

	def reconnect(self, xmms=None):
		if not xmms is None:
			self.xmms = xmms
		self.in_id = io_add_watch(self.xmms.get_fd(), IO_IN, self.handle_in)
		self.out_id = None

	def disconnect(self):
		if not self.in_id is None:
			self.in_id = None
		if not self.out_id is None:
			self.out_id = None

and then in my functions I lead with this :-

xmms = xmmsclient.XMMS("myfunc")
except IOError, detail:
    print "Connection failed:", detail
conn = GLibConnector(xmms)

then to get the current playing medialib id I can do something like :-

def get_current_id():
    result = xmms.playback_current_id()
    if result.is_error():
        return False
    return result

Like I said, everything works fine and I have no reason to change it except that gi.repository is not included with a standard install of q4os and I would like to make this with as few as possible extra install requirements. Plus of course it would be better to have my app completely "qt".
I have been looking at other xmms2 skins that use qt, but lack the current understanding of how they use the connections.
Any advice/suggestions welcome.


P.s. If anyone is interested I have attached a current screenshot of it working. smile

png xmms-skin.png, Size: 84.39 KiB, Downloads: 910


Board footer

Powered by FluxBB