@@ -106,8 +106,37 @@ def _get_title(obj, depth=0, maxnames=3):
106
106
return ', ' .join (names )
107
107
108
108
109
- def _edit_dialog (parent , obj = None , title = '' , minvalue = None , maxvalue = None , readonly = False , depth = 0 ,
110
- display_caller_info = True , add_larray_functions = None ):
109
+ def create_edit_dialog (parent , obj = None , title = '' , minvalue = None , maxvalue = None , readonly = False , depth = 0 ,
110
+ display_caller_info = True , add_larray_functions = None ):
111
+ """
112
+ Opens a new editor window.
113
+
114
+ Parameters
115
+ ----------
116
+ obj : np.ndarray, Array, Session, dict, str, Path, REOPEN_LAST_FILE or None, optional
117
+ Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
118
+ Passing the constant REOPEN_LAST_FILE loads the last opened file.
119
+ Defaults to None, which gathers all variables (global and local) where the function was called.
120
+ title : str, optional
121
+ Title for the current object. Defaults to the name of the first object found in the caller namespace which
122
+ corresponds to `obj` (it will use a combination of the 3 first names if several names correspond to the same
123
+ object).
124
+ minvalue : scalar, optional
125
+ Minimum value allowed.
126
+ maxvalue : scalar, optional
127
+ Maximum value allowed.
128
+ readonly : bool, optional
129
+ Whether editing array values is forbidden. Defaults to False.
130
+ depth : int, optional
131
+ Stack depth where to look for variables. Defaults to 0 (where this function was called).
132
+ display_caller_info: bool, optional
133
+ Whether to display the filename and line number where the Editor has been called.
134
+ Defaults to True.
135
+ add_larray_functions: bool or None, optional
136
+ Whether to make LArray top-level functions (e.g. ndtest, zeros, ...) available in the console.
137
+ Defaults to None, which means False when obj is None and True otherwise.
138
+ """
139
+
111
140
caller_frame = sys ._getframe (depth + 1 )
112
141
caller_info = getframeinfo (caller_frame ) if display_caller_info else None
113
142
if add_larray_functions is None :
@@ -141,87 +170,7 @@ def _edit_dialog(parent, obj=None, title='', minvalue=None, maxvalue=None, reado
141
170
return None
142
171
143
172
144
- def edit (obj = None , title = '' , minvalue = None , maxvalue = None , readonly = False , depth = 0 , display_caller_info = True ,
145
- add_larray_functions = None ):
146
- """
147
- Opens a new editor window.
148
-
149
- Parameters
150
- ----------
151
- obj : np.ndarray, Array, Session, dict, str, Path, REOPEN_LAST_FILE or None, optional
152
- Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
153
- Passing the constant REOPEN_LAST_FILE loads the last opened file.
154
- Defaults to None, which gathers all variables (global and local) where the function was called.
155
- title : str, optional
156
- Title for the current object. Defaults to the name of the first object found in the caller namespace which
157
- corresponds to `obj` (it will use a combination of the 3 first names if several names correspond to the same
158
- object).
159
- minvalue : scalar, optional
160
- Minimum value allowed.
161
- maxvalue : scalar, optional
162
- Maximum value allowed.
163
- readonly : bool, optional
164
- Whether or not editing array values is forbidden. Defaults to False.
165
- depth : int, optional
166
- Stack depth where to look for variables. Defaults to 0 (where this function was called).
167
- display_caller_info: bool, optional
168
- Whether or not to display the filename and line number where the Editor has been called.
169
- Defaults to True.
170
- add_larray_functions: bool or None, optional
171
- Whether or not to make LArray top-level functions (e.g. ndtest, zeros, ...) available in the console.
172
- Defaults to None, which means False when obj is None and True otherwise.
173
-
174
- Examples
175
- --------
176
- >>> a1 = ndtest(3) # doctest: +SKIP
177
- >>> a2 = ndtest(3) + 1 # doctest: +SKIP
178
- >>> # will open an editor with all the arrays available at this point
179
- >>> # (a1 and a2 in this case)
180
- >>> edit() # doctest: +SKIP
181
- >>> # will open an editor for a1 only
182
- >>> edit(a1) # doctest: +SKIP
183
- """
184
- _show_dialog ("Viewer" , _edit_dialog , obj = obj , title = title , minvalue = minvalue , maxvalue = maxvalue , readonly = readonly ,
185
- depth = depth + 2 , display_caller_info = display_caller_info , add_larray_functions = add_larray_functions )
186
-
187
-
188
- def view (obj = None , title = '' , depth = 0 , display_caller_info = True , add_larray_functions = None ):
189
- """
190
- Opens a new viewer window. Arrays are loaded in readonly mode and their content cannot be modified.
191
-
192
- Parameters
193
- ----------
194
- obj : np.ndarray, Array, Session, dict, str or Path, optional
195
- Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
196
- Defaults to the collection of all local variables where the function was called.
197
- title : str, optional
198
- Title for the current object. Defaults to the name of the first object found in the caller namespace which
199
- corresponds to `obj` (it will use a combination of the 3 first names if several names correspond to the same
200
- object).
201
- depth : int, optional
202
- Stack depth where to look for variables. Defaults to 0 (where this function was called).
203
- display_caller_info: bool, optional
204
- Whether or not to display the filename and line number where the Editor has been called.
205
- Defaults to True.
206
- add_larray_functions: bool or None, optional
207
- Whether or not to make LArray top-level functions (e.g. ndtest, zeros, ...) available in the console.
208
- Defaults to None, which means False when obj is None and True otherwise.
209
-
210
- Examples
211
- --------
212
- >>> a1 = ndtest(3) # doctest: +SKIP
213
- >>> a2 = ndtest(3) + 1 # doctest: +SKIP
214
- >>> # will open a viewer showing all the arrays available at this point
215
- >>> # (a1 and a2 in this case)
216
- >>> view() # doctest: +SKIP
217
- >>> # will open a viewer showing only a1
218
- >>> view(a1) # doctest: +SKIP
219
- """
220
- _show_dialog ("Viewer" , _edit_dialog , obj = obj , title = title , readonly = True ,
221
- depth = depth + 2 , display_caller_info = display_caller_info , add_larray_functions = add_larray_functions )
222
-
223
-
224
- def _debug_dialog (parent , stack_summary , stack_pos = None ):
173
+ def create_debug_dialog (parent , stack_summary , stack_pos = None ):
225
174
assert isinstance (stack_summary , StackSummary )
226
175
dlg = MappingEditor (parent )
227
176
if dlg .setup_and_check (stack_summary , stack_pos = stack_pos ):
@@ -230,26 +179,7 @@ def _debug_dialog(parent, stack_summary, stack_pos=None):
230
179
return None
231
180
232
181
233
- def debug (depth = 0 ):
234
- r"""
235
- Opens a new debug window.
236
-
237
- Parameters
238
- ----------
239
- depth : int, optional
240
- Stack depth where to look for variables. Defaults to 0 (where this function was called).
241
- """
242
- caller_frame = sys ._getframe (depth + 1 )
243
- stack_summary = extract_stack (caller_frame )
244
- _show_dialog ("Debugger" , _debug_dialog , stack_summary )
245
-
246
-
247
- def _compare_dialog (parent , * args , ** kwargs ):
248
- title = kwargs .pop ('title' , '' )
249
- names = kwargs .pop ('names' , None )
250
- depth = kwargs .pop ('depth' , 0 )
251
- display_caller_info = kwargs .pop ('display_caller_info' , True )
252
-
182
+ def create_compare_dialog (parent , * args , title = '' , names = None , depth = 0 , display_caller_info = True , ** kwargs ):
253
183
caller_frame = sys ._getframe (depth + 1 )
254
184
if display_caller_info :
255
185
caller_info = getframeinfo (caller_frame )
@@ -291,50 +221,6 @@ def get_name(i, obj, depth=0):
291
221
return None
292
222
293
223
294
- def compare (* args , ** kwargs ):
295
- """
296
- Opens a new comparator window, comparing arrays or sessions.
297
-
298
- Parameters
299
- ----------
300
- *args : Arrays, Sessions, str or Path.
301
- Arrays or sessions to compare. Strings or Path will be loaded as Sessions from the corresponding files.
302
- title : str, optional
303
- Title for the window. Defaults to ''.
304
- names : list of str, optional
305
- Names for arrays or sessions being compared. Defaults to the name of the first objects found in the caller
306
- namespace which correspond to the passed objects.
307
- depth : int, optional
308
- Stack depth where to look for variables. Defaults to 0 (where this function was called).
309
- display_caller_info: bool, optional
310
- Whether or not to display the filename and line number where the Editor has been called.
311
- Defaults to True.
312
- rtol : float or int, optional
313
- The relative tolerance parameter (see Notes). Defaults to 0.
314
- atol : float or int, optional
315
- The absolute tolerance parameter (see Notes). Defaults to 0.
316
- nans_equal : boolean, optional
317
- Whether or not to consider NaN values at the same positions in the two arrays as equal.
318
- By default, an array containing NaN values is never equal to another array, even if that other array
319
- also contains NaN values at the same positions. The reason is that a NaN value is different from
320
- *anything*, including itself. Defaults to True.
321
-
322
- Notes
323
- -----
324
- For finite values, the following equation is used to test whether two values are equal:
325
-
326
- absolute(array1 - array2) <= (atol + rtol * absolute(array2))
327
-
328
- Examples
329
- --------
330
- >>> a1 = ndtest(3) # doctest: +SKIP
331
- >>> a2 = ndtest(3) + 1 # doctest: +SKIP
332
- >>> compare(a1, a2, title='first comparison') # doctest: +SKIP
333
- >>> compare(a1 + 1, a2, title='second comparison', names=['a1+1', 'a2']) # doctest: +SKIP
334
- """
335
- _show_dialog ("Comparator" , _compare_dialog , * args , ** kwargs )
336
-
337
-
338
224
_orig_except_hook = sys .excepthook
339
225
340
226
@@ -418,11 +304,132 @@ def excepthook(type, value, tback):
418
304
stack = extract_tb (main_tb , limit = tb_limit )
419
305
stack_pos = user_tb_length - 1 if user_tb_length is not None and usercode_frame else None
420
306
print ("\n launching larray editor to debug..." , file = sys .stderr )
421
- _show_dialog ("Debugger" , _debug_dialog , stack , stack_pos = stack_pos )
307
+ _show_dialog ("Debugger" , create_debug_dialog , stack , stack_pos = stack_pos )
422
308
423
309
return excepthook
424
310
425
311
312
+ def edit (obj = None , title = '' , minvalue = None , maxvalue = None , readonly = False , depth = 0 ):
313
+ """
314
+ Opens a new editor window.
315
+
316
+ Parameters
317
+ ----------
318
+ obj : np.ndarray, Array, Session, dict, str, Path, REOPEN_LAST_FILE or None, optional
319
+ Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
320
+ Passing the constant REOPEN_LAST_FILE loads the last opened file.
321
+ Defaults to None, which gathers all variables (global and local) where the function was called.
322
+ title : str, optional
323
+ Title for the current object. Defaults to the name of the first object found in the caller namespace which
324
+ corresponds to `obj` (it will use a combination of the 3 first names if several names correspond to the same
325
+ object).
326
+ minvalue : scalar, optional
327
+ Minimum value allowed.
328
+ maxvalue : scalar, optional
329
+ Maximum value allowed.
330
+ readonly : bool, optional
331
+ Whether editing array values is forbidden. Defaults to False.
332
+ depth : int, optional
333
+ Stack depth where to look for variables. Defaults to 0 (where this function was called).
334
+
335
+ Examples
336
+ --------
337
+ >>> a1 = ndtest(3) # doctest: +SKIP
338
+ >>> a2 = ndtest(3) + 1 # doctest: +SKIP
339
+ >>> # will open an editor with all the arrays available at this point
340
+ >>> # (a1 and a2 in this case)
341
+ >>> edit() # doctest: +SKIP
342
+ >>> # will open an editor for a1 only
343
+ >>> edit(a1) # doctest: +SKIP
344
+ """
345
+ _show_dialog ("Viewer" , create_edit_dialog , obj = obj , title = title , minvalue = minvalue , maxvalue = maxvalue ,
346
+ readonly = readonly , depth = depth + 1 )
347
+
348
+
349
+ def view (obj = None , title = '' , depth = 0 ):
350
+ """
351
+ Opens a new viewer window. Arrays are loaded in readonly mode and their content cannot be modified.
352
+
353
+ Parameters
354
+ ----------
355
+ obj : np.ndarray, Array, Session, dict, str or Path, optional
356
+ Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
357
+ Defaults to the collection of all local variables where the function was called.
358
+ title : str, optional
359
+ Title for the current object. Defaults to the name of the first object found in the caller namespace which
360
+ corresponds to `obj` (it will use a combination of the 3 first names if several names correspond to the same
361
+ object).
362
+ depth : int, optional
363
+ Stack depth where to look for variables. Defaults to 0 (where this function was called).
364
+
365
+ Examples
366
+ --------
367
+ >>> a1 = ndtest(3) # doctest: +SKIP
368
+ >>> a2 = ndtest(3) + 1 # doctest: +SKIP
369
+ >>> # will open a viewer showing all the arrays available at this point
370
+ >>> # (a1 and a2 in this case)
371
+ >>> view() # doctest: +SKIP
372
+ >>> # will open a viewer showing only a1
373
+ >>> view(a1) # doctest: +SKIP
374
+ """
375
+ _show_dialog ("Viewer" , create_edit_dialog , obj = obj , title = title , readonly = True , depth = depth + 1 )
376
+
377
+
378
+ def debug (depth = 0 ):
379
+ r"""
380
+ Opens a new debug window.
381
+
382
+ Parameters
383
+ ----------
384
+ depth : int, optional
385
+ Stack depth where to look for variables. Defaults to 0 (where this function was called).
386
+ """
387
+ caller_frame = sys ._getframe (depth + 1 )
388
+ stack_summary = extract_stack (caller_frame )
389
+ _show_dialog ("Debugger" , create_debug_dialog , stack_summary )
390
+
391
+
392
+ def compare (* args , depth = 0 , ** kwargs ):
393
+ """
394
+ Opens a new comparator window, comparing arrays or sessions.
395
+
396
+ Parameters
397
+ ----------
398
+ *args : Arrays, Sessions, str or Path.
399
+ Arrays or sessions to compare. Strings or Path will be loaded as Sessions from the corresponding files.
400
+ title : str, optional
401
+ Title for the window. Defaults to ''.
402
+ names : list of str, optional
403
+ Names for arrays or sessions being compared. Defaults to the name of the first objects found in the caller
404
+ namespace which correspond to the passed objects.
405
+ rtol : float or int, optional
406
+ The relative tolerance parameter (see Notes). Defaults to 0.
407
+ atol : float or int, optional
408
+ The absolute tolerance parameter (see Notes). Defaults to 0.
409
+ nans_equal : boolean, optional
410
+ Whether to consider NaN values at the same positions in the two arrays as equal.
411
+ By default, an array containing NaN values is never equal to another array, even if that other array
412
+ also contains NaN values at the same positions. The reason is that a NaN value is different from
413
+ *anything*, including itself. Defaults to True.
414
+ depth : int, optional
415
+ Stack depth where to look for variables. Defaults to 0 (where this function was called).
416
+
417
+ Notes
418
+ -----
419
+ For finite values, the following equation is used to test whether two values are equal:
420
+
421
+ absolute(array1 - array2) <= (atol + rtol * absolute(array2))
422
+
423
+ Examples
424
+ --------
425
+ >>> a1 = ndtest(3) # doctest: +SKIP
426
+ >>> a2 = ndtest(3) + 1 # doctest: +SKIP
427
+ >>> compare(a1, a2, title='first comparison') # doctest: +SKIP
428
+ >>> compare(a1 + 1, a2, title='second comparison', names=['a1+1', 'a2']) # doctest: +SKIP
429
+ """
430
+ _show_dialog ("Comparator" , create_compare_dialog , * args , depth = depth + 1 , ** kwargs )
431
+
432
+
426
433
def run_editor_on_exception (root_path = None , usercode_traceback = True , usercode_frame = True ):
427
434
"""
428
435
Run the editor when an unhandled exception (a fatal error) happens.
0 commit comments