Browse Source

Styling and preparing 3.0.0

sisyphus
JezerM 3 years ago
parent
commit
634751a0b0
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 3
      .coafile
  2. 11
      .doclets.yml
  3. 13
      web-greeter/bridge/Greeter.py
  4. 4
      web-greeter/bridge/__init__.py
  5. 29
      web-greeter/globals.py
  6. 11
      web-greeter/main.py
  7. 21
      web-greeter/resources/css/style.css
  8. 7
      web-greeter/utils/errorPrompt.py
  9. 9
      web-greeter/utils/keyboard.py
  10. 5
      web-greeter/utils/theme.py

3
.coafile

@ -14,10 +14,12 @@ cpplint_ignore = whitespace/tab
[JavaScript] [JavaScript]
bears = JSHintBear bears = JSHintBear
files = **/*.js files = **/*.js
ignore = node_modules/
[Python] [Python]
bears=PEP8Bear,PyCommentedCodeBear,PyImportSortBear,PyLintBear,PyUnusedCodeBear bears=PEP8Bear,PyCommentedCodeBear,PyImportSortBear,PyLintBear,PyUnusedCodeBear
files = **/*.py files = **/*.py
ignore = build/**/*.py
[Docker] [Docker]
bears= DockerfileLintBear bears= DockerfileLintBear
@ -30,3 +32,4 @@ files = **/*.md
[JSON] [JSON]
bears = JSONFormatBear bears = JSONFormatBear
files = **/*.json files = **/*.json
ignore = node_modules/**/*.json

11
.doclets.yml

@ -1,11 +0,0 @@
files:
- web-greeter/resources/js/docs/LightDMObjects.js
- web-greeter/resources/js/docs/Greeter.js
- web-greeter/resources/js/docs/GreeterConfig.js
- web-greeter/resources/js/ThemeUtils.js
- web-greeter/resources/js/bootstrap.js
articles:
- Overview: README.md
branches:
- master
- stable

13
web-greeter/bridge/Greeter.py

@ -55,6 +55,7 @@ from . import (
LightDMGreeter = LightDM.Greeter() LightDMGreeter = LightDM.Greeter()
LightDMUsers = LightDM.UserList() LightDMUsers = LightDM.UserList()
def changeBrightness(self, method: str, quantity: int): def changeBrightness(self, method: str, quantity: int):
if self._config.features.backlight["enabled"] != True: if self._config.features.backlight["enabled"] != True:
return return
@ -67,23 +68,26 @@ def changeBrightness(self, method: str, quantity: int):
logger.error("Brightness: {}".format(err)) logger.error("Brightness: {}".format(err))
else: else:
self.brightness_update.emit() self.brightness_update.emit()
pass
def getBrightness(self): def getBrightness(self):
if self._config.features.backlight["enabled"] != True: if self._config.features.backlight["enabled"] != True:
return -1 return -1
try: try:
level = subprocess.run(["xbacklight", "-get"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True) level = subprocess.run(["xbacklight", "-get"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, check=True)
return int(level.stdout) return int(level.stdout)
except Exception as err: except Exception as err:
logger.error("Brightness: {}".format(err)) logger.error("Brightness: {}".format(err))
return -1 return -1
def updateBattery(self): def updateBattery(self):
if self._config.features.battery != True: if self._config.features.battery != True:
return return
try: try:
acpi = subprocess.run(["acpi", "-b"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True) acpi = subprocess.run(["acpi", "-b"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, check=True)
self._battery.update(acpi.stdout) self._battery.update(acpi.stdout)
except Exception as err: except Exception as err:
@ -91,6 +95,7 @@ def updateBattery(self):
else: else:
self.property_changed.emit() self.property_changed.emit()
class Greeter(BridgeObject): class Greeter(BridgeObject):
# LightDM.Greeter Signals # LightDM.Greeter Signals
@ -147,7 +152,6 @@ class Greeter(BridgeObject):
lambda greeter, msg, mtype: self._emit_signal(self.show_prompt, msg, mtype) lambda greeter, msg, mtype: self._emit_signal(self.show_prompt, msg, mtype)
) )
def _emit_signal(self, _signal, *args): def _emit_signal(self, _signal, *args):
self.property_changed.emit() self.property_changed.emit()
QTimer().singleShot(300, lambda: _signal.emit(*args)) QTimer().singleShot(300, lambda: _signal.emit(*args))
@ -371,4 +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()

4
web-greeter/bridge/__init__.py

@ -50,6 +50,7 @@ stream_handler.setFormatter(formatter)
logger.setLevel(DEBUG) logger.setLevel(DEBUG)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
class setInterval: class setInterval:
def __init__(self, interval, action): def __init__(self, interval, action):
self.interval = interval self.interval = interval
@ -64,6 +65,7 @@ class setInterval:
nextTime += self.interval nextTime += self.interval
self.action() self.action()
class Battery: class Battery:
_name = "" _name = ""
_level = -1 _level = -1
@ -90,6 +92,7 @@ class Battery:
def get_state(self): def get_state(self):
return self._state return self._state
def language_to_dict(lang): def language_to_dict(lang):
if (not lang): if (not lang):
return dict() return dict()
@ -131,6 +134,7 @@ def user_to_dict(user):
username=user.get_name(), username=user.get_name(),
) )
def battery_to_dict(battery): def battery_to_dict(battery):
if (not battery): if (not battery):
return dict() return dict()

29
web-greeter/globals.py

@ -57,6 +57,7 @@ from logging import (
from PyQt5.QtWidgets import QMainWindow from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
from PyQt5.QtCore import QResource
import subprocess import subprocess
from utils import theme from utils import theme
@ -81,12 +82,15 @@ logger.addHandler(stream_handler)
initial_timeout = 0 initial_timeout = 0
def setScreenSaver(timeout: int): def setScreenSaver(timeout: int):
global initial_timeout global initial_timeout
timeout = timeout if timeout >= 0 else 300 timeout = timeout if timeout >= 0 else 300
try: try:
child = subprocess.Popen(["xset", "q"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) child = subprocess.Popen(["xset", "q"], stdout=subprocess.PIPE,
awk = subprocess.run(["awk", "/^ timeout: / {print $2}"], stdout=subprocess.PIPE, stdin=child.stdout, text=True) stderr=subprocess.PIPE, text=True)
awk = subprocess.run(
["awk", "/^ timeout: / {print $2}"], stdout=subprocess.PIPE, stdin=child.stdout, text=True)
initial_timeout = int(awk.stdout.replace("\n", "")) initial_timeout = int(awk.stdout.replace("\n", ""))
@ -97,6 +101,7 @@ def setScreenSaver(timeout: int):
else: else:
logger.debug("Screensaver timeout set") logger.debug("Screensaver timeout set")
def resetScreenSaver(): def resetScreenSaver():
try: try:
subprocess.run(["xset", "s", str(initial_timeout)]) subprocess.run(["xset", "s", str(initial_timeout)])
@ -105,19 +110,31 @@ def resetScreenSaver():
else: else:
logger.debug("Screensaver reset") logger.debug("Screensaver reset")
def getDefaultCursor(): def getDefaultCursor():
cursor_theme = "" cursor_theme = ""
try: try:
child = subprocess.Popen(["cat", "/usr/share/icons/default/index.theme"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) child = subprocess.Popen(["cat", "/usr/share/icons/default/index.theme"],
awk = subprocess.run(["awk", "-F=", "/Inherits/ {print $2}"], stdout=subprocess.PIPE, stdin=child.stdout, text=True) stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
awk = subprocess.run(
["awk", "-F=", "/Inherits/ {print $2}"], stdout=subprocess.PIPE, stdin=child.stdout, text=True)
cursor_theme = awk.stdout.replace("\n", "") cursor_theme = awk.stdout.replace("\n", "")
except Exception as err: except Exception as err:
logger.error("Default cursor couldn't be get") logger.error("Default cursor couldn't be get")
return cursor_theme return cursor_theme
def loadStyle(path):
file = QResource(path)
file = file.uncompressedData()
file = str(file.data(), encoding='utf-8')
return file
BASE_DIR = os.path.dirname(os.path.realpath(__file__)) BASE_DIR = os.path.dirname(os.path.realpath(__file__))
CONFIG_FILE = os.path.join(BASE_DIR, 'whither.yml') CONFIG_FILE = os.path.join(BASE_DIR, 'whither.yml')
class WebGreeter(App): class WebGreeter(App):
greeter = None # type: ClassVar[BridgeObj] | None greeter = None # type: ClassVar[BridgeObj] | None
greeter_config = None # type: ClassVar[BridgeObj] | None greeter_config = None # type: ClassVar[BridgeObj] | None
@ -131,6 +148,8 @@ class WebGreeter(App):
self.theme_utils = ThemeUtils(self.greeter, self.config) self.theme_utils = ThemeUtils(self.greeter, self.config)
self._web_container.bridge_objects = (self.greeter, self.greeter_config, self.theme_utils) self._web_container.bridge_objects = (self.greeter, self.greeter_config, self.theme_utils)
style = loadStyle(":/_greeter/css/style.css")
self._main_window.widget.setStyleSheet(style)
page = self._main_window.widget.centralWidget().page() page = self._main_window.widget.centralWidget().page()
page.setBackgroundColor(QColor(0, 0, 0)) page.setBackgroundColor(QColor(0, 0, 0))
@ -189,6 +208,7 @@ class WebGreeter(App):
theme_url = '/{0}/{1}/index.html'.format(self.config.themes_dir, self.config.greeter.theme) theme_url = '/{0}/{1}/index.html'.format(self.config.themes_dir, self.config.greeter.theme)
self._web_container.load(theme_url) self._web_container.load(theme_url)
global custom_config global custom_config
global greeter global greeter
custom_config = { custom_config = {
@ -199,4 +219,3 @@ custom_config = {
"greeter": {} "greeter": {}
} }
} }

11
web-greeter/main.py

@ -46,6 +46,7 @@ from utils import errorPrompt, keyboard
import globals import globals
from globals import WebGreeter, logger from globals import WebGreeter, logger
def loadWhitherConf(): def loadWhitherConf():
global whither_yaml global whither_yaml
global webGreeter_conf global webGreeter_conf
@ -58,6 +59,7 @@ def loadWhitherConf():
whither_yaml = yaml.safe_load(file_test) whither_yaml = yaml.safe_load(file_test)
webGreeter_conf = whither_yaml["WebGreeter"] webGreeter_conf = whither_yaml["WebGreeter"]
def show_help(): def show_help():
version = webGreeter_conf["app"]["version"]["full"] version = webGreeter_conf["app"]["version"]["full"]
help_text = """Usage: help_text = """Usage:
@ -84,6 +86,7 @@ def changeConfig(option: str, value):
custom_config[option] = value custom_config[option] = value
return return
def debugMode(value: bool): def debugMode(value: bool):
window = dict(custom_config["whither"]["window"]) window = dict(custom_config["whither"]["window"])
greeter = dict(custom_config["app"]["greeter"]) greeter = dict(custom_config["app"]["greeter"])
@ -99,6 +102,7 @@ def debugMode(value: bool):
custom_config["whither"]["window"] = window custom_config["whither"]["window"] = window
custom_config["app"]["greeter"] = greeter custom_config["app"]["greeter"] = greeter
def changeTheme(theme: str): def changeTheme(theme: str):
dirlist = listThemes(True) dirlist = listThemes(True)
@ -108,6 +112,7 @@ def changeTheme(theme: str):
logger.error("Theme not found. Going with config theme") logger.error("Theme not found. Going with config theme")
return return
def listThemes(quiet = False): def listThemes(quiet = False):
themes_dir = webGreeter_conf["app"]["themes_dir"] themes_dir = webGreeter_conf["app"]["themes_dir"]
themes_dir = themes_dir if os.path.exists(themes_dir) else "/usr/share/web-greeter/themes" themes_dir = themes_dir if os.path.exists(themes_dir) else "/usr/share/web-greeter/themes"
@ -125,8 +130,10 @@ def listThemes(quiet = False):
return dirlist return dirlist
args_lenght = sys.argv.__len__() args_lenght = sys.argv.__len__()
def yargs(args: List[str]): def yargs(args: List[str]):
loadWhitherConf() loadWhitherConf()
used = 0 used = 0
@ -142,11 +149,9 @@ def yargs(args: List[str]):
elif args[0] == "--debug": elif args[0] == "--debug":
debugMode(True) debugMode(True)
used += 1 used += 1
pass
elif args[0] == "--normal": elif args[0] == "--normal":
debugMode(False) debugMode(False)
used += 1 used += 1
pass
elif args[0] == "--theme": elif args[0] == "--theme":
if args.__len__() > 1: if args.__len__() > 1:
changeTheme(args[1]) changeTheme(args[1])
@ -167,7 +172,7 @@ def yargs(args: List[str]):
args.pop(0) args.pop(0)
if args.__len__() != 0: if args.__len__() != 0:
yargs(args) yargs(args)
pass
if __name__ == '__main__': if __name__ == '__main__':
custom_config = globals.custom_config custom_config = globals.custom_config

21
web-greeter/resources/css/style.css

@ -1,9 +1,18 @@
window, QMainWindow {
GtkWindow {
background: #000000; background: #000000;
} }
dialog .dialog-vbox > label, /*QWidget {*/
GtkDialog .dialog-vbox > GtkLabel { /*background: #282828;*/
margin: 20px 15px; /*color: #ebdbb2;*/
} /*}*/
/*window,*/
/*GtkWindow {*/
/*background: #000000;*/
/*}*/
/*dialog .dialog-vbox > label,*/
/*GtkDialog .dialog-vbox > GtkLabel {*/
/*margin: 20px 15px;*/
/*}*/

7
web-greeter/utils/errorPrompt.py

@ -52,6 +52,7 @@ stream_handler.setFormatter(formatter)
logger.setLevel(DEBUG) logger.setLevel(DEBUG)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
def javaScriptConsoleMessage(self, level: WebPage.JavaScriptConsoleMessageLevel, message: str, lineNumber: int, sourceID: str): def javaScriptConsoleMessage(self, level: WebPage.JavaScriptConsoleMessageLevel, message: str, lineNumber: int, sourceID: str):
if sourceID == "": if sourceID == "":
sourceID = "console" sourceID = "console"
@ -79,9 +80,11 @@ def javaScriptConsoleMessage(self, level: WebPage.JavaScriptConsoleMessageLevel,
logger.handle(record) logger.handle(record)
if logLevel == 40: if logLevel == 40:
errorMessage = "{source} {line}: {msg}".format(source = sourceID, line = lineNumber, msg = message) errorMessage = "{source} {line}: {msg}".format(
source=sourceID, line=lineNumber, msg=message)
errorPrompt(errorMessage) errorPrompt(errorMessage)
class ErrorDialog(QDialog): class ErrorDialog(QDialog):
def __init__(self, parent=None, err=""): def __init__(self, parent=None, err=""):
super().__init__(parent) super().__init__(parent)
@ -113,6 +116,7 @@ class ErrorDialog(QDialog):
def handle_reload(self, value: bool): def handle_reload(self, value: bool):
self.done(2) self.done(2)
def errorPrompt(err): def errorPrompt(err):
if not globals.greeter.config.greeter.detect_theme_errors: if not globals.greeter.config.greeter.detect_theme_errors:
@ -136,4 +140,5 @@ def errorPrompt(err):
return return
WebPage.javaScriptConsoleMessage = javaScriptConsoleMessage WebPage.javaScriptConsoleMessage = javaScriptConsoleMessage

9
web-greeter/utils/keyboard.py

@ -32,14 +32,15 @@ from PyQt5.QtGui import QKeyEvent
import globals import globals
def keyPressEvent(self, keyEvent: QKeyEvent): def keyPressEvent(self, keyEvent: QKeyEvent):
super(MainWindow, self).keyPressEvent(keyEvent) super(MainWindow, self).keyPressEvent(keyEvent)
if (keyEvent.key() == Qt.Key.Key_MonBrightnessUp): if (keyEvent.key() == Qt.Key.Key_MonBrightnessUp):
globals.greeter.greeter.brightnessIncrease(globals.greeter.config.features.backlight["value"]) globals.greeter.greeter.brightnessIncrease(
globals.greeter.config.features.backlight["value"])
if (keyEvent.key() == Qt.Key.Key_MonBrightnessDown): if (keyEvent.key() == Qt.Key.Key_MonBrightnessDown):
globals.greeter.greeter.brightnessDecrease(globals.greeter.config.features.backlight["value"]) globals.greeter.greeter.brightnessDecrease(
globals.greeter.config.features.backlight["value"])
MainWindow.keyPressEvent = keyPressEvent MainWindow.keyPressEvent = keyPressEvent

5
web-greeter/utils/theme.py

@ -53,6 +53,7 @@ stream_handler.setFormatter(formatter)
logger.setLevel(DEBUG) logger.setLevel(DEBUG)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
def checkTheme(self): def checkTheme(self):
themes = listThemes(self) themes = listThemes(self)
config_theme = self.config.greeter.theme config_theme = self.config.greeter.theme
@ -60,7 +61,8 @@ def checkTheme(self):
if self.config.greeter.theme in themes: if self.config.greeter.theme in themes:
pass pass
else: else:
logger.error("Config theme not valid: \"{0}\". Going with \"{1}\" theme".format(config_theme, default)) logger.error("Config theme not valid: \"{0}\". Going with \"{1}\" theme".format(
config_theme, default))
self.config.greeter.theme = default self.config.greeter.theme = default
@ -87,6 +89,7 @@ class Theme:
Attributes: Attributes:
data (PackageJSON): The theme's data sourced from its `package.json` file. data (PackageJSON): The theme's data sourced from its `package.json` file.
""" """
def __init__(self, path: str) -> None: def __init__(self, path: str) -> None:
self.path = path self.path = path

Loading…
Cancel
Save