Skip to content

Commit

Permalink
cleanup themes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanCarloMachado committed Dec 8, 2024
1 parent 6763d14 commit f8dec68
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 57 deletions.
15 changes: 15 additions & 0 deletions python_search/apps/theme/BaseTheme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BaseTheme:
colors = None

def get_colorful(self):
import colorful as cf

cf.update_palette(self.colors)
return cf

def __init__(self):
self.backgroud = self.colors["backgroud"]
self.text = self.colors["text"]

self.font_size = 19
self.font = "SF Pro"
42 changes: 42 additions & 0 deletions python_search/apps/theme/ThemeSelector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from python_search.apps.theme.theme import D2Theme, DesertTheme, NewLight


import datetime
import os


class ThemeSelector:
"""
A class that selects theme.
If the user has a theme file in their home directory, it will use that theme.
Otherwise, it will use the NewLight theme during the day and the Desert theme at night.
Methods:
get_theme(): Returns the theme to use based on the current time.
"""

_HOUR_FROM = 8
_HOUR_TO = 15

def get_theme(self) -> str:
"""
Returns the theme to use based on the current time.
Returns:
str: The selected theme.
"""
import os

home = os.environ["HOME"]
if os.path.exists(home + "/.python_search/theme"):
theme = open(home + "/.python_search/theme").read().strip()
if theme == "Desert":
return DesertTheme()
elif theme == "D2":
return D2Theme()

now = datetime.datetime.now()
if now.hour >= self._HOUR_FROM and now.hour <= self._HOUR_TO:
return NewLight()
else:
return DesertTheme()
Empty file.
57 changes: 2 additions & 55 deletions python_search/theme.py → python_search/apps/theme/theme.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,5 @@
import datetime


class ThemeSelector:
"""
A class that selects theme.
If the user has a theme file in their home directory, it will use that theme.
Otherwise, it will use the NewLight theme during the day and the Desert theme at night.
Methods:
get_theme(): Returns the theme to use based on the current time.
"""

_HOUR_FROM = 8
_HOUR_TO = 17

def get_theme(self) -> str:
"""
Returns the theme to use based on the current time.
Returns:
str: The selected theme.
"""
import os

home = os.environ["HOME"]
if os.path.exists(home + "/.python_search/theme"):
theme = open(home + "/.python_search/theme").read().strip()
if theme == "Desert":
return DesertTheme()
elif theme == "D2":
return D2Theme()

now = datetime.datetime.now()
if now.hour >= self._HOUR_FROM and now.hour <= self._HOUR_TO:
return NewLight()
else:
return DesertTheme()


class BaseTheme:
colors = None

def get_colorful(self):
import colorful as cf

cf.update_palette(self.colors)
return cf

def __init__(self):
self.backgroud = self.colors["backgroud"]
self.text = self.colors["text"]

self.font_size = 19
self.font = "SF Pro"

from python_search.apps.theme.BaseTheme import BaseTheme

class NewLight(BaseTheme):
def __init__(self):
Expand Down Expand Up @@ -117,4 +63,5 @@ def __init__(self):


def get_current_theme() -> BaseTheme:
from python_search.apps.theme.ThemeSelector import ThemeSelector
return ThemeSelector().get_theme()
2 changes: 1 addition & 1 deletion python_search/search/search_ui/kitty_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def launch(self) -> None:

def get_kitty_complete_cmd(self) -> str:
terminal = KittyTerminal()
from python_search.theme import get_current_theme
from python_search.apps.theme.theme import get_current_theme
theme = get_current_theme()
return f"""{self.get_kitty_cmd()} \
--title {self._title} \
Expand Down
2 changes: 1 addition & 1 deletion python_search/search/search_ui/terminal_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from python_search.search.search_ui.search_actions import Actions
from python_search.search.search_ui.search_utils import setup_datadog

from python_search.theme import get_current_theme
from python_search.apps.theme.theme import get_current_theme
from python_search.host_system.system_paths import SystemPaths
from getch import getch

Expand Down

0 comments on commit f8dec68

Please sign in to comment.