Skip to content

Commit

Permalink
icon signal
Browse files Browse the repository at this point in the history
  • Loading branch information
eltonfabricio10 authored Nov 13, 2022
1 parent ab1c040 commit 9272911
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions bigbashview/usr/lib/python3/dist-packages/bbv/ui/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from PySide6.QtWidgets import QWidget, QHBoxLayout, QSplitter, QApplication
from PySide6.QtGui import QIcon, QColor, QKeySequence, QShortcut, QCursor
from PySide6.QtWebEngineWidgets import QWebEngineView

from bbv.globaldata import ICON, TITLE


class Window(QWidget):
def __init__(self):
self.app = QApplication(sys.argv)
Expand All @@ -40,7 +40,8 @@ def __init__(self):
else:
self.web.titleChanged.connect(self.title_changed)
self.web.page().windowCloseRequested.connect(self.close_window)
self.web.page().featurePermissionRequested.connect(self.onFeaturePermissionRequested)
self.web.page().featurePermissionRequested.connect(self.onFeature)
self.web.iconChanged.connect(self.icon_changed)
self.web.loadFinished.connect(self.add_script)
self.key_f5 = QShortcut(QKeySequence(Qt.Key_F5), self.web)
self.key_f5.activated.connect(self.web.reload)
Expand All @@ -49,22 +50,30 @@ def __init__(self):

# pagesplitter
self.hbox = QHBoxLayout(self)
self.hbox.setContentsMargins(0,0,0,0)
self.hbox.setContentsMargins(0, 0, 0, 0)
self.splitter = QSplitter(Qt.Horizontal)
self.splitter.addWidget(self.web)
self.splitter2 = QSplitter(Qt.Horizontal)
self.hbox.addWidget(self.splitter)
self.setLayout(self.hbox)

def onFeaturePermissionRequested(self, url, feature):
def onFeature(self, url, feature):
if feature in (
self.web.page().MediaAudioCapture,
self.web.page().MediaVideoCapture,
self.web.page().MediaAudioVideoCapture,
):
self.web.page().setFeaturePermission(url, feature, self.web.page().PermissionGrantedByUser)
self.web.page().setFeaturePermission(
url,
feature,
self.web.page().PermissionGrantedByUser
)
else:
self.web.page().setFeaturePermission(url, feature, self.web.page().PermissionDeniedByUser)
self.web.page().setFeaturePermission(
url,
feature,
self.web.page().PermissionDeniedByUser
)

def devpage(self):
if self.splitter.count() == 1 or self.splitter2.count() == 1:
Expand All @@ -86,7 +95,7 @@ def devpage(self):
def add_script(self, event):
script = '''
function _run(run){
// https://dmitripavlutin.com/javascript-fetch-async-await/#4-canceling-a-fetch-request
//https://dmitripavlutin.com/javascript-fetch-async-await/#4-canceling-a-fetch-request
// Step 1: instantiate the abort controller
const controller = new AbortController();
Expand All @@ -97,7 +106,6 @@ def add_script(self, event):
};
'''


if event:
self.web.page().runJavaScript(script)

Expand All @@ -116,7 +124,7 @@ def viewer(self, window_state):
self.setWindowFlags(Qt.FramelessWindowHint)
self.show()
elif window_state == "framelessTop":
self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.show()
elif window_state == "fixedTop":
self.setWindowFlags(Qt.WindowStaysOnTopHint)
Expand All @@ -131,10 +139,13 @@ def close_window(self):
self.app.quit()

def title_changed(self, title):
os.system('''xprop -id "$(xprop -root '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)" \
os.system('''xprop -id "$(xprop -root '\t$0' _NET_ACTIVE_WINDOW | cut -f2)" \
-f WM_CLASS 8s -set WM_CLASS "%s"''' % title)
self.setWindowTitle(title)

def icon_changed(self, icon):
self.setWindowIcon(QIcon(icon))

def load_url(self, url):
self.url = QUrl.fromEncoded(url.encode("utf-8"))
self.web.load(self.url)
Expand Down Expand Up @@ -173,7 +184,7 @@ def style(self, colorful):
b = float(int(b)/255)
self.web.page().setBackgroundColor(QColor.fromRgbF(r, g, b, 1))
else:
self.web.page().setBackgroundColor(QColor.fromRgbF(0, 0, 0, 0))
self.web.page().setBackgroundColor(QColor.fromRgbF(0, 0, 0, 0))

else:
self.web.page().setBackgroundColor(QColor.fromRgbF(0, 0, 0, 0))

0 comments on commit 9272911

Please sign in to comment.