Skip to content

Commit

Permalink
fix: Statusbar clock is removed and now available as extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Apr 1, 2024
1 parent 046f2aa commit 2a1d0c5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 41 deletions.
9 changes: 7 additions & 2 deletions biscuit/core/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
19 changes: 5 additions & 14 deletions biscuit/core/layout/statusbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions biscuit/core/layout/statusbar/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions biscuit/core/layout/statusbar/clock.py

This file was deleted.

3 changes: 0 additions & 3 deletions biscuit/core/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions biscuit/core/utils/sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dataclasses import dataclass
from textwrap import dedent

import psutil

if typing.TYPE_CHECKING:
from ... import App

Expand All @@ -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(
Expand Down

0 comments on commit 2a1d0c5

Please sign in to comment.