Hi,
Ingmar Steen wrote:
I'm trying to use the new PyQt4 dbus mainloop, but it crashes with an
assertion error when I try to get an object from the bus. I'm using Sip
4.6,
PyQt4.2, Qt 4.2.3, Python 2.5.1, DBus 1.0.2 and dbus-python 0.80.1. Am I
doing something fundamentally insane or wrong?
If I remove the QDBusQtMainLoop(set_as_default=True) line, it works just
fine. The assertion also happens if app.exec_() and get the bus object from
a QTimer event.
Here is some code which works for me. You'll have to strip it down
yourself though. I'm lazy like that. ;-)
cheers,
--
Simon Edwards | KDE-NL, Guidance tools, Guarddog Firewall
[EMAIL PROTECTED] | http://www.simonzone.com/software/
Nijmegen, The Netherlands | "ZooTV? You made the right choice."
#!/usr/bin/python
import sys
import os
import time
import gobject
import signal
import dbus
import dbus.service
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
from PyQt4 import QtCore
############################################################################
class ServerIFace(dbus.service.Object):
def __init__(self, bus_name, object_path='/com/simonzone/watchdog/Server'):
dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.signal('com.simonzone.watchdog.ServerIFace')
def packetHit(self, message): pass
############################################################################
class WatchdogServerApp(QtCore.QCoreApplication):
def __init__(self,argv):
QtCore.QCoreApplication.__init__(self,argv)
self.log_pipe_fd = -1
self.log_pipe = None
def pipeReady(self,source,condition):
print "Pipe ready! "
try:
data = self.log_pipe.readline()
while data!="":
self.handleLine(data)
data = self.log_pipe.readline()
except IOError,e:
#print e
self.connectToPipe()
print "-----------------------"
return True
def connectToPipe(self):
print "connectToPipe()"
if self.log_pipe is not None:
gobject.source_remove(self.log_event_source)
self.log_pipe.close()
self.log_pipe = None
self.log_pipe_fd = os.open("/var/lib/WATCHDOGPIPE",os.O_RDONLY|os.O_NONBLOCK)
self.log_pipe = os.fdopen(self.log_pipe_fd,"r")
# Qt's QSocketNotifier just doesn't work right when used with pipes.
# It just keeps on sending the same signal. gobject's works.
self.log_event_source = gobject.io_add_watch(self.log_pipe_fd, gobject.IO_IN, self.pipeReady)
print "log_pipe_fd:",self.log_pipe_fd
def exec_(self):
self.bus = dbus.SystemBus()
self.bus_name = dbus.service.BusName('com.simonzone.watchdog.ServerIFace', bus=self.bus)
self.iface = ServerIFace(self.bus_name)
self.startTimer(1000)
self.connectToPipe()
# Use the glib main loop
mainloop = gobject.MainLoop()
mainloop.run()
#QtCore.QCoreApplication.exec_()
print "Done running"
def timerEvent(self,event):
print "Timer event"
self.iface.packetHit('I sent a hello signal')
def handleLine(self, line):
# is this a package log message?
if "kernel:" not in line:
return
if "IN=" not in line:
return
############################################################################
def main():
app = WatchdogServerApp(sys.argv)
app.exec_()
main()
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt