Coverage for src/fsl_pipe_gui/placeholder_tab.py: 32%

31 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-11 11:06 +0100

1""" 

2Textual tab allowing the editing of placeholder values. 

3 

4The main goal of this tab is to allow the placeholder values 

5to be changed from that included within the user-provied `FileTree`. 

6These changes are immediately made into the `FileTree`. 

7""" 

8from textual.app import App, ComposeResult 

9from textual.containers import Grid, Vertical 

10from textual.widgets import Button, Footer, Header, Input, Label 

11 

12from .all_panes import AllPanes, PipelineSelector 

13 

14 

15class PlaceholderEditor(App): 

16 """ 

17 GUI to view pipeline. 

18 

19 There are two separate pages (visiblity set by `show_page`): 

20 - `placeholder_tab` allows the user to change the placeholder values. 

21 - `output_tab` allows the user to select the requested output files. 

22 """ 

23 

24 TITLE = "FSL pipeline" 

25 CSS_PATH = "css/placeholder.css" 

26 

27 def __init__(self, selector: PipelineSelector): 

28 """Create the pipeline GUI.""" 

29 super().__init__() 

30 self.selector = selector 

31 file_tree = selector.file_tree 

32 self.keys = [Label(k) for k in file_tree.placeholders.keys()] 

33 self.values = [ 

34 Input(", ".join(v) if isinstance(v, list) else v) 

35 for v in file_tree.placeholders.values() 

36 ] 

37 

38 def compose(self) -> ComposeResult: 

39 """Build the pipeline GUI.""" 

40 table_parts = [] 

41 for key, value in zip(self.keys, self.values): 

42 table_parts.append(key) 

43 table_parts.append(value) 

44 yield Header() 

45 yield Vertical( 

46 Label("step 1: optionally edit placeholder values"), 

47 Grid(Label("Placeholders"), Label("Values"), *table_parts, id="grid"), 

48 ) 

49 yield Footer() 

50 

51 def on_button_pressed(self, event: Button.Pressed): 

52 """Continue to the next app.""" 

53 new_placeholders = {} 

54 for key, value in zip(self.keys, self.values): 

55 text = value.value 

56 if "," in text: 

57 new_value = [elem.strip() for elem in text.split(",")] 

58 else: 

59 new_value = text.strip() 

60 new_placeholders[str(key.renderable)] = new_value 

61 

62 self.selector.update_placeholders(**new_placeholders) 

63 self.exit(AllPanes.SELECTOR)