diff --git a/biscuit/core/api/__init__.py b/biscuit/core/api/__init__.py index d421ee71..831a4b99 100644 --- a/biscuit/core/api/__init__.py +++ b/biscuit/core/api/__init__.py @@ -2,15 +2,16 @@ import typing -from biscuit.core.api.editors import Editors - if typing.TYPE_CHECKING: from biscuit.core import App __all__ = ["ExtensionsAPI"] +from biscuit.core.api.editors import Editors from biscuit.core.components import BaseEditor, BaseGame from biscuit.core.components.editors import Languages +from biscuit.core.components.floating.palette.actionset import ActionSet +from biscuit.core.layout.statusbar import SButton from .commands import Commands from .logger import Logger @@ -27,6 +28,7 @@ def __init__(self, base: App) -> None: self.statusbar = self.base.statusbar self.sidebar = self.base.sidebar self.panel = self.base.panel + self.sysinfo = self.base.sysinfo self.editorsmanager = self.base.editorsmanager self.terminalmanager = self.base.terminalmanager self.languageservermanager = self.base.language_server_manager @@ -41,6 +43,9 @@ def __init__(self, base: App) -> None: self.Game = BaseGame self.Editor = BaseEditor + self.SButton = SButton + self.ActionSet = ActionSet + # Enum of supported languages self.LANGUAGES = Languages self.register_comment_prefix = self.base.register_comment_prefix diff --git a/biscuit/core/layout/statusbar/__init__.py b/biscuit/core/layout/statusbar/__init__.py index e21016c2..35c18869 100644 --- a/biscuit/core/layout/statusbar/__init__.py +++ b/biscuit/core/layout/statusbar/__init__.py @@ -19,7 +19,6 @@ from biscuit.core.components.utils import Frame, textutils from .button import SButton, TerminalButton -from .clock import SClock if typing.TYPE_CHECKING: from ...components.editors.texteditor import Text @@ -108,25 +107,17 @@ def __init__(self, master: Root, *args, **kwargs) -> None: # show/hide notifications self.notif = SButton(self, icon="bell", function=self.base.notifications.show, description="No notifications") self.notif.pack(side=tk.RIGHT, padx=(0, 10)) - - # clock - self.clock = SClock(self, text="H:M:S", description="Time") - self.time_actionset = ActionSet( - "Configure clock format", "time:", - [("12 hours", lambda e=None: self.clock.use_24_hour_format(False)), - ("24 hours", lambda e=None: self.clock.use_24_hour_format(True)),], - ) - self.base.palette.register_actionset(lambda: self.time_actionset) - self.clock.change_function(function=self.base.events.change_time_format) - self.clock.set_pack_data(side=tk.RIGHT) - self.clock.show() + + def add_button(self, text: str, icon: str=None, side: str=tk.LEFT, function: typing.Callable=None, description: str=None) -> SButton: + btn = SButton(self, text=text, icon=icon, function=function, description=description) + btn.pack(side=side) + return btn def toggle_terminal(self) -> None: self.base.toggle_terminal() def toggle_editmode(self, state: bool) -> None: if state: - self.clock.show() self.file_type.show() self.eol.show() self.encoding.show() diff --git a/biscuit/core/layout/statusbar/button.py b/biscuit/core/layout/statusbar/button.py index 70cbbf0d..3e7a2c19 100644 --- a/biscuit/core/layout/statusbar/button.py +++ b/biscuit/core/layout/statusbar/button.py @@ -16,10 +16,10 @@ def get_pos(self) -> str: class SButton(Frame): - def __init__(self, master: Statusbar, text: str=None, icon: str=None, function=lambda *_: None, + def __init__(self, master: Statusbar, text: str=None, icon: str=None, function=None, description: str=None, padx: int=5, pady: int=1, *args, **kwargs) -> None: super().__init__(master, padx=padx, pady=pady, *args, **kwargs) - self.function = function + self.function = function or (lambda *_: None) self.bg, self.fg, self.hbg, self.hfg = self.base.theme.layout.statusbar.button.values() self.config(bg=self.bg) diff --git a/biscuit/core/layout/statusbar/clock.py b/biscuit/core/layout/statusbar/clock.py deleted file mode 100644 index 4cae2208..00000000 --- a/biscuit/core/layout/statusbar/clock.py +++ /dev/null @@ -1,20 +0,0 @@ -import time - -from .button import SButton - - -class SClock(SButton): - def __init__(self, *args, **kwargs) -> None: - super().__init__(*args, **kwargs) - self.hour_24_format = True - self.update() - - def update(self) -> None: - time_live = time.strftime("%H:%M:%S" if self.hour_24_format else "%I:%M:%S") - self.text_label.config(text=time_live) - self.after(200, self.update) - - def use_24_hour_format(self, flag: str) -> None: - "Use 24 hour format for clock" - self.hour_24_format = flag - self.update() diff --git a/biscuit/core/utils/events.py b/biscuit/core/utils/events.py index 39ae9a2a..38206145 100644 --- a/biscuit/core/utils/events.py +++ b/biscuit/core/utils/events.py @@ -268,9 +268,6 @@ def show_goto_palette(self, *_) -> None: def change_git_branch(self, *_) -> None: self.base.palette.show('branch:') - def change_time_format(self, *_) -> None: - self.base.palette.show('time:') - def show_run_config_palette(self, command) -> None: self.base.palette.show('runconf:', command) diff --git a/biscuit/core/utils/sysinfo.py b/biscuit/core/utils/sysinfo.py index 2e1f1252..0ae77fb7 100644 --- a/biscuit/core/utils/sysinfo.py +++ b/biscuit/core/utils/sysinfo.py @@ -7,6 +7,8 @@ from dataclasses import dataclass from textwrap import dedent +import psutil + if typing.TYPE_CHECKING: from ... import App @@ -25,6 +27,16 @@ def __init__(self, base: App) -> None: self.processor = platform.processor() self.python_version = sys.version self.tk_version = tk.TclVersion + + def get_current_stats(self) -> str: + """Get current CPU and Memory usage""" + + cpu_percent = psutil.cpu_percent(interval=0) + memory_percent = psutil.virtual_memory().percent + # memory = psutil.virtual_memory() + # total_memory_gb = round(memory.total / (1024**3), 2) + # used_memory_gb = round((memory.total - memory.available) / (1024**3), 2) + return f"CPU: {cpu_percent}% | Mem: {memory_percent}%" def __str__(self) -> None: return dedent(