From 6398735d8166573034ab7028fc10491350a9bb14 Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Tue, 24 Sep 2024 19:49:33 +0200 Subject: [PATCH] Add editors --- .../shiny_express_all_new_style.py | 2 + pytabulator/editors.py | 65 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/docs/examples/getting_started/shiny_express_all_new_style.py b/docs/examples/getting_started/shiny_express_all_new_style.py index 99e3a43..97500ad 100644 --- a/docs/examples/getting_started/shiny_express_all_new_style.py +++ b/docs/examples/getting_started/shiny_express_all_new_style.py @@ -4,6 +4,7 @@ from pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator from pytabulator.utils import create_columns from pytabulator.formatters import ProgressFormatter, TickCrossFormatter +from pytabulator.editors import ListEditor from shiny import reactive, render from shiny.express import input, ui @@ -83,6 +84,7 @@ def tabulator(): .set_options(editTriggerEvent="dblclick") .set_column_formatter("Fare", ProgressFormatter(), hoz_align="left") .set_column_formatter("Survived", TickCrossFormatter(), hoz_align="center") + .set_column_editor("Sex", ListEditor()) ) diff --git a/pytabulator/editors.py b/pytabulator/editors.py index 50b71e3..47ab6c8 100644 --- a/pytabulator/editors.py +++ b/pytabulator/editors.py @@ -1,16 +1,20 @@ from pydantic import BaseModel -from typing import Optional +from typing import Optional, Literal from ._utils import as_camel_dict_recursive from enum import Enum class Editors(Enum): - NUMBER = "number" INPUT = "input" + TEXTAREA = "textarea" + NUMBER = "number" + RANGE = "range" + TICK_CROSS = "tickCross" STAR = "star" PROGRESS = "progress" + LIST = "list" class Editor(BaseModel): @@ -22,21 +26,69 @@ def to_dict(self) -> dict: return as_camel_dict_recursive(self.model_dump(exclude_none=True)) +class InputEditor(Editor): + search: Optional[bool] = None + mask: Optional[str] = None + select_contents: Optional[bool] = None + element_attributes: Optional[dict] = None + + @property + def name(self) -> str: + return Editors.INPUT.value + + +class TextareaEditor(Editor): + mask: Optional[str] = None + select_contents: Optional[bool] = None + vertical_navigation: Literal["hybrid", "editor", "table"] = None + shift_enter_submit: Optional[bool] = None + + @property + def name(self) -> str: + return Editors.TEXTAREA.value + + class NumberEditor(Editor): min: Optional[float] = None max: Optional[float] = None step: Optional[float] = None + element_attributes: Optional[dict] = None + mask: Optional[str] = None + select_contents: Optional[bool] = None + vertical_navigation: Literal["editor", "table"] = None @property def name(self) -> str: return Editors.NUMBER.value +class RangeEditor(Editor): + min: Optional[float] = None + max: Optional[float] = None + step: Optional[float] = None + element_attributes: Optional[dict] = None + + @property + def name(self) -> str: + return Editors.RANGE.value + + +class TickCrossEditor(Editor): + true_value: Optional[str] = None + false_value: Optional[str] = None + element_attributes: Optional[dict] = None + + @property + def name(self) -> str: + return Editors.TICK_CROSS.value + + class StarEditor(Editor): @property def name(self) -> str: return Editors.STAR.value + class ProgressEditor(Editor): min: Optional[float] = None max: Optional[float] = None @@ -45,3 +97,12 @@ class ProgressEditor(Editor): @property def name(self) -> str: return Editors.PROGRESS.value + + +class ListEditor(Editor): + values: Optional[list] = None + values_lookup: Optional[bool] = True + + @property + def name(self) -> str: + return Editors.LIST.value