Browse Source

snuffler: close window confirmation dialog

- can be bypassed when called from script: snuffle(instant_close=True)
- collateral fix: clean shutdown when window is closed from titlebar
  close box
pull/204/head
Sebastian Heimann 3 weeks ago
parent
commit
5f33b36b57
6 changed files with 39 additions and 15 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +8
    -4
      src/gui/pile_viewer.py
  3. +5
    -3
      src/gui/snuffler.py
  4. +19
    -3
      src/gui/snuffler_app.py
  5. +4
    -4
      test/base/test_obspy_compat.py
  6. +1
    -1
      test/gui/test_gui.py

+ 2
- 0
CHANGELOG.md View File

@ -38,6 +38,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
problems when included in XeLaTeX).
- QuakeML: Not strictly requiring preferred origin to be set anymore when
extracting Pyrocko event objects.
- Snuffler now asks for confirmation when the user attempts to close the
window.
## [2020.10.26]


+ 8
- 4
src/gui/pile_viewer.py View File

@ -3751,17 +3751,18 @@ def MakePileViewerMainClass(base):
self.update()
def myclose(self, return_tag=''):
self.return_tag = return_tag
self.window().close()
def cleanup(self):
self.about_to_close.emit()
self.timer.stop()
if self.follow_timer is not None:
self.follow_timer.stop()
self.window().close()
for snuffling in list(self.snufflings):
self.remove_snuffling(snuffling)
self.about_to_close.emit()
self.return_tag = return_tag
def set_error_message(self, key, value):
if value is None:
if key in self.error_messages:
@ -4044,6 +4045,9 @@ class PileViewer(qw.QFrame):
self.viewer.about_to_close.connect(
self.save_inputline_history)
def cleanup(self):
self.viewer.cleanup()
def get_progressbars(self):
return self.progressbars


+ 5
- 3
src/gui/snuffler.py View File

@ -17,7 +17,7 @@ from os.path import join as pjoin
from optparse import OptionParser
from pyrocko import pile
from pyrocko import pile as pile_mod
from pyrocko import util
from pyrocko import model
from pyrocko import config
@ -74,12 +74,14 @@ def snuffle(pile=None, **kwargs):
:param want_markers: bool, whether markers should be returned
:param launch_hook: callback function called before snuffler window is
shown
:param instant_close: bool, whether to bypass close window confirmation
dialog
'''
from .snuffler_app import SnufflerWindow, \
setup_acquisition_sources, PollInjector
if pile is None:
pile = pile.make_pile()
pile = pile_mod.make_pile()
app = get_snuffler_instance()
@ -298,7 +300,7 @@ def snuffler_from_commandline(args=None):
if options.gui_toolkit_qt5:
config.override_gui_toolkit = 'qt5'
this_pile = pile.Pile()
this_pile = pile_mod.Pile()
stations = []
for stations_fn in extend_paths(options.station_fns):
stations.extend(model.station.load_stations(stations_fn))


+ 19
- 3
src/gui/snuffler_app.py View File

@ -570,10 +570,12 @@ class SnufflerWindow(qw.QMainWindow):
def __init__(
self, pile, stations=None, events=None, markers=None, ntracks=12,
follow=None, controls=True, opengl=False):
follow=None, controls=True, opengl=False, instant_close=False):
qw.QMainWindow.__init__(self)
self.instant_close = instant_close
self.dockwidget_to_toggler = {}
self.dockwidgets = []
@ -728,9 +730,23 @@ class SnufflerWindow(qw.QMainWindow):
def return_tag(self):
return self.get_view().return_tag
def confirm_close(self):
ret = qw.QMessageBox.question(
self,
'Snuffler',
'Close Snuffler window?',
qw.QMessageBox.Cancel | qw.QMessageBox.Ok,
qw.QMessageBox.Ok)
return ret == qw.QMessageBox.Ok
def closeEvent(self, event):
event.accept()
self.closing = True
if self.instant_close or self.confirm_close():
self.closing = True
self.pile_viewer.cleanup()
event.accept()
else:
event.ignore()
def is_closing(self):
return self.closing


+ 4
- 4
test/base/test_obspy_compat.py View File

@ -23,20 +23,20 @@ class ObsPyCompatTestCase(unittest.TestCase):
fn = common.test_data_file('test1.mseed')
stream = obspy.read(fn)
stream.snuffle(launch_hook=close_win)
stream.snuffle(launch_hook=close_win, instant_close=True)
trace = stream[0]
trace.snuffle(launch_hook=close_win)
trace.snuffle(launch_hook=close_win, instant_close=True)
@common.require_gui
def test_obspy_fiddle(self):
fn = common.test_data_file('test1.mseed')
stream = obspy.read(fn)
stream2 = stream.fiddle(launch_hook=close_win) # noqa
stream2 = stream.fiddle(launch_hook=close_win, instant_close=True) # noqa
trace = stream[0]
trace2 = trace.fiddle(launch_hook=close_win) # noqa
trace2 = trace.fiddle(launch_hook=close_win, instant_close=True) # noqa
def test_to_obspy_trace(self):
traces = io.load(common.test_data_file('test1.mseed'))


+ 1
- 1
test/gui/test_gui.py View File

@ -67,7 +67,7 @@ class GUITest(unittest.TestCase):
fpath = common.test_data_file('test2.mseed')
p = make_pile(fpath, show_progress=False)
cls.win = SnufflerWindow(pile=p)
cls.win = SnufflerWindow(pile=p, instant_close=True)
cls.pile_viewer = cls.win.pile_viewer
cls.viewer = cls.win.pile_viewer.viewer
pv = cls.pile_viewer


Loading…
Cancel
Save