Skip to content

Commit

Permalink
Merge pull request #25 from ubopod/stack
Browse files Browse the repository at this point in the history
remove current_application and current_menu from MenuWidget and keep everything in \"stack\"
  • Loading branch information
sassanh authored Feb 4, 2024
2 parents 1d6fc89 + d7846fb commit 8239390
Show file tree
Hide file tree
Showing 16 changed files with 602 additions and 296 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## Version 0.9.1

- hotfix: remove debug background rectangle

## Version 0.9.0

- refactor: remove `current_application` and `current_menu` from `MenuWidget`, just
keep them as a proxy for the top item of the `stack`
- refactor: clean subscriptions in different levels of screen, widget and item
- feat: allow action items to return subscribable menus
- feat: add `logger` and log subscriptions

## Version 0.8.0

- feat: add a mechanism to sync properties with subscribable values (defined in python-redux).
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ubo-gui"
version = "0.8.0"
version = "0.9.1"
description = "GUI sdk for Ubo Pod"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion ubo_gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

Factory.register('AnimatedSlider', module='ubo_gui.animated_slider')
Factory.register('GaugeWidget', module='ubo_gui.gauge')
Factory.register('ItemWidget', module='ubo_gui.menu.item_widget')
Factory.register('ItemWidget', module='ubo_gui.menu.widgets.item_widget')
Factory.register('MenuWidget', module='ubo_gui.menu')
Factory.register('NotificationWidget', module='ubo_gui.notification')
Factory.register('PromptWidget', module='ubo_gui.prompt')
Expand Down
3 changes: 2 additions & 1 deletion ubo_gui/animated_slider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def on_max(self: AnimatedSlider, *largs: float) -> None:

def on_animated_value(
self: AnimatedSlider,
_instance: AnimatedSlider,
_: AnimatedSlider,
new_value: float,
) -> None:
"""Handle the `animated_value` property being set to a new value.
Expand All @@ -60,5 +60,6 @@ def on_animated_value(
Arguments:
---------
new_value: The new value that the `animated_value` property is being set to.
"""
Animation(value=new_value, duration=0.2).start(self)
69 changes: 69 additions & 0 deletions ubo_gui/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ruff: noqa: D100, D101, D102, D103, D104, D107
from __future__ import annotations

import logging
import sys

logger = logging.getLogger('ubo-gui')
logger.propagate = False


class ExtraFormatter(logging.Formatter):
def_keys = (
'name',
'msg',
'args',
'levelname',
'levelno',
'pathname',
'filename',
'module',
'exc_info',
'exc_text',
'stack_info',
'lineno',
'funcName',
'created',
'msecs',
'relativeCreated',
'thread',
'threadName',
'processName',
'process',
'message',
)

def format(self: ExtraFormatter, record: logging.LogRecord) -> str:
string = super().format(record)
extra = {k: v for k, v in record.__dict__.items() if k not in self.def_keys}
if len(extra) > 0:
string += ' - extra: ' + str(extra)

return string


def add_stdout_handler(level: int = logging.DEBUG) -> None:
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(level)
stdout_handler.setFormatter(
ExtraFormatter(
'%(created)f [%(levelname)s] %(message)s',
'%Y-%m-%d %H:%M:%S',
),
)
logger.addHandler(stdout_handler)


def add_file_handler(level: int = logging.DEBUG) -> None:
file_handler = logging.FileHandler('ubo-gui.log')
file_handler.setLevel(level)
file_handler.setFormatter(
ExtraFormatter(
'%(created)f [%(levelname)s] %(message)s',
'%Y-%m-%d %H:%M:%S',
),
)
logger.addHandler(file_handler)


__all__ = ('logger', 'add_stdout_handler', 'add_file_handler')
Loading

0 comments on commit 8239390

Please sign in to comment.