2018-04-25 19:14:11 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-05-06 23:24:06 +00:00
|
|
|
import sys, os
|
2018-04-25 19:14:11 +00:00
|
|
|
|
2018-05-06 23:24:06 +00:00
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
from PyQt5.QtCore import QObject, QUrl, Qt
|
|
|
|
from PyQt5.QtCore import pyqtProperty, pyqtSlot, pyqtSignal
|
|
|
|
from PyQt5.QtGui import QIcon
|
|
|
|
from PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine
|
2018-04-26 18:45:10 +00:00
|
|
|
|
2018-04-26 07:49:00 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
2018-04-26 17:32:08 +00:00
|
|
|
# file path definitions
|
2018-04-26 07:49:00 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
2018-04-26 17:32:08 +00:00
|
|
|
PROGRAM_PATH = "."
|
|
|
|
ICON_PATH = PROGRAM_PATH + "/icon/icon.png"
|
|
|
|
ICON_TABLET_OFF_PATH = PROGRAM_PATH + "/icon/icon_tablet_off.png"
|
|
|
|
ICON_TABLET_ON_PATH = PROGRAM_PATH + "/icon/icon_tablet_on.png"
|
|
|
|
|
2018-04-26 08:32:44 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
2018-05-06 23:24:06 +00:00
|
|
|
# QML Backend class
|
2018-04-26 18:45:10 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
2018-05-06 23:24:06 +00:00
|
|
|
class Backend(QObject):
|
|
|
|
width_changed = pyqtSignal(int)
|
|
|
|
virtScreenChanged = pyqtSignal(bool)
|
|
|
|
vncChanged = pyqtSignal(bool)
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(Backend, self).__init__(parent)
|
|
|
|
# Virtual screen properties
|
|
|
|
self._width = 1368
|
|
|
|
self._height = 1024
|
|
|
|
self._portrait = True
|
|
|
|
self._hidpi = False
|
|
|
|
self._virtScreenCreated = False
|
|
|
|
# VNC server properties
|
|
|
|
self._vncPort = 5900
|
|
|
|
self._vncPassword = ""
|
|
|
|
self._vncState = False
|
2018-04-25 19:14:11 +00:00
|
|
|
|
2018-05-06 23:24:06 +00:00
|
|
|
@pyqtProperty(int, notify=width_changed)
|
|
|
|
def width(self):
|
|
|
|
return self._width
|
|
|
|
@width.setter
|
|
|
|
def width(self, width):
|
|
|
|
self._width = width
|
|
|
|
self.width_changed.emit(self._width)
|
2018-04-25 19:14:11 +00:00
|
|
|
|
2018-05-06 23:24:06 +00:00
|
|
|
@pyqtProperty(int)
|
|
|
|
def height(self):
|
|
|
|
return self._height
|
|
|
|
@height.setter
|
|
|
|
def height(self, height):
|
|
|
|
self._height = height
|
|
|
|
|
|
|
|
@pyqtProperty(bool)
|
|
|
|
def portrait(self):
|
|
|
|
return self._portrait
|
|
|
|
@portrait.setter
|
|
|
|
def portrait(self, portrait):
|
|
|
|
self._portrait = portrait
|
|
|
|
|
|
|
|
@pyqtProperty(bool)
|
|
|
|
def hidpi(self):
|
|
|
|
return self._hidpi
|
|
|
|
@hidpi.setter
|
|
|
|
def hidpi(self, hidpi):
|
|
|
|
self._hidpi = hidpi
|
2018-04-25 19:14:11 +00:00
|
|
|
|
2018-05-06 23:24:06 +00:00
|
|
|
@pyqtProperty(bool)
|
|
|
|
def virtScreenCreated(self):
|
|
|
|
return self._virtScreenCreated
|
2018-04-25 19:14:11 +00:00
|
|
|
|
2018-05-06 23:24:06 +00:00
|
|
|
@pyqtProperty(int)
|
|
|
|
def vncPort(self):
|
|
|
|
return self._vncPort
|
|
|
|
@vncPort.setter
|
|
|
|
def vncPort(self, vncPort):
|
|
|
|
self._vncPort = vncPort
|
|
|
|
|
|
|
|
@pyqtProperty(str)
|
|
|
|
def vncPassword(self):
|
|
|
|
return self._vncPassword
|
|
|
|
@vncPassword.setter
|
|
|
|
def vncPassword(self, vncPassword):
|
|
|
|
self._vncPassword = vncPassword
|
|
|
|
print(self._vncPassword)
|
|
|
|
|
|
|
|
# Qt Slots
|
2018-04-26 04:55:37 +00:00
|
|
|
@pyqtSlot()
|
|
|
|
def quitProgram(self):
|
2018-05-06 23:24:06 +00:00
|
|
|
QApplication.instance().quit()
|
2018-04-25 19:14:11 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Main Code
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
2018-05-06 23:24:06 +00:00
|
|
|
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
2018-04-25 19:14:11 +00:00
|
|
|
app = QApplication(sys.argv)
|
2018-05-06 23:24:06 +00:00
|
|
|
app.setWindowIcon(QIcon(ICON_PATH))
|
|
|
|
# os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
|
|
|
|
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Fusion"
|
|
|
|
|
|
|
|
# Register the Python type. Its URI is 'People', it's v1.0 and the type
|
|
|
|
# will be called 'Person' in QML.
|
|
|
|
qmlRegisterType(Backend, 'VirtScreen.Backend', 1, 0, 'Backend')
|
|
|
|
|
|
|
|
# Create a component factory and load the QML script.
|
|
|
|
engine = QQmlApplicationEngine()
|
|
|
|
engine.load(QUrl('main.qml'))
|
|
|
|
if not engine.rootObjects():
|
|
|
|
print("Failed to load qml")
|
|
|
|
exit(1)
|
2018-04-25 19:14:11 +00:00
|
|
|
sys.exit(app.exec_())
|