Skip to content

Commit

Permalink
fix: remove current_theme property from tui (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Nov 18, 2024
1 parent d8db241 commit c6499eb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
16 changes: 8 additions & 8 deletions dooit/ui/api/api_components/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@


if TYPE_CHECKING: # pragma: no cover
from dooit.ui.tui import Dooit
from dooit.ui.api.dooit_api import DooitAPI


class VarManager(ApiComponent):
def __init__(self, app: "Dooit") -> None:
def __init__(self, api: "DooitAPI") -> None:
super().__init__()
self.app = app
self.api = api
self._show_confirm = True

@property
Expand All @@ -29,27 +29,27 @@ def show_confirm(self, value: bool):

@property
def mode(self) -> str:
return self.app.current_mode
return self.api.app._mode

@property
def theme(self) -> DooitThemeBase:
return self.app.current_theme
return self.api.css.theme

@property
def workspaces_tree(self) -> WorkspacesTree:
return self.app.query_one(WorkspacesTree)
return self.api.app.query_one(WorkspacesTree)

@property
def current_workspace(self) -> Optional[Workspace]:
tree = self.app.workspace_tree
tree = self.api.vars.workspaces_tree
if tree.highlighted is None:
return None

return tree.current_model

@property
def todos_tree(self) -> Optional[TodosTree]:
todo_switcher = self.app.query_one(
todo_switcher = self.api.app.query_one(
"#todo_switcher", expect_type=ContentSwitcher
)
if todo_switcher.visible_content and isinstance(
Expand Down
2 changes: 1 addition & 1 deletion dooit/ui/api/dooit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, app: "Dooit") -> None:
self.layouts = LayoutManager(self.app)
self.formatter = Formatter(self)
self.bar = BarManager(self)
self.vars = VarManager(self.app)
self.vars = VarManager(self)
self.dashboard = DashboardManager(self.app)

self.css.refresh_css()
Expand Down
6 changes: 1 addition & 5 deletions dooit/ui/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from textual import on
from textual.app import App
from textual.binding import Binding

from dooit.api.theme import DooitThemeBase

from dooit.ui.api.events import ModeChanged, DooitEvent, ModeType, Startup, _QuitApp
from dooit.ui.api.events.events import ShutDown
from dooit.ui.widgets import BarSwitcher
Expand Down Expand Up @@ -73,10 +73,6 @@ def bar_switcher(self) -> BarSwitcher:
def get_mode(self) -> ModeType:
return self._mode

@property
def current_theme(self) -> DooitThemeBase:
return self.api.css.theme

async def poll(self): # pragma: no cover
def refresh_all_trees():
trees = self.query(ModelTree)
Expand Down
6 changes: 3 additions & 3 deletions dooit/utils/css_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
theme: DooitThemeBase = DooitThemeBase(),
cache_path: Path = dooit_cache_path,
):
self.theme = theme
self.theme: DooitThemeBase = theme
self.cache_path = cache_path
self.stylesheets: Path = cache_path / "stylesheets"
self.css_file: Path = cache_path / "dooit.tcss"
Expand Down Expand Up @@ -59,14 +59,14 @@ def refresh_css(self):
self.write(css)

def add_theme(self, theme: Type[DooitThemeBase]):
self.themes[theme._name] = theme
self.themes[theme._name] = theme()
self.refresh_css()

def set_theme(self, theme: Union[str, Type[DooitThemeBase]]):
if isinstance(theme, str):
self.theme = self.themes.get(theme, DooitThemeBase)
else:
self.theme = theme
self.theme = theme()

self.refresh_css()

Expand Down
18 changes: 10 additions & 8 deletions dooit/utils/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@subscribe(ModeChanged)
def get_mode(api: DooitAPI, event: ModeChanged):
theme = api.app.current_theme
theme = api.vars.theme
mode = event.mode

MODES = {
Expand All @@ -32,7 +32,7 @@ def get_mode(api: DooitAPI, event: ModeChanged):

@timer(1)
def get_clock(api: DooitAPI):
theme = api.app.current_theme
theme = api.vars.theme
time = datetime.now().strftime("%H:%M:%S")
return Text(
f" {time} ",
Expand All @@ -45,7 +45,7 @@ def get_clock(api: DooitAPI):

@subscribe(Startup)
def get_user(api: DooitAPI, _: Startup):
theme = api.app.current_theme
theme = api.vars.theme
try:
username = os.getlogin()
except OSError:
Expand All @@ -65,17 +65,19 @@ def get_user(api: DooitAPI, _: Startup):
# Todo formatters


def todo_status_formatter(status: str, todo: Todo, api: DooitAPI):
def todo_status_formatter(status: str, _: Todo, api: DooitAPI):
text = "o"
color = api.app.current_theme.yellow
theme = api.vars.theme

color = theme.yellow

if status == "completed":
text = "x"
color = api.app.current_theme.green
color = theme.green

if status == "overdue":
text = "!"
color = api.app.current_theme.red
color = theme.red

return Text(text, style=Style(color=color, bold=True))

Expand All @@ -96,7 +98,7 @@ def todo_urgency_formatter(urgency, _, api: DooitAPI):
if urgency == 0:
return ""

theme = api.app.current_theme
theme = api.vars.theme
colors = {
1: theme.green,
2: theme.yellow,
Expand Down

0 comments on commit c6499eb

Please sign in to comment.