def __init__(self): dbus_main_loop = dbus.glib.DBusGMainLoop(set_as_default=True) session_bus = dbus.SessionBus(dbus_main_loop) bus_name = dbus.service.BusName("com.mikeasoft.statusnet", bus=session_bus) dbus.service.Object.__init__(self, object_path="/synchronize", bus_name=bus_name) self.app = QCoreApplication(sys.argv) signal.signal(signal.SIGINT, signal.SIG_DFL) self.client = gconf.client_get_default() self.api_path = self.client.get_string( '/apps/ControlPanel/Statusnet/api_path') self.latest = self.client.get_int( '/apps/ControlPanel/Statusnet/latest') self.eventService = EventFeedService('statusnet', 'StatusNet') self.eventService.local_name = "com.mikeasoft.statusnet.eventcallback" self.eventService.DEFAULT_INTF = "com.mikeasoft.statusnet.eventcallback" if not self.api_path: return self.cacheDir = QDesktopServices.storageLocation( QDesktopServices.CacheLocation) if not os.path.exists(self.cacheDir): os.mkdir(self.cacheDir) sys.exit(self.app.exec_())
def testTypes(self): o = MyBaseObject() o.app = QCoreApplication(sys.argv) o.app.exec_() for e in o.events: self.assertTrue(isinstance(e, MyEvent)) o.app = None
def start(self, startMainLoop=False): if startMainLoop: from PySide.QtCore import QCoreApplication self.qtApplication = QCoreApplication(sys.argv) # we import QGeoPositionInfoSource after the Qt Application is # created to get rid of the: # " # QDBusConnection: system D-Bus connection created before QCoreApplication. Application may misbehave. # QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave. # " # warnings from QtMobility.Location import QGeoPositionInfoSource self.source = QGeoPositionInfoSource.createDefaultSource(None) if self.source is not None: self.source.positionUpdated.connect(self._positionUpdateCB) log.info("position source created") # TODO: custom interval setting self.source.setUpdateInterval(1000) self.source.startUpdates() log.info("started") # only start the mainloop if the source was created successfully, # otherwise it would never end as the signal provided by the source, # that stops the main loop, would never be triggered if startMainLoop: log.info("starting headless mainloop") self.qtApplication.exec_() else: log.error("source creation failed")
def install(app=None, timeout=0.02, engine=None): """ Creates a :class:`~PySide.QtCore.QTimer` instance that will be triggered continuously to call :func:`Engine.poll() <pants.engine.Engine.poll>`, ensuring that Pants remains responsive. ========= ======== ============ Argument Default Description ========= ======== ============ app None *Optional.* The :class:`~PySide.QtCore.QCoreApplication` to attach to. If no application is provided, it will attempt to find an existing application in memory, or, failing that, create a new application instance. timeout ``0.02`` *Optional.* The maximum time to wait, in seconds, before running :func:`Engine.poll() <pants.engine.Engine.poll>`. engine *Optional.* The :class:`pants.engine.Engine` instance to use. ========= ======== ============ """ global timer global _timeout global _engine _engine = engine or Engine.instance() _engine._install_poller(_Qt()) if app is None: app = QCoreApplication.instance() if app is None: app = QCoreApplication([]) _timeout = timeout * 1000 timer = QTimer(app) timer.timeout.connect(do_poll) timer.start(_timeout)
def main(): parser = OptionParser(description='A chat client/server') parser.add_option('-s', '--server', help='Start a server. If not ' 'given, a client will be started', action='store_true') opts, args = parser.parse_args() if opts.server: from PySide.QtCore import QCoreApplication app = QCoreApplication(sys.argv) # spawn a server server = ChatServer() listening = server.listen(HOST_ADDRESS, PORT) if not listening: # a server error print('Server start failed: {}'.format(server.errorString()), file=sys.stderr) server.serverShutdown.connect(app.quit) # print everything received by the server to standard output server.textReceived.connect(partial(print, '>>')) else: app = QApplication(sys.argv) chat_window = ChatWindow() chat_window.show() app.exec_()
def setUp(self): '''Set up resources''' global _core_instance if _core_instance is None: _core_instance = QCoreApplication([]) self.app = _core_instance
def testScriptQProperty(self): qapp = QCoreApplication([]) myEngine = QScriptEngine() obj = MyObject() scriptObj = myEngine.newQObject(obj) myEngine.globalObject().setProperty("obj", scriptObj) myEngine.evaluate("obj.x = 42") self.assertEqual(scriptObj.property("x").toInt32(), 42) self.assertEqual(obj.property("x"), 42)
def setUp(self): #Acquire resources self.called = False self.app = QCoreApplication([]) self.socket = QUdpSocket() self.server = QUdpSocket() self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)
def testBlockingSignal(self): app = QCoreApplication.instance() or QCoreApplication([]) eventloop = QEventLoop() emitter = Emitter() receiver = Receiver(eventloop) emitter.connect(emitter, SIGNAL("signal(int)"), receiver.receive, Qt.BlockingQueuedConnection) emitter.start() retval = eventloop.exec_() emitter.wait() self.assertEqual(retval, 0)
def main(): app = QCoreApplication(sys.argv) context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='input') observer = QUDevMonitorObserver(monitor) observer.deviceAdded.connect( partial(print_mouse_status, status_message="added")) observer.deviceRemoved.connect( partial(print_mouse_status, status_message="removed")) monitor.start() app.exec_()
def __init__(self): self._reads = {} self._writes = {} self._notifiers = {} self._timer = QTimer() self._timer.setSingleShot(True) QObject.connect(self._timer, SIGNAL("timeout()"), self.iterate) self.qApp = QCoreApplication.instance() self._ownApp = False if self.qApp is None: self.qApp = QCoreApplication([]) self._ownApp = True self._blockApp = None posixbase.PosixReactorBase.__init__(self)
def testQCoreAppChildren(self): #QObject.children() after creating a QCoreApplication # Minimal test: # 1- Create QCoreApp # 2- Create parent and childrens # 3- While keeping the children alive, call parent.children() # 4- Delete parent app = QCoreApplication([]) parent = QObject() children = [QObject(parent) for x in range(25)] # Uncomment the lines below to make the test pass # del children # del child2 del parent # XXX Segfaults here self.assert_(True)
def testEmitOutsideThread(self): global thread_run app = QCoreApplication([]) source = Source() thread = ThreadJustConnects(source) QObject.connect(thread, SIGNAL('finished()'), lambda: app.exit(0)) thread.start() while not thread_run: pass source.emit_sig() app.exec_() thread.wait() self.assert_(thread.target.called)
def __init__(self): self.app = QApplication.instance() if self.app is None: self.app = QCoreApplication([]) self.engine = QScriptEngine() self.globalObject = self.engine.globalObject() # There were some problems evalating javascript inside a function callback. QtSide's bindings for QScriptEngine # didn't seem prepared to handle it (it breaks in weird hard-to-debug ways) # It is however not a problem if you use a wrapped QObject for the callback instead of using engine.newFunction(). # The workaround here is to pass a wrapped QObject, and then evaluate javascript to create a function that calls # a method of the wrapped QObject. # Also note: Wrapped QObjects passed to QtSide are not refcounted in Python! To work around this, a reference to # "RequireObj" is stored in the JSEngine instance self.requireObj = JsEngineRequireClass(self.engine) self.addObject('RequireObj', self.requireObj) self.evaluate(""" function require(arg) { return RequireObj.require(arg); } """)
def setUp(self): #Create fixtures self.app = QCoreApplication([])
with SkProfiler(): for i in range(1): t = translate(s, to=to, fr=fr) print t print type(t) #session = requests #with SkProfiler(): # for i in range(10): # t = translate(s, to=to, fr=fr) #print t app.quit() from PySide.QtCore import QCoreApplication, QTimer app = QCoreApplication(sys.argv) QTimer.singleShot(0, test) app.exec_() # EOF #import urllib, urllib2 #url = createUrl(text, to=INFOSEEK_LCODE[to], fr=INFOSEEK_LCODE[fr]) #try: # # See: http://stackoverflow.com/questions/3465704/python-urllib2-urlerror-http-status-code # response = urllib2.urlopen(url) # ret = response.read() #except urllib2.HTTPError, e: # dwarn("http error code =", e.code) # return "" #except urllib2.URLError, e:
def main(): app = QCoreApplication(sys.argv) server = Server() signal.signal(signal.SIGINT, exit_handler) return app.exec_()
def testQCoreApplicationInstance(self): #Tests QCoreApplication.instance() self.assertEqual(QCoreApplication.instance(), None) app = QCoreApplication([]) self.assertEqual(QCoreApplication.instance(), app)
return True @dbus.service.method('de.ch.blink', out_signature='as') def get_available_clips(self): return list(player.clips.keys()) @dbus.service.method('de.ch.blink', out_signature='as') def get_playlist(self): lis = [ "%d -> %s" % (idx, str(item["alias"])) for idx, item in enumerate(playlist_items) ] return lis if __name__ == "__main__": signal.signal(signal.SIGINT, signal.SIG_DFL) player = AVRPlayer() if len(sys.argv) == 2: files = json.load(open(sys.argv[1], "r")) player.load_clips(files) elif os.path.isfile("playlist.cfg"): files = json.load(open("playlist.cfg", "r")) player.load_clips(files) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) thread = BlinkDisplayThread() thread.start() service = MyDBUSService() app = QCoreApplication([]) app.exec_()