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. 31
      web-greeter/globals.py
  6. 29
      web-greeter/main.py
  7. 21
      web-greeter/resources/css/style.css
  8. 13
      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]
bears = JSHintBear
files = **/*.js
ignore = node_modules/
[Python]
bears=PEP8Bear,PyCommentedCodeBear,PyImportSortBear,PyLintBear,PyUnusedCodeBear
files = **/*.py
ignore = build/**/*.py
[Docker]
bears= DockerfileLintBear
@ -30,3 +32,4 @@ files = **/*.md
[JSON]
bears = JSONFormatBear
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()
LightDMUsers = LightDM.UserList()
def changeBrightness(self, method: str, quantity: int):
if self._config.features.backlight["enabled"] != True:
return
@ -67,23 +68,26 @@ def changeBrightness(self, method: str, quantity: int):
logger.error("Brightness: {}".format(err))
else:
self.brightness_update.emit()
pass
def getBrightness(self):
if self._config.features.backlight["enabled"] != True:
return -1
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)
except Exception as err:
logger.error("Brightness: {}".format(err))
return -1
def updateBattery(self):
if self._config.features.battery != True:
return
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)
except Exception as err:
@ -91,6 +95,7 @@ def updateBattery(self):
else:
self.property_changed.emit()
class Greeter(BridgeObject):
# LightDM.Greeter Signals
@ -147,7 +152,6 @@ class Greeter(BridgeObject):
lambda greeter, msg, mtype: self._emit_signal(self.show_prompt, msg, mtype)
)
def _emit_signal(self, _signal, *args):
self.property_changed.emit()
QTimer().singleShot(300, lambda: _signal.emit(*args))
@ -371,4 +375,3 @@ class Greeter(BridgeObject):
@bridge.method(result=bool)
def suspend(self):
return LightDM.suspend()

4
web-greeter/bridge/__init__.py

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

31
web-greeter/globals.py

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

29
web-greeter/main.py

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

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

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

13
web-greeter/utils/errorPrompt.py

@ -52,6 +52,7 @@ stream_handler.setFormatter(formatter)
logger.setLevel(DEBUG)
logger.addHandler(stream_handler)
def javaScriptConsoleMessage(self, level: WebPage.JavaScriptConsoleMessageLevel, message: str, lineNumber: int, sourceID: str):
if sourceID == "":
sourceID = "console"
@ -79,9 +80,11 @@ def javaScriptConsoleMessage(self, level: WebPage.JavaScriptConsoleMessageLevel,
logger.handle(record)
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)
class ErrorDialog(QDialog):
def __init__(self, parent=None, err=""):
super().__init__(parent)
@ -113,6 +116,7 @@ class ErrorDialog(QDialog):
def handle_reload(self, value: bool):
self.done(2)
def errorPrompt(err):
if not globals.greeter.config.greeter.detect_theme_errors:
@ -123,17 +127,18 @@ def errorPrompt(err):
dia.exec()
result = dia.result()
if result == 0: # Cancel
if result == 0: # Cancel
return
elif result == 1: # Default theme
elif result == 1: # Default theme
globals.custom_config["app"]["greeter"]["theme"] = "gruvbox"
globals.greeter.get_and_apply_user_config()
globals.greeter.load_theme()
return
elif result == 2: # Reload
elif result == 2: # Reload
globals.greeter.load_theme()
return
return
WebPage.javaScriptConsoleMessage = javaScriptConsoleMessage

9
web-greeter/utils/keyboard.py

@ -32,14 +32,15 @@ from PyQt5.QtGui import QKeyEvent
import globals
def keyPressEvent(self, keyEvent: QKeyEvent):
super(MainWindow, self).keyPressEvent(keyEvent)
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):
globals.greeter.greeter.brightnessDecrease(globals.greeter.config.features.backlight["value"])
globals.greeter.greeter.brightnessDecrease(
globals.greeter.config.features.backlight["value"])
MainWindow.keyPressEvent = keyPressEvent

5
web-greeter/utils/theme.py

@ -53,6 +53,7 @@ stream_handler.setFormatter(formatter)
logger.setLevel(DEBUG)
logger.addHandler(stream_handler)
def checkTheme(self):
themes = listThemes(self)
config_theme = self.config.greeter.theme
@ -60,7 +61,8 @@ def checkTheme(self):
if self.config.greeter.theme in themes:
pass
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
@ -87,6 +89,7 @@ class Theme:
Attributes:
data (PackageJSON): The theme's data sourced from its `package.json` file.
"""
def __init__(self, path: str) -> None:
self.path = path

Loading…
Cancel
Save