Skip to content

Commit

Permalink
FIX: twisted reactor not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
kbumsik committed May 21, 2018
1 parent 4676979 commit a88525f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 15 additions & 7 deletions virtscreen/virtscreen.py
Original file line number Diff line number Diff line change
@@ -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
# -------------------------------------------------------------------------------
Expand All @@ -37,6 +39,7 @@
QML_PATH = BASE_PATH + "/qml"
MAIN_QML_PATH = QML_PATH + "/main.qml"


# -------------------------------------------------------------------------------
# Subprocess wrapper
# -------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a88525f

Please sign in to comment.