|
41 | 41 | from PyQt5.QtWidgets import ( |
42 | 42 | QCheckBox, |
43 | 43 | QComboBox, |
| 44 | + QFileDialog, |
44 | 45 | QInputDialog, |
45 | 46 | QListWidgetItem, |
46 | 47 | QMainWindow, |
|
53 | 54 | from .error import QgistWorkbenchNameError |
54 | 55 | from .dtype_fsm import dtype_fsm_class |
55 | 56 | from .ui_manager_base import ui_manager_base_class |
| 57 | +from ..config import config_class |
56 | 58 | from ..error import ( |
57 | 59 | Qgist_ALL_Errors, |
58 | 60 | QgistTypeError, |
@@ -100,7 +102,7 @@ def __init__(self, plugin_root_fld, mainwindow, combobox_workbench, combobox_wor |
100 | 102 |
|
101 | 103 | def _connect_ui(self): |
102 | 104 |
|
103 | | - for item in ('new', 'delete', 'save', 'rename'): |
| 105 | + for item in ('new', 'delete', 'save', 'rename', 'import', 'export'): |
104 | 106 | self._ui_dict['toolbutton_{NAME:s}'.format(NAME = item)].clicked.connect( |
105 | 107 | getattr(self, '_toolbutton_{NAME:s}_clicked'.format(NAME = item)) |
106 | 108 | ) |
@@ -211,6 +213,50 @@ def _toolbutton_rename_clicked(self): |
211 | 213 | self.reject() |
212 | 214 | return |
213 | 215 |
|
| 216 | + def _toolbutton_import_clicked(self): |
| 217 | + |
| 218 | + fn, user_ok = QFileDialog.getOpenFileName( |
| 219 | + self, |
| 220 | + translate('global', 'Import workbench from file'), |
| 221 | + '', |
| 222 | + 'JSON files (*.json);;All Files (*)', |
| 223 | + options = QFileDialog.Options(), |
| 224 | + ) |
| 225 | + if not user_ok: |
| 226 | + return |
| 227 | + |
| 228 | + try: |
| 229 | + self._fsm.import_workbench(config_class.import_config(fn), self._mainwindow) |
| 230 | + self._update_workbenches() |
| 231 | + self._uptdate_items() |
| 232 | + except QgistWorkbenchNameError as e: |
| 233 | + msg_warning(e, self) |
| 234 | + return |
| 235 | + except Qgist_ALL_Errors as e: |
| 236 | + msg_critical(e, self) |
| 237 | + self.reject() |
| 238 | + return |
| 239 | + |
| 240 | + def _toolbutton_export_clicked(self): |
| 241 | + |
| 242 | + fn, user_ok = QFileDialog.getSaveFileName( |
| 243 | + self, |
| 244 | + translate('global', 'Export workbench to file'), |
| 245 | + '', |
| 246 | + 'JSON files (*.json);;All Files (*)', |
| 247 | + options = QFileDialog.Options(), |
| 248 | + ) |
| 249 | + if not user_ok: |
| 250 | + return |
| 251 | + |
| 252 | + try: |
| 253 | + name = self._workbench_index_to_name(self._ui_dict['list_workbenches'].currentRow()) |
| 254 | + config_class.export_config(fn, self._fsm.export_workbench(name)) |
| 255 | + except Qgist_ALL_Errors as e: |
| 256 | + msg_critical(e, self) |
| 257 | + self.reject() |
| 258 | + return |
| 259 | + |
214 | 260 | def _update_workbenches(self): |
215 | 261 |
|
216 | 262 | self._ui_dict['list_workbenches'].setEnabled(False) |
|
0 commit comments