1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-03-09 15:40:18 +00:00

Fixed: VNCState inner class handling

This commit is contained in:
Bumsik Kim 2018-05-11 17:42:46 -04:00
parent 807371a69c
commit 3c31266c5c
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6

View file

@ -327,6 +327,13 @@ class ProcessProtocol(protocol.ProcessProtocol):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class Backend(QObject): class Backend(QObject):
""" Backend class for QML frontend """ """ Backend class for QML frontend """
class VNCState:
""" Enum to indicate a state of the VNC server """
OFF = 0
WAITING = 1
CONNECTED = 2
Q_ENUMS(VNCState)
# Virtual screen properties # Virtual screen properties
settings: Dict settings: Dict
xrandr: XRandR xrandr: XRandR
@ -339,7 +346,7 @@ class Backend(QObject):
# VNC server properties # VNC server properties
_vncPort: int _vncPort: int
_vncPassword: str = "" _vncPassword: str = ""
_vncState: int _vncState: VNCState
_vncAutoStart: bool _vncAutoStart: bool
_ipAddresses: List[str] = [] _ipAddresses: List[str] = []
# Primary screen and mouse posistion # Primary screen and mouse posistion
@ -347,14 +354,6 @@ class Backend(QObject):
_cursor_x: int _cursor_x: int
_cursor_y: int _cursor_y: int
class VNCState:
""" Enum to indicate a state of the VNC server """
OFF = 0
WAITING = 1
CONNECTED = 2
Q_ENUMS(VNCState)
# Signals # Signals
onVirtScreenCreatedChanged = pyqtSignal(bool) onVirtScreenCreatedChanged = pyqtSignal(bool)
onVirtScreenIndexChanged = pyqtSignal(int) onVirtScreenIndexChanged = pyqtSignal(int)
@ -385,7 +384,7 @@ class Backend(QObject):
self._vncPort = self.settings['vnc']['port'] self._vncPort = self.settings['vnc']['port']
self._vncAutoStart = self.settings['vnc']['autostart'] self._vncAutoStart = self.settings['vnc']['autostart']
# create objects # create objects
self._vncState: Backend.VNCState = Backend.VNCState.OFF self._vncState = self.VNCState.OFF
self.xrandr = XRandR() self.xrandr = XRandR()
self._screens = self.xrandr.screens self._screens = self.xrandr.screens
self._virtScreenIndex = self.xrandr.virt_idx self._virtScreenIndex = self.xrandr.virt_idx
@ -497,7 +496,7 @@ class Backend(QObject):
@pyqtSlot() @pyqtSlot()
def deleteVirtScreen(self): def deleteVirtScreen(self):
print("Deleting the Virtual Screen...") print("Deleting the Virtual Screen...")
if self.vncState is not Backend.VNCState.OFF: if self.vncState is not self.VNCState.OFF:
print("Turn off the VNC server first") print("Turn off the VNC server first")
self.virtScreenCreated = True self.virtScreenCreated = True
return return
@ -510,7 +509,7 @@ class Backend(QObject):
if not self.virtScreenCreated: if not self.virtScreenCreated:
print("Virtual Screen not crated.") print("Virtual Screen not crated.")
return return
if self.vncState is not Backend.VNCState.OFF: if self.vncState is not self.VNCState.OFF:
print("VNC Server is already running.") print("VNC Server is already running.")
return return
# regex used in callbacks # regex used in callbacks
@ -518,15 +517,15 @@ class Backend(QObject):
# define callbacks # define callbacks
def _onConnected(): def _onConnected():
print("VNC started.") print("VNC started.")
self.vncState = Backend.VNCState.WAITING self.vncState = self.VNCState.WAITING
def _onReceived(data): def _onReceived(data):
data = data.decode("utf-8") data = data.decode("utf-8")
if (self._vncState is not Backend.VNCState.CONNECTED) and re_connection.search(data): if (self._vncState is not self.VNCState.CONNECTED) and re_connection.search(data):
print("VNC connected.") print("VNC connected.")
self.vncState = Backend.VNCState.CONNECTED self.vncState = self.VNCState.CONNECTED
def _onEnded(exitCode): def _onEnded(exitCode):
print("VNC Exited.") print("VNC Exited.")
self.vncState = Backend.VNCState.OFF self.vncState = self.VNCState.OFF
atexit.unregister(self.stopVNC) atexit.unregister(self.stopVNC)
# Set password # Set password
password = False password = False
@ -556,7 +555,7 @@ class Backend(QObject):
# Usually called from atexit(). # Usually called from atexit().
self.vncServer.kill() self.vncServer.kill()
time.sleep(2) # Make sure X11VNC shutdown before execute next atexit. time.sleep(2) # Make sure X11VNC shutdown before execute next atexit.
if self._vncState in (Backend.VNCState.WAITING, Backend.VNCState.CONNECTED): if self._vncState in (self.VNCState.WAITING, self.VNCState.CONNECTED):
self.vncServer.kill() self.vncServer.kill()
else: else:
print("stopVNC called while it is not running") print("stopVNC called while it is not running")