Skip to content

Commit 00b84e4

Browse files
committed
factorize get_app_and_window function to avoid some repetition
1 parent 69e6577 commit 00b84e4

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

larray_editor/api.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616
__all__ = ['view', 'edit', 'debug', 'compare', 'REOPEN_LAST_FILE', 'run_editor_on_exception']
1717

1818

19-
def qapplication():
20-
return QApplication(sys.argv)
19+
def get_app_and_window(app_name):
20+
_app = QApplication.instance()
21+
if _app is None:
22+
_app = QApplication(sys.argv)
23+
_app.setOrganizationName("LArray")
24+
_app.setApplicationName(app_name)
25+
parent = None
26+
else:
27+
parent = _app.activeWindow()
28+
return _app, parent
2129

2230

2331
def find_names(obj, depth=0):
@@ -110,14 +118,7 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
110118
orig_except_hook = sys.excepthook
111119
sys.excepthook = _qt_except_hook
112120

113-
_app = QApplication.instance()
114-
if _app is None:
115-
_app = qapplication()
116-
_app.setOrganizationName("LArray")
117-
_app.setApplicationName("Viewer")
118-
parent = None
119-
else:
120-
parent = _app.activeWindow()
121+
_app, parent = get_app_and_window("Viewer")
121122

122123
caller_frame = sys._getframe(depth + 1)
123124
if display_caller_info:
@@ -192,14 +193,7 @@ def _debug(stack_summary, stack_pos=None):
192193
orig_except_hook = sys.excepthook
193194
sys.excepthook = _qt_except_hook
194195

195-
_app = QApplication.instance()
196-
if _app is None:
197-
_app = qapplication()
198-
_app.setOrganizationName("LArray")
199-
_app.setApplicationName("Debugger")
200-
parent = None
201-
else:
202-
parent = _app.activeWindow()
196+
_app, parent = get_app_and_window("Debugger")
203197

204198
assert isinstance(stack_summary, StackSummary)
205199
dlg = MappingEditor(parent)
@@ -276,14 +270,7 @@ def compare(*args, **kwargs):
276270
depth = kwargs.pop('depth', 0)
277271
display_caller_info = kwargs.pop('display_caller_info', True)
278272

279-
_app = QApplication.instance()
280-
if _app is None:
281-
_app = qapplication()
282-
_app.setOrganizationName("LArray")
283-
_app.setApplicationName("Viewer")
284-
parent = None
285-
else:
286-
parent = _app.activeWindow()
273+
_app, parent = get_app_and_window("Viewer")
287274

288275
caller_frame = sys._getframe(depth + 1)
289276
if display_caller_info:

0 commit comments

Comments
 (0)