Skip to content

feat: add calculator widget - #1182

Open
mihaf-a wants to merge 2 commits into
amnweb:mainfrom
mihaf-a:feat/calculator-widget
Open

mihaf-a wants to merge 2 commits into
amnweb:mainfrom
mihaf-a:feat/calculator-widget

Conversation

@mihaf-a

@mihaf-a mihaf-a commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

Adds a new calculator widget that opens a full calculator in a PopupWidget when clicked.

Features

  • Basic arithmetic: +, -, *, / with AST-based safe evaluation (no eval)
  • Percent (%), sign toggle, backspace, clear (AC)
  • Parentheses via keyboard input
  • Full keyboard support while popup is open (digits, operators, Enter, Backspace, Esc)
  • Divide-by-zero and invalid-expression error handling
  • Configurable popup: blur, round_corners, border_color, alignment, direction, offset_top, offset_left, width
  • Documented in docs/widgets/(Widget)-Calculator.md with styling example

Files changed

  • src/core/widgets/yasb/calculator.py — widget implementation
  • src/core/validation/widgets/yasb/calculator.py — Pydantic validation schema
  • docs/widgets/(Widget)-Calculator.md — documentation
  • docs/_Sidebar.md — sidebar link

Testing

  • ruff format and ruff check pass
  • Safe-eval unit tests pass (arithmetic, unary minus, parentheses, divide-by-zero)
  • Validation model: defaults, extra-field rejection verified
  • Widget registers as yasb.calculator.CalculatorWidget in the widget registry
  • schema.json regenerated locally and includes CalculatorEntry/CalculatorConfig

AI Disclosure: A significant portion of code was generated by AI (namely by an Opencode Agent). However, the code has been thoroughly reviewed manually and corrected to make sure there are no mistakes or errors.

image

Add a calculator widget that opens a popup calculator on click.

- Basic arithmetic: +, -, *, / with AST-based safe evaluation
- Percent, sign toggle (±), backspace, parentheses (keyboard)
- Full keyboard input while popup is open
- Configurable popup (blur, corners, alignment, direction, width)
- Documented in docs/widgets/(Widget)-Calculator.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant