def connect(server, password=None): """ Connect to a VNCServer and return a Client instance that is usable in the main thread of non-Twisted Python Applications, EXPERIMENTAL. >>> from vncdotool import threaded >>> client = threaded.connect('host') >>> client.keyPress('c') >>> client.join() You may then call any regular VNCDoToolClient method on client from your application code. If you are using a GUI toolkit or other major async library please read http://twistedmatrix.com/documents/13.0.0/core/howto/choosing-reactor.html for a better method of intergrating vncdotool. """ observer = PythonLoggingObserver() observer.start() factory = VNCDoToolFactory() if password is not None: factory.password = password client = ThreadedVNCClientProxy(factory) host, port = command.parse_host(server) client.connect(host, port) client.start() return client
def build_tool(options, args): factory = VNCDoToolFactory() if options.verbose: factory.deferred.addCallbacks(log_connected) if args == ['-']: lex = shlex.shlex(posix=True) lex.whitespace_split = True args = list(lex) build_command_list(factory, args, options.delay, options.warp) factory.deferred.addCallback(stop) factory.deferred.addErrback(error) reactor.connectTCP(options.host, int(options.port), factory) reactor.exit_status = 1 return factory
def connect(server, password=None): """ Connect to a VNCServer and return a Client instance that is usable in the main thread of non-Twisted Python Applications, EXPERIMENTAL. >>> from vncdotool import api >>> client = api.connect('host') >>> client.keyPress('c') >>> api.shutdown() You may then call any regular VNCDoToolClient method on client from your application code. If you are using a GUI toolkit or other major async library please read http://twistedmatrix.com/documents/13.0.0/core/howto/choosing-reactor.html for a better method of intergrating vncdotool. """ if not reactor.running: global _THREAD _THREAD = threading.Thread(target=reactor.run, name='Twisted', kwargs={'installSignalHandlers': False}) _THREAD.daemon = True _THREAD.start() observer = PythonLoggingObserver() observer.start() factory = VNCDoToolFactory() if password is not None: factory.password = password client = ThreadedVNCClientProxy(factory) host, port = command.parse_host(server) client.connect(host, port) return client