|
17 | 17 | You should have received a copy of the GNU General Public License |
18 | 18 | along with MAP Client. If not, see <http://www.gnu.org/licenses/>.. |
19 | 19 | """ |
20 | | -import json |
21 | 20 | import os |
22 | 21 | from copy import deepcopy |
23 | 22 |
|
24 | | -from PySide6 import QtGui, QtWidgets |
| 23 | +from PySide6 import QtWidgets |
25 | 24 |
|
26 | 25 | from mapclient.core.managers.pluginmanager import CONST_DEFAULT_PROFILE |
27 | 26 | from mapclient.tools.pluginmanager.ui.ui_pluginmanagerdialog import Ui_PluginManagerDialog |
@@ -143,7 +142,11 @@ def _add_directory_clicked(self): |
143 | 142 | if last: |
144 | 143 | last = last.text() |
145 | 144 |
|
146 | | - directory = QtWidgets.QFileDialog.getExistingDirectory(self, caption='Select External Plugin Directory', dir=last, options=QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontResolveSymlinks | QtWidgets.QFileDialog.ReadOnly) |
| 145 | + dlg_options = (QtWidgets.QFileDialog.Option.ShowDirsOnly | |
| 146 | + QtWidgets.QFileDialog.Option.DontResolveSymlinks | |
| 147 | + QtWidgets.QFileDialog.Option.ReadOnly) |
| 148 | + directory = QtWidgets.QFileDialog.getExistingDirectory( |
| 149 | + self, caption='Select External Plugin Directory', dir=last, options=dlg_options) |
147 | 150 | if len(directory) > 0: |
148 | 151 | current_profile = self._ui.profileComboBox.currentText() |
149 | 152 | self._profile_directories[current_profile].append(directory) |
@@ -200,153 +203,3 @@ def directories(self): |
200 | 203 | def save_profile_data(self): |
201 | 204 | self._plugin_manager.set_current_profile(self._ui.profileComboBox.currentText()) |
202 | 205 | self._plugin_manager.set_profile_directories(self._profile_directories) |
203 | | - |
204 | | -# import sys |
205 | | -# import json |
206 | | -# import os |
207 | | -# from PySide6.QtWidgets import ( |
208 | | -# QApplication, QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QListView, |
209 | | -# QPushButton, QMessageBox, QInputDialog |
210 | | -# ) |
211 | | -# from PySide6.QtGui import QStandardItemModel, QStandardItem |
212 | | -# |
213 | | -DATA_FILE = "models_data.json" |
214 | | -# |
215 | | -initial_data = { |
216 | | - "default": ["/path/1", "/path/2"], |
217 | | - "sparc": ["/path/4", "/path/5"], |
218 | | -} |
219 | | - |
220 | | - |
221 | | -class ModelManager(QtWidgets.QWidget): |
222 | | - def __init__(self): |
223 | | - super().__init__() |
224 | | - self.setWindowTitle("Model Manager") |
225 | | - |
226 | | - main_layout = QtWidgets.QVBoxLayout(self) |
227 | | - control_layout = QtWidgets.QHBoxLayout() |
228 | | - path_control_layout = QtWidgets.QHBoxLayout() |
229 | | - |
230 | | - self.combo_box = QtWidgets.QComboBox() |
231 | | - self.list_view = QtWidgets.QListView() |
232 | | - self.save_button = QtWidgets.QPushButton("Save to Disk") |
233 | | - self.add_key_button = QtWidgets.QPushButton("Add Key") |
234 | | - self.remove_key_button = QtWidgets.QPushButton("Remove Key") |
235 | | - self.add_path_button = QtWidgets.QPushButton("Add Path") |
236 | | - self.remove_path_button = QtWidgets.QPushButton("Remove Path") |
237 | | - |
238 | | - control_layout.addWidget(self.combo_box) |
239 | | - control_layout.addWidget(self.add_key_button) |
240 | | - control_layout.addWidget(self.remove_key_button) |
241 | | - |
242 | | - path_control_layout.addWidget(self.add_path_button) |
243 | | - path_control_layout.addWidget(self.remove_path_button) |
244 | | - |
245 | | - main_layout.addLayout(control_layout) |
246 | | - main_layout.addWidget(self.list_view) |
247 | | - main_layout.addLayout(path_control_layout) |
248 | | - main_layout.addWidget(self.save_button) |
249 | | - |
250 | | - self.list_models = {} |
251 | | - self.load_data() |
252 | | - |
253 | | - self.combo_box.addItems(self.list_models.keys()) |
254 | | - self.combo_box.currentIndexChanged.connect(self.update_list_model) |
255 | | - self.save_button.clicked.connect(self.save_data) |
256 | | - self.add_key_button.clicked.connect(self.add_key) |
257 | | - self.remove_key_button.clicked.connect(self.remove_key) |
258 | | - self.add_path_button.clicked.connect(self.add_path) |
259 | | - self.remove_path_button.clicked.connect(self.remove_path) |
260 | | - |
261 | | - self.update_list_model(0) |
262 | | - |
263 | | - def create_model(self, paths): |
264 | | - model = QtGui.QStandardItemModel() |
265 | | - for path in paths: |
266 | | - item = QtGui.QStandardItem(path) |
267 | | - item.setEditable(True) |
268 | | - model.appendRow(item) |
269 | | - return model |
270 | | - |
271 | | - def update_list_model(self, index): |
272 | | - if index < 0 or self.combo_box.count() == 0: |
273 | | - self.list_view.setModel(QtGui.QStandardItemModel()) |
274 | | - return |
275 | | - key = self.combo_box.itemText(index) |
276 | | - self.list_view.setModel(self.list_models[key]) |
277 | | - |
278 | | - def save_data(self): |
279 | | - data_to_save = { |
280 | | - key: [self.list_models[key].item(i).text() for i in range(self.list_models[key].rowCount())] |
281 | | - for key in self.list_models |
282 | | - } |
283 | | - try: |
284 | | - with open(DATA_FILE, "w") as f: |
285 | | - json.dump(data_to_save, f, indent=2) |
286 | | - QtWidgets.QMessageBox.information(self, "Success", "Data saved successfully.") |
287 | | - except Exception as e: |
288 | | - QtWidgets.QMessageBox.critical(self, "Error", f"Failed to save data: {e}") |
289 | | - |
290 | | - def load_data(self): |
291 | | - if os.path.exists(DATA_FILE): |
292 | | - try: |
293 | | - with open(DATA_FILE, "r") as f: |
294 | | - loaded_data = json.load(f) |
295 | | - except Exception as e: |
296 | | - QtWidgets.QMessageBox.critical(self, "Error", f"Failed to load data: {e}") |
297 | | - loaded_data = initial_data |
298 | | - else: |
299 | | - loaded_data = initial_data |
300 | | - |
301 | | - for key, paths in loaded_data.items(): |
302 | | - self.list_models[key] = self.create_model(paths) |
303 | | - |
304 | | - def add_key(self): |
305 | | - key, ok = QtWidgets.QInputDialog.getText(self, "Add Key", "Enter new key name:") |
306 | | - if ok and key: |
307 | | - if key in self.list_models: |
308 | | - QtWidgets.QMessageBox.warning(self, "Warning", "Key already exists.") |
309 | | - return |
310 | | - self.list_models[key] = self.create_model([]) |
311 | | - self.combo_box.addItem(key) |
312 | | - self.combo_box.setCurrentText(key) |
313 | | - |
314 | | - def remove_key(self): |
315 | | - index = self.combo_box.currentIndex() |
316 | | - if index < 0: |
317 | | - return |
318 | | - key = self.combo_box.itemText(index) |
319 | | - confirm = QtWidgets.QMessageBox.question(self, "Confirm", f"Delete key '{key}'?") |
320 | | - if confirm == QtWidgets.QMessageBox.StandardButton.Yes: |
321 | | - self.combo_box.removeItem(index) |
322 | | - del self.list_models[key] |
323 | | - self.update_list_model(self.combo_box.currentIndex()) |
324 | | - |
325 | | - def add_path(self): |
326 | | - index = self.combo_box.currentIndex() |
327 | | - if index < 0: |
328 | | - return |
329 | | - key = self.combo_box.itemText(index) |
330 | | - path, ok = QtWidgets.QInputDialog.getText(self, "Add Path", "Enter new path:") |
331 | | - if ok and path: |
332 | | - item = QtGui.QStandardItem(path) |
333 | | - item.setEditable(True) |
334 | | - self.list_models[key].appendRow(item) |
335 | | - |
336 | | - def remove_path(self): |
337 | | - index = self.combo_box.currentIndex() |
338 | | - if index < 0: |
339 | | - return |
340 | | - key = self.combo_box.itemText(index) |
341 | | - selected_indexes = self.list_view.selectedIndexes() |
342 | | - if not selected_indexes: |
343 | | - QtWidgets.QMessageBox.warning(self, "Warning", "No path selected.") |
344 | | - return |
345 | | - for idx in selected_indexes: |
346 | | - self.list_models[key].removeRow(idx.row()) |
347 | | - |
348 | | -# if __name__ == "__main__": |
349 | | -# app = QApplication(sys.argv) |
350 | | -# window = ModelManager() |
351 | | -# window.show() |
352 | | -# sys.exit(app.exec()) |
0 commit comments