Skip to content

Commit 9c8282e

Browse files
committed
fixed exceptions in the viewer crashing it when a Qt app was created (e.g. from a plot) before the viewer was started (closes #58)
1 parent 9c203ab commit 9c8282e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

larray_editor/api.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import sys
44
import traceback
55
from collections import OrderedDict
6-
import numpy as np
7-
import larray as la
86

97
from qtpy.QtWidgets import QApplication, QMainWindow
8+
import larray as la
9+
1010
from larray_editor.editor import REOPEN_LAST_FILE
1111

1212
__all__ = ['view', 'edit', 'compare', 'REOPEN_LAST_FILE']
@@ -98,9 +98,10 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
9898
>>> # will open an editor for a1 only
9999
>>> edit(a1) # doctest: +SKIP
100100
"""
101+
install_except_hook()
102+
101103
_app = QApplication.instance()
102104
if _app is None:
103-
install_except_hook()
104105
_app = qapplication()
105106
_app.setOrganizationName("LArray")
106107
_app.setApplicationName("Viewer")
@@ -131,8 +132,8 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
131132
_app.exec_()
132133
else:
133134
dlg.exec_()
134-
if parent is None:
135-
restore_except_hook()
135+
136+
restore_except_hook()
136137

137138

138139
def view(obj=None, title='', depth=0):
@@ -185,11 +186,12 @@ def compare(*args, **kwargs):
185186
>>> compare(a1, a2, title='first comparison') # doctest: +SKIP
186187
>>> compare(a1 + 1, a2, title='second comparison', names=['a1+1', 'a2']) # doctest: +SKIP
187188
"""
189+
install_except_hook()
190+
188191
title = kwargs.pop('title', '')
189192
names = kwargs.pop('names', None)
190193
_app = QApplication.instance()
191194
if _app is None:
192-
install_except_hook()
193195
_app = qapplication()
194196
parent = None
195197
else:
@@ -219,8 +221,8 @@ def get_name(i, obj, depth=0):
219221
dlg.show()
220222
else:
221223
dlg.exec_()
222-
if parent is None:
223-
restore_except_hook()
224+
225+
restore_except_hook()
224226

225227
_orig_except_hook = sys.excepthook
226228

@@ -258,6 +260,7 @@ def restore_display_hook():
258260

259261
if __name__ == "__main__":
260262
"""Array editor test"""
263+
import numpy as np
261264

262265
lipro = la.Axis(['P%02d' % i for i in range(1, 16)], 'lipro')
263266
age = la.Axis('age=0..115')

0 commit comments

Comments
 (0)