Skip to content

Commit f269544

Browse files
committed
feat: add labels to all the inputs fields
1 parent a689f34 commit f269544

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

src/edit_python_pe/main.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,46 @@
2424
load_file_into_form)
2525

2626

27+
class LabeledInput(Vertical):
28+
29+
DEFAULT_CSS = """
30+
LabeledInput {
31+
height: auto;
32+
33+
}
34+
LabeledInput Static {
35+
width: 25%;
36+
37+
}
38+
LabeledInput Input {
39+
width: 100%;
40+
}
41+
"""
42+
43+
def __init__(
44+
self, label: str, placeholder: str = "", value: str = "", **kwargs
45+
):
46+
super().__init__(**kwargs)
47+
self.label = label
48+
self.placeholder = placeholder
49+
self._value = value
50+
51+
def compose(self) -> ComposeResult:
52+
yield Static(self.label, classes="label")
53+
yield Input(
54+
id="input", placeholder=self.placeholder, value=self._value
55+
)
56+
57+
@property
58+
def value(self):
59+
return self._value
60+
61+
@value.setter
62+
def value(self, v: str):
63+
self._value = v
64+
self.query_one(selector="#input").value = v
65+
66+
2767
class SocialEntry(Horizontal):
2868
DEFAULT_CSS = """
2969
SocialEntry Select {
@@ -129,10 +169,18 @@ def on_mount(self) -> None:
129169

130170
# 2) Build the form portion, hidden at first
131171
self.form_header = Static(FORM_HEADER, classes="header")
132-
self.name_input = Input(placeholder=PLACEHOLDER_NAME)
133-
self.email_input = Input(placeholder=PLACEHOLDER_EMAIL)
134-
self.city_input = Input(placeholder=PLACEHOLDER_CITY)
135-
self.homepage_input = Input(placeholder=PLACEHOLDER_HOMEPAGE)
172+
self.name_input = LabeledInput(
173+
f"{PLACEHOLDER_NAME}:", placeholder=PLACEHOLDER_NAME
174+
)
175+
self.email_input = LabeledInput(
176+
f"{PLACEHOLDER_EMAIL}:", placeholder=PLACEHOLDER_EMAIL
177+
)
178+
self.city_input = LabeledInput(
179+
f"{PLACEHOLDER_CITY}:", placeholder=PLACEHOLDER_CITY
180+
)
181+
self.homepage_input = LabeledInput(
182+
f"{PLACEHOLDER_HOMEPAGE}:", placeholder=PLACEHOLDER_HOMEPAGE
183+
)
136184

137185
self.who_area = TextArea()
138186
self.python_area = TextArea()
@@ -233,7 +281,7 @@ def clear_form(self) -> None:
233281
def on_list_view_selected(self, event: ListView.Selected) -> None:
234282
"""User clicked on a file in the list. Parse it into the form fields."""
235283
item_text_widget = event.item.children[0]
236-
filename = item_text_widget.renderable
284+
filename = item_text_widget.content
237285
self.current_file = filename
238286

239287
self.clear_form()

0 commit comments

Comments
 (0)