@@ -53,7 +53,6 @@ def __init__(self) -> None:
53
53
54
54
def closeEvent (self , event ):
55
55
self .save_settings ()
56
- settings .clean_up ()
57
56
event .accept ()
58
57
59
58
def setup_connections (self ) -> None :
@@ -66,9 +65,6 @@ def setup_connections(self) -> None:
66
65
self .ui .action_open_folder .triggered .connect (self .browse_folder )
67
66
self .ui .action_load_tof .triggered .connect (self .browse_tof )
68
67
self .ui .action_export .triggered .connect (self .export )
69
- self .ui .action_project_save .triggered .connect (self .save )
70
- self .ui .action_project_save_as .triggered .connect (self .save_as )
71
- self .ui .action_project_open .triggered .connect (self .load_settings )
72
68
self .ui .action_restart .triggered .connect (restart )
73
69
self .ui .action_link_inp .triggered .connect (
74
70
lambda : QDesktopServices .openUrl (URL_INP ) # type: ignore
@@ -78,7 +74,7 @@ def setup_connections(self) -> None:
78
74
)
79
75
80
76
# image_viewer connections
81
- self .ui .image_viewer .file_dropped .connect (self .load_images_adapter )
77
+ self .ui .image_viewer .file_dropped .connect (self .load )
82
78
self .ui .roi_plot .norm_range .sigRegionChanged .connect (
83
79
self .update_norm_range_labels
84
80
)
@@ -234,8 +230,22 @@ def setup_connections(self) -> None:
234
230
)
235
231
236
232
def setup_sync (self ) -> None :
237
- if (path := (self .last_file_dir / "settings.blitz" )).exists ():
238
- settings .new_settings (path )
233
+ screen_geometry = QApplication .primaryScreen ().availableGeometry ()
234
+ relative_size = settings .get ("window/relative_size" )
235
+ width = int (screen_geometry .width () * relative_size )
236
+ height = int (screen_geometry .height () * relative_size )
237
+ self .setGeometry (
238
+ (screen_geometry .width () - width ) // 2 ,
239
+ (screen_geometry .height () - height ) // 2 ,
240
+ width ,
241
+ height ,
242
+ )
243
+ if relative_size == 1.0 :
244
+ self .showMaximized ()
245
+
246
+ if (docks_arrangement := settings .get ("window/docks" )):
247
+ self .ui .dock_area .restoreState (docks_arrangement )
248
+
239
249
settings .connect_sync (
240
250
self .ui .checkbox_load_8bit .stateChanged ,
241
251
self .ui .checkbox_load_8bit .isChecked ,
@@ -278,90 +288,62 @@ def setup_sync(self) -> None:
278
288
self .ui .token_edit .setText ,
279
289
"web/token" ,
280
290
)
281
-
282
291
settings .connect_sync (
283
292
self .ui .checkbox_sync_file .stateChanged ,
284
293
self .ui .checkbox_sync_file .isChecked ,
285
294
self .ui .checkbox_sync_file .setChecked ,
286
295
"data/sync" ,
287
296
)
288
- if (settings .get ("data/sync" )
289
- and ((path := settings .get ("data/path" )) != "" )):
290
- if Path (path ).exists ():
291
- mask = settings .get ("data/mask" )[1 :]
292
- crop = settings .get ("data/cropped" )
293
- self .load_images (
294
- Path (path ),
295
- mask = mask if mask else None ,
296
- crop = crop if crop else None ,
297
- )
298
- else :
299
- log ("Path to dataset in .blitz project file does not point to "
300
- "a valid file or folder location. Deleting entry..." ,
301
- color = "red" )
302
- settings .set ("data/path" , "" )
303
- else :
304
- self .ui .image_viewer .load_data ()
305
297
306
- settings .connect_sync (
298
+ def sync_project (self ) -> None :
299
+ settings .connect_sync_project (
307
300
self .ui .checkbox_flipx .stateChanged ,
308
301
self .ui .checkbox_flipx .isChecked ,
309
302
self .ui .checkbox_flipx .setChecked ,
310
- "data/ flipped_x" ,
303
+ "flipped_x" ,
311
304
lambda : self .ui .image_viewer .manipulate ("flip_x" ),
312
305
True ,
313
306
)
314
- settings .connect_sync (
307
+ settings .connect_sync_project (
315
308
self .ui .checkbox_flipy .stateChanged ,
316
309
self .ui .checkbox_flipy .isChecked ,
317
310
self .ui .checkbox_flipy .setChecked ,
318
- "data/ flipped_y" ,
311
+ "flipped_y" ,
319
312
lambda : self .ui .image_viewer .manipulate ("flip_y" ),
320
313
True ,
321
314
)
322
- settings .connect_sync (
315
+ settings .connect_sync_project (
323
316
self .ui .checkbox_transpose .stateChanged ,
324
317
self .ui .checkbox_transpose .isChecked ,
325
318
self .ui .checkbox_transpose .setChecked ,
326
- "data/ transposed" ,
319
+ "transposed" ,
327
320
lambda : self .ui .image_viewer .manipulate ("transpose" ),
328
321
True ,
329
322
)
330
- settings .connect_sync (
323
+ settings .connect_sync_project (
331
324
self .ui .spinbox_pixel .editingFinished ,
332
325
self .ui .spinbox_pixel .value ,
333
326
self .ui .spinbox_pixel .setValue ,
334
- "default/ measure_tool_pixels" ,
327
+ "measure_tool_pixels" ,
335
328
)
336
- settings .connect_sync (
329
+ settings .connect_sync_project (
337
330
self .ui .spinbox_mm .editingFinished ,
338
331
self .ui .spinbox_mm .value ,
339
332
self .ui .spinbox_mm .setValue ,
340
- "default/ measure_tool_au" ,
333
+ "measure_tool_au" ,
341
334
)
342
- settings .connect_sync (
343
- self .ui .image_viewer .ui .histogram .item .sigLevelChangeFinished ,
344
- self .ui .image_viewer .get_lut_config ,
345
- self .ui .image_viewer .load_lut_config ,
346
- "viewer/LUT" ,
347
- rule_out_default = {},
348
- )
349
- settings .connect_sync (
350
- self .ui .image_viewer .ui .histogram .item .sigLookupTableChanged ,
351
- self .ui .image_viewer .get_lut_config ,
352
- self .ui .image_viewer .load_lut_config ,
353
- "viewer/LUT" ,
354
- rule_out_default = {},
335
+ settings .connect_sync_project (
336
+ self .ui .spinbox_iso_smoothing .editingFinished ,
337
+ self .ui .spinbox_iso_smoothing .value ,
338
+ self .ui .spinbox_iso_smoothing .setValue ,
339
+ "isocurve_smoothing" ,
355
340
)
356
341
357
342
def reset_options (self ) -> None :
358
- self .ui .spinbox_max_ram .setRange (.1 , .8 * get_available_ram ())
359
- self .ui .spinbox_max_ram .setValue (settings .get ("default/max_ram" ))
360
- self .ui .button_apply_mask .setChecked (False )
361
- self .ui .checkbox_flipx .setChecked (settings .get ("data/flipped_x" ))
362
- self .ui .checkbox_flipy .setChecked (settings .get ("data/flipped_y" ))
363
- self .ui .checkbox_transpose .setChecked (settings .get ("data/transposed" ))
364
343
self .ui .combobox_reduce .setCurrentIndex (0 )
344
+ self .ui .checkbox_flipx .setChecked (False )
345
+ self .ui .checkbox_flipy .setChecked (False )
346
+ self .ui .checkbox_transpose .setChecked (False )
365
347
if self .ui .image_viewer .data .is_single_image ():
366
348
self .ui .combobox_reduce .setEnabled (False )
367
349
else :
@@ -422,9 +404,6 @@ def reset_options(self) -> None:
422
404
self .ui .spinbox_rosee_smoothing .setMaximum (
423
405
min (self .ui .image_viewer .data .shape )
424
406
)
425
- self .ui .spinbox_iso_smoothing .setValue (
426
- settings .get ("default/isocurve_smoothing" )
427
- )
428
407
self .ui .spinbox_isocurves .setValue (1 )
429
408
self .ui .checkbox_rosee_active .setChecked (False )
430
409
self .ui .checkbox_rosee_h .setEnabled (False )
@@ -491,9 +470,10 @@ def crop(self) -> None:
491
470
def undo_crop (self ) -> None :
492
471
with LoadingManager (self , "Undo Cropping..." ):
493
472
success = self .ui .image_viewer .undo_crop ()
494
- if not success :
495
- self .load_images (self .last_file_dir / self .last_file )
496
- self .reset_options ()
473
+ if success :
474
+ self .reset_options ()
475
+ else :
476
+ self .load (self .last_file_dir / self .last_file )
497
477
498
478
def apply_mask (self ) -> None :
499
479
with LoadingManager (self , "Masking..." ):
@@ -688,14 +668,14 @@ def browse_file(self) -> None:
688
668
directory = str (self .last_file_dir ),
689
669
)
690
670
if file_path :
691
- self .load_images (Path (file_path ))
671
+ self .load (Path (file_path ))
692
672
693
673
def browse_folder (self ) -> None :
694
674
folder_path = QFileDialog .getExistingDirectory (
695
675
directory = str (self .last_file_dir ),
696
676
)
697
677
if folder_path :
698
- self .load_images (Path (folder_path ))
678
+ self .load (Path (folder_path ))
699
679
700
680
def export (self ) -> None :
701
681
with LoadingManager (self , "Exporting..." ):
@@ -759,49 +739,76 @@ def end_web_connection(self, img: ImageData | None) -> None:
759
739
self .ui .button_disconnect .setEnabled (False )
760
740
self ._web_connection .deleteLater ()
761
741
762
- def load_images_adapter (
763
- self ,
764
- file_path : Optional [Path | str ] = None ,
765
- ) -> None :
766
- if isinstance (file_path , str ):
767
- file_path = Path (file_path )
768
- if file_path is not None :
769
- if file_path .suffix == ".blitz" :
770
- log (f"Loading '{ file_path .name } ' configuration file..." ,
771
- color = "green" )
772
- settings .new_settings (file_path )
773
- restart ()
774
- else :
775
- self .load_images (file_path )
742
+ def load (self , path : Optional [Path | str ] = None ) -> None :
743
+ if path is None :
744
+ return self .ui .image_viewer .load_data ()
745
+
746
+ if isinstance (path , str ):
747
+ path = Path (path )
748
+ project_file = path .parent / (path .name .split ("." )[0 ] + ".blitz" )
749
+
750
+ if path .suffix == ".blitz" :
751
+ self .load_project (path )
752
+ elif self .ui .checkbox_sync_file .isChecked () and project_file .exists ():
753
+ self .load_project (project_file )
776
754
else :
777
- self .load_images ()
778
-
779
- def load_images (
780
- self ,
781
- file_path : Optional [Path ] = None ,
782
- mask : Optional [tuple [slice , slice ]] = None ,
783
- crop : Optional [tuple [int , int ]] = None ,
784
- ) -> None :
785
- text = f"Loading { '...' if file_path is None else file_path } "
786
- with LoadingManager (self , text ) as lm :
755
+ self .load_images (path )
756
+ if self .ui .checkbox_sync_file .isChecked ():
757
+ settings .create_project (
758
+ path .parent / (path .name .split ("." )[0 ] + ".blitz" )
759
+ )
760
+ settings .set_project ("path" , path )
761
+ self .sync_project ()
762
+
763
+ def load_project (self , path : Path ) -> None :
764
+ log (f"Loading '{ path .name } ' configuration file..." ,
765
+ color = "green" )
766
+ self .last_file_dir = path .parent
767
+ self .last_file = path .name
768
+ settings .create_project (path )
769
+ saved_path = Path (settings .get_project ("path" ))
770
+ if saved_path .exists ():
771
+ mask = settings .get_project ("mask" )[1 :]
772
+ crop = settings .get_project ("cropped" )
773
+ with LoadingManager (self , f"Loading { saved_path } " ) as lm :
774
+ self .ui .image_viewer .load_data (
775
+ saved_path ,
776
+ size_ratio = self .ui .spinbox_load_size .value (),
777
+ subset_ratio = self .ui .spinbox_load_subset .value (),
778
+ max_ram = self .ui .spinbox_max_ram .value (),
779
+ convert_to_8_bit =
780
+ self .ui .checkbox_load_8bit .isChecked (),
781
+ grayscale = self .ui .checkbox_load_grayscale .isChecked (),
782
+ mask = mask ,
783
+ crop = crop ,
784
+ )
785
+ log (f"Loaded in { lm .duration :.2f} s" )
786
+ self .last_file_dir = saved_path .parent
787
+ self .last_file = saved_path .name
788
+ self .update_statusbar ()
789
+ self .reset_options ()
790
+ self .sync_project ()
791
+ else :
792
+ log ("Path to dataset in .blitz project file does not point to "
793
+ "a valid file or folder location. Deleting entry..." ,
794
+ color = "red" )
795
+ settings .set ("path" , "" )
796
+
797
+ def load_images (self , path : Path ) -> None :
798
+ with LoadingManager (self , f"Loading { path } " ) as lm :
787
799
self .ui .image_viewer .load_data (
788
- file_path ,
800
+ path ,
789
801
size_ratio = self .ui .spinbox_load_size .value (),
790
802
subset_ratio = self .ui .spinbox_load_subset .value (),
791
803
max_ram = self .ui .spinbox_max_ram .value (),
792
804
convert_to_8_bit = self .ui .checkbox_load_8bit .isChecked (),
793
805
grayscale = self .ui .checkbox_load_grayscale .isChecked (),
794
- mask = mask ,
795
- crop = crop ,
796
806
)
797
- if file_path is not None :
798
- log (f"Loaded in { lm .duration :.2f} s" )
799
- self .last_file_dir = file_path .parent
800
- self .last_file = file_path .name
801
- self .update_statusbar ()
802
- self .reset_options ()
803
- if self .ui .checkbox_sync_file .isChecked ():
804
- self .save ()
807
+ log (f"Loaded in { lm .duration :.2f} s" )
808
+ self .last_file_dir = path .parent
809
+ self .last_file = path .name
810
+ self .update_statusbar ()
811
+ self .reset_options ()
805
812
806
813
def operation_changed (self ) -> None :
807
814
self .update_statusbar ()
@@ -832,39 +839,11 @@ def update_roi_settings(self) -> None:
832
839
return
833
840
self .ui .measure_roi .update_labels ()
834
841
835
- def save (self ) -> None :
836
- name = self .last_file
837
- if name == "" :
838
- name = "settings"
839
- if "." in name :
840
- name = name .split ("." )[0 ]
841
- name += ".blitz"
842
- if (self .last_file_dir / name ).exists ():
843
- log (f"Loading '{ name } ' configuration file..." , color = "green" )
844
- settings .new_settings (self .last_file_dir / name )
845
- restart ()
846
- else :
847
- settings .export (self .last_file_dir / name )
848
- self .save_settings ()
849
-
850
- def save_as (self ) -> None :
851
- settings .export ()
852
- self .save_settings ()
853
-
854
842
def save_settings (self ):
855
- settings .set (
856
- "window/docks" ,
857
- self .ui .dock_area .saveState (),
858
- )
843
+ settings .set ("window/docks" , self .ui .dock_area .saveState ())
859
844
screen_geometry = QApplication .primaryScreen ().availableGeometry ()
860
- settings .set (
861
- "window/relative_size" ,
845
+ settings .set ("window/relative_size" ,
862
846
self .width () / screen_geometry .width (),
863
847
)
864
- self .ui .image_viewer .data .save_options ()
865
- if (settings .get ("data/sync" ) and (self .last_file != "" )):
866
- settings .set ("data/path" , str (self .last_file_dir / self .last_file ))
867
-
868
- def load_settings (self ) -> None :
869
- if settings .select ():
870
- restart ()
848
+ if self .ui .checkbox_sync_file .isChecked ():
849
+ self .ui .image_viewer .data .save_options ()
0 commit comments