Skip to content

Commit 150b44f

Browse files
committed
Use inherited Dialogs using plugintools' load_ui
1 parent d377258 commit 150b44f

11 files changed

+83
-31
lines changed

nlsgpkgloader/nls_geopackage_loader.py

+30-24
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,44 @@
2121

2222
import io
2323
import os
24-
import sqlite3
2524
import xml.etree.ElementTree
2625
import zipfile
2726
from zipfile import BadZipFile
2827

29-
import processing
3028
import requests
3129
from osgeo import ogr
32-
from qgis.PyQt import uic
33-
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTimer, QTranslator, qVersion
34-
from qgis.PyQt.QtGui import QIcon
35-
from qgis.PyQt.QtWidgets import QAction, QListWidgetItem, QMessageBox
3630
from qgis.core import (
37-
QgsCoordinateReferenceSystem,
38-
QgsFeature,
39-
QgsFeatureRequest,
31+
QgsApplication,
4032
QgsLayerTreeGroup,
4133
QgsMessageLog,
42-
QgsProcessingFeedback,
4334
QgsProject,
44-
QgsVectorFileWriter,
4535
QgsVectorLayer,
4636
)
47-
from qgis.gui import QgsBusyIndicatorDialog, QgsFileWidget
37+
from qgis.gui import QgsFileWidget
38+
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTimer, QTranslator, qVersion
39+
from qgis.PyQt.QtGui import QIcon
40+
from qgis.PyQt.QtWidgets import QAction, QListWidgetItem, QMessageBox
4841

49-
NLS_USER_KEY_DIALOG_FILE = "nls_geopackage_loader_dialog_NLS_user_key.ui"
50-
MUNICIPALITIES_DIALOG_FILE = "nls_geopackage_loader_dialog_municipality_selection.ui"
51-
NLS_PROGRESS_DIALOG_FILE = "nls_geopackage_loader_dialog_progress.ui"
42+
from nlsgpkgloader.nls_geopackage_loader_mtk_productdata import (
43+
MTK_ALL_PRODUCTS_TITLE,
44+
MTK_ALL_PRODUCTS_URL,
45+
MTK_LAYERS_KEY_PREFIX,
46+
MTK_PRESELECTED_PRODUCTS,
47+
MTK_PRODUCT_NAMES,
48+
MTK_STYLED_LAYERS,
49+
)
50+
from nlsgpkgloader.nls_geopackage_loader_tasks import (
51+
CleanUpTask,
52+
ClipLayersTask,
53+
CreateGeoPackageTask,
54+
DissolveFeaturesTask,
55+
)
56+
from nlsgpkgloader.qgis_plugin_tools.tools.resources import resources_path
57+
from nlsgpkgloader.ui import (
58+
NLSGeoPackageLoaderMunicipalitySelectionDialog,
59+
NLSGeoPackageLoaderProgressDialog,
60+
NLSGeoPackageLoaderUserKeyDialog,
61+
)
5262

5363

5464
class NLSGeoPackageLoader:
@@ -90,9 +100,8 @@ def __init__(self, iface):
90100
self.path = os.path.dirname(__file__)
91101
self.data_download_dir = self.path
92102

93-
self.nls_user_key_dialog = uic.loadUi(
94-
os.path.join(self.path, NLS_USER_KEY_DIALOG_FILE)
95-
)
103+
self.nls_user_key_dialog = NLSGeoPackageLoaderUserKeyDialog()
104+
96105
self.first_run = QSettings().value("/NLSgpkgloader/first_run", True, type=bool)
97106
if self.first_run:
98107
QSettings().setValue("/NLSgpkgloader/first_run", False)
@@ -240,9 +249,8 @@ def run(self):
240249

241250
self.product_types = self.downloadNLSProductTypes()
242251

243-
self.municipalities_dialog = uic.loadUi(
244-
os.path.join(self.path, MUNICIPALITIES_DIALOG_FILE)
245-
)
252+
self.municipalities_dialog = NLSGeoPackageLoaderMunicipalitySelectionDialog()
253+
246254
self.municipalities_dialog.settingsPushButton.clicked.connect(
247255
self.showSettingsDialog
248256
)
@@ -298,9 +306,7 @@ def run(self):
298306
else:
299307
return
300308

301-
self.progress_dialog = uic.loadUi(
302-
os.path.join(self.path, NLS_PROGRESS_DIALOG_FILE)
303-
)
309+
self.progress_dialog = NLSGeoPackageLoaderProgressDialog()
304310
self.progress_dialog.progressBar.hide()
305311
self.progress_dialog.label.setText("Initializing...")
306312
self.progress_dialog.show()

nlsgpkgloader/ui/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .nls_geopackage_loader_dialog import NLSGeoPackageLoaderDialog
2+
from .nls_geopackage_loader_municipality_dialog import (
3+
NLSGeoPackageLoaderMunicipalitySelectionDialog,
4+
)
5+
from .nls_geopackage_loader_progress_dialog import NLSGeoPackageLoaderProgressDialog
6+
from .nls_geopackage_loader_user_key_dialog import NLSGeoPackageLoaderUserKeyDialog
7+
8+
__all__ = [
9+
"NLSGeoPackageLoaderUserKeyDialog",
10+
"NLSGeoPackageLoaderDialog",
11+
"NLSGeoPackageLoaderProgressDialog",
12+
"NLSGeoPackageLoaderMunicipalitySelectionDialog",
13+
]

nlsgpkgloader/nls_geopackage_loader_dialog.py nlsgpkgloader/ui/nls_geopackage_loader_dialog.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@
2020
# You should have received a copy of the GNU General Public License
2121
# along with NLSgpkgloadert. If not, see <https://www.gnu.org/licenses/>.
2222

23-
import os
23+
from qgis.PyQt import QtWidgets
2424

25-
from qgis.PyQt import QtWidgets, uic
25+
from nlsgpkgloader.qgis_plugin_tools.tools.resources import load_ui
2626

2727
# This loads your .ui file so that PyQt can populate your plugin with the
2828
# elements from Qt Designer
29-
FORM_CLASS, _ = uic.loadUiType(
30-
os.path.join(os.path.dirname(__file__), "nls_geopackage_loader_dialog_base.ui")
31-
)
29+
FORM_CLASS = load_ui("nls_geopackage_loader_dialog_base.ui")
3230

3331

3432
class NLSGeoPackageLoaderDialog(QtWidgets.QDialog, FORM_CLASS):
3533
def __init__(self, parent=None):
3634
"""Constructor."""
37-
super(NLSGeoPackageLoaderDialog, self).__init__(parent)
35+
super().__init__(parent)
3836
# Set up the user interface from Designer through FORM_CLASS.
3937
# After self.setupUi() you can access any designer object by doing
4038
# self.<objectname>, and you can use autoconnect slots - see
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from qgis.PyQt.QtWidgets import QDialog
2+
3+
from nlsgpkgloader.qgis_plugin_tools.tools.resources import load_ui
4+
5+
FORM_CLASS = load_ui("nls_geopackage_loader_dialog_municipality_selection.ui")
6+
7+
8+
class NLSGeoPackageLoaderMunicipalitySelectionDialog(QDialog, FORM_CLASS):
9+
def __init__(self, parent=None):
10+
super().__init__(parent)
11+
self.setupUi(self)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from qgis.PyQt.QtWidgets import QDialog
2+
3+
from nlsgpkgloader.qgis_plugin_tools.tools.resources import load_ui
4+
5+
FORM_CLASS = load_ui("nls_geopackage_loader_dialog_progress.ui")
6+
7+
8+
class NLSGeoPackageLoaderProgressDialog(QDialog, FORM_CLASS):
9+
def __init__(self, parent=None):
10+
super().__init__(parent)
11+
self.setupUi(self)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from qgis.PyQt.QtWidgets import QDialog
2+
3+
from nlsgpkgloader.qgis_plugin_tools.tools.resources import load_ui
4+
5+
FORM_CLASS = load_ui("nls_geopackage_loader_dialog_NLS_user_key.ui")
6+
7+
8+
class NLSGeoPackageLoaderUserKeyDialog(QDialog, FORM_CLASS):
9+
def __init__(self, parent=None):
10+
super().__init__(parent)
11+
self.setupUi(self)
12+
13+
print(dir(self))

tests/test_nls_geopackage_loader_dialog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import pytest
1717
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
1818

19-
from nlsgpkgloader.nls_geopackage_loader_dialog import NLSGeoPackageLoaderDialog
19+
from nlsgpkgloader.ui.nls_geopackage_loader_dialog import NLSGeoPackageLoaderDialog
2020

2121

2222
@pytest.fixture

0 commit comments

Comments
 (0)