@@ -80,9 +80,9 @@ def on_input_submitted(self, user_input: Input.Submitted):
8080 user_input: Input.Submitted - the choice of the user
8181 """
8282
83- clean_input : str = re .sub (r"\"" , "'" , user_input .value )
83+ clean_input : str = re .sub (r'"' , "'" , user_input .value )
8484 clean_input = re .sub (r"(\[)(\s*)" , "[ " , clean_input )
85- clean_input = re .sub (r"(\s*)(\ ])" , " ]" , clean_input )
85+ clean_input = re .sub (r"(\s*)(])" , " ]" , clean_input )
8686 self .dismiss (clean_input )
8787
8888
@@ -292,14 +292,17 @@ def handle_return_from_variable_addition(data: tuple[str, Types | None] | None)
292292 """
293293
294294 if data :
295- if data [1 ] == Types .LIST and (not re .search (r"^\s*\[[^\ ]]*\ ]\s*$" , data [0 ])):
295+ if data [1 ] == Types .LIST and (not re .search (r"^\s*\[[^]]*]\s*$" , data [0 ])):
296296 self .notify ("You lost (or gained) a bracket! Not updating" , title = "error adding option" , severity = "error" )
297297 if type_as_defined :
298298 self .app .push_screen (RecommendedTypeOrChooseType (type_as_defined ),
299299 handle_return_from_variable_addition )
300300 else :
301301 self .app .push_screen (AddScreenVariableSelection (), handle_return_from_variable_addition )
302- elif data [1 ] == Types .STRING and (not re .search (r"^\s*'[^']*'\s*$" , data [0 ])):
302+ elif data [1 ] == Types .STRING and (
303+ (not re .search (r"^\s*'[^']*'\s*$" , data [0 ])) and
304+ (not re .search (r"^\s*''[^'']*''\s*$" , data [0 ]))
305+ ):
303306 self .notify ("You lost (or gained) a speech mark! Not updating" , title = "error adding option" , severity = "error" )
304307 if type_as_defined :
305308 self .app .push_screen (RecommendedTypeOrChooseType (type_as_defined ),
@@ -322,7 +325,7 @@ def handle_return_from_variable_addition(data: tuple[str, Types | None] | None)
322325 else :
323326 self .app .pop_screen ()
324327
325- if re .search (r"[^a-zA-Z_]" , path .value ):
328+ if re .search (r"[^a-zA-Z_. ]" , path .value ):
326329 self .notify ("You have entered invalid character(s) for the path of your option, not adding" , title = "error adding option" , severity = "error" )
327330 self .dismiss (None )
328331 else :
@@ -365,36 +368,29 @@ def recursive_addition(self, node: UIConnectorNode, path: list, data: str, path_
365368 bool - true if the function added the variable and false if otherwise
366369 """
367370 if len (path ) > 1 :
368- path_bit_already_exists = False
369371 for child in node .children :
370372 if child .label .plain == path [0 ]:
371- path_bit_already_exists = True
372373 del path [0 ]
373374 return self .recursive_addition (child , path , data , path_as_list , data_type )
374- if not path_bit_already_exists :
375- new_node = node .add (path [0 ])
376- if new_node .parent .is_root :
377- self .__operations .append (f"Section { path [0 ]} added" )
378- else :
379- self .__operations .append (f"Section { '.' .join (work_out_full_path (new_node , []))} added" )
380- del path [0 ]
381- return self .recursive_addition (new_node , path , data , path_as_list , data_type )
375+ new_node = node .add (path [0 ])
376+ if new_node .parent .is_root :
377+ self .__operations .append (f"Section { path [0 ]} added" )
378+ else :
379+ self .__operations .append (f"Section { '.' .join (work_out_full_path (new_node , []))} added" )
380+ del path [0 ]
381+ return self .recursive_addition (new_node , path , data , path_as_list , data_type )
382+
383+ for child in node .children :
384+ if child .label .plain .split ("=" )[0 ] == self .__path .split ("." )[- 1 ]:
385+ self .notify ("variable already exists" , severity = "error" )
386+ return False
387+ if not path_as_list :
388+ node .add_leaf (self .__path .split ("." )[- 1 ] + "=" + data ,
389+ data = {self .__path : data , "type" : data_type })
382390 else :
383- var_already_exists = False
384- for child in node .children :
385- if child .label .plain .split ("=" )[0 ] == self .__path .split ("." )[- 1 ]:
386- var_already_exists = True
387- self .notify ("variable already exists" , severity = "error" )
388- return False
389- if not var_already_exists :
390- if not path_as_list :
391- node .add_leaf (self .__path .split ("." )[- 1 ] + "=" + data ,
392- data = {self .__path : data , "type" : data_type })
393- else :
394- node .add_leaf (self .__path .split ("." )[- 1 ] + "=" + data ,
395- data = {'.' .join (path_as_list ) + "." + self .__path : data , "type" : data_type })
396- return True
397- return None
391+ node .add_leaf (self .__path .split ("." )[- 1 ] + "=" + data ,
392+ data = {'.' .join (path_as_list ) + "." + self .__path : data , "type" : data_type })
393+ return True
398394
399395 def action_quit_pressed (self ) -> None :
400396 """Quits the screen when one of the quit buttons are pressed"""
0 commit comments