changeset 11:191f6296a2a4

display the output of the respective viewer command in a separate log view
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 21 Sep 2014 03:23:17 +0200
parents dfefc456dc93
children 3fdb5db9bedb
files RemoteViewer/Connection.py RemoteViewer/LogViewer.py RemoteViewer/LogViewer.ui RemoteViewer/RemoteViewer.py RemoteViewer/Viewer.py
diffstat 5 files changed, 68 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/RemoteViewer/Connection.py	Sun Sep 21 02:45:24 2014 +0200
+++ b/RemoteViewer/Connection.py	Sun Sep 21 03:23:17 2014 +0200
@@ -24,19 +24,19 @@
         return 'connection "{}" of type {} to {} with user {} and geometry {}'.format(self.title, self.type,  self.host, self.user, self.geometry)
 
     def setType(self, type):
-        '''This method is connected to a slot in the GUI'''
+        '''This is a slot that is connected to a signal in the GUI'''
         self.type = type
 
     def setHost(self, hostname):
-        '''This method is connected to a slot in the GUI'''
+        '''This is a slot that is connected to a signal in the GUI'''
         self.host = hostname
 
     def setUser(self, user):
-        '''This method is connected to a slot in the GUI'''
+        '''This is a slot that is connected to a signal in the GUI'''
         self.user= user
 
     def setGeometry(self, geometry):
-        '''This method is connected to a slot in the GUI'''
+        '''This is a slot that is connected to a signal in the GUI'''
         self.geometry = geometry
 
     def displayString(self):
@@ -55,10 +55,10 @@
                 json[key] = getattr(self,  key)
         return json
 
-    def open(self):
+    def open(self, parent):
         if self.type == 'vnc':
-            VncViewer(self).open()
+            VncViewer(self).open(parent)
         elif self.type == 'rdp':
-            FreeRdp(self).open()
+            FreeRdp(self).open(parent)
         else:
             raise ValueError('unknown type: ' + self.type)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RemoteViewer/LogViewer.py	Sun Sep 21 03:23:17 2014 +0200
@@ -0,0 +1,15 @@
+from PyQt4.QtCore import pyqtSignal
+from PyQt4.QtGui import QDialog
+from .Ui_LogViewer import Ui_LogViewer
+
+class LogViewer(QDialog):
+    appendSignal = pyqtSignal(['QString'])
+
+    def __init__(self):
+        super(LogViewer, self).__init__()
+        self.ui = Ui_LogViewer()
+        self.ui.setupUi(self)
+        self.appendSignal.connect(self.ui.logText.appendPlainText)
+
+    def append(self, line):
+        self.appendSignal.emit(line)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RemoteViewer/LogViewer.ui	Sun Sep 21 03:23:17 2014 +0200
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LogViewer</class>
+ <widget class="QDialog" name="LogViewer">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>613</width>
+    <height>463</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QPlainTextEdit" name="logText">
+     <property name="plainText">
+      <string notr="true"/>
+     </property>
+     <property name="textInteractionFlags">
+      <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--- a/RemoteViewer/RemoteViewer.py	Sun Sep 21 02:45:24 2014 +0200
+++ b/RemoteViewer/RemoteViewer.py	Sun Sep 21 03:23:17 2014 +0200
@@ -33,7 +33,7 @@
     @ExceptionSafeSlot('QModelIndex')
     def openConnection(self, index):
         connection = index.internalPointer()
-        connection.open()
+        connection.open(self)
 
     def close(self):
         self.settings.persist()
--- a/RemoteViewer/Viewer.py	Sun Sep 21 02:45:24 2014 +0200
+++ b/RemoteViewer/Viewer.py	Sun Sep 21 03:23:17 2014 +0200
@@ -1,32 +1,43 @@
 import subprocess
+
 from threading import Thread
+from .LogViewer import LogViewer
 
 class ReadThread(Thread):
-    def __init__(self, output):
+    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')
             print(line)
+            self.viewer.append(line)
 
 class AbstractViewer(object):
     def __init__(self,  connection):
         self.connection = connection
         self.process = None
 
-    def open(self):
+    def open(self, parent):
         command = self.buildCommand()
         self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         self.__startLogThread(self.process.stdout)
         self.process.wait()
 
     def __startLogThread(self, output):
-        readThread = ReadThread(output)
+        logViewer = self.__createLogViewer()
+        readThread = ReadThread(output,  logViewer)
         readThread.start()
+        logViewer.exec_()
+
+    def __createLogViewer(self):
+        viewer = LogViewer()
+        viewer.setWindowTitle(self.connection.displayString())
+        return viewer
 
 class VncViewer(AbstractViewer):
     def buildCommand(self):