view RemoteViewer/Viewer.py @ 24:9d7245e45379

update command invocation for VNC
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 26 Sep 2014 04:33:38 +0200
parents 8f93457656b4
children 2e5a12e3598e
line wrap: on
line source

import subprocess

from threading import Thread
from .LogViewer import LogViewer

class ReadThread(Thread):
    def __init__(self, output, viewer):
        super(ReadThread, self).__init__()
        self.daemon = True
        self.output = output
        self.viewer = viewer

    def run(self):
        for line in iter(self.output.readline, b''):
            line = line.decode('utf-8')
            line = line.rstrip('\n')
            self.viewer.append(line)

class AbstractViewer(object):
    def __init__(self,  connection):
        self.connection = connection
        self.process = None

    def open(self, parent):
        self.buildCommand()
        self.process = subprocess.Popen(self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        self.__startLogThread()
        self.process.wait()

    def __startLogThread(self):
        logViewer = self.__createLogViewer()
        readThread = ReadThread(self.process.stdout, logViewer)
        readThread.start()
        logViewer.exec_()

    def __createLogViewer(self):
        viewer = LogViewer()
        viewer.setWindowTitle(self.connection.displayString())
        command = 'running ' + ' '.join(self.command) + '\n'
        viewer.append(command)
        return viewer

class VncViewer(AbstractViewer):
    def buildCommand(self):
        self.command = ['vncviewer']
        self.append('-geometry', self.connection.geometry)
        self.append('-DesktopSize', self.connection.geometry)
        self.command.append(self.connection.host)

    def append(self, option, value):
        if value is not None:
            self.command.append(option)
            self.command.append(value)

class FreeRdp(AbstractViewer):
    def buildCommand(self):
        self.command = ['xfreerdp', '+clipboard' ]
        self.append('/v:', self.connection.host)
        self.append('/t:', self.connection.displayString())
        self.append('/u:', self.connection.user)
        self.append('/size:', self.connection.geometry)

    def append(self, option, value):
        if value is not None:
            self.command.append(option + value)