From a8d2bf31c2c97b618154b73a1e380db2fbbcba28 Mon Sep 17 00:00:00 2001 From: JezerM Date: Fri, 4 Feb 2022 09:40:24 -0600 Subject: [PATCH] Fix bridge objects initialization and some other issues --- src/__main__.py | 13 ++++++++++--- src/bridge/Config.py | 2 -- src/bridge/Greeter.py | 4 +--- src/bridge/ThemeUtils.py | 3 --- src/bridge/__init__.py | 5 +++++ src/browser/browser.py | 16 ++++++++-------- src/browser/window.py | 4 ++-- src/utils/battery.py | 2 +- src/utils/brightness.py | 2 +- 9 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index ece3017..1a76b88 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -110,8 +110,15 @@ if __name__ == '__main__': import globales from browser.browser import Browser + from bridge import Greeter, Config, ThemeUtils globales.greeter = Browser() - greeter = globales.greeter - greeter.show() - greeter.run() + browser = globales.greeter + + browser.greeter = Greeter() + browser.greeter_config = Config() + browser.theme_utils = ThemeUtils(browser.greeter) + + browser.load() + browser.show() + browser.run() diff --git a/src/bridge/Config.py b/src/bridge/Config.py index 2547d91..1a8b4bd 100644 --- a/src/bridge/Config.py +++ b/src/bridge/Config.py @@ -88,5 +88,3 @@ class Config(BridgeObject): @Bridge.prop(QVariant, notify=noop_signal) def layouts(self): return self._layouts - -config = Config() diff --git a/src/bridge/Greeter.py b/src/bridge/Greeter.py index 3ff27b1..c0b1e31 100644 --- a/src/bridge/Greeter.py +++ b/src/bridge/Greeter.py @@ -327,7 +327,7 @@ class Greeter(BridgeObject): @Bridge.method(int) def brightness_decrease(self, quantity): - self._brightness_controller.inc_brightness(quantity) + self._brightness_controller.dec_brightness(quantity) @Bridge.method() def cancel_authentication(self): @@ -375,5 +375,3 @@ class Greeter(BridgeObject): @Bridge.method(result=bool) def suspend(self): return LightDM.suspend() - -greeter = Greeter() diff --git a/src/bridge/ThemeUtils.py b/src/bridge/ThemeUtils.py index b957a4b..ca664e0 100644 --- a/src/bridge/ThemeUtils.py +++ b/src/bridge/ThemeUtils.py @@ -41,7 +41,6 @@ from browser.bridge import Bridge, BridgeObject from config import web_greeter_config from logger import logger -from bridge.Greeter import greeter class ThemeUtils(BridgeObject): # pylint: disable=no-self-use,missing-function-docstring,too-many-public-methods,invalid-name @@ -101,5 +100,3 @@ class ThemeUtils(BridgeObject): result.sort() return result - -theme_utils = ThemeUtils(greeter) diff --git a/src/bridge/__init__.py b/src/bridge/__init__.py index 14ce51a..1ada15b 100644 --- a/src/bridge/__init__.py +++ b/src/bridge/__init__.py @@ -93,3 +93,8 @@ def battery_to_dict(battery): "time": battery.get_time(), "watt": battery.get_watt() } + +# pylint: disable=wrong-import-position +from .Greeter import Greeter +from .Config import Config +from .ThemeUtils import ThemeUtils diff --git a/src/browser/browser.py b/src/browser/browser.py index b627211..f6dfe01 100644 --- a/src/browser/browser.py +++ b/src/browser/browser.py @@ -50,6 +50,9 @@ from PyQt5.QtWebEngineWidgets import ( ) from PyQt5.QtGui import QColor, QIcon from PyQt5.QtWebChannel import QWebChannel +from bridge.Config import Config +from bridge.Greeter import Greeter +from bridge.ThemeUtils import ThemeUtils from browser.error_prompt import WebPage from browser.url_scheme import QtUrlSchemeHandler @@ -58,9 +61,6 @@ from browser.window import MainWindow from logger import logger from config import web_greeter_config -from bridge.Greeter import greeter -from bridge.Config import config -from bridge.ThemeUtils import theme_utils from utils.screensaver import screensaver # pylint: disable-next=unused-import @@ -118,6 +118,10 @@ class Application: desktop: QDesktopWidget window: QMainWindow states = WINDOW_STATES + greeter: Greeter + greeter_config: Config + theme_utils: ThemeUtils + bridge_objects: Tuple[Greeter, Config, ThemeUtils] def __init__(self): QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) @@ -130,7 +134,6 @@ class Application: self.window.setAttribute(Qt.WA_DeleteOnClose) self.window.setWindowTitle("Web Greeter") - self.window.setWindowFlags( self.window.windowFlags() | Qt.MaximizeUsingFullscreenGeometryHint ) @@ -236,7 +239,7 @@ class Browser(Application): def __init__(self): super().__init__() self.init() - self.load() + # self.load() def init(self): """Initialize browser""" @@ -291,9 +294,6 @@ class Browser(Application): def load(self): """Load theme and initialize bridge""" self.load_theme() - self.greeter = greeter - self.greeter_config = config - self.theme_utils = theme_utils self.bridge_objects = (self.greeter, self.greeter_config, self.theme_utils) self.initialize_bridge_objects() diff --git a/src/browser/window.py b/src/browser/window.py index 40904e5..718a0b4 100644 --- a/src/browser/window.py +++ b/src/browser/window.py @@ -65,13 +65,13 @@ class MainWindow(QMainWindow): """Increase brightness""" if globales.greeter: value = web_greeter_config["config"]["features"]["backlight"]["value"] - globales.greeter.greeter.inc_brightness(value) + globales.greeter.greeter.brightness_increase(value) @classmethod def dec_brightness(cls): """Decrease brightness""" if globales.greeter: value = web_greeter_config["config"]["features"]["backlight"]["value"] - globales.greeter.greeter.dec_brightness(value) + globales.greeter.greeter.brightness_decrease(value) @classmethod def update_brightness(cls): diff --git a/src/utils/battery.py b/src/utils/battery.py index a3924bc..361d118 100644 --- a/src/utils/battery.py +++ b/src/utils/battery.py @@ -144,7 +144,7 @@ class Battery: self.perc = self.perc if self.perc is not None else 0 - if hasattr(globales, "greeter"): + if hasattr(globales, "greeter") and hasattr(globales.greeter, "greeter"): globales.greeter.greeter.battery_update.emit() time.sleep(0.1) diff --git a/src/utils/brightness.py b/src/utils/brightness.py index ab75e20..3d6757d 100644 --- a/src/utils/brightness.py +++ b/src/utils/brightness.py @@ -52,7 +52,7 @@ class EventHandler(pyinotify.ProcessEvent): @classmethod def process_IN_MODIFY(cls, _): # pylint: disable=invalid-name,missing-function-docstring - if hasattr(globales, "greeter"): + if hasattr(globales, "greeter") and hasattr(globales.greeter, "greeter"): globales.greeter.greeter.brightness_update.emit()