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. 15
      web-greeter/main.py
  3. 38
      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)

15
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
custom_config["app"]["greeter"]["theme"] = theme
def listThemes(quiet = False):

38
web-greeter/utils/battery.py

@ -143,23 +143,27 @@ class Battery:
self.watt = 0
elif self.status != "Full":
rate_time = 0
if (sum_rate_power > 0 or sum_rate_current > 0):
div = (sum_rate_power > 0 and sum_rate_power) or sum_rate_current
if self.status == "Charging":
rate_time = (sum_energy_full - sum_energy_now) / div
else:
rate_time = sum_energy_now / div
if 0 < rate_time and rate_time < 0.01:
rate_time_magnitude = tonumber(abs(math.floor(math.log10(rate_time))))
rate_time = rate_time * 10 ^ (rate_time_magnitude - 2)
hours = math.floor(rate_time)
minutes = math.floor((rate_time - hours) * 60)
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)
if (sum_rate_power > 0 or sum_rate_current > 0):
div = (sum_rate_power > 0 and sum_rate_power) or sum_rate_current
if self.status == "Charging":
rate_time = (sum_energy_full - sum_energy_now) / div
else:
rate_time = sum_energy_now / div
if 0 < rate_time and rate_time < 0.01:
rate_time_magnitude = tonumber(abs(math.floor(math.log10(rate_time))))
rate_time = rate_time * 10 ^ (rate_time_magnitude - 2)
hours = math.floor(rate_time)
minutes = math.floor((rate_time - hours) * 60)
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