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): 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)

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

38
web-greeter/utils/battery.py

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