Added theme install and path detection

pull/86/head
aristocratos 2020-08-22 20:20:58 +02:00
parent c6a3c4b3ec
commit 8109e9e890
4 changed files with 44 additions and 33 deletions

1
.gitignore vendored
View File

@ -17,5 +17,6 @@ syntax: glob
.tox/ .tox/
build/ build/
dist/ dist/
__pycache__
.mypy_cache .mypy_cache
.vscode .vscode

1
bpytop-themes Symbolic link
View File

@ -0,0 +1 @@
themes

View File

@ -17,7 +17,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os, sys, threading, signal, re, subprocess, logging, logging.handlers import os, sys, threading, signal, re, subprocess, logging, logging.handlers, site
import urllib.request import urllib.request
from time import time, sleep, strftime, localtime from time import time, sleep, strftime, localtime
from datetime import timedelta from datetime import timedelta
@ -186,10 +186,15 @@ if not os.path.isdir(CONFIG_DIR):
raise SystemExit(1) raise SystemExit(1)
CONFIG_FILE: str = f'{CONFIG_DIR}/bpytop.conf' CONFIG_FILE: str = f'{CONFIG_DIR}/bpytop.conf'
THEME_DIR: str = "" THEME_DIR: str = ""
for td in ["local/", ""]: for td in site.getsitepackages() + [site.getusersitepackages()]:
if os.path.isdir(f'/usr/{td}share/bpytop/themes'): if os.path.isdir(f'{td}/bpytop-themes'):
THEME_DIR = f'/usr/{td}share/bpytop/themes' THEME_DIR = f'{td}/bpytop-themes'
break break
else:
for td in ["local/", ""]:
if os.path.isdir(f'/usr/{td}share/bpytop/themes'):
THEME_DIR = f'/usr/{td}share/bpytop/themes'
break
USER_THEME_DIR: str = f'{CONFIG_DIR}/themes' USER_THEME_DIR: str = f'{CONFIG_DIR}/themes'
CORES: int = psutil.cpu_count(logical=False) or 1 CORES: int = psutil.cpu_count(logical=False) or 1
@ -3811,6 +3816,9 @@ class Menu:
setattr(CONFIG, selected, input_val) setattr(CONFIG, selected, input_val)
if selected.startswith("net_"): if selected.startswith("net_"):
NetCollector.net_min = {"download" : -1, "upload" : -1} NetCollector.net_min = {"download" : -1, "upload" : -1}
elif selected == "draw_clock":
Box.clock_on = True if len(CONFIG.draw_clock) > 0 else False
if not Box.clock_on: Draw.clear("clock", saved=True)
Term.refresh(force=True) Term.refresh(force=True)
cls.resized = False cls.resized = False
elif key == "backspace" and len(input_val) > 0: elif key == "backspace" and len(input_val) > 0:
@ -3974,6 +3982,31 @@ class Init:
initbg_down: Graph initbg_down: Graph
resized = False resized = False
@classmethod
def start(cls):
Draw.buffer("init", z=1)
Draw.buffer("initbg", z=10)
for i in range(51):
for _ in range(2): cls.initbg_colors.append(Color.fg(i, i, i))
Draw.buffer("banner", (f'{Banner.draw(Term.height // 2 - 10, center=True)}{Mv.d(1)}{Mv.l(11)}{Colors.black_bg}{Colors.default}'
f'{Fx.b}{Fx.i}Version: {VERSION}{Fx.ui}{Fx.ub}{Term.bg}{Term.fg}{Color.fg("#50")}'), z=2)
for _i in range(7):
perc = f'{str(round((_i + 1) * 14 + 2)) + "%":>5}'
Draw.buffer("+banner", f'{Mv.to(Term.height // 2 - 2 + _i, Term.width // 2 - 28)}{Fx.trans(perc)}{Symbol.v_line}')
Draw.out("banner")
Draw.buffer("+init!", f'{Color.fg("#cc")}{Fx.b}{Mv.to(Term.height // 2 - 2, Term.width // 2 - 21)}{Mv.save}')
cls.initbg_data = [randint(0, 100) for _ in range(Term.width * 2)]
cls.initbg_up = Graph(Term.width, Term.height // 2, cls.initbg_colors, cls.initbg_data, invert=True)
cls.initbg_down = Graph(Term.width, Term.height // 2, cls.initbg_colors, cls.initbg_data, invert=False)
@classmethod
def success(cls):
if not CONFIG.show_init or cls.resized: return
cls.draw_bg(5)
Draw.buffer("+init!", f'{Mv.restore}{Symbol.ok}\n{Mv.r(Term.width // 2 - 22)}{Mv.save}')
@staticmethod @staticmethod
def fail(err): def fail(err):
if CONFIG.show_init: if CONFIG.show_init:
@ -3982,32 +4015,6 @@ class Init:
errlog.exception(f'{err}') errlog.exception(f'{err}')
clean_quit(1, errmsg=f'Error during init! See {CONFIG_DIR}/error.log for more information.') clean_quit(1, errmsg=f'Error during init! See {CONFIG_DIR}/error.log for more information.')
@classmethod
def success(cls, start: bool = False):
if not CONFIG.show_init or cls.resized: return
if start:
Draw.buffer("init", z=1)
Draw.buffer("initbg", z=10)
for i in range(51):
for _ in range(2): cls.initbg_colors.append(Color.fg(i, i, i))
Draw.buffer("banner", (f'{Banner.draw(Term.height // 2 - 10, center=True)}{Mv.d(1)}{Mv.l(11)}{Colors.black_bg}{Colors.default}'
f'{Fx.b}{Fx.i}Version: {VERSION}{Fx.ui}{Fx.ub}{Term.bg}{Term.fg}{Color.fg("#50")}'), z=2)
for _i in range(7):
perc = f'{str(round((_i + 1) * 14 + 2)) + "%":>5}'
Draw.buffer("+banner", f'{Mv.to(Term.height // 2 - 2 + _i, Term.width // 2 - 28)}{Fx.trans(perc)}{Symbol.v_line}')
Draw.out("banner")
Draw.buffer("+init!", f'{Color.fg("#cc")}{Fx.b}{Mv.to(Term.height // 2 - 2, Term.width // 2 - 21)}{Mv.save}')
cls.initbg_data = [randint(0, 100) for _ in range(Term.width * 2)]
cls.initbg_up = Graph(Term.width, Term.height // 2, cls.initbg_colors, cls.initbg_data, invert=True)
cls.initbg_down = Graph(Term.width, Term.height // 2, cls.initbg_colors, cls.initbg_data, invert=False)
if start: return
cls.draw_bg(5)
Draw.buffer("+init!", f'{Mv.restore}{Symbol.ok}\n{Mv.r(Term.width // 2 - 22)}{Mv.save}')
@classmethod @classmethod
def draw_bg(cls, times: int = 5): def draw_bg(cls, times: int = 5):
for _ in range(times): for _ in range(times):
@ -4380,11 +4387,13 @@ def main():
Draw.now(Term.alt_screen, Term.clear, Term.hide_cursor, Term.mouse_on, Term.title("BpyTOP")) Draw.now(Term.alt_screen, Term.clear, Term.hide_cursor, Term.mouse_on, Term.title("BpyTOP"))
Term.echo(False) Term.echo(False)
Term.refresh(force=True) Term.refresh(force=True)
#? Start a thread checking for updates while running init
if CONFIG.update_check: UpdateChecker.run() if CONFIG.update_check: UpdateChecker.run()
#? Draw banner and init status #? Draw banner and init status
if CONFIG.show_init: if CONFIG.show_init and not Init.resized:
Init.success(start=True) Init.start()
#? Load theme #? Load theme
if CONFIG.show_init: if CONFIG.show_init:
@ -4462,7 +4471,6 @@ def main():
else: else:
Init.success() Init.success()
Init.done() Init.done()
Term.refresh() Term.refresh()
Draw.out(clear=True) Draw.out(clear=True)

View File

@ -4,6 +4,7 @@ version = "1.0.16"
description = "Resource monitor that shows usage and stats for processor, memory, disks, network and processes." description = "Resource monitor that shows usage and stats for processor, memory, disks, network and processes."
authors = ["Aristocratos <jakob@qvantnet.com>"] authors = ["Aristocratos <jakob@qvantnet.com>"]
license = "Apache-2.0" license = "Apache-2.0"
include = ["bpytop-themes/*.theme"]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.6" python = "^3.6"