Skip to content

Commit

Permalink
Merge pull request #55 from DuckBoss/duckboss/gui-themes
Browse files Browse the repository at this point in the history
JJMB-26: Implemented GUI themes and commands
  • Loading branch information
Jason Jerome authored Apr 25, 2023
2 parents 75f8ec3 + 4f379f3 commit 3867c76
Show file tree
Hide file tree
Showing 17 changed files with 603 additions and 155 deletions.
5 changes: 5 additions & 0 deletions config/config_template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ safe_mode_plugins = []


### GUI Settings ###
[settings.gui]
enable = true
themes_path = "config/gui_theme.toml"
selected_theme = "dark" # Default themes available: "light", "dark", "highcontrast"

[output.gui]
enable = true

Expand Down
8 changes: 8 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SysArgs:
SYS_ENV_FILE: str = "env_file"
SYS_CONFIG_FILE: str = "config_file"
SYS_LOG_CONFIG_FILE: str = "log_config_file"
SYS_GUI_THEMES_FILE: str = "gui_themes_file"
SYS_DB_LOCALDBPATH: str = "local_database_path"
SYS_DB_LOCALDBDIALECT: str = "local_database_dialect"
SYS_DB_LOCALDBDRIVER: str = "local_database_driver"
Expand All @@ -82,6 +83,7 @@ class SysArgs:
# Config Constants
DEFAULT_PATH_CONFIG_FILE: str = "config/config.toml"
DEFAULT_PATH_LOGGING_CONFIG_FILE: str = "config/logging.toml"
DEFAULT_PATH_GUI_THEMES_FILE: str = "config/gui_themes.toml"


class DefaultPermissionGroups:
Expand Down Expand Up @@ -166,6 +168,7 @@ class MumimoCfgSections:
SETTINGS_MEDIA_AUDIODUCKING: str = f"{SETTINGS_MEDIA}.audio_ducking"
SETTINGS_MEDIA_YOUTUBEDL: str = f"{SETTINGS_MEDIA}.youtube_dl"
SETTINGS_PLUGINS: str = f"{SETTINGS}.plugins"
SETTINGS_GUI: str = f"{SETTINGS}.gui"

OUTPUT: str = "output"
OUTPUT_GUI: str = f"{OUTPUT}.gui"
Expand Down Expand Up @@ -225,6 +228,11 @@ class PLUGINS:
DISABLED_PLUGINS: str = f"{MumimoCfgSections.SETTINGS_PLUGINS}.disabled_plugins"
SAFE_MODE_PLUGINS: str = f"{MumimoCfgSections.SETTINGS_PLUGINS}.safe_mode_plugins"

class GUI:
ENABLE: str = f"{MumimoCfgSections.SETTINGS_GUI}.enable"
THEMES_PATH: str = f"{MumimoCfgSections.SETTINGS_GUI}.themes_path"
SELECTED_THEME: str = f"{MumimoCfgSections.SETTINGS_GUI}.selected_theme"

class OUTPUT:
class GUI:
ENABLE: str = f"{MumimoCfgSections.OUTPUT_GUI}.enable"
Expand Down
5 changes: 5 additions & 0 deletions src/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def __init__(self, msg: str, logger: Optional[logging.Logger] = None) -> None:
super().__init__(msg, logger)


class GUIError(LoggedException):
def __init__(self, msg: str, logger: Optional[logging.Logger] = None) -> None:
super().__init__(msg, logger)


class ServiceError(LoggedException):
def __init__(self, msg: str, logger: Optional[logging.Logger] = None) -> None:
super().__init__(msg, logger=logger)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/frameworks/gui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TextTypes(Enum):
TITLE = 0
HEADER = 1
BODY = 2
TITLE = "title"
HEADER = "header"
BODY = "body"
44 changes: 38 additions & 6 deletions src/lib/frameworks/gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import logging

from typing import Optional, Union, List
from typing import Optional, Union, List, TYPE_CHECKING
from .constants import TextTypes
from .utility import FontModifiers, AlignmentModifiers
from ....utils import mumble_utils
from ....settings import settings
from ....constants import MumimoCfgFields
from ....exceptions import GUIError

if TYPE_CHECKING:
from ....config import Config


logger = logging.getLogger(__name__)
Expand All @@ -18,11 +24,12 @@ class ContentBox:
_box_close: str
_box_rows: List[str]

def __init__(self, settings: Optional["Settings"] = None) -> None:
def __init__(self, settings: Optional["Settings"] = None, **kwargs) -> None:
if settings is not None:
self.settings = settings
else:
self.settings = self.Settings()
self.settings.update(**kwargs)
self.is_open = False
self._box_open = ""
self._box_close = ""
Expand Down Expand Up @@ -71,29 +78,54 @@ def compile(self) -> str:
return _msg

class Settings:
text_type: TextTypes = TextTypes.HEADER
text_type: TextTypes = TextTypes.BODY
text_color: str = "yellow"
text_align: str = "center"

table_align: str = "center"
table_align: str = "left"
table_bg_color: str = "black"

row_align: str = "left"
row_bg_color: str = "black"

def __init__(self, **kwargs) -> None:
self._from_config()
self.update(**kwargs)

def _from_config(self) -> None:
_themes: Optional["Config"] = settings.configs.get_gui_themes()
if not _themes:
raise GUIError("Unable to load gui themes: could not retrieve gui themes from settings.")
_config: Optional["Config"] = settings.configs.get_mumimo_config()
if not _config:
raise GUIError("Unable to load gui themes: mumimo config could not be retrieved from settings.")

_selected_theme = _config.get(MumimoCfgFields.SETTINGS.GUI.SELECTED_THEME, None)
_theme = _themes.get(_selected_theme, None)
if not _selected_theme or not _theme:
_selected_theme = "light"
logger.warning("Unable to find selected gui theme, falling back to default 'light' theme.")

_theme = _themes.get(_selected_theme, None)
if not _theme:
raise GUIError(f"Unable to find gui theme: [{_selected_theme}], falling back to default 'light' theme.", logger=logger)

self.update(**_theme)

def update(self, **kwargs) -> "GUIFramework.ContentBox.Settings":
self.text_type = kwargs.get("text_type", self.text_type)
_text_type = kwargs.get("text_type", self.text_type)
if not isinstance(_text_type, TextTypes):
_text_type = TextTypes(_text_type)
self.text_type = _text_type

self.text_color = kwargs.get("text_color", self.text_color)
self.text_align = kwargs.get("text_align", self.text_align)

self.table_align = kwargs.get("table_align", self.table_align)
self.table_bg_color = kwargs.get("table_bg_color", self.table_bg_color)

self.row_align = kwargs.get("row_align", self.row_align)
self.row_bg_color = kwargs.get("bg_color", self.row_bg_color)
self.row_bg_color = kwargs.get("row_bg_color", self.row_bg_color)
return self

@staticmethod
Expand Down
5 changes: 4 additions & 1 deletion src/lib/frameworks/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ def verify_parameters(self, func_name: str, data: "Command") -> Optional[Dict[st
return
_compiled_parameters: Optional[Dict[str, Any]] = _compiled_result.result
if _compiled_parameters is None:
GUIFramework.gui(f"'{data.command}' command error: parameters failed to compile.")
GUIFramework.gui(
f"'{data.command}' command error: parameters failed to compile.",
target_users=mumble_utils.get_user_by_id(data.actor),
)
return
return _compiled_parameters

Expand Down
Loading

0 comments on commit 3867c76

Please sign in to comment.