ATLAS Offline Software
wrappers.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 import curses
4 import logging
5 from typing import Any, Tuple
6 
7 from AthenaConfiguration.iconfTool.gui.modals import (
8  DoubleHelpModal,
9  SearchModal,
10  SingleHelpModal,
11 )
12 from AthenaConfiguration.iconfTool.gui.pad import Pad
13 from AthenaConfiguration.iconfTool.models.loaders import (
14  ComponentsDiffFileLoader,
15  ComponentsFileLoader,
16 )
17 from AthenaConfiguration.iconfTool.models.structure import ComponentsStructure
18 
19 logger = logging.getLogger(__name__)
20 
21 
22 class GuiLoader:
23  def __init__(self, data_loader: ComponentsFileLoader) -> None:
24  self.data_loader: ComponentsFileLoader = data_loader
25  self.data_structure: ComponentsStructure = self.data_loader.get_data()
26  self.width: int = 0
27  self.height: int = 0
28  self.pad_height: int = 0
29  self.pad: Pad
30  self.actual_offset: int = 0
31  self.screen: Any
32 
33  def _initialize_window(self) -> None:
34  self.height, self.width = self.screen.getmaxyx()
35  self.window = curses.newwin(self.height, self.width, 0, 0)
36  self.pad = Pad(self.data_structure, self.width, self.height)
37  self.pad_height = self.height - 1
38  self.pad.refresh()
39 
40  def _initialize(self, stdscreen) -> None:
41  self.screen = stdscreen
42  self.screen.refresh()
43  self._initialize_window()
44  self._start_event_loop()
45 
46  def load_gui(self) -> None:
47  curses.wrapper(self._initialize)
48 
49  def search(self, strict: bool = False) -> None:
50  search_size: int = 50
51  b_starty: int = 0
52  b_startx: int = self.width - search_size - 2
53  b_width: int = search_size
54  b_height: int = 3
55  cursor_pos: Tuple[int, int] = curses.getsyx()
56  search: SearchModal = SearchModal(
57  b_startx, b_starty, b_width, b_height
58  )
59  text: str = search.edit()
60  curses.setsyx(cursor_pos[0], cursor_pos[1])
61  self.pad.filter(text)
62 
63  def refresh_whole_screen(self) -> None:
64  self.window.refresh()
65  self.pad.refresh()
66 
67  def show_help(self):
68  search_size: int = 60
69  b_width: int = search_size
70  b_height: int = 15
71  b_starty: int = self.screen.getmaxyx()[0] - b_height
72  b_startx: int = self.width - search_size - 2
73  cursor_pos: Tuple[int, int] = curses.getsyx()
74  search: SingleHelpModal = SingleHelpModal(
75  b_startx, b_starty, b_width, b_height
76  )
77  curses.setsyx(*cursor_pos)
78  search.show_help()
79  self.pad.initialize_cursor()
80 
81  def _start_event_loop(self) -> None:
82  self.show_help()
83  while True:
84  event: int = self.screen.getch()
85  logger.debug(f"Key pressed: [{event}, {chr(event)}]")
86  if event == ord("q"):
87  break
88  elif event == ord("m"):
89  self.search()
90  elif event == ord("h"):
91  self.show_help()
92  elif event == ord("r"):
93  self.data_structure = self.data_loader.get_data()
94  self.pad.reload_data(self.data_structure)
95  self.pad.redraw()
96  else:
97  self.pad.handle_event(event)
98 
99 
100 class DoublePad:
101  def __init__(self, data_loader: ComponentsDiffFileLoader) -> None:
102  self.data_loader: ComponentsDiffFileLoader = data_loader
103  self.data_structure: ComponentsStructure
104  self.diff_structure: ComponentsStructure
105  self.data_structure, self.diff_structure = self.data_loader.get_data()
106  self.width: int = 0
107  self.height: int = 0
108  self.pad_height: int = 0
109  self.pad: Pad
110  self.diff_pad: Pad
111  self.current_pad: Pad
112  self.inactive_pad: Pad
113  self.actual_offset: int = 0
114  self.screen: Any
115  self.show_diff_only: bool = False
116 
117  def _initialize_window(self) -> None:
118  self.height, self.width = self.screen.getmaxyx()
119  self.window = curses.newwin(self.height, self.width, 0, 0)
120  self.pad = Pad(
121  self.data_structure, int(self.width / 2 - 1), self.height
122  )
123  self.diff_pad = Pad(
124  self.diff_structure,
125  int(self.width / 2) - 1,
126  self.height,
127  int(self.width / 2) + 2,
128  )
129  self.pad_height = self.height - 1
130  self.current_pad, self.inactive_pad = self.pad, self.diff_pad
131  self.diff_pad.hide_cursor()
132  self.diff_pad.refresh()
133  self.pad.refresh()
134 
135  def _initialize(self, stdscreen) -> None:
136  self.screen = stdscreen
137  self.screen.refresh()
138  self._initialize_window()
139  self._start_event_loop()
140 
141  def load_gui(self) -> None:
142  curses.wrapper(self._initialize)
143 
144  def search(self):
145  search_size: int = 50
146  b_starty: int = 0
147  b_startx: int = self.width - search_size - 2
148  b_width: int = search_size
149  b_height: int = 3
150  cursor_pos: Tuple[int, int] = curses.getsyx()
151  search: SearchModal = SearchModal(
152  b_startx, b_starty, b_width, b_height
153  )
154  text: str = search.edit()
155  curses.setsyx(cursor_pos[0], cursor_pos[1])
156  self.current_pad.filter(text)
157  self.inactive_pad.filter(text)
158 
159  def refresh_whole_screen(self) -> None:
160  self.window.refresh()
161  self.current_pad.refresh()
162  self.inactive_pad.refresh()
163 
164  def change_actual_pad(self) -> None:
165  if self.inactive_pad.lines_empty():
166  return
167  self.current_pad.hide_cursor()
168  self.current_pad, self.inactive_pad = (
169  self.inactive_pad,
170  self.current_pad,
171  )
172  self.inactive_pad.refresh()
173  self.current_pad.refresh()
174  self.current_pad.show_cursor()
175 
176  def show_help(self):
177  search_size: int = 60
178  b_width: int = search_size
179  b_height: int = 17
180  b_starty: int = self.screen.getmaxyx()[0] - b_height
181  b_startx: int = self.width - search_size - 2
182  cursor_pos: Tuple[int, int] = curses.getsyx()
183  search: DoubleHelpModal = DoubleHelpModal(
184  b_startx, b_starty, b_width, b_height
185  )
186  curses.setsyx(*cursor_pos)
187  search.show_help()
188  self.current_pad.initialize_cursor()
189 
190  def _start_event_loop(self) -> None:
191  self.show_help()
192  while True:
193  event = self.screen.getch()
194  logger.debug(f"Key pressed: [{event}, {chr(event)}]")
195  if event == ord("q"):
196  break
197  elif event == ord("\t"):
198  self.change_actual_pad()
199  elif event == ord("h"):
200  self.show_help()
201  elif event == ord("m"):
202  self.search()
203  elif event == ord("r"):
204  self.pad.clear()
205  self.diff_pad.clear()
206  (
207  self.data_structure,
208  self.diff_structure,
209  ) = self.data_loader.get_data()
210  self.pad.reload_data(self.data_structure)
211  self.diff_pad.reload_data(self.diff_structure)
212 
213  self.pad.redraw()
214  self.diff_pad.redraw()
215 
216  else:
217  self.current_pad.handle_event(event)
python.iconfTool.gui.wrappers.GuiLoader.show_help
def show_help(self)
Definition: wrappers.py:67
python.iconfTool.gui.wrappers.GuiLoader.window
window
Definition: wrappers.py:35
python.iconfTool.gui.wrappers.DoublePad.diff_pad
diff_pad
Definition: wrappers.py:123
python.iconfTool.gui.wrappers.GuiLoader.width
width
Definition: wrappers.py:34
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.iconfTool.gui.wrappers.GuiLoader.search
None search(self, bool strict=False)
Definition: wrappers.py:49
python.iconfTool.gui.wrappers.DoublePad.pad
pad
Definition: wrappers.py:120
python.iconfTool.gui.wrappers.GuiLoader
Definition: wrappers.py:22
python.iconfTool.gui.wrappers.GuiLoader._initialize
None _initialize(self, stdscreen)
Definition: wrappers.py:40
python.iconfTool.gui.wrappers.DoublePad.width
width
Definition: wrappers.py:118
python.iconfTool.gui.wrappers.DoublePad.search
def search(self)
Definition: wrappers.py:144
python.iconfTool.gui.wrappers.DoublePad.pad_height
pad_height
Definition: wrappers.py:129
python.iconfTool.gui.wrappers.DoublePad._initialize
None _initialize(self, stdscreen)
Definition: wrappers.py:135
python.iconfTool.gui.wrappers.DoublePad.inactive_pad
inactive_pad
Definition: wrappers.py:130
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.iconfTool.gui.wrappers.DoublePad.show_help
def show_help(self)
Definition: wrappers.py:176
python.iconfTool.gui.wrappers.DoublePad._initialize_window
None _initialize_window(self)
Definition: wrappers.py:117
python.iconfTool.gui.wrappers.DoublePad
Definition: wrappers.py:100
python.iconfTool.gui.wrappers.DoublePad.window
window
Definition: wrappers.py:119
python.iconfTool.gui.wrappers.DoublePad.refresh_whole_screen
None refresh_whole_screen(self)
Definition: wrappers.py:159
python.iconfTool.gui.wrappers.DoublePad.load_gui
None load_gui(self)
Definition: wrappers.py:141
python.iconfTool.gui.wrappers.GuiLoader._start_event_loop
None _start_event_loop(self)
Definition: wrappers.py:81
python.iconfTool.gui.wrappers.DoublePad.screen
screen
Definition: wrappers.py:136
python.iconfTool.gui.wrappers.DoublePad.__init__
None __init__(self, ComponentsDiffFileLoader data_loader)
Definition: wrappers.py:101
python.iconfTool.gui.wrappers.GuiLoader.pad_height
pad_height
Definition: wrappers.py:37
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
python.iconfTool.gui.wrappers.GuiLoader.screen
screen
Definition: wrappers.py:41
python.iconfTool.gui.wrappers.DoublePad._start_event_loop
None _start_event_loop(self)
Definition: wrappers.py:190
python.iconfTool.gui.wrappers.DoublePad.change_actual_pad
None change_actual_pad(self)
Definition: wrappers.py:164
python.iconfTool.gui.wrappers.GuiLoader.__init__
None __init__(self, ComponentsFileLoader data_loader)
Definition: wrappers.py:23
python.iconfTool.gui.wrappers.DoublePad.diff_structure
diff_structure
Definition: wrappers.py:105
python.iconfTool.gui.wrappers.GuiLoader.pad
pad
Definition: wrappers.py:36
python.iconfTool.gui.wrappers.GuiLoader.data_structure
data_structure
Definition: wrappers.py:93
python.iconfTool.gui.wrappers.GuiLoader.load_gui
None load_gui(self)
Definition: wrappers.py:46
python.iconfTool.gui.wrappers.GuiLoader.refresh_whole_screen
None refresh_whole_screen(self)
Definition: wrappers.py:63
python.iconfTool.gui.wrappers.GuiLoader._initialize_window
None _initialize_window(self)
Definition: wrappers.py:33