Skip to content

Commit cc8f7dc

Browse files
authored
put all strings into a separate module (strings.py), fixes #12 (#21)
1 parent aa29fa4 commit cc8f7dc

File tree

3 files changed

+168
-88
lines changed

3 files changed

+168
-88
lines changed

src/edit_python_pe/main.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
from textual.widgets import (Button, Input, ListItem, ListView, Select, Static,
99
TextArea)
1010

11+
from .strings import (BUTTON_ADD, BUTTON_ADD_ALIAS, BUTTON_ADD_SOCIAL,
12+
BUTTON_BACK, BUTTON_DELETE, BUTTON_QUIT, BUTTON_SAVE,
13+
FORM_HEADER, LIST_TITLE, MESSAGE_EXIT, MESSAGE_QUIT,
14+
PLACEHOLDER_ALIAS, PLACEHOLDER_CITY, PLACEHOLDER_EMAIL,
15+
PLACEHOLDER_HOMEPAGE, PLACEHOLDER_NAME,
16+
PLACEHOLDER_SOCIAL_URL, SECTION_ALIASES, SECTION_AVAIL,
17+
SECTION_CONTRIB, SECTION_PYTHON, SECTION_SOCIAL,
18+
SECTION_WHO)
1119
from .utils import (build_md_content, create_pr, fork_repo, get_repo,
1220
load_file_into_form)
1321

@@ -38,12 +46,12 @@ def compose(self) -> ComposeResult:
3846

3947
def on_mount(self) -> None:
4048
# 1) Build the list portion
41-
self.list_title = Static("Archivos en 'blog/members':")
49+
self.list_title = Static(LIST_TITLE)
4250
self.list_view = ListView()
43-
self.quit_list_button = Button("Salir", id="quit_list")
51+
self.quit_list_button = Button(BUTTON_QUIT, id="quit_list")
4452

4553
self.list_container.mount(self.list_title)
46-
self.add_list_button = Button("Añadir", id="add_list")
54+
self.add_list_button = Button(BUTTON_ADD, id="add_list")
4755
self.list_container.mount(self.list_view)
4856
self.list_container.mount(self.add_list_button)
4957
self.list_container.mount(self.quit_list_button)
@@ -56,11 +64,11 @@ def on_mount(self) -> None:
5664
self.list_view.append(ListItem(Static(basename)))
5765

5866
# 2) Build the form portion, hidden at first
59-
self.form_header = Static("Formulario de Miembro", classes="header")
60-
self.name_input = Input(placeholder="Nombre")
61-
self.email_input = Input(placeholder="Correo electrónico")
62-
self.city_input = Input(placeholder="Ciudad")
63-
self.homepage_input = Input(placeholder="Página personal")
67+
self.form_header = Static(FORM_HEADER, classes="header")
68+
self.name_input = Input(placeholder=PLACEHOLDER_NAME)
69+
self.email_input = Input(placeholder=PLACEHOLDER_EMAIL)
70+
self.city_input = Input(placeholder=PLACEHOLDER_CITY)
71+
self.homepage_input = Input(placeholder=PLACEHOLDER_HOMEPAGE)
6472

6573
self.who_area = TextArea()
6674
self.python_area = TextArea()
@@ -69,48 +77,42 @@ def on_mount(self) -> None:
6977

7078
self.social_container = Vertical()
7179
self.alias_container = Vertical()
72-
self.add_social_button = Button("Agregar Red Social", id="add_social")
73-
self.add_alias_button = Button("Agregar Alias", id="add_alias")
80+
self.add_social_button = Button(BUTTON_ADD_SOCIAL, id="add_social")
81+
self.add_alias_button = Button(BUTTON_ADD_ALIAS, id="add_alias")
7482

75-
self.save_button = Button("Guardar", id="save")
76-
self.back_button = Button("Atrás", id="back")
77-
self.quit_button = Button("Salir", id="quit")
83+
self.save_button = Button(BUTTON_SAVE, id="save")
84+
self.back_button = Button(BUTTON_BACK, id="back")
85+
self.quit_button = Button(BUTTON_QUIT, id="quit")
7886

7987
# 3) Mount them in the form container
8088
self.form_container.mount(self.form_header)
8189
self.form_container.mount(self.name_input)
8290
self.form_container.mount(self.email_input)
8391

84-
self.form_container.mount(
85-
Static("Redes Sociales", classes="subheader")
86-
)
92+
self.form_container.mount(Static(SECTION_SOCIAL, classes="subheader"))
8793
self.form_container.mount(self.social_container)
8894
self.form_container.mount(self.add_social_button)
8995

90-
self.form_container.mount(Static("Aliases", classes="subheader"))
96+
self.form_container.mount(Static(SECTION_ALIASES, classes="subheader"))
9197
self.form_container.mount(self.alias_container)
9298
self.form_container.mount(self.add_alias_button)
9399

94100
self.form_container.mount(self.city_input)
95101
self.form_container.mount(self.homepage_input)
96-
self.form_container.mount(
97-
Static("¿Quién eres y a qué te dedicas?", classes="subheader")
98-
)
102+
self.form_container.mount(Static(SECTION_WHO, classes="subheader"))
99103
self.form_container.mount(self.who_area)
100-
self.form_container.mount(
101-
Static("¿Cómo programas en Python?", classes="subheader")
102-
)
104+
self.form_container.mount(Static(SECTION_PYTHON, classes="subheader"))
103105
self.form_container.mount(self.python_area)
104106
self.form_container.mount(
105107
Static(
106-
"¿Tienes algún aporte a la comunidad de Python?",
108+
SECTION_CONTRIB,
107109
classes="subheader",
108110
)
109111
)
110112
self.form_container.mount(self.contributions_area)
111113
self.form_container.mount(
112114
Static(
113-
"¿Estás disponible para hacer mentoring, consultorías, charlas?",
115+
SECTION_AVAIL,
114116
classes="subheader",
115117
)
116118
)
@@ -177,7 +179,7 @@ def on_list_view_selected(self, event: ListView.Selected) -> None:
177179
def on_button_pressed(self, event: Button.Pressed) -> None:
178180
bid = event.button.id
179181
if bid == "quit_list":
180-
self.exit("¡Hasta la próxima!")
182+
self.exit(message=MESSAGE_EXIT)
181183
elif bid == "add_social":
182184
self.add_social_entry()
183185
elif bid == "add_alias":
@@ -193,7 +195,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
193195
self.clear_form()
194196
self.show_list()
195197
elif bid == "quit":
196-
self.exit("Saliendo de la aplicación.")
198+
self.exit(MESSAGE_QUIT)
197199
elif bid and bid.startswith("delete_social_"):
198200
index = int(bid.replace("delete_social_", ""))
199201
self.remove_social_entry(index)
@@ -205,13 +207,13 @@ def add_social_entry(self) -> None:
205207
class SocialEntry(Horizontal):
206208
DEFAULT_CSS = """
207209
SocialEntry Select {
208-
width: 25%;
210+
width: 25%;
209211
}
210212
SocialEntry Input {
211-
width: 50%;
213+
width: 50%;
212214
}
213215
SocialEntry Button {
214-
width: 25%;
216+
width: 25%;
215217
}
216218
"""
217219

@@ -229,10 +231,12 @@ def __init__(se, index):
229231
("X", "x"),
230232
("YouTube", "youtube"),
231233
],
232-
prompt="Red Social",
234+
prompt="Social Network",
235+
)
236+
se.url_input = Input(placeholder=PLACEHOLDER_SOCIAL_URL)
237+
se.delete_btn = Button(
238+
BUTTON_DELETE, id=f"delete_social_{index}"
233239
)
234-
se.url_input = Input(placeholder="URL de la red social")
235-
se.delete_btn = Button("Eliminar", id=f"delete_social_{index}")
236240

237241
def compose(se) -> ComposeResult:
238242
yield se.select
@@ -258,18 +262,20 @@ def add_alias_entry(self) -> None:
258262
class AliasEntry(Horizontal):
259263
DEFAULT_CSS = """
260264
AliasEntry Input {
261-
width: 75%;
265+
width: 75%;
262266
}
263267
AliasEntry Button {
264-
width: 25%;
268+
width: 25%;
265269
}
266270
"""
267271

268272
def __init__(se, index):
269273
super().__init__()
270274
se.index = index
271-
se.alias_input = Input(placeholder="Alias")
272-
se.delete_btn = Button("Eliminar", id=f"delete_alias_{index}")
275+
se.alias_input = Input(placeholder=PLACEHOLDER_ALIAS)
276+
se.delete_btn = Button(
277+
BUTTON_DELETE, id=f"delete_alias_{index}"
278+
)
273279

274280
def compose(se) -> ComposeResult:
275281
yield se.alias_input

src/edit_python_pe/strings.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Field, control, and message labels for edit_python_pe
2+
3+
# List and form titles
4+
LIST_TITLE = "Files in 'blog/members':"
5+
FORM_HEADER = "Member Form"
6+
7+
# Button labels
8+
BUTTON_QUIT = "Quit"
9+
BUTTON_ADD = "Add"
10+
BUTTON_SAVE = "Save"
11+
BUTTON_BACK = "Back"
12+
BUTTON_ADD_SOCIAL = "Add Social Network"
13+
BUTTON_ADD_ALIAS = "Add Alias"
14+
BUTTON_DELETE = "Delete"
15+
16+
# Input placeholders
17+
PLACEHOLDER_NAME = "Name"
18+
PLACEHOLDER_EMAIL = "Email"
19+
PLACEHOLDER_CITY = "City"
20+
PLACEHOLDER_HOMEPAGE = "Homepage"
21+
PLACEHOLDER_SOCIAL_URL = "Social network URL"
22+
PLACEHOLDER_ALIAS = "Alias"
23+
24+
# Section headers
25+
SECTION_SOCIAL = "Social Networks"
26+
SECTION_ALIASES = "Aliases"
27+
SECTION_WHO = "Who are you and what do you do?"
28+
SECTION_PYTHON = "How do you program in Python?"
29+
SECTION_CONTRIB = "Do you have any contributions to the Python community?"
30+
SECTION_AVAIL = "Are you available for mentoring, consulting, talks?"
31+
32+
# Messages
33+
MESSAGE_PROMPT_FOR_GITHUB_TOKEN = (
34+
"Please enter your GitHub personal access token: "
35+
)
36+
MESSAGE_EXIT = "See you next time!"
37+
MESSAGE_QUIT = "Exiting the application."
38+
MESSAGE_FILE_READ_ERROR = "Error reading file {filename}: {error}"
39+
MESSAGE_UNAUTHORIZED = "Unauthorized access. Please check your access token."
40+
MESSAGE_REPO_NOT_FOUND = (
41+
"Repository not found. Please check your access token."
42+
)
43+
MESSAGE_FILE_EDITED_PR = (
44+
"File {name_file} edited, commit and changes sent to existing PR."
45+
)
46+
MESSAGE_FILE_SAVED_PR = "File {name_file} saved, commit and PR ready."
47+
MESSAGE_CREATE_ENTRY = (
48+
"Creating a new entry to `blog/members` for {name} (alias: {first_alias})."
49+
)
50+
MESSAGE_CHANGE_ENTRY = (
51+
"Changing an entry to `blog/members` for {name} (alias: {first_alias})."
52+
)
53+
MESSAGE_LOAD_FILE_ERROR = "Error reading file {filename}: {error}"
54+
55+
# build_md_content markdown dictionary (English keys, Spanish values for now)
56+
MD_CONTENT = {
57+
"yaml_start": "---",
58+
"yaml_blogpost": "blogpost: true",
59+
"yaml_date": "date: {date}",
60+
"yaml_author": "author: {author}",
61+
"yaml_location": "location: {city}",
62+
"yaml_category": "category: members",
63+
"yaml_language": "language: Español",
64+
"yaml_image": "image: 1",
65+
"yaml_excerpt": "excerpt: 1",
66+
"yaml_end": "---",
67+
"header_name": "# {name}",
68+
"gravatar_block": '```{{gravatar}} {email}\n---\nwidth: 200\nclass: "member-gravatar"\n---\n```',
69+
"social_block_start": "```{{raw}} html",
70+
"social_ul_start": '<ul class="social-media profile">',
71+
"social_li": ' <li>\n <a class="external reference" href="{url}">\n <iconify-icon icon="simple-icons:{platform}" style="font-size:2em"></iconify-icon>\n </a>\n </li>',
72+
"social_ul_end": "</ul>",
73+
"social_block_end": "```",
74+
"aliases": ":Aliases: {aliases}",
75+
"city": ":Ciudad: {city}",
76+
"homepage": ":Homepage: {homepage}",
77+
"section_about": "## Sobre mí",
78+
"section_who": "### ¿Quién eres y a qué te dedicas?",
79+
"section_python": "### ¿Cómo programas en Python?",
80+
"section_contrib": "### ¿Tienes algún aporte a la comunidad de Python?",
81+
"section_avail": "### ¿Estás disponible para hacer mentoring, consultorías, charlas?",
82+
}

0 commit comments

Comments
 (0)