Browse Source

Fix bridge objects initialization and some other issues

sisyphus
JezerM 3 years ago
parent
commit
a8d2bf31c2
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 13
      src/__main__.py
  2. 2
      src/bridge/Config.py
  3. 4
      src/bridge/Greeter.py
  4. 3
      src/bridge/ThemeUtils.py
  5. 5
      src/bridge/__init__.py
  6. 16
      src/browser/browser.py
  7. 4
      src/browser/window.py
  8. 2
      src/utils/battery.py
  9. 2
      src/utils/brightness.py

13
src/__main__.py

@ -110,8 +110,15 @@ if __name__ == '__main__':
import globales import globales
from browser.browser import Browser from browser.browser import Browser
from bridge import Greeter, Config, ThemeUtils
globales.greeter = Browser() globales.greeter = Browser()
greeter = globales.greeter browser = globales.greeter
greeter.show()
greeter.run() browser.greeter = Greeter()
browser.greeter_config = Config()
browser.theme_utils = ThemeUtils(browser.greeter)
browser.load()
browser.show()
browser.run()

2
src/bridge/Config.py

@ -88,5 +88,3 @@ class Config(BridgeObject):
@Bridge.prop(QVariant, notify=noop_signal) @Bridge.prop(QVariant, notify=noop_signal)
def layouts(self): def layouts(self):
return self._layouts return self._layouts
config = Config()

4
src/bridge/Greeter.py

@ -327,7 +327,7 @@ class Greeter(BridgeObject):
@Bridge.method(int) @Bridge.method(int)
def brightness_decrease(self, quantity): def brightness_decrease(self, quantity):
self._brightness_controller.inc_brightness(quantity) self._brightness_controller.dec_brightness(quantity)
@Bridge.method() @Bridge.method()
def cancel_authentication(self): def cancel_authentication(self):
@ -375,5 +375,3 @@ class Greeter(BridgeObject):
@Bridge.method(result=bool) @Bridge.method(result=bool)
def suspend(self): def suspend(self):
return LightDM.suspend() return LightDM.suspend()
greeter = Greeter()

3
src/bridge/ThemeUtils.py

@ -41,7 +41,6 @@ from browser.bridge import Bridge, BridgeObject
from config import web_greeter_config from config import web_greeter_config
from logger import logger from logger import logger
from bridge.Greeter import greeter
class ThemeUtils(BridgeObject): class ThemeUtils(BridgeObject):
# pylint: disable=no-self-use,missing-function-docstring,too-many-public-methods,invalid-name # pylint: disable=no-self-use,missing-function-docstring,too-many-public-methods,invalid-name
@ -101,5 +100,3 @@ class ThemeUtils(BridgeObject):
result.sort() result.sort()
return result return result
theme_utils = ThemeUtils(greeter)

5
src/bridge/__init__.py

@ -93,3 +93,8 @@ def battery_to_dict(battery):
"time": battery.get_time(), "time": battery.get_time(),
"watt": battery.get_watt() "watt": battery.get_watt()
} }
# pylint: disable=wrong-import-position
from .Greeter import Greeter
from .Config import Config
from .ThemeUtils import ThemeUtils

16
src/browser/browser.py

@ -50,6 +50,9 @@ from PyQt5.QtWebEngineWidgets import (
) )
from PyQt5.QtGui import QColor, QIcon from PyQt5.QtGui import QColor, QIcon
from PyQt5.QtWebChannel import QWebChannel 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.error_prompt import WebPage
from browser.url_scheme import QtUrlSchemeHandler from browser.url_scheme import QtUrlSchemeHandler
@ -58,9 +61,6 @@ from browser.window import MainWindow
from logger import logger from logger import logger
from config import web_greeter_config 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 from utils.screensaver import screensaver
# pylint: disable-next=unused-import # pylint: disable-next=unused-import
@ -118,6 +118,10 @@ class Application:
desktop: QDesktopWidget desktop: QDesktopWidget
window: QMainWindow window: QMainWindow
states = WINDOW_STATES states = WINDOW_STATES
greeter: Greeter
greeter_config: Config
theme_utils: ThemeUtils
bridge_objects: Tuple[Greeter, Config, ThemeUtils]
def __init__(self): def __init__(self):
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
@ -130,7 +134,6 @@ class Application:
self.window.setAttribute(Qt.WA_DeleteOnClose) self.window.setAttribute(Qt.WA_DeleteOnClose)
self.window.setWindowTitle("Web Greeter") self.window.setWindowTitle("Web Greeter")
self.window.setWindowFlags( self.window.setWindowFlags(
self.window.windowFlags() | Qt.MaximizeUsingFullscreenGeometryHint self.window.windowFlags() | Qt.MaximizeUsingFullscreenGeometryHint
) )
@ -236,7 +239,7 @@ class Browser(Application):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.init() self.init()
self.load() # self.load()
def init(self): def init(self):
"""Initialize browser""" """Initialize browser"""
@ -291,9 +294,6 @@ class Browser(Application):
def load(self): def load(self):
"""Load theme and initialize bridge""" """Load theme and initialize bridge"""
self.load_theme() 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.bridge_objects = (self.greeter, self.greeter_config, self.theme_utils)
self.initialize_bridge_objects() self.initialize_bridge_objects()

4
src/browser/window.py

@ -65,13 +65,13 @@ class MainWindow(QMainWindow):
"""Increase brightness""" """Increase brightness"""
if globales.greeter: if globales.greeter:
value = web_greeter_config["config"]["features"]["backlight"]["value"] value = web_greeter_config["config"]["features"]["backlight"]["value"]
globales.greeter.greeter.inc_brightness(value) globales.greeter.greeter.brightness_increase(value)
@classmethod @classmethod
def dec_brightness(cls): def dec_brightness(cls):
"""Decrease brightness""" """Decrease brightness"""
if globales.greeter: if globales.greeter:
value = web_greeter_config["config"]["features"]["backlight"]["value"] value = web_greeter_config["config"]["features"]["backlight"]["value"]
globales.greeter.greeter.dec_brightness(value) globales.greeter.greeter.brightness_decrease(value)
@classmethod @classmethod
def update_brightness(cls): def update_brightness(cls):

2
src/utils/battery.py

@ -144,7 +144,7 @@ class Battery:
self.perc = self.perc if self.perc is not None else 0 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() globales.greeter.greeter.battery_update.emit()
time.sleep(0.1) time.sleep(0.1)

2
src/utils/brightness.py

@ -52,7 +52,7 @@ class EventHandler(pyinotify.ProcessEvent):
@classmethod @classmethod
def process_IN_MODIFY(cls, _): def process_IN_MODIFY(cls, _):
# pylint: disable=invalid-name,missing-function-docstring # 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() globales.greeter.greeter.brightness_update.emit()

Loading…
Cancel
Save