Browse Source

Improved Devtools, Dialog, and Brightness keys

sisyphus
JezerM 3 years ago
parent
commit
1361b89ad6
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 2
      web-greeter/__main__.py
  2. 76
      web-greeter/bridge/Greeter.py
  3. 1
      web-greeter/bridge/__init__.py
  4. 34
      web-greeter/browser/browser.py
  5. 48
      web-greeter/browser/error_prompt.py
  6. 53
      web-greeter/browser/window.py

2
web-greeter/__main__.py

@ -61,7 +61,7 @@ def set_debug(value: bool):
conf = config.web_greeter_config["config"] conf = config.web_greeter_config["config"]
app = config.web_greeter_config["app"] app = config.web_greeter_config["app"]
conf["greeter"]["debug_mode"] = value conf["greeter"]["debug_mode"] = value
app["decorated"] = value app["frame"] = value
app["fullscreen"] = not value app["fullscreen"] = not value
def parse(argv): def parse(argv):

76
web-greeter/bridge/Greeter.py

@ -27,6 +27,7 @@
# along with Web Greeter; If not, see <http://www.gnu.org/licenses/>. # along with Web Greeter; If not, see <http://www.gnu.org/licenses/>.
# Standard Lib # Standard Lib
from browser.error_prompt import Dialog
import subprocess import subprocess
import threading import threading
@ -36,9 +37,11 @@ gi.require_version('LightDM', '1')
from gi.repository import LightDM from gi.repository import LightDM
from browser.bridge import Bridge, BridgeObject from browser.bridge import Bridge, BridgeObject
from PyQt5.QtCore import QVariant, QTimer from PyQt5.QtCore import QFileSystemWatcher, QVariant, QTimer
from config import web_greeter_config from config import web_greeter_config
from utils.battery import Battery
import globals
# This Application # This Application
from . import ( from . import (
@ -56,19 +59,52 @@ LightDMGreeter = LightDM.Greeter()
LightDMUsers = LightDM.UserList() LightDMUsers = LightDM.UserList()
def changeBrightness(self, method: str, quantity: int): def changeBrightness(method: str, quantity: int = None):
if self._config["features"]["backlight"]["enabled"] != True: backlight = web_greeter_config["config"]["features"]["backlight"]
if not backlight["enabled"]:
return return
if not quantity:
quantity = backlight["value"]
try: try:
steps = self._config["features"]["backlight"]["steps"] steps = backlight["steps"]
child = subprocess.run(["xbacklight", method, str(quantity), "-steps", str(steps)]) child = subprocess.run(["xbacklight", method, str(quantity), "-steps", str(steps)])
if child.returncode == 1: if child.returncode == 1:
raise ChildProcessError("xbacklight returned 1") raise ChildProcessError("xbacklight returned 1")
except Exception as err: except Exception as err:
logger.error("Brightness: {}".format(err)) logger.error("Brightness: {}".format(err))
else: else:
self.brightness_update.emit() if globals.greeter:
globals.greeter.greeter.brightness_update.emit()
def increaseBrightness(quantity: int = None):
backlight = web_greeter_config["config"]["features"]["backlight"]
if not backlight["enabled"]:
return
if not quantity:
quantity = backlight["value"]
thread = threading.Thread(target=changeBrightness,
args=("-inc", quantity))
thread.start()
def decreaseBrightness(quantity: int = None):
backlight = web_greeter_config["config"]["features"]["backlight"]
if not backlight["enabled"]:
return
if not quantity:
quantity = backlight["value"]
thread = threading.Thread(target=changeBrightness,
args=("-dec", quantity))
thread.start()
def setBrightness(quantity: int = None):
backlight = web_greeter_config["config"]["features"]["backlight"]
if not backlight["enabled"]:
return
if not quantity:
quantity = backlight["value"]
thread = threading.Thread(target=changeBrightness,
args=("-set", quantity))
thread.start()
def getBrightness(self): def getBrightness(self):
if self._config["features"]["backlight"]["enabled"] != True: if self._config["features"]["backlight"]["enabled"] != True:
@ -106,13 +142,23 @@ class Greeter(BridgeObject):
self._shared_data_directory = '' self._shared_data_directory = ''
self._themes_directory = web_greeter_config["app"]["theme_dir"] self._themes_directory = web_greeter_config["app"]["theme_dir"]
# if self._config.features.battery == True: if self._config["features"]["battery"]:
# self._battery = battery.Battery() self._battery = Battery()
try:
LightDMGreeter.connect_to_daemon_sync() LightDMGreeter.connect_to_daemon_sync()
except Exception as err:
logger.error(err)
dia = Dialog(title="An error ocurred",
message="Detected a problem that could interfere with the system login process",
detail="LightDM: {0}\nYou can continue without major problems, but you won't be able to log in".format(err),
buttons=["Okay"])
dia.exec()
pass
self._connect_signals() self._connect_signals()
self._determine_shared_data_directory_path() self._determine_shared_data_directory_path()
logger.debug("LightDM API connected")
def _determine_shared_data_directory_path(self): def _determine_shared_data_directory_path(self):
user = LightDMUsers.get_users()[0] user = LightDMUsers.get_users()[0]
@ -174,9 +220,7 @@ class Greeter(BridgeObject):
@brightness.setter @brightness.setter
def brightness(self, quantity): def brightness(self, quantity):
thread = threading.Thread(target=changeBrightness, setBrightness(quantity)
args=(self, "-set", quantity))
thread.start()
@Bridge.prop(bool, notify=noop_signal) @Bridge.prop(bool, notify=noop_signal)
def can_hibernate(self): def can_hibernate(self):
@ -305,21 +349,15 @@ class Greeter(BridgeObject):
@Bridge.method(int) @Bridge.method(int)
def brightnessSet(self, quantity): def brightnessSet(self, quantity):
thread = threading.Thread(target=changeBrightness, setBrightness(quantity)
args=(self, "-set", quantity))
thread.start()
@Bridge.method(int) @Bridge.method(int)
def brightnessIncrease(self, quantity): def brightnessIncrease(self, quantity):
thread = threading.Thread(target=changeBrightness, increaseBrightness(quantity)
args=(self, "-inc", quantity))
thread.start()
@Bridge.method(int) @Bridge.method(int)
def brightnessDecrease(self, quantity): def brightnessDecrease(self, quantity):
thread = threading.Thread(target=changeBrightness, decreaseBrightness(quantity)
args=(self, "-dec", quantity))
thread.start()
@Bridge.method() @Bridge.method()
def cancel_authentication(self): def cancel_authentication(self):

1
web-greeter/bridge/__init__.py

@ -119,6 +119,7 @@ def battery_to_dict(battery):
name = battery.get_name(), name = battery.get_name(),
level = battery.get_level(), level = battery.get_level(),
state = battery.get_state(), state = battery.get_state(),
ac_status = battery.get_ac_status(),
capacity = battery.get_capacity(), capacity = battery.get_capacity(),
time = battery.get_time(), time = battery.get_time(),
watt = battery.get_watt() watt = battery.get_watt()

34
web-greeter/browser/browser.py

@ -29,7 +29,6 @@
# Standard lib # Standard lib
from browser.window import MainWindow from browser.window import MainWindow
from browser.devtools import DevTools
import os import os
from typing import ( from typing import (
Dict, Dict,
@ -39,10 +38,10 @@ from typing import (
# 3rd-Party Libs # 3rd-Party Libs
from PyQt5.QtCore import QUrl, Qt, QCoreApplication, QFile from PyQt5.QtCore import QUrl, Qt, QCoreApplication, QFile
from PyQt5.QtWidgets import QApplication, QDesktopWidget, QDockWidget, QMainWindow from PyQt5.QtWidgets import QAction, QApplication, QDesktopWidget, QDockWidget, QMainWindow, qApp
from PyQt5.QtWebEngineCore import QWebEngineUrlScheme from PyQt5.QtWebEngineCore import QWebEngineUrlScheme
from PyQt5.QtWebEngineWidgets import QWebEngineScript, QWebEngineProfile, QWebEngineSettings, QWebEngineView, QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEngineScript, QWebEngineProfile, QWebEngineSettings, QWebEngineView, QWebEnginePage
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor, QIcon
from PyQt5.QtWebChannel import QWebChannel from PyQt5.QtWebChannel import QWebChannel
from browser.error_prompt import WebPage from browser.error_prompt import WebPage
@ -106,7 +105,13 @@ class Application:
self.window.windowFlags() | Qt.WindowType.MaximizeUsingFullscreenGeometryHint self.window.windowFlags() | Qt.WindowType.MaximizeUsingFullscreenGeometryHint
) )
if web_greeter_config["app"]["frame"]:
self._init_menu_bar()
state = self.states['NORMAL'] state = self.states['NORMAL']
if web_greeter_config["app"]["fullscreen"]:
state = self.states["FULLSCREEN"]
try: try:
self.window.windowHandle().setWindowState(state) self.window.windowHandle().setWindowState(state)
except Exception: except Exception:
@ -127,6 +132,27 @@ class Application:
logger.debug("Web Greeter started") logger.debug("Web Greeter started")
return self.app.exec_() return self.app.exec_()
def _init_menu_bar(self):
exit_action = QAction(QIcon('exit.png'), '&Exit', self.window)
exit_action.setShortcut('Ctrl+Q')
exit_action.setStatusTip('Exit application')
exit_action.triggered.connect(qApp.quit)
menu_bar = self.window.menuBar()
file_menu = menu_bar.addMenu('&File')
file_menu.addAction(exit_action)
edit_menu = menu_bar.addMenu('&Edit')
edit_menu.addAction(exit_action)
view_menu = menu_bar.addMenu('&View')
view_menu.addAction(exit_action)
about_menu = menu_bar.addMenu('&About')
about_menu.addAction(exit_action)
class Browser(Application): class Browser(Application):
url_scheme: QWebEngineUrlScheme url_scheme: QWebEngineUrlScheme
@ -211,8 +237,10 @@ class Browser(Application):
return return
if self.qdock.isVisible(): if self.qdock.isVisible():
self.qdock.hide() self.qdock.hide()
self.view.setFocus()
else: else:
self.qdock.show() self.qdock.show()
self.dev_view.setFocus()
def _initialize_page(self): def _initialize_page(self):
page_settings = self.page.settings().globalSettings() page_settings = self.page.settings().globalSettings()

48
web-greeter/browser/error_prompt.py

@ -28,8 +28,9 @@
# Standard lib # Standard lib
# 3rd-Party Libs # 3rd-Party Libs
from typing import List
from PyQt5.QtWebEngineWidgets import QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWidgets import QDialogButtonBox, QDialog, QVBoxLayout, QLabel, QPushButton from PyQt5.QtWidgets import QAbstractButton, QDialogButtonBox, QDialog, QVBoxLayout, QLabel, QPushButton
from config import web_greeter_config from config import web_greeter_config
import globals import globals
@ -86,54 +87,49 @@ class WebPage(QWebEnginePage):
source=sourceID, line=lineNumber, msg=message) source=sourceID, line=lineNumber, msg=message)
errorPrompt(errorMessage) errorPrompt(errorMessage)
class ErrorDialog(QDialog): class Dialog(QDialog):
def __init__(self, parent=None, err=""): def __init__(self, parent=None, title:str = "Dialog", message:str = "Message", detail:str = "", buttons: List[str] = []):
super().__init__(parent) super().__init__(parent)
self.setWindowTitle(title)
self.setWindowTitle("Error")
self.buttonBox = QDialogButtonBox() self.buttonBox = QDialogButtonBox()
cancelBtn = QPushButton("Cancel") for i in range(0, len(buttons)):
defaultBtn = QPushButton("Set default theme") button = QPushButton(buttons[i])
reloadBtn = QPushButton("Reload theme") button.role = i
self.buttonBox.addButton(button, QDialogButtonBox.ButtonRole.NoRole)
reloadBtn.clicked.connect(self.handle_reload)
self.buttonBox.addButton(defaultBtn, QDialogButtonBox.ButtonRole.AcceptRole)
self.buttonBox.addButton(reloadBtn, QDialogButtonBox.ButtonRole.ResetRole)
self.buttonBox.addButton(cancelBtn, QDialogButtonBox.ButtonRole.RejectRole)
self.buttonBox.accepted.connect(self.accept) self.buttonBox.clicked.connect(self.handle_click)
self.buttonBox.rejected.connect(self.reject)
self.layout = QVBoxLayout() self.layout = QVBoxLayout()
message = QLabel("An error ocurred. Do you want to change to default theme?") self.layout.addWidget(QLabel(message))
err = QLabel(err) self.layout.addWidget(QLabel(detail))
self.layout.addWidget(message)
self.layout.addWidget(err)
self.layout.addWidget(self.buttonBox) self.layout.addWidget(self.buttonBox)
self.setLayout(self.layout)
def handle_reload(self, value: bool): self.setLayout(self.layout)
self.done(2)
def handle_click(self, button: QAbstractButton):
self.done(button.role)
def errorPrompt(err): def errorPrompt(err):
if not web_greeter_config["config"]["greeter"]["detect_theme_errors"]: if not web_greeter_config["config"]["greeter"]["detect_theme_errors"]:
return return
dia = ErrorDialog(globals.greeter.window, err) dia = Dialog(parent=globals.greeter.window, title="Error",
message="An error ocurred. Do you want to change to default theme?",
detail=err,
buttons=["Reload theme", "Set default theme", "Cancel"],
)
dia.exec() dia.exec()
result = dia.result() result = dia.result()
if result == 0: # Cancel if result == 2: # Cancel
return return
elif result == 1: # Default theme elif result == 1: # Default theme
web_greeter_config["config"]["greeter"]["theme"] = "gruvbox" web_greeter_config["config"]["greeter"]["theme"] = "gruvbox"
globals.greeter.load_theme() globals.greeter.load_theme()
return return
elif result == 2: # Reload elif result == 0: # Reload
globals.greeter.load_theme() globals.greeter.load_theme()
return return

53
web-greeter/browser/window.py

@ -25,22 +25,49 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Web Greeter; If not, see <http://www.gnu.org/licenses/>. # along with Web Greeter; If not, see <http://www.gnu.org/licenses/>.
from PyQt5.QtCore import Qt from bridge.Greeter import changeBrightness, decreaseBrightness, increaseBrightness
from PyQt5.QtWidgets import QMainWindow from PyQt5.QtCore import QFileSystemWatcher, Qt
from PyQt5.QtWidgets import QAction, QMainWindow
from PyQt5.QtGui import QKeyEvent from PyQt5.QtGui import QKeyEvent
from config import web_greeter_config
import globals import globals
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def keyPressEvent(self, keyEvent: QKeyEvent) -> None: def __init__(self):
super().keyPressEvent(keyEvent) super().__init__()
key = keyEvent.key() self.init_actions()
mod = keyEvent.modifiers() # type: Qt.KeyboardModifiers # self.watchBrightness()
if (key == Qt.Key.Key_MonBrightnessUp):
pass def init_actions(self):
elif (key == Qt.Key.Key_MonBrightnessDown): devAct = QAction(text="&Toggle Devtools", parent=self)
pass devAct.setShortcut("Shift+Ctrl+I")
elif (key == Qt.Key.Key_I devAct.triggered.connect(self.toggle_devtools)
and mod & Qt.KeyboardModifier.ControlModifier
and mod & Qt.KeyboardModifier.ShiftModifier): monBUp = QAction(text="&Increase brightness", parent=self)
monBDo = QAction(text="&Decrease brightness", parent=self)
monBUp.setShortcut(Qt.Key.Key_MonBrightnessUp)
monBDo.setShortcut(Qt.Key.Key_MonBrightnessDown)
monBUp.triggered.connect(self.inc_brightness)
monBDo.triggered.connect(self.dec_brightness)
self.addAction(devAct)
self.addAction(monBUp)
self.addAction(monBDo)
def toggle_devtools(self):
globals.greeter.toggle_devtools() globals.greeter.toggle_devtools()
def inc_brightness(self):
increaseBrightness()
def dec_brightness(self):
decreaseBrightness()
def watchBrightness(self):
self.watcher = QFileSystemWatcher(parent=self)
self.watcher.addPath("/sys/class/backlight/intel_backlight/brightness")
self.watcher.fileChanged.connect(self.updateBrightness)
def updateBrightness(self):
if globals.greeter:
globals.greeter.greeter.brightness_update.emit()

Loading…
Cancel
Save