104 lines
3.0 KiB
Python
104 lines
3.0 KiB
Python
import base
|
|
from core.sight.threads.jsrun_worker import JsRunWorker
|
|
from callhandler import CallHandler
|
|
from browser import Browser
|
|
from PyQt6.QtCore import Qt
|
|
from PyQt6.QtWidgets import QMainWindow, QWidget, QVBoxLayout
|
|
from PyQt6.QtCore import QThread,QThreadPool, QObject, pyqtSignal as Signal, pyqtSlot as Slot
|
|
from queue import Queue
|
|
import time
|
|
|
|
class Sight(QWidget):
|
|
|
|
def __init__(self, id, page):
|
|
super().__init__()
|
|
|
|
self.id = id
|
|
self.page = page
|
|
self.data = {} # private data(s) of the sight
|
|
self.children = []
|
|
self.parent = None
|
|
self.pool = QThreadPool.globalInstance()
|
|
|
|
base.data["active_sight"] = self.id
|
|
self.title = id
|
|
|
|
if base.frameSupported():
|
|
self.setWindowFlags(Qt.WindowType(0x00000800)) # remove the os windows frame (borders, close and other buttons
|
|
self.setAttribute(Qt.WidgetAttribute(0x78)) # (int: 120)) # Make Transparent
|
|
|
|
self.browser = Browser()
|
|
self.browser.addObject('handler', CallHandler(self) )
|
|
|
|
#self.browser.loadAdminContent(page)
|
|
if "sight-admin" in id:
|
|
self.browser.loadAdminContent(page)
|
|
else:
|
|
self.browser.loadContent(page)
|
|
|
|
self.layout = QVBoxLayout()
|
|
self.layout.addWidget(self.browser)
|
|
self.layout.setSpacing(0);
|
|
self.layout.setContentsMargins(1, 1, 1, 1); #Need 1,1,1,1 if it is 0,0,0,0 I got setgeometry warnings
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
def addJob(self, js_script, page_id):
|
|
worker = JsRunWorker(js_script, page_id)
|
|
worker.signals.completed.connect(self.complete)
|
|
worker.signals.jsrun.connect(self.runJs)
|
|
worker.signals.started.connect(self.start)
|
|
self.pool.start(worker)
|
|
|
|
def start(self, n):
|
|
print(f'Job in "{n}" page started...')
|
|
|
|
def complete(self, n):
|
|
print(f'Job in "{n}" page completed.')
|
|
|
|
def runJs(self,request_js):
|
|
self.browser.page().runJavaScript(request_js)
|
|
|
|
# use when the frameSupported is False (for instance wayland)
|
|
def closeEvent(self, event):
|
|
self.pool.clear()
|
|
|
|
base.sights.close(self.id)
|
|
|
|
def getParent(self):
|
|
return self.parent
|
|
|
|
def getPageId(self):
|
|
return self.page
|
|
|
|
def setParent(self, id):
|
|
self.parent = id
|
|
|
|
def addChild(self, id):
|
|
self.children.insert(0, id)
|
|
print(self.children)
|
|
|
|
def getChildren(self):
|
|
return self.children
|
|
|
|
def removeChild(self, id):
|
|
if id in self.children:
|
|
self.children.remove(id)
|
|
print(self.children)
|
|
|
|
def setLayoutContentMargins(self,a,b,c,d):
|
|
self.layout.setContentsMargins(a, b, c, d)
|
|
|
|
def setTitle(self, title):
|
|
self.title = title
|
|
|
|
def getTitle(self):
|
|
return self.title
|
|
def getId(self):
|
|
return self.id
|
|
def addData(self, key, value):
|
|
self.data[key] = value
|
|
def getData(self, key):
|
|
if key in self.data:
|
|
return self.data[key]
|
|
return None |