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): def load_theme(self):
self.logger.debug('Loading theme...') self.logger.debug('Loading theme...')
theme.checkTheme(self) theme_url = theme.checkTheme(self)
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)

13
web-greeter/main.py

@ -31,12 +31,7 @@ import sys
import ruamel.yaml as yaml import ruamel.yaml as yaml
import pkg_resources import pkg_resources
import os import os
from typing import ( from typing import ( List )
ClassVar,
Type,
List,
Tuple,
)
# 3rd-Party Libs # 3rd-Party Libs
@ -104,13 +99,7 @@ def debugMode(value: bool):
def changeTheme(theme: str): def changeTheme(theme: str):
dirlist = listThemes(True)
if theme in dirlist:
custom_config["app"]["greeter"]["theme"] = theme custom_config["app"]["greeter"]["theme"] = theme
else:
logger.error("Theme not found. Going with config theme")
return
def listThemes(quiet = False): 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.perc = math.floor(min(100, (sum_energy_now / sum_energy_full) * 100) + 0.5)
self.time = "{:02d}:{:02d}".format(hours, minutes) self.time = "{:02d}:{:02d}".format(hours, minutes)
self.watt = "{:.2f}".format(sum_rate_energy / 1e6) 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 self.perc = self.perc == None and 0 or self.perc

27
web-greeter/utils/theme.py

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

Loading…
Cancel
Save