mostly working modal
This commit is contained in:
parent
2c5310fe0d
commit
9c55adb88e
@ -14,6 +14,7 @@ from ..utils import (
|
|||||||
get_text_from_editor,
|
get_text_from_editor,
|
||||||
)
|
)
|
||||||
from .keymodal import KeyModal
|
from .keymodal import KeyModal
|
||||||
|
from .modals import ChoiceModal #DateModal
|
||||||
|
|
||||||
ELLIPSIS = "…"
|
ELLIPSIS = "…"
|
||||||
|
|
||||||
@ -31,9 +32,11 @@ def _enum_preprocessor(enumCls):
|
|||||||
return val
|
return val
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise NotifyValidationError(
|
raise NotifyValidationError(
|
||||||
f"Invalid value. Use: {[s.value for s in enumCls]}"
|
f"Invalid value {val}. Use: {[s.value for s in enumCls]}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return preprocessor
|
||||||
|
|
||||||
|
|
||||||
class TableColumnConfig:
|
class TableColumnConfig:
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -333,15 +336,21 @@ class TableEditor(App):
|
|||||||
if cconf.read_only:
|
if cconf.read_only:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# save cursor before callback, so correct position updates
|
||||||
self._save_cursor()
|
self._save_cursor()
|
||||||
current_value = self.table.get_cell_at(
|
current_value = self.table.get_cell_at(
|
||||||
(self.table.cursor_row, self.table.cursor_column)
|
(self.table.cursor_row, self.table.cursor_column)
|
||||||
)
|
)
|
||||||
if current_value.endswith(ELLIPSIS):
|
|
||||||
self.notify("multi-line text, use (e)dit")
|
if cconf.enum:
|
||||||
return
|
self.push_screen(ChoiceModal(cconf.enum, current_value),
|
||||||
current_value = remove_rich_tag(current_value)
|
self.apply_change)
|
||||||
self._show_input("edit", current_value)
|
elif current_value.endswith(ELLIPSIS):
|
||||||
|
self.action_start_edit()
|
||||||
|
else:
|
||||||
|
# default edit mode
|
||||||
|
current_value = remove_rich_tag(current_value)
|
||||||
|
self._show_input("edit", current_value)
|
||||||
|
|
||||||
def action_start_edit(self):
|
def action_start_edit(self):
|
||||||
cconf = self._active_column_config()
|
cconf = self._active_column_config()
|
||||||
|
54
src/tt/tui/modals.py
Normal file
54
src/tt/tui/modals.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
from textual.screen import ModalScreen
|
||||||
|
from textual.containers import Grid
|
||||||
|
from textual.binding import Binding
|
||||||
|
|
||||||
|
from textual.widgets import RadioSet, RadioButton, Label
|
||||||
|
|
||||||
|
class ChoiceModal(ModalScreen):
|
||||||
|
|
||||||
|
CSS = """
|
||||||
|
ChoiceModal {
|
||||||
|
align: center middle;
|
||||||
|
background: $primary 30%;
|
||||||
|
}
|
||||||
|
ChoiceModal Label {
|
||||||
|
height: 1;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
BINDINGS = [
|
||||||
|
("j", "cursor_down", "Down"),
|
||||||
|
("k", "cursor_up", "Up"),
|
||||||
|
# TODO: get this to work as override
|
||||||
|
Binding("enter", "select", "Select", priority=True),
|
||||||
|
("c", "select", "Select"),
|
||||||
|
("escape", "cancel", "cancel")
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, enum, selected):
|
||||||
|
self._enum = enum
|
||||||
|
self.selected = selected
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def compose(self):
|
||||||
|
yield Label(f"{self._enum.__name__}")
|
||||||
|
yield RadioSet(
|
||||||
|
*[
|
||||||
|
RadioButton(str(e.value), value=self.selected==str(e.value)) for e in self._enum
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def action_cursor_down(self):
|
||||||
|
self.query_one(RadioSet).action_next_button()
|
||||||
|
|
||||||
|
def action_cursor_up(self):
|
||||||
|
self.query_one(RadioSet).action_previous_button()
|
||||||
|
|
||||||
|
def action_select(self):
|
||||||
|
rs = self.query_one(RadioSet)
|
||||||
|
rs.action_toggle_button()
|
||||||
|
pressed = rs.pressed_button
|
||||||
|
self.dismiss(str(pressed.label))
|
||||||
|
|
||||||
|
def action_cancel(self):
|
||||||
|
self.app.pop_screen()
|
Loading…
Reference in New Issue
Block a user