2
2
3
3
import sys
4
4
import traceback
5
+ from inspect import getframeinfo
5
6
from collections import OrderedDict
6
7
7
- from qtpy .QtWidgets import QApplication , QMainWindow
8
+ from qtpy .QtWidgets import QApplication
8
9
import larray as la
9
10
10
11
from larray_editor .editor import REOPEN_LAST_FILE , MappingEditor , ArrayEditor
@@ -65,7 +66,7 @@ def get_title(obj, depth=0, maxnames=3):
65
66
return ', ' .join (names )
66
67
67
68
68
- def edit (obj = None , title = '' , minvalue = None , maxvalue = None , readonly = False , depth = 0 ):
69
+ def edit (obj = None , title = '' , minvalue = None , maxvalue = None , readonly = False , depth = 0 , display_caller_info = True ):
69
70
"""
70
71
Opens a new editor window.
71
72
@@ -87,6 +88,9 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
87
88
Whether or not editing array values is forbidden. Defaults to False.
88
89
depth : int, optional
89
90
Stack depth where to look for variables. Defaults to 0 (where this function was called).
91
+ display_caller_info: bool, optional
92
+ Whether or not to display the filename and line number where the Editor has been called.
93
+ Defaults to True.
90
94
91
95
Examples
92
96
--------
@@ -109,8 +113,13 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
109
113
else :
110
114
parent = _app .activeWindow ()
111
115
116
+ caller_frame = sys ._getframe (depth + 1 )
117
+ if display_caller_info :
118
+ caller_info = getframeinfo (caller_frame )
119
+ else :
120
+ caller_info = None
121
+
112
122
if obj is None :
113
- caller_frame = sys ._getframe (depth + 1 )
114
123
global_vars = caller_frame .f_globals
115
124
local_vars = caller_frame .f_locals
116
125
obj = OrderedDict ()
@@ -126,10 +135,11 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
126
135
if obj is REOPEN_LAST_FILE or isinstance (obj , (str , la .Session )):
127
136
dlg = MappingEditor (parent )
128
137
assert minvalue is None and maxvalue is None
129
- setup_ok = dlg .setup_and_check (obj , title = title , readonly = readonly )
138
+ setup_ok = dlg .setup_and_check (obj , title = title , readonly = readonly , caller_info = caller_info )
130
139
else :
131
140
dlg = ArrayEditor (parent )
132
- setup_ok = dlg .setup_and_check (obj , title = title , readonly = readonly , minvalue = minvalue , maxvalue = maxvalue )
141
+ setup_ok = dlg .setup_and_check (obj , title = title , readonly = readonly , minvalue = minvalue , maxvalue = maxvalue ,
142
+ caller_info = caller_info )
133
143
134
144
if setup_ok :
135
145
dlg .show ()
@@ -138,7 +148,7 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
138
148
restore_except_hook ()
139
149
140
150
141
- def view (obj = None , title = '' , depth = 0 ):
151
+ def view (obj = None , title = '' , depth = 0 , display_caller_info = True ):
142
152
"""
143
153
Opens a new viewer window. Arrays are loaded in readonly mode and their content cannot be modified.
144
154
@@ -153,6 +163,9 @@ def view(obj=None, title='', depth=0):
153
163
object).
154
164
depth : int, optional
155
165
Stack depth where to look for variables. Defaults to 0 (where this function was called).
166
+ display_caller_info: bool, optional
167
+ Whether or not to display the filename and line number where the Editor has been called.
168
+ Defaults to True.
156
169
157
170
Examples
158
171
--------
@@ -164,7 +177,7 @@ def view(obj=None, title='', depth=0):
164
177
>>> # will open a viewer showing only a1
165
178
>>> view(a1) # doctest: +SKIP
166
179
"""
167
- edit (obj , title = title , readonly = True , depth = depth + 1 )
180
+ edit (obj , title = title , readonly = True , depth = depth + 1 , display_caller_info = display_caller_info )
168
181
169
182
170
183
def compare (* args , ** kwargs ):
@@ -182,6 +195,9 @@ def compare(*args, **kwargs):
182
195
namespace which correspond to the passed objects.
183
196
depth : int, optional
184
197
Stack depth where to look for variables. Defaults to 0 (where this function was called).
198
+ display_caller_info: bool, optional
199
+ Whether or not to display the filename and line number where the Editor has been called.
200
+ Defaults to True.
185
201
186
202
Examples
187
203
--------
@@ -195,13 +211,20 @@ def compare(*args, **kwargs):
195
211
title = kwargs .pop ('title' , '' )
196
212
names = kwargs .pop ('names' , None )
197
213
depth = kwargs .pop ('depth' , 0 )
214
+ display_caller_info = kwargs .pop ('display_caller_info' , True )
198
215
_app = QApplication .instance ()
199
216
if _app is None :
200
217
_app = qapplication ()
201
218
parent = None
202
219
else :
203
220
parent = _app .activeWindow ()
204
221
222
+ caller_frame = sys ._getframe (depth + 1 )
223
+ if display_caller_info :
224
+ caller_info = getframeinfo (caller_frame )
225
+ else :
226
+ caller_info = None
227
+
205
228
if any (isinstance (a , la .Session ) for a in args ):
206
229
from larray_editor .comparator import SessionComparator
207
230
dlg = SessionComparator (parent )
@@ -221,7 +244,7 @@ def get_name(i, obj, depth=0):
221
244
else :
222
245
assert isinstance (names , list ) and len (names ) == len (args )
223
246
224
- if dlg .setup_and_check (args , names = names , title = title ):
247
+ if dlg .setup_and_check (args , names = names , title = title , caller_info = caller_info ):
225
248
dlg .show ()
226
249
_app .exec_ ()
227
250
0 commit comments