mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-23 14:51:50 +03:00
Refactor: remove class LabeledInput so it's easy to get at the Inputs
Now that I'm creating the inputs dynamically, it doesn't help to have a class for labeled inputs. And `self._inputs_by_letter[component_letter] = labeled_inputs[-1].query_one(Input)` failed, because it's not mounted yet.
This commit is contained in:
parent
0fdbce1f77
commit
cf979114a9
@ -137,22 +137,6 @@ class ColorGrid(Container):
|
|||||||
# """Called when a color button is clicked."""
|
# """Called when a color button is clicked."""
|
||||||
# self.selected_color = self._color_by_button[event.control]
|
# self.selected_color = self._color_by_button[event.control]
|
||||||
|
|
||||||
class LabeledInput(Container):
|
|
||||||
"""A label and an input field."""
|
|
||||||
|
|
||||||
def __init__(self, label_text: str, value: str | None = None, **kwargs: Any) -> None:
|
|
||||||
"""Initialize the LabeledInput."""
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
self.label_text = label_text
|
|
||||||
self.value = value
|
|
||||||
|
|
||||||
def compose(self) -> list[Widget]:
|
|
||||||
"""Compose the widget."""
|
|
||||||
return [
|
|
||||||
Label(self.label_text, classes="label"),
|
|
||||||
Input(self.value, classes="input"),
|
|
||||||
]
|
|
||||||
|
|
||||||
class LuminosityRamp(Widget):
|
class LuminosityRamp(Widget):
|
||||||
"""A vertical slider to select a luminosity, previewing the color at each luminosity with a gradient."""
|
"""A vertical slider to select a luminosity, previewing the color at each luminosity with a gradient."""
|
||||||
|
|
||||||
@ -291,7 +275,7 @@ class EditColorsDialogWindow(DialogWindow):
|
|||||||
super().__init__(handle_button=self.handle_button, *children, title=title, **kwargs)
|
super().__init__(handle_button=self.handle_button, *children, title=title, **kwargs)
|
||||||
self._color_to_highlight = selected_color
|
self._color_to_highlight = selected_color
|
||||||
self._color_by_button: dict[Button, str] = {}
|
self._color_by_button: dict[Button, str] = {}
|
||||||
# self._inputs_by_letter: dict[str, Input] = {}
|
self._inputs_by_letter: dict[str, Input] = {}
|
||||||
self.handle_selected_color = handle_selected_color
|
self.handle_selected_color = handle_selected_color
|
||||||
|
|
||||||
def handle_button(self, button: Button) -> None:
|
def handle_button(self, button: Button) -> None:
|
||||||
@ -306,7 +290,7 @@ class EditColorsDialogWindow(DialogWindow):
|
|||||||
self.color_grid = ColorGrid(basic_colors)
|
self.color_grid = ColorGrid(basic_colors)
|
||||||
verticals_for_inputs: list[Vertical] = []
|
verticals_for_inputs: list[Vertical] = []
|
||||||
for color_model in ["hsl", "rgb"]:
|
for color_model in ["hsl", "rgb"]:
|
||||||
labeled_inputs: list[LabeledInput] = []
|
input_containers: list[Container] = []
|
||||||
for component_letter in color_model:
|
for component_letter in color_model:
|
||||||
text_with_hotkey: str = {
|
text_with_hotkey: str = {
|
||||||
"h": "Hu&e:",
|
"h": "Hu&e:",
|
||||||
@ -317,9 +301,12 @@ class EditColorsDialogWindow(DialogWindow):
|
|||||||
"b": "Bl&ue:",
|
"b": "Bl&ue:",
|
||||||
}[component_letter]
|
}[component_letter]
|
||||||
text_without_hotkey = text_with_hotkey.replace("&", "")
|
text_without_hotkey = text_with_hotkey.replace("&", "")
|
||||||
labeled_inputs.append(LabeledInput(text_without_hotkey, classes=component_letter))
|
input = Input()
|
||||||
# self._inputs_by_letter[component_letter] = labeled_inputs[-1].query_one(Input)
|
label = Label(text_without_hotkey)
|
||||||
verticals_for_inputs.append(Vertical(*labeled_inputs))
|
container = Container(label, input, classes="input_container")
|
||||||
|
input_containers.append(container)
|
||||||
|
self._inputs_by_letter[component_letter] = input
|
||||||
|
verticals_for_inputs.append(Vertical(*input_containers))
|
||||||
|
|
||||||
self.content.mount(
|
self.content.mount(
|
||||||
Horizontal(
|
Horizontal(
|
||||||
|
@ -363,16 +363,16 @@ EditColorsDialogWindow Vertical {
|
|||||||
height: auto;
|
height: auto;
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
EditColorsDialogWindow LabeledInput {
|
EditColorsDialogWindow .input_container {
|
||||||
width: 16;
|
width: 16;
|
||||||
height: auto;
|
height: auto;
|
||||||
margin-bottom: 1;
|
margin-bottom: 1;
|
||||||
layout: horizontal;
|
layout: horizontal;
|
||||||
}
|
}
|
||||||
EditColorsDialogWindow LabeledInput Input {
|
EditColorsDialogWindow .input_container Input {
|
||||||
width: 8;
|
width: 8;
|
||||||
}
|
}
|
||||||
EditColorsDialogWindow LabeledInput Label {
|
EditColorsDialogWindow .input_container Label {
|
||||||
width: 1fr;
|
width: 1fr;
|
||||||
height: auto;
|
height: auto;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
Loading…
Reference in New Issue
Block a user