168 lines
4.9 KiB
Plaintext
168 lines
4.9 KiB
Plaintext
|
|
import os
|
||
|
|
import sys
|
||
|
|
import random
|
||
|
|
|
||
|
|
import base
|
||
|
|
from PyQt6.QtCore import QUrl, QObject, pyqtSlot, Qt
|
||
|
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||
|
|
from PyQt6.QtWidgets import QMainWindow
|
||
|
|
from PyQt6.QtWebChannel import QWebChannel
|
||
|
|
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout
|
||
|
|
|
||
|
|
class CallHandler(QObject):
|
||
|
|
def __init__(self, sight):
|
||
|
|
super().__init__()
|
||
|
|
self.sight = sight
|
||
|
|
|
||
|
|
@pyqtSlot(str)
|
||
|
|
def test(self, t):
|
||
|
|
print(t)
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=str)
|
||
|
|
def test2(self, t):
|
||
|
|
print(t)
|
||
|
|
return t+"_return"
|
||
|
|
|
||
|
|
@pyqtSlot(str)
|
||
|
|
def create(self, t):
|
||
|
|
id = str(random.randrange(1000,9999))
|
||
|
|
createSight(id)
|
||
|
|
base.data["sight_processes"][id].show()
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def activeSight(self):
|
||
|
|
print("active")
|
||
|
|
if base.data["active_sight"] != self.sight.getId():
|
||
|
|
print(self.sight.getId())
|
||
|
|
base.data["active_sight"] = self.sight.getId()
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def close(self):
|
||
|
|
closeSight(self.sight.id)
|
||
|
|
"""if self.sight.id == "main":
|
||
|
|
app.exit(0)
|
||
|
|
else:
|
||
|
|
try:
|
||
|
|
base.data["sight_processes"][self.sight.id].close()
|
||
|
|
base.data["sight_processes"][self.sight.id].destroy()
|
||
|
|
del base.data["sight_processes"][self.sight.id]
|
||
|
|
print("The '"+self.sight.id+"' is closed now!")
|
||
|
|
base.processSight()
|
||
|
|
except KeyError:
|
||
|
|
print("KeyError: when closing "+self.sight.id)"""
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def setMaximized(self):
|
||
|
|
self.sight.showMaximized()
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def setMinimize(self):
|
||
|
|
self.sight.showMinimized()
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def restoreDown(self):
|
||
|
|
self.sight.showNormal()
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def setFullscreen(self):
|
||
|
|
self.sight.showFullScreen()
|
||
|
|
|
||
|
|
@pyqtSlot(result=str)
|
||
|
|
def getTitle(self):
|
||
|
|
print("IIIIID: ")
|
||
|
|
return self.sight.getTitle();
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def move(self):
|
||
|
|
base.data["move"] = True
|
||
|
|
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def endmove(self):
|
||
|
|
base.data["move"] = False
|
||
|
|
|
||
|
|
@pyqtSlot()
|
||
|
|
def resize(self):
|
||
|
|
global mousectrl
|
||
|
|
new_height = base.mousectrl.position[1]-self.sight.pos().y()
|
||
|
|
new_width = base.mousectrl.position[0]-self.sight.pos().x()
|
||
|
|
if(new_height<250):
|
||
|
|
new_height = 250
|
||
|
|
if(new_width<250):
|
||
|
|
new_width = 250
|
||
|
|
self.sight.resize( new_width, new_height)
|
||
|
|
|
||
|
|
|
||
|
|
class Browser(QWebEngineView):
|
||
|
|
def __init__(self):
|
||
|
|
super().__init__()
|
||
|
|
self.channel = QWebChannel()
|
||
|
|
|
||
|
|
def addHandler(self, id, call_handler):
|
||
|
|
self.handler = call_handler
|
||
|
|
self.channel.registerObject(id, self.handler)
|
||
|
|
self.page().setWebChannel(self.channel)
|
||
|
|
|
||
|
|
class Sight(QWidget):
|
||
|
|
def __init__(self, sight_id):
|
||
|
|
super().__init__()
|
||
|
|
|
||
|
|
self.id = sight_id
|
||
|
|
base.data["active_sight"] = self.id
|
||
|
|
self.title = sight_id
|
||
|
|
self.setWindowFlags(Qt.WindowType.FramelessWindowHint | self.windowFlags())
|
||
|
|
|
||
|
|
self.browser = Browser()
|
||
|
|
self.browser.addHandler('handler', CallHandler(self) )
|
||
|
|
#self.channel = QWebChannel()
|
||
|
|
#self.handler = CallHandler(self)
|
||
|
|
#self.channel.registerObject('handler', self.handler)
|
||
|
|
#self.browser.page().setWebChannel(self.channel)
|
||
|
|
|
||
|
|
current_folder = os.path.abspath(os.getcwd())
|
||
|
|
html_file = current_folder + os.path.sep + "place" + os.path.sep + "templates" + os.path.sep + "base" + os.path.sep + "index.html"
|
||
|
|
print(html_file)
|
||
|
|
url = QUrl.fromLocalFile(html_file)
|
||
|
|
|
||
|
|
self.browser.load(url)
|
||
|
|
|
||
|
|
lay = QVBoxLayout(self)
|
||
|
|
lay.setSpacing(0);
|
||
|
|
lay.setContentsMargins(0, 0, 0, 0);
|
||
|
|
lay.addWidget(self.browser)
|
||
|
|
#self.setCentralWidget(self.browser)
|
||
|
|
|
||
|
|
def setTitle(self, title):
|
||
|
|
self.title = title
|
||
|
|
def getTitle(self):
|
||
|
|
return self.title
|
||
|
|
|
||
|
|
def getId(self):
|
||
|
|
return self.id
|
||
|
|
|
||
|
|
def createSight(id):
|
||
|
|
if id != "main":
|
||
|
|
base.data["sight_processes"][id] = Sight(id)
|
||
|
|
base.data["sight_processes"][id].show()
|
||
|
|
print("The '"+id+"' is opened now!")
|
||
|
|
base.processSight()
|
||
|
|
else:
|
||
|
|
print("The 'main' id is the main active windows which is occupied!")
|
||
|
|
|
||
|
|
def closeSight(id):
|
||
|
|
if id == "main":
|
||
|
|
app.exit(0)
|
||
|
|
else:
|
||
|
|
try:
|
||
|
|
base.data["sight_processes"][id] .close()
|
||
|
|
base.data["sight_processes"][id] .destroy()
|
||
|
|
del base.data["sight_processes"][id]
|
||
|
|
print("The '"+id+"' is closed now!")
|
||
|
|
base.processSight()
|
||
|
|
except KeyError:
|
||
|
|
print("KeyError: when closing "+id)
|
||
|
|
|
||
|
|
app = QApplication(sys.argv)
|
||
|
|
base.data["sight_processes"]["main"] = Sight("main")
|
||
|
|
base.data["sight_processes"]["main"].show()
|
||
|
|
app.exec()
|