Skip to content

Commit

Permalink
PRJ: correct parameters for tab widgets; ENH: fix option multi box wi…
Browse files Browse the repository at this point in the history
…dget; PRJ: no consecutive analysis feature on Windows
  • Loading branch information
leloup314 committed Sep 8, 2017
1 parent 0745f68 commit 35b57e0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 44 deletions.
13 changes: 9 additions & 4 deletions testbeam_analysis/gui/analysis_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,20 @@ def _select_widget(self, dtype, name, default_value, optional, tooltip):
# Create widget according to data type
if ('scalar' in dtype and ('tuple' in dtype or 'iterable' in dtype) or
'int' in dtype and ('tuple' in dtype or 'iterable' in dtype) or
('iterable' in dtype and 'iterable of iterable' not in dtype)):
('iterable' in dtype and 'iterable of iterable' not in dtype and 'duts' not in name)):
widget = option_widget.OptionMultiSlider(
name=name, labels=self.setup['dut_names'],
default_value=default_value,
optional=optional, tooltip=tooltip, parent=self)
elif 'iterable of iterable' in dtype:
# determine whether "iterable of iterable" or "iterable"
labels_y = self.setup['dut_names']
elif 'iterable of iterable' in dtype or 'iterable' in dtype and 'duts' in name:

labels_x = self.setup['dut_names']
labels_y = self.setup['dut_names']

# determine whether "iterable of iterable" or "iterable of duts"
if 'iterable of iterable' not in dtype and 'duts' in name:
labels_y = None

if name in ['Align duts']:
labels_x = ['Align %i.' % (i + 1) for i in range(self.setup['n_duts'])]

Expand Down
57 changes: 24 additions & 33 deletions testbeam_analysis/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ def _init_menu(self):
self.settings_menu.addAction('&Global', self.global_settings)
self.menuBar().addMenu(self.settings_menu)

self.run_menu = QtWidgets.QMenu('&Run', self)
self.run_menu.setToolTipsVisible(True)
self.run_menu.addAction('&Run consecutive analysis', self.run_consecutive_analysis, QtCore.Qt.CTRL + QtCore.Qt.Key_R)
# Disable consecutive analysis until setup is done
self.run_menu.actions()[0].setEnabled(False)
self.run_menu.actions()[0].setToolTip('Finish data selection and testbeam setup to enable')
self.menuBar().addMenu(self.run_menu)
# FIXME: Don't support this feature for Windows now, since it causes crashes
if platform.system() != 'Windows':
self.run_menu = QtWidgets.QMenu('&Run', self)
self.run_menu.setToolTipsVisible(True)
self.run_menu.addAction('&Run consecutive analysis', self.run_consecutive_analysis, QtCore.Qt.CTRL + QtCore.Qt.Key_R)
# Disable consecutive analysis until setup is done
self.run_menu.actions()[0].setEnabled(False)
self.run_menu.actions()[0].setToolTip('Finish data selection and testbeam setup to enable')
self.menuBar().addMenu(self.run_menu)

self.appearance_menu = QtWidgets.QMenu('&Appearance', self)
self.appearance_menu.setToolTipsVisible(True)
Expand Down Expand Up @@ -545,8 +547,9 @@ def new_analysis(self):
self.tw = {}

# Disable consecutive analysis until setup is done
self.run_menu.actions()[0].setEnabled(False)
self.run_menu.actions()[0].setToolTip('Finish data selection and testbeam setup to enable')
if platform.system() != 'Windows':
self.run_menu.actions()[0].setEnabled(False)
self.run_menu.actions()[0].setToolTip('Finish data selection and testbeam setup to enable')

for i in reversed(range(self.main_splitter.count())):
w = self.main_splitter.widget(i)
Expand Down Expand Up @@ -600,13 +603,19 @@ def run_consecutive_analysis(self):
# Connect starting tab and all following
if self.tab_order.index(tab) >= self.tab_order.index(self.starting_tab_rca):

# Wait for analysis_thread to finish correctly
# self.tw[tab].analysis_thread.wait()

# Handle consecutive analysis
self.tw[tab].proceedAnalysis.connect(lambda tab_list: self.tw[tab_list[0]].btn_ok.clicked.emit())
self.tw[tab].proceedAnalysis.connect(lambda tab_list: handle_rca(tab_list))

# Check whether or not alignment is skipped
if tab == 'Track finding' and self.options['skip_alignment']:
for x in [lambda tab_list: self.tw[tab_list[0]].skipAlignment.emit(),
lambda tab_list: self.tw[tab_list[0]].proceedAnalysis.emit(self.tw[tab_list[0]].tl)]:
self.tw[tab].proceedAnalysis.connect(x)

else:
if tab != self.tab_order[-1]:
self.tw[tab].proceedAnalysis.connect(lambda tab_list: self.tw[tab_list[0]].btn_ok.clicked.emit())

# Start analysis by clicking ok button on starting tab
self.tw[self.starting_tab_rca].btn_ok.clicked.emit()
self.p_bar_rca.setValue(self.tab_order.index(self.starting_tab_rca))
Expand Down Expand Up @@ -650,36 +659,18 @@ def handle_rca(tab_list=None, interrupt=False):
else:
tab_name = tab_list

# Synchronize to worker thread / wait for current analysis_thread to finish correctly
# self.tw[self.tab_order[self.tab_order.index(tab_name) - 1]].analysis_thread.wait()
# self.tw[tab_name].analysis_thread.wait()

if tab_name in self.tab_order:

# Update progressbar
self.p_bar_rca.setFormat(tab_name)
self.p_bar_rca.setValue(self.tab_order.index(tab_name))

# Set current tab to last finished
# self.tabs.setCurrentIndex(self.tab_order.index(tab_name) - 1)

# Click proceed button
# try:
# self.tw[tab_name].btn_ok.clicked.emit()
# except Exception as e:
# # Alignment is skipped
# if tab_name == 'Alignment':
# self.tw[tab_name].skipAlignment.emit()
# self.tw[tab_name].proceedAnalysis.emit(self.tw[tab_name].tl)
# # Re-raise exception
# else:
# self.handle_exceptions(exception=e, trace_back=traceback.format_exc(),
# tab=tab_name, cause='consecutive analysis')

else:
# Last tab finished
self.p_bar_rca.setValue(len(self.tab_order))
self.label_rca.setText('Done!')
# Remove consecutive analysis progressbar
self.remove_widget(widget=self.widget_rca, layout=self.main_layout)

def handle_exceptions(self, exception, trace_back, tab, cause):
"""
Expand Down
20 changes: 13 additions & 7 deletions testbeam_analysis/gui/tab_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,12 @@ def __init__(self, parent, setup, options, name, tab_list):
func=apply_alignment,
fixed=True)

self.add_option(option='use_duts',
func=apply_alignment,
default_value=range(setup['n_duts']),
optional=True)

# Fix options that should not be changed
self.add_option(option='use_duts', func=apply_alignment,
default_value=range(setup['n_duts']), fixed=True)
self.add_option(option='inverse', func=apply_alignment, fixed=True)
self.add_option(option='force_prealignment', func=apply_alignment,
default_value=True, fixed=True)
Expand Down Expand Up @@ -361,7 +364,7 @@ def __init__(self, parent, setup, options, name, tab_list):
self.add_option(option='use_duts',
default_value=range(setup['n_duts']),
func=apply_alignment,
fixed=True)
optional=True)

for x in [lambda _tab_list: self.proceedAnalysis.emit(_tab_list),
lambda: self._connect_vitables(files=output_file),
Expand Down Expand Up @@ -471,9 +474,12 @@ def __init__(self, parent, setup, options, name, tab_list):
func=fit_tracks,
optional=True)

self.add_option(option='fit_duts',
func=fit_tracks,
default_value=range(setup['n_duts']),
optional=True)

# Set and fix options
self.add_option(option='fit_duts', func=fit_tracks,
default_value=range(setup['n_duts']), fixed=True)
self.add_option(option='force_prealignment', func=fit_tracks,
default_value=options['skip_alignment'], fixed=True)
self.add_option(option='exclude_dut_hit', func=fit_tracks,
Expand Down Expand Up @@ -557,7 +563,7 @@ def __init__(self, parent, setup, options, name, tab_list):
self.add_option(option='use_duts',
default_value=range(setup['n_duts']),
func=calculate_residuals,
fixed=True)
optional=True)

for x in [lambda _tab_list: self.proceedAnalysis.emit(_tab_list),
lambda: self._connect_vitables(files=output_file)]:
Expand Down Expand Up @@ -618,7 +624,7 @@ def __init__(self, parent, setup, options, name, tab_list):
self.add_option(option='use_duts',
default_value=range(setup['n_duts']),
func=calculate_efficiency,
fixed=True)
optional=True)

for x in [lambda _tab_list: self.proceedAnalysis.emit(_tab_list),
lambda: self._connect_vitables(files=output_file)]:
Expand Down

0 comments on commit 35b57e0

Please sign in to comment.