Added: frameSupported() method. If it is False then remove titlebar and any other functions which is related with mouse or windows event from html, and use the standard OS interface (like in wayland) if it is True then it use the html frame and switch automatically.

Fixed the children closing method on linux (wayland) and every sight closing method happen in the sightfactory.py (moved from the callhandler).
main
Balazs Birtalan 2023-10-30 19:43:35 +00:00
parent a91cc436bd
commit abcc4f41eb
9 changed files with 91 additions and 34 deletions

12
base.py
View File

@ -7,6 +7,7 @@ from pynput import mouse
from sightfactory import SightFactory from sightfactory import SightFactory
from PyQt6.QtWidgets import QApplication from PyQt6.QtWidgets import QApplication
from pynput.mouse import Controller from pynput.mouse import Controller
import subprocess
def init(): def init():
global data, sights, mousectrl, app global data, sights, mousectrl, app
@ -22,6 +23,12 @@ def init():
data["sight_processes"] = {} data["sight_processes"] = {}
data["mouse_distance_x"] = 0 data["mouse_distance_x"] = 0
data["mouse_distance_y"] = 0 data["mouse_distance_y"] = 0
data["display_server"] = ""
if data["platform"]["system"] == "Linux":
args = ["echo -n $XDG_SESSION_TYPE"]
result = subprocess.check_output(args, shell=True)
data["display_server"] = result.decode('ascii')
print("D "+data["display_server"])
data["base_dir"]=os.path.abspath(os.getcwd())+os.path.sep data["base_dir"]=os.path.abspath(os.getcwd())+os.path.sep
data["template_dir"]=data["base_dir"]+"place"+os.path.sep+"templates"+os.path.sep data["template_dir"]=data["base_dir"]+"place"+os.path.sep+"templates"+os.path.sep
#LOAD the template config content #LOAD the template config content
@ -30,6 +37,11 @@ def init():
mouseevent = MouseEvents() mouseevent = MouseEvents()
start() start()
def frameSupported():
if data["display_server"] == "wayland":
return False
return True
def loadConfigTemplate(): def loadConfigTemplate():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.sections() config.sections()

View File

@ -22,6 +22,10 @@ class CallHandler(QObject):
def getDefaultTemplate(self): def getDefaultTemplate(self):
return base.data["default_template"] return base.data["default_template"]
@pyqtSlot(result=int)
def frameSupported(self):
return base.frameSupported()
@pyqtSlot(int) @pyqtSlot(int)
def setWidth(self, width): def setWidth(self, width):
self.sight.resize(width, self.sight.height()); self.sight.resize(width, self.sight.height());
@ -43,6 +47,7 @@ class CallHandler(QObject):
self.sight.addChild(new_id) self.sight.addChild(new_id)
""" The child remember its parent. When the child is closed the parent will be know about that. """ """ The child remember its parent. When the child is closed the parent will be know about that. """
base.sights.get(new_id).setParent(self.sight.getId()) base.sights.get(new_id).setParent(self.sight.getId())
print("PARENT " + str(base.sights.get(new_id).getParent()))
return new_id; return new_id;
@pyqtSlot(str, str, bool) @pyqtSlot(str, str, bool)
@ -64,19 +69,8 @@ class CallHandler(QObject):
print("Active - " + self.sight.getId()) print("Active - " + self.sight.getId())
base.data["active_sight"] = self.sight.getId() base.data["active_sight"] = self.sight.getId()
@pyqtSlot() @pyqtSlot()
def close(self): def close(self):
""" CLOSE ITS CHILDREN. It doesnt close the children's children just the current parent children
will be closed. """
for cid in self.sight.getChildren():
base.sights.close(cid)
print("CLOSED - " + cid)
""" If the parent doesn't exist anymore! """
if base.sights.get(self.sight.getParent()) is not None:
""" The child will be removed from his parent. So the parent wont be know about that because its child closed. """
base.sights.get(self.sight.getParent()).removeChild(self.sight.getId())
base.sights.close(self.sight.getId()) base.sights.close(self.sight.getId())
@pyqtSlot() @pyqtSlot()

View File

@ -12,6 +12,8 @@ class MouseEvents():
# MOUSE EVENTS/LISTENER # MOUSE EVENTS/LISTENER
def on_move(x, y): def on_move(x, y):
if base.data["move"]: if base.data["move"]:
print("MOVING")
if base.data["mouse_distance_x"] == 0: if base.data["mouse_distance_x"] == 0:
base.data["mouse_distance_x"] = base.sights.get(base.data["active_sight"]).pos().x()-x base.data["mouse_distance_x"] = base.sights.get(base.data["active_sight"]).pos().x()-x
if base.data["mouse_distance_y"] == 0: if base.data["mouse_distance_y"] == 0:
@ -19,7 +21,8 @@ def on_move(x, y):
x_point = x+base.data["mouse_distance_x"] x_point = x+base.data["mouse_distance_x"]
y_point = y+base.data["mouse_distance_y"] y_point = y+base.data["mouse_distance_y"]
#print( str(x_point) + " x " + str(y_point))
print( str(x_point) + " x " + str(y_point))
base.sights.get(base.data["active_sight"]).move(x_point, y_point) base.sights.get(base.data["active_sight"]).move(x_point, y_point)
def on_click(x, y, button, pressed): def on_click(x, y, button, pressed):
@ -35,3 +38,4 @@ def on_scroll(x, y, dx, dy):
print('Scrolled {0} at {1}'.format( print('Scrolled {0} at {1}'.format(
'down' if dy < 0 else 'up', 'down' if dy < 0 else 'up',
(x, y))) (x, y)))

View File

@ -19,9 +19,9 @@ body {
-ms-user-select: none; /* Internet Explorer/Edge */ -ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by any browser but < IE9 */ user-select: none; /* Non-prefixed version, currently supported by any browser but < IE9 */
} }
#sight #sresize { #sight #sresize[display="show"] {
cursor: nw-resize; cursor: nw-resize;
width: 15px; width: 15px;
height: 15px; height: 15px;
background-color: none; background-color: none;
right: 0; right: 0;
@ -29,12 +29,25 @@ body {
bottom: 0; bottom: 0;
position: absolute; position: absolute;
} }
#sight #sresize {
display: none;
}
#sight { #sight {
border: 4px solid grey;
display: block; display: block;
width: 100%; width: 100%;
} }
#sight[display="show"] {
border: 4px solid grey;
}
#sight {
border = 0;
}
#sight #stitlebar[display="show"] {
display: block;
}
#sight #stitlebar { #sight #stitlebar {
display: none;
width: 100%; width: 100%;
height: 25px; height: 25px;
background-color: grey; background-color: grey;

View File

@ -2,6 +2,13 @@ if(navigator.userAgent.indexOf("QtWebEngine") > 0) {
new QWebChannel(qt.webChannelTransport, function (channel) { new QWebChannel(qt.webChannelTransport, function (channel) {
// now I retrieve my object // now I retrieve my object
window.sight = channel.objects.handler; window.sight = channel.objects.handler;
window.sight.frameSupported(function(result) {
if(result == 1) {
document.querySelector("#stitlebar").setAttribute("display","show")
document.querySelector("#sresize").setAttribute("display","show")
document.querySelector("#sight").setAttribute("display","show")
}
});
}); });
} }
@ -168,6 +175,11 @@ function load(url, element)
} }
*/ */
$(document).ready(function(){ $(document).ready(function(){
if(typeof window.sight.console === "undefined") {
/* Maybe the document ready but still the window.sight didnt loaded in the time */
location.reload();
}
const scontent = document.querySelectorAll('[scontent]'); const scontent = document.querySelectorAll('[scontent]');
scontent.forEach((element) => { scontent.forEach((element) => {
$("[scontent="+element.getAttribute("scontent")+"]").load("content/"+element.getAttribute("scontent")+"/content.html"); $("[scontent="+element.getAttribute("scontent")+"]").load("content/"+element.getAttribute("scontent")+"/content.html");
@ -177,6 +189,7 @@ $(document).ready(function(){
// INIT the Sight from init_sight variable // INIT the Sight from init_sight variable
if (typeof init_sight !== 'undefined') { if (typeof init_sight !== 'undefined') {
for ( const [key,value] of Object.entries( init_sight ) ) { for ( const [key,value] of Object.entries( init_sight ) ) {
window.sight.console(key + " - " + value) window.sight.console(key + " - " + value)
switch(key) { switch(key) {
case 'width': case 'width':

View File

@ -12,8 +12,8 @@ body {
font-size: larger; font-size: larger;
float: left; float: left;
} }
#sight { #sight[display="show"]{
border: 4px solid #4f9af3; border: 4px solid #4f9af3;
} }
#sight #content { #sight #content {
padding: 5px; padding: 5px;

View File

@ -17,7 +17,7 @@ class Sight(QWidget):
base.data["active_sight"] = self.id base.data["active_sight"] = self.id
self.title = id self.title = id
if base.data["platform"]["system"] != "Linux": if base.frameSupported():
self.setWindowFlags(Qt.WindowType(0x00000800)) # remove the os windows frame (borders, close and other buttons 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.setAttribute(Qt.WidgetAttribute(0x78)) # (int: 120)) # Make Transparent
@ -32,6 +32,10 @@ class Sight(QWidget):
self.setLayout(self.layout) self.setLayout(self.layout)
# use when the frameSupported is False (for instance wayland)
def closeEvent(self, event):
base.sights.close(self.id)
def getParent(self): def getParent(self):
return self.parent return self.parent
@ -46,8 +50,9 @@ class Sight(QWidget):
return self.children return self.children
def removeChild(self, id): def removeChild(self, id):
self.children.remove(id) if id in self.children:
print(self.children) self.children.remove(id)
print(self.children)
def setLayoutContentMargins(self,a,b,c,d): def setLayoutContentMargins(self,a,b,c,d):
self.layout.setContentsMargins(a, b, c, d) self.layout.setContentsMargins(a, b, c, d)

View File

@ -34,7 +34,6 @@ class SightFactory():
id = self.createUniqueId() id = self.createUniqueId()
self.list[id] = Sight(id, page) self.list[id] = Sight(id, page)
print("The ['"+page+"'-'"+str(id)+"'] is created now!")
return id return id
def show(self, id): def show(self, id):
@ -53,15 +52,32 @@ class SightFactory():
return self.list[id] return self.list[id]
"""print("This '"+str(id)+"' id isn't exist to get!")""" """print("This '"+str(id)+"' id isn't exist to get!")"""
def close(self, id): def closeChildren(self, id, removeFromParent = True):
""" CLOSE ITS CHILDREN. It doesnt close the children's children just the current parent children
will be closed. """
for cid in self.get(id).getChildren():
self.close(cid)
print("CLOSED - " + cid)
if removeFromParent:
""" If the parent doesn't exist anymore! """
if self.get(self.get(id).getParent()) is not None:
children = self.get(self.get(id).getParent()).getChildren()
if len(children) > 0:
self.get(self.get(id).getParent()).removeChild(id)
print("AFTER REMOVED CHILDREN " + str(self.get(self.get(id).getParent()).getChildren()) )
def close(self, id, closeChildrenToo=True):
if closeChildrenToo:
self.closeChildren(id)
if self.checkKey(id): if self.checkKey(id):
self.eventMessage("CLOSING", "sight", id) self.eventMessage("CLOSING", "sight", id)
if id == "main": if id == "main":
print("Program Exit!") print("Program Exit!")
base.app.exit(0) base.app.exit(0)
self.list[id].close() self.list[id].close()
self.list[id].deleteLater() if id in self.list:
del self.list[id] self.list[id].deleteLater()
del self.list[id]
"""print("The '"+str(id)+"' is closed now!")""" """print("The '"+str(id)+"' is closed now!")"""
self.eventMessage("CLOSED", "sight", id) self.eventMessage("CLOSED", "sight", id)
return True return True