@@ -50,15 +50,18 @@ def compose(self) -> ComposeResult:
5050 yield Header (id = "project_select_header" )
5151 yield Button ("Main Menu" , id = "all_main_menu_buttons" )
5252 yield Container (
53- * [Button (name , id = name ) for name in self .project_names ],
53+ * [
54+ Button (name , id = self .name_to_id (name ))
55+ for name in self .project_names
56+ ],
5457 id = "project_select_top_container" ,
5558 )
5659
5760 def on_button_pressed (self , event : Button .Pressed ) -> None :
5861 """Handle a button press on ProjectSelectorScreen."""
59- if event .button .id in self .project_names :
60- project_name = event .button .id
62+ project_name = self .id_to_name (event .button .id )
6163
64+ if project_name in self .project_names :
6265 interface = Interface ()
6366 success , output = interface .select_existing_project (project_name )
6467
@@ -69,3 +72,17 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
6972
7073 elif event .button .id == "all_main_menu_buttons" :
7174 self .dismiss (False )
75+
76+ @staticmethod
77+ def name_to_id (name : str ):
78+ """Convert the project name to a textual ID.
79+
80+ Textual ids cannot start with a number, so ensure
81+ all ids are prefixed with text instead of the project name.
82+ """
83+ return f"safety_prefix_{ name } "
84+
85+ @staticmethod
86+ def id_to_name (id : str ):
87+ """See `name_to_id()`."""
88+ return id [len ("safety_prefix_" ) :]
0 commit comments