Skip to content

Commit

Permalink
Merge pull request #794 from mantidproject/793_fix_bragg_peak_waterfa…
Browse files Browse the repository at this point in the history
…ll_crash

Fix bug that causes continual calls to "toggle_waterfall"
  • Loading branch information
SilkeSchomann authored Jun 17, 2022
2 parents f584d1c + 8ba7b3c commit a425b85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mslice/plotting/plot_window/cut_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ def setup_connections(self, plot_window):
plot_window.action_gen_script.triggered.connect(self.generate_script)
plot_window.action_gen_script_clipboard.triggered.connect(lambda: self.generate_script(clipboard=True))
plot_window.action_waterfall.triggered.connect(self.toggle_waterfall)
plot_window.waterfall_x_edt.editingFinished.connect(self.toggle_waterfall)
plot_window.waterfall_y_edt.editingFinished.connect(self.toggle_waterfall)
plot_window.waterfall_x_edt.editingFinished.connect(self.update_waterfall)
plot_window.waterfall_y_edt.editingFinished.connect(self.update_waterfall)
plot_window.waterfall_x_edt.editingFinished.connect(plot_window.lose_waterfall_x_edt_focus)
plot_window.waterfall_y_edt.editingFinished.connect(plot_window.lose_waterfall_y_edt_focus)
plot_window.action_aluminium.triggered.connect(
partial(toggle_overplot_line, self, self._cut_plotter_presenter, 'Aluminium', False))
plot_window.action_copper.triggered.connect(
Expand Down Expand Up @@ -440,13 +442,16 @@ def get_line_visible(self, line_index: int) -> bool:
return line_visible

def toggle_waterfall(self):
self._datum_dirty = True
self.update_bragg_peaks(refresh=True)
self.update_waterfall()

def update_waterfall(self):
if self.waterfall:
self._apply_offset(self.plot_window.waterfall_x, self.plot_window.waterfall_y)
else:
self._apply_offset(0., 0.)

self._datum_dirty = True
self.update_bragg_peaks(refresh=True)
self._canvas.draw()

def _cache_line(self, line):
Expand Down Expand Up @@ -490,8 +495,8 @@ def on_newplot(self, ax, plot_over):
if line not in self._waterfall_cache:
self._waterfall_cache[line] = [line.get_xdata(), line.get_ydata()]
new_line = True
if new_line and num_lines > 1:
self.toggle_waterfall()
if new_line and num_lines > 1 and self.plot_window.waterfall:
self.update_waterfall()

self._datum_dirty = True
self.update_bragg_peaks(refresh=True)
Expand Down
15 changes: 15 additions & 0 deletions mslice/plotting/plot_window/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, manager, parent=None):
self._first_time_show = False

def closeEvent(self, _):
self.lose_waterfall_x_edt_focus() # lose focus so toggle_waterfall does not trigger upon close
self.lose_waterfall_y_edt_focus()
self.canvas.manager.window_closing()

def showEvent(self, evt):
Expand Down Expand Up @@ -158,6 +160,7 @@ def add_toolbar_actions(self, toolbar):

def add_waterfall_edit(self, parent):
self.waterfall_x_lbl = QtWidgets.QLabel("x:", parent)
self.waterfall_x_lbl.setFocusPolicy(QtCore.Qt.TabFocus)
self.waterfall_y_lbl = QtWidgets.QLabel("y:", parent)
self.waterfall_x_edt = QtWidgets.QLineEdit("0", parent)
self.waterfall_y_edt = QtWidgets.QLineEdit("0", parent)
Expand All @@ -184,6 +187,18 @@ def toggle_waterfall_edit(self):
self.waterfall_x_edt_act.setVisible(is_waterfall)
self.waterfall_y_edt_act.setVisible(is_waterfall)

def lose_waterfall_x_edt_focus(self):
self._lose_focus_without_signal(self.waterfall_x_edt)

def lose_waterfall_y_edt_focus(self):
self._lose_focus_without_signal(self.waterfall_y_edt)

@staticmethod
def _lose_focus_without_signal(qt_obj):
qt_obj.blockSignals(True) # prevents a subsequent call to this function
qt_obj.clearFocus()
qt_obj.blockSignals(False)

def create_status_bar(self):
self.statusbar = QtWidgets.QStatusBar(self)
self.stock_toolbar.message.connect(self.statusbar.showMessage)
Expand Down

0 comments on commit a425b85

Please sign in to comment.