def run(self): GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.application.quit) if USE_TWISTED: reactor.registerGApplication(self.application) reactor.run() else: self.application.run(sys.argv)
def runReactor(self, app, reactor): """ Register the app, run the reactor, make sure app was activated, and that reactor was running, and that reactor can be stopped. """ if not hasattr(app, "quit"): raise SkipTest("Version of PyGObject is too old.") result = [] def stop(): result.append("stopped") reactor.stop() def activate(widget): result.append("activated") reactor.callLater(0, stop) app.connect('activate', activate) # We want reactor.stop() to *always* stop the event loop, even if # someone has called hold() on the application and never done the # corresponding release() -- for more details see # http://developer.gnome.org/gio/unstable/GApplication.html. app.hold() reactor.registerGApplication(app) ReactorBuilder.runReactor(self, reactor) self.assertEqual(result, ["activated", "stopped"])
def SibylStart( protocol, # 'UDP' or TCP' protocolType, # 'text' or 'binary' port, host, debugFlag): """The main for the twisted Sibyl client""" # logging.basicConfig() log = logging.getLogger('sibyl_client') log.setLevel(logging.INFO) formatter = logging.Formatter('[%(levelname)s] [%(name)s] %(message)s') handler = logging.StreamHandler() handler.setFormatter(formatter) log.addHandler(handler) if port > 65536 or port <= 1500: print("Invalid port: the port number has to be between 1501 and 65536") exit(-1) if debugFlag: log.setLevel(logging.DEBUG) usingUdp = False if protocol == 'UDP': usingUdp = True if protocolType == 'text': protocol = 'sibyl.protocol.sibyl_client_udp_text' protocol += '_protocol.SibylClientUdpTextProtocol' elif protocolType == 'binary': protocol = 'sibyl.protocol.sibyl_client_udp_bin' protocol += '_protocol.SibylClientUdpBinProtocol' elif protocol == 'TCP': if protocolType == 'text': protocol = 'sibyl.protocol.sibyl_client_tcp_text' protocol += '_protocol.SibylClientTcpTextProtocol' elif protocolType == 'binary': protocol = 'sibyl.protocol.sibyl_client_tcp_bin' protocol += '_protocol.SibylClientTcpBinProtocol' else: print("Invalid transport protocol: protocol has to be 'UDP' or 'TCP'") module = importlib.import_module(protocol.rsplit('.', 1)[0]) protocolName = getattr(module, protocol.rsplit('.', 1)[1]) log.debug("importing module=%s, protocol=%s", module, protocolName) # host = reactor.resolve(host) log.info("MAIN_INFO: Starting the SibylClientApp") sibylClientAppInstance = SibylClientApplication(protocolName, usingUdp, host, port) log.info("MAIN_INFO: Registering the sibylClientApp") reactor.registerGApplication(sibylClientAppInstance) log.info("MAIN_INFO: Starting the reactor") reactor.run()
def main(args=[]): log = logging.getLogger(__name__) log.debug('Running main with args: %s', args) if not args: args = [] Gst.init(None) app = App() try: GLib.unix_signal_add_full(GLib.PRIORITY_HIGH, signal.SIGINT, lambda *args: reactor.callFromThread(reactor.stop), None) except AttributeError: pass reactor.registerGApplication(app) reactor.run()
def test_cantRegisterTwice(self): """ It is not possible to register more than one C{Application}. """ reactor = gireactor.GIReactor(useGtk=False) self.addCleanup(self.unbuildReactor, reactor) app = Gio.Application( application_id='com.twistedmatrix.trial.gireactor', flags=Gio.ApplicationFlags.FLAGS_NONE) reactor.registerGApplication(app) app2 = Gio.Application( application_id='com.twistedmatrix.trial.gireactor2', flags=Gio.ApplicationFlags.FLAGS_NONE) exc = self.assertRaises(RuntimeError, reactor.registerGApplication, app2) self.assertEqual(exc.args[0], "Can't register more than one application instance.")
def main(args=[]): logging.basicConfig(level=logging.DEBUG, format='%(name)s (%(levelname)s): %(message)s') log = logging.getLogger(__name__) log.debug('Running main with args: %s', args) if not args: args = [] Gst.init(None) app = KeysignApp() try: GLib.unix_signal_add_full( GLib.PRIORITY_HIGH, signal.SIGINT, lambda *args: reactor.callFromThread(reactor.stop), None) except AttributeError: pass reactor.registerGApplication(app) reactor.run()
def main(args=[]): logging.basicConfig( level=logging.DEBUG, format='%(name)s (%(levelname)s): %(message)s') log = logging.getLogger(__name__) log.debug('Running main with args: %s', args) if not args: args = [] Gst.init(None) app = KeysignApp() try: GLib.unix_signal_add_full(GLib.PRIORITY_HIGH, signal.SIGINT, lambda *args: reactor.callFromThread(reactor.stop), None) except AttributeError: pass reactor.registerGApplication(app) reactor.run()
# we could have possibly pressed this button, i.e. # from the keypresentwidget or the result page log.debug("Send Headerbutton %r clicked! %r", button, args) current = self.send_app.stack.get_visible_child() klw = self.send_app.klw kpw = self.send_app.kpw # If we are in the keypresentwidget if current == kpw: self.send_stack.set_visible_child(klw) self.send_app.deactivate() # Else we are in the result page else: self.send_stack.remove(current) self.send_app.set_saved_child_visible() self.send_app.on_key_activated(None, self.send_app.key) def on_header_button_clicked(self, button, *args): log.debug("Headerbutton %r clicked! %r", button, args) return self.on_send_header_button_clicked(button, *args) if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) app = App() try: GLib.unix_signal_add_full(GLib.PRIORITY_HIGH, signal.SIGINT, lambda *args: reactor.callFromThread(reactor.stop), None) except AttributeError: pass reactor.registerGApplication(app) reactor.run()
def __init__(self): app = gtk.Application() app.connect("activate", app_activate) reactor.registerGApplication(app) f = UiFactory(app) reactor.connectTCP("localhost", 38497, f)
def start(port, known_nodes): app = BitTalksApp(udp_port, known_nodes) reactor.registerGApplication(app) reactor.run()