Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilipp committed Apr 26, 2019
1 parent 8b56b5e commit 89c04b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion straditize/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def add_straditizer(self, stradi):
def reset_control(self):
"""Reset the GUI of straditize"""
if getattr(self.selection_toolbar, '_pattern_selection', None):
self.selection_toolbar._pattern_selection.dock.close()
self.selection_toolbar._pattern_selection.remove_plugin()
del self.selection_toolbar._pattern_selection
if getattr(self.digitizer, '_samples_editor', None):
self.digitizer._close_samples_fig()
Expand Down
35 changes: 29 additions & 6 deletions straditize/widgets/pattern_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(self, arr, data_obj, remove_selection=False, *args, **kwargs):
self.toggle_selection)

self.btn_cancel.clicked.connect(self.cancel)
self.btn_close.clicked.connect(self.close)
self.btn_close.clicked.connect(self.remove_plugin)

def toggle_template_selection(self):
"""Enable or disable the template selection"""
Expand Down Expand Up @@ -446,9 +446,9 @@ def cancel(self):
if self.btn_select.isChecked():
self.btn_select.setChecked(False)
self.toggle_selection()
self.close()
self.remove_plugin()

def close(self):
def remove_plugin(self):
from psyplot_gui.main import mainwindow
if self.selector is not None:
self.selector.disconnect_events()
Expand All @@ -463,10 +463,33 @@ def close(self):
self.toggle_correlation_plot()
if self.key_press_cid is not None:
self.data_obj.ax.figure.canvas.mpl_disconnect(self.key_press_cid)
for attr in ['data_obj', 'arr', 'template', 'key_press_cid']:
try:
self.template_im.remove()
except (AttributeError, ValueError):
pass
try:
self.template_fig.delaxes(self.axes)
except (AttributeError, ValueError, RuntimeError):
pass
try:
self.template_fig.close()
except (AttributeError, RuntimeError):
pass
for attr in ['data_obj', 'arr', 'template', 'key_press_cid',
'_orig_selection_arr', '_selected_labels', '_select_cmap',
'_select_norm', '_correlation', 'axes', 'template_fig',
'template_im']:
try:
delattr(self, attr)
except AttributeError:
pass
mainwindow.removeDockWidget(self.dock)
return super(PatternSelectionWidget, self).close()
try:
super().remove_plugin()
except RuntimeError: # already removed
pass
if self.dock is not None:
try:
mainwindow.dockwidgets.remove(self.dock)
except (ValueError, AttributeError):
pass
del self.dock
3 changes: 1 addition & 2 deletions straditize/widgets/selection_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ def start_pattern_selection(self):
w.raise_()
elif self._pattern_selection is not None:
self._pattern_selection.cancel()
self._pattern_selection.close()
self.uncheck_pattern_selection()
del self._pattern_selection

Expand Down Expand Up @@ -844,7 +843,7 @@ def _on_axes_leave(self, event):
def end_selection(self):
"""Finish the selection and disconnect everything"""
if getattr(self, '_pattern_selection', None) is not None:
self._pattern_selection.close()
self._pattern_selection.remove_plugin()
del self._pattern_selection
self._selecting = False
self._action_clicked = None
Expand Down

0 comments on commit 89c04b8

Please sign in to comment.