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 test_default(self): command.parse_host(self.options) assert self.options.host == '127.0.0.1' assert self.options.port == 5900
def test_just_display(self): host, port = command.parse_host(':10') assert host == '127.0.0.1' assert port == 5910
def test_host_port(self): host, port = command.parse_host('10.11.12.13::4444') assert host == '10.11.12.13' assert port == 4444
def test_default(self): host, port = command.parse_host('') assert host == '127.0.0.1' assert port == 5900
def test_just_port(self): self.options.server = '::1111' command.parse_host(self.options) assert self.options.host == '127.0.0.1' assert self.options.port == 1111
def test_just_display(self): self.options.server = ':10' command.parse_host(self.options) assert self.options.host == '127.0.0.1' assert self.options.port == 5910
def test_just_host(self): self.options.server = '10.11.12.13' command.parse_host(self.options) assert self.options.server == '10.11.12.13' assert self.options.port == 5900
def test_host_port(self): self.options.server = '10.11.12.13::4444' command.parse_host(self.options) assert self.options.host == '10.11.12.13' assert self.options.port == 4444
def test_host_display(self): self.options.server = '10.11.12.13:10' command.parse_host(self.options) assert self.options.host == '10.11.12.13' assert self.options.port == 5910
def test_host_display(self): host, port = command.parse_host('10.11.12.13:10') assert host == '10.11.12.13' assert port == 5910
def test_just_host(self): host, port = command.parse_host('10.11.12.13') assert host == '10.11.12.13' assert port == 5900
def test_just_port(self): host, port = command.parse_host('::1111') assert host == '127.0.0.1' assert port == 1111
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