Browse Source

Battery bugs fixed and custom path to theme kind of added

sisyphus
JezerM 3 years ago
parent
commit
8864d153b0
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 3
      web-greeter/globals.py
  2. 13
      web-greeter/main.py
  3. 4
      web-greeter/utils/battery.py
  4. 27
      web-greeter/utils/theme.py

3
web-greeter/globals.py

@ -206,8 +206,7 @@ class WebGreeter(App):
def load_theme(self):
self.logger.debug('Loading theme...')
theme.checkTheme(self)
theme_url = '/{0}/{1}/index.html'.format(self.config.themes_dir, self.config.greeter.theme)
theme_url = theme.checkTheme(self)
self._web_container.load(theme_url)

13
web-greeter/main.py

@ -31,12 +31,7 @@ import sys
import ruamel.yaml as yaml
import pkg_resources
import os
from typing import (
ClassVar,
Type,
List,
Tuple,
)
from typing import ( List )
# 3rd-Party Libs
@ -104,13 +99,7 @@ def debugMode(value: bool):
def changeTheme(theme: str):
dirlist = listThemes(True)
if theme in dirlist:
custom_config["app"]["greeter"]["theme"] = theme
else:
logger.error("Theme not found. Going with config theme")
return
def listThemes(quiet = False):

4
web-greeter/utils/battery.py

@ -160,6 +160,10 @@ class Battery:
self.perc = math.floor(min(100, (sum_energy_now / sum_energy_full) * 100) + 0.5)
self.time = "{:02d}:{:02d}".format(hours, minutes)
self.watt = "{:.2f}".format(sum_rate_energy / 1e6)
elif self.status == "Full":
self.perc = 100
self.time = "00:00"
self.watt = 0
self.perc = self.perc == None and 0 or self.perc

27
web-greeter/utils/theme.py

@ -29,6 +29,7 @@
# Standard Lib
import os
from os.path import abspath
# This Application
from .pkg_json import PackageJSON
@ -55,15 +56,23 @@ logger.addHandler(stream_handler)
def checkTheme(self):
themes = listThemes(self)
config_theme = self.config.greeter.theme
default = "gruvbox"
if self.config.greeter.theme in themes:
pass
else:
logger.error("Config theme not valid: \"{0}\". Going with \"{1}\" theme".format(
config_theme, default))
self.config.greeter.theme = default
theme: str = self.config.greeter.theme
dir = self.config.themes_dir
path_to_theme: str = os.path.join(dir, theme, "index.html")
def_theme = "gruvbox"
if theme.startswith("/"): path_to_theme = theme;
elif "." in theme or "/" in theme:
path_to_theme = os.path.abspath(theme)
if not path_to_theme.endswith(".html"):
path_to_theme = os.path.join(path_to_theme, "index.html")
if not os.path.exists(path_to_theme):
logger.error("\"{0}\" theme does not exists. Using \"{1}\"".format(theme, def_theme))
path_to_theme = os.path.join(dir, def_theme, "index.html")
return path_to_theme
def listThemes(self):

Loading…
Cancel
Save