From a88525fdd8a5c6d16388a428cfd9ece7b4c6cd6d Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Mon, 21 May 2018 14:40:17 -0400 Subject: [PATCH] FIX: twisted reactor not defined --- setup.py | 2 +- virtscreen/virtscreen.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 49d597b..9d8bd74 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ # For a discussion on single-sourcing the version across setup.py and the # project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.1.1', # Required + version='0.1.2', # Required # This is a one-line description or tagline of what your project does. This # corresponds to the "Summary" metadata field: diff --git a/virtscreen/virtscreen.py b/virtscreen/virtscreen.py index 198f50d..9858954 100755 --- a/virtscreen/virtscreen.py +++ b/virtscreen/virtscreen.py @@ -1,18 +1,20 @@ -#!/usr/bin/env python +#!/usr/bin/python3 +# Python standard packages import sys, os, subprocess, signal, re, atexit, time, json, shutil from pathlib import Path from enum import Enum from typing import List, Dict - +# PyQt5 packages from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QObject, QUrl, Qt, pyqtProperty, pyqtSlot, pyqtSignal, Q_ENUMS from PyQt5.QtGui import QIcon, QCursor from PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine, QQmlListProperty - +# Twisted and netifaces from twisted.internet import protocol, error from netifaces import interfaces, ifaddresses, AF_INET + # ------------------------------------------------------------------------------- # file path definitions # ------------------------------------------------------------------------------- @@ -37,6 +39,7 @@ QML_PATH = BASE_PATH + "/qml" MAIN_QML_PATH = QML_PATH + "/main.qml" + # ------------------------------------------------------------------------------- # Subprocess wrapper # ------------------------------------------------------------------------------- @@ -64,6 +67,10 @@ def __init__(self, onConnected, onOutReceived, onErrRecevied, onProcessEnded, lo self.onErrRecevied = onErrRecevied self.onProcessEnded = onProcessEnded self.logfile = logfile + # We cannot import this at the top of the file because qt5reactor should + # be installed in the main function first. + from twisted.internet import reactor # pylint: disable=E0401 + self.reactor = reactor def run(self, arg: str): """Spawn a process @@ -73,7 +80,7 @@ def run(self, arg: str): """ args = arg.split() - reactor.spawnProcess(self, args[0], args=args, env=os.environ) + self.reactor.spawnProcess(self, args[0], args=args, env=os.environ) def kill(self): """Kill a spawned process @@ -551,7 +558,8 @@ def _onReceived(data): def _onEnded(exitCode): if exitCode is not 0: self.vncState = self.VNCState.ERROR - self.onError.emit('X11VNC: Error occurred.\nDouble check if the port is already used.') + self.onError.emit('X11VNC: Error occurred.\n' + 'Double check if the port is already used.') self.vncState = self.VNCState.OFF # TODO: better handling error state else: self.vncState = self.VNCState.OFF @@ -651,10 +659,10 @@ def main(): "Cannot create ~/.virtscreen") sys.exit(1) + # Replace Twisted reactor with qt5reactor import qt5reactor # pylint: disable=E0401 - qt5reactor.install() - from twisted.internet import utils, reactor # pylint: disable=E0401 + from twisted.internet import reactor # pylint: disable=E0401 app.setWindowIcon(QIcon(ICON_PATH)) os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"