@@ -351,7 +351,7 @@ def quick_get_narrow_datatypes():
351
351
return flat_narrow_datatypes
352
352
353
353
354
- def in_place_update_settings_for_narrow_datatype ( settings : dict ):
354
+ def in_place_update_narrow_datatypes_if_required ( user_settings : dict ):
355
355
"""
356
356
In versions < v0.6.0, only 'broad' datatypes were implemented
357
357
and available in the TUI. Since, 'narrow' datatypes are introduced
@@ -360,8 +360,39 @@ def in_place_update_settings_for_narrow_datatype(settings: dict):
360
360
361
361
This function converts the old format to the new format so that
362
362
all broad datatype settings (on / off) are maintained in
363
- then new version.
363
+ then new version. It does this by copying the full default
364
+ parameters and overwriting them with the available user-set
365
+ defaults. This is the best approach, as it maintains the
366
+ order of the datatypes (otherwise, inserting non-existing
367
+ datatypes into the user datatype dict results in the wrong order).
368
+
364
369
"""
370
+ has_narrow_datatypes = isinstance (
371
+ user_settings ["tui" ]["create_checkboxes_on" ]["behav" ], dict
372
+ ) # added 'narrow datatype' v0.6.0 with major refactor to dict
373
+
374
+ all_narrow_datatypes = quick_get_narrow_datatypes ()
375
+
376
+ is_not_missing_narrow_datatypes = all (
377
+ [
378
+ dtype in all_narrow_datatypes
379
+ for dtype in user_settings ["tui" ]["create_checkboxes_on" ]
380
+ ]
381
+ )
382
+
383
+ if is_not_missing_narrow_datatypes :
384
+ assert all (
385
+ [
386
+ dtype in all_narrow_datatypes
387
+ for dtype in user_settings ["tui" ]["transfer_checkboxes_on" ]
388
+ ]
389
+ )
390
+
391
+ if has_narrow_datatypes and is_not_missing_narrow_datatypes :
392
+ return
393
+
394
+ # Copy TUI defaults that include narrow-datatype defaults
395
+
365
396
canonical_tui_configs = get_tui_config_defaults ()
366
397
367
398
new_create_checkbox_configs = copy .deepcopy (
@@ -371,18 +402,35 @@ def in_place_update_settings_for_narrow_datatype(settings: dict):
371
402
canonical_tui_configs ["tui" ]["transfer_checkboxes_on" ]
372
403
)
373
404
405
+ # Copy the pre-existing settings for broad datatypes
374
406
for key in ["behav" , "ephys" , "funcimg" , "anat" ]:
375
- new_create_checkbox_configs [key ]["on" ] = settings ["tui" ][
407
+ new_create_checkbox_configs [key ]["on" ] = user_settings ["tui" ][
376
408
"create_checkboxes_on"
377
409
][key ]
378
- new_transfer_checkbox_configs [key ]["on" ] = settings ["tui" ][
410
+ new_transfer_checkbox_configs [key ]["on" ] = user_settings ["tui" ][
379
411
"transfer_checkboxes_on"
380
412
][key ]
381
413
414
+ # Copy the pre-existing settings for the transfer checkboxes
382
415
for key in ["all" , "all_datatype" , "all_non_datatype" ]:
383
- new_transfer_checkbox_configs [key ]["on" ] = settings ["tui" ][
416
+ new_transfer_checkbox_configs [key ]["on" ] = user_settings ["tui" ][
384
417
"transfer_checkboxes_on"
385
418
][key ]
386
419
387
- settings ["tui" ]["create_checkboxes_on" ] = new_create_checkbox_configs
388
- settings ["tui" ]["transfer_checkboxes_on" ] = new_transfer_checkbox_configs
420
+ for narrow_datatype in all_narrow_datatypes :
421
+ if (
422
+ narrow_datatype
423
+ not in user_settings ["tui" ]["create_checkboxes_on" ].keys ()
424
+ ):
425
+ user_settings ["tui" ][
426
+ "create_checkboxes_on"
427
+ ] = new_create_checkbox_configs
428
+
429
+ for narrow_datatype in all_narrow_datatypes :
430
+ if (
431
+ narrow_datatype
432
+ not in user_settings ["tui" ]["transfer_checkboxes_on" ].keys ()
433
+ ):
434
+ user_settings ["tui" ][
435
+ "transfer_checkboxes_on"
436
+ ] = new_transfer_checkbox_configs
0 commit comments