@@ -14,6 +14,8 @@ def __init__(self, mainwindow):
1414 self .listWidget .clicked .connect (self .listwidget_doubleclick )
1515 self .lineEdit_jump .returnPressed .connect (self .mainwindow .jump_to )
1616
17+ self .setAcceptDrops (True )
18+
1719 def generate_item_and_itemwidget (self , file_name ):
1820 item = QtWidgets .QListWidgetItem ()
1921 item .setSizeHint (QtCore .QSize (200 , 30 ))
@@ -58,3 +60,88 @@ def listwidget_doubleclick(self):
5860 row = self .listWidget .currentRow ()
5961 self .mainwindow .current_index = row
6062 self .mainwindow .show_image (row )
63+
64+ def dragEnterEvent (self , event ):
65+ if event .mimeData ().hasUrls ():
66+ event .accept ()
67+ else :
68+ event .ignore ()
69+
70+ def dropEvent (self , event ):
71+ if len (event .mimeData ().urls ()) != 1 :
72+ QtWidgets .QMessageBox .warning (self , 'Warning' , 'Only support one path or dir.' )
73+ return
74+ # 这里与mainwindow.opend_dir逻辑一致
75+ path = event .mimeData ().urls ()[0 ].toLocalFile ()
76+ if os .path .isdir (path ):
77+ dir = path
78+ # 等待sam线程退出,并清空特征缓存
79+ if self .mainwindow .use_segment_anything :
80+ self .mainwindow .seganythread .wait ()
81+ self .mainwindow .seganythread .results_dict .clear ()
82+
83+ self .mainwindow .files_list .clear ()
84+ self .mainwindow .files_dock_widget .listWidget .clear ()
85+
86+ files = []
87+ suffixs = tuple (
88+ ['{}' .format (fmt .data ().decode ('ascii' ).lower ()) for fmt in QtGui .QImageReader .supportedImageFormats ()])
89+ for f in os .listdir (dir ):
90+ if f .lower ().endswith (suffixs ):
91+ # f = os.path.join(dir, f)
92+ files .append (f )
93+ files = sorted (files )
94+ self .mainwindow .files_list = files
95+
96+ self .mainwindow .files_dock_widget .update_widget ()
97+
98+ self .mainwindow .current_index = 0
99+
100+ self .mainwindow .image_root = dir
101+ self .mainwindow .actionOpen_dir .setStatusTip ("Image root: {}" .format (self .mainwindow .image_root ))
102+
103+ self .mainwindow .label_root = dir
104+ self .mainwindow .actionSave_dir .setStatusTip ("Label root: {}" .format (self .mainwindow .label_root ))
105+
106+ if os .path .exists (os .path .join (dir , 'isat.yaml' )):
107+ # load setting yaml
108+ self .mainwindow .config_file = os .path .join (dir , 'isat.yaml' )
109+ self .mainwindow .reload_cfg ()
110+
111+ self .mainwindow .show_image (self .mainwindow .current_index )
112+
113+ if os .path .isfile (path ):
114+ # 等待sam线程退出,并清空特征缓存
115+ if self .mainwindow .use_segment_anything :
116+ self .mainwindow .seganythread .wait ()
117+ self .mainwindow .seganythread .results_dict .clear ()
118+
119+ self .mainwindow .files_list .clear ()
120+ self .mainwindow .files_dock_widget .listWidget .clear ()
121+
122+ suffixs = tuple (
123+ ['{}' .format (fmt .data ().decode ('ascii' ).lower ()) for fmt in QtGui .QImageReader .supportedImageFormats ()])
124+
125+ dir , file = os .path .split (path )
126+ files = []
127+ if path .lower ().endswith (suffixs ):
128+ files = [file ]
129+
130+ self .mainwindow .files_list = files
131+
132+ self .mainwindow .files_dock_widget .update_widget ()
133+
134+ self .mainwindow .current_index = 0
135+
136+ self .mainwindow .image_root = dir
137+ self .mainwindow .actionOpen_dir .setStatusTip ("Image root: {}" .format (self .mainwindow .image_root ))
138+
139+ self .mainwindow .label_root = dir
140+ self .mainwindow .actionSave_dir .setStatusTip ("Label root: {}" .format (self .mainwindow .label_root ))
141+
142+ if os .path .exists (os .path .join (dir , 'isat.yaml' )):
143+ # load setting yaml
144+ self .mainwindow .config_file = os .path .join (dir , 'isat.yaml' )
145+ self .mainwindow .reload_cfg ()
146+
147+ self .mainwindow .show_image (self .mainwindow .current_index )
0 commit comments