@@ -38,18 +38,25 @@ def format_Warning(message, category, filename, lineno, line=""):
3838
3939class Loader (QWidget ):
4040 def __init__ (self , parent : "napari.viewer.Viewer" ):
41- super ().__init__ ()
41+ super (Loader , self ).__init__ ()
42+
4243 # self.master = parent
4344 self ._viewer = parent
4445 self .opath = ""
4546 self .modpath = ""
47+ self .filetype = ""
48+
4649 self .btn1 = QPushButton ("Open" , self )
4750 self .btn1 .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
4851 self .btn1 .clicked .connect (self .show_dialog_o )
4952 self .btn2 = QPushButton ("Open" , self )
5053 self .btn2 .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
5154 self .btn2 .clicked .connect (self .show_dialog_mod )
5255
56+ self .filetype_choice = QComboBox ()
57+ self .filetype_choice .addItems ([".png" , ".tif" ])
58+ self .filetype_choice .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
59+
5360 self .textbox = QLineEdit (self )
5461 self .textbox .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
5562
@@ -58,27 +65,38 @@ def __init__(self, parent: "napari.viewer.Viewer"):
5865
5966 self .btn4 = QPushButton ("Start reviewing" , self )
6067 self .btn4 .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
61- self .btn4 .clicked .connect (self .launch_napari )
62- self .btn4 .clicked .connect (self .close )
68+
69+ self .btn4 .clicked .connect (self .run_review )
70+ # self.btn4.clicked.connect(self.close)
6371 self .btnb = QPushButton ("Close" , self )
6472 self .btnb .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
6573 self .btnb .clicked .connect (self .close )
6674 self .lbl = QLabel ("Images directory" , self )
6775 self .lbl2 = QLabel ("Labels directory" , self )
6876 self .lbl4 = QLabel ("Model name" , self )
6977 #####################################################################
70- # TODO
78+ # TODO remove once done
7179 self .btntest = QPushButton ("test" , self )
80+ self .lblft = QLabel ("Filetype :" , self )
81+ self .lblft2 = QLabel ("(Folders of .png or single .tif files)" )
7282 self .btntest .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Fixed )
7383 self .btntest .clicked .connect (self .run_test )
7484 #####################################################################
85+
7586 self .build ()
7687
7788 def build (self ):
89+
7890 vbox = QVBoxLayout ()
91+
7992 vbox .addWidget (utils .combine_blocks (self .btn1 , self .lbl ))
93+
8094 vbox .addWidget (utils .combine_blocks (self .btn2 , self .lbl2 ))
95+ vbox .addWidget (self .lblft2 )
96+ vbox .addWidget (utils .combine_blocks (self .filetype_choice , self .lblft ))
97+
8198 vbox .addWidget (utils .combine_blocks (self .textbox , self .lbl4 ))
99+
82100 vbox .addWidget (self .checkBox )
83101 vbox .addWidget (self .btn4 )
84102 vbox .addWidget (self .btnb )
@@ -109,56 +127,82 @@ def close(self):
109127 # self.master.setCurrentIndex(0)
110128 self ._viewer .window .remove_dock_widget (self )
111129
112- def launch_napari (self ):
113- images = utils .load_images (self .opath )
130+ def run_review (self ):
131+
132+ self .filetype = self .filetype_choice .currentText ()
133+ images = utils .load_images (self .opath , self .filetype )
114134 if self .modpath == "" : # saves empty images of the same size as original images
115135 labels = np .zeros_like (images .compute ()) # dask to numpy
116136 self .modpath = os .path .join (
117137 os .path .dirname (self .opath ), self .textbox .text ()
118138 )
119139 os .makedirs (self .modpath , exist_ok = True )
120140 filenames = [
121- fn .name for fn in sorted (list (Path (self .opath ).glob ("./*png" )))
141+ fn .name
142+ for fn in sorted (list (Path (self .opath ).glob ("./*" + self .filetype )))
122143 ]
123144 for i in range (len (labels )):
124145 io .imsave (
125- os .path .join (self .modpath , str (i ).zfill (4 ) + ".png" ), labels [i ]
146+ os .path .join (self .modpath , str (i ).zfill (4 ) + self .filetype ),
147+ labels [i ],
126148 )
127149 else :
128- labels = utils .load_saved_masks (self .modpath )
150+ labels = utils .load_saved_masks (self .modpath , self . filetype )
129151 try :
130- labels_raw = utils .load_raw_masks (self .modpath + "_raw" )
152+ labels_raw = utils .load_raw_masks (self .modpath + "_raw" , self . filetype )
131153 except :
132154 labels_raw = None
133155 # TODO: viewer argument ?
134- view1 = launch_viewers (
135- self ._viewer ,
136- images ,
137- labels ,
138- labels_raw ,
139- self .modpath ,
140- self .textbox .text (),
141- self .checkBox .isChecked (),
142- )
156+ global launched
157+ if launched :
158+ new_viewer = napari .Viewer ()
159+ view1 = launch_viewers (
160+ new_viewer ,
161+ images ,
162+ labels ,
163+ labels_raw ,
164+ self .modpath ,
165+ self .textbox .text (),
166+ self .checkBox .isChecked (),
167+ self .filetype ,
168+ )
169+ warnings .warn (
170+ "WARNING : Opening several loader sessions in one window is not supported; opening in new window"
171+ )
172+ self ._viewer .close ()
173+ else :
174+ new_viewer = self ._viewer
175+
176+ view1 = launch_viewers (
177+ new_viewer ,
178+ images ,
179+ labels ,
180+ labels_raw ,
181+ self .modpath ,
182+ self .textbox .text (),
183+ self .checkBox .isChecked (),
184+ self .filetype ,
185+ )
186+ launched = True
187+ self .close ()
188+ # global view_l
189+ # view_l.close() # why does it not close the window ?? #use self.close() ?
143190
144- # global view_l
145- # view_l.close() # why does it not close the window ?? #TODO use self.close() ?
146- # self.close
147191 return view1
148192
149193 ########################
150194 # TODO : remove once done
151195 def run_test (self ):
152- tif = False
196+ self . filetype = self . filetype_choice . currentText ()
153197
154198 self .opath = "C:/Users/Cyril/Desktop/Proj_bachelor/data/visual_png/sample"
155199 self .modpath = (
156200 "C:/Users/Cyril/Desktop/Proj_bachelor/data/visual_png/sample_labels"
157201 )
158- if tif :
202+ if self . filetype == ". tif" :
159203 self .opath = "C:/Users/Cyril/Desktop/Proj_bachelor/data/visual_tif/volumes"
160204 self .modpath = "C:/Users/Cyril/Desktop/Proj_bachelor/data/visual_tif/labels"
161- self .launch_napari ()
162- self .close ()
205+ self .run_review ()
206+ # self.close()
163207
164208 ########################
0 commit comments