-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from kartoza/tim
Fix unwanted deps
- Loading branch information
Showing
16 changed files
with
1,208 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,3 +66,4 @@ nix-result/ | |
data | ||
core | ||
app.py | ||
/geest.zip |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .base_dialog import BaseDialog | ||
from .osm_downloader_dialog import OSMDownloaderDialog | ||
from .index_score_dialog import IndexScoreDialog | ||
|
||
__all__ = ['BaseDialog', 'OSMDownloaderDialog', 'IndexScoreDialog'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from abc import ABC, abstractmethod | ||
from qgis.PyQt.QtWidgets import QDialog, QVBoxLayout, QLabel, QHBoxLayout, QPushButton | ||
from qgis.PyQt.QtCore import Qt | ||
|
||
from GEEST2.geest.gui.widgets.widget_factory import WidgetFactory | ||
|
||
|
||
class BaseDialog(QDialog, ABC): | ||
def __init__(self, input_specs: dict, on_accept_callback, parent=None): | ||
""" | ||
Initialize the base dialog. | ||
:param input_specs: Dictionary containing dialog specifications. | ||
:param on_accept_callback: Callback function to handle inputs upon acceptance. | ||
:param parent: Parent widget. | ||
""" | ||
super().__init__(parent) | ||
self.input_specs = input_specs | ||
self.widgets = {} | ||
self.on_accept_callback = on_accept_callback | ||
self.init_ui() | ||
|
||
def init_ui(self): | ||
# Set dialog properties | ||
self.setWindowTitle(self.input_specs.get('title', 'Dialog')) | ||
self.layout = QVBoxLayout() | ||
self.setLayout(self.layout) | ||
|
||
# Iterate over input specifications to create widgets | ||
for element in self.input_specs.get('elements', []): | ||
widget_type = element.get('type') | ||
label_text = element.get('label', '') | ||
widget = self.create_widget(widget_type, element) | ||
|
||
if label_text: | ||
label = QLabel(label_text) | ||
label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) | ||
self.layout.addWidget(label) | ||
|
||
if widget: | ||
self.layout.addWidget(widget) | ||
self.widgets[element.get('name')] = widget | ||
|
||
# Add dialog buttons | ||
self.add_buttons() | ||
|
||
def add_buttons(self): | ||
button_layout = QHBoxLayout() | ||
self.ok_button = QPushButton("OK") | ||
self.cancel_button = QPushButton("Cancel") | ||
self.ok_button.clicked.connect(self.handle_accept) | ||
self.cancel_button.clicked.connect(self.reject) | ||
button_layout.addStretch() | ||
button_layout.addWidget(self.ok_button) | ||
button_layout.addWidget(self.cancel_button) | ||
self.layout.addLayout(button_layout) | ||
|
||
def create_widget(self, widget_type, spec): | ||
return WidgetFactory.create_widget(widget_type, spec, self) | ||
|
||
def get_inputs(self): | ||
inputs = {} | ||
for name, widget in self.widgets.items(): | ||
spec = next((elem for elem in self.input_specs['elements'] if elem['name'] == name), None) | ||
if spec: | ||
inputs[name] = WidgetFactory.get_widget_value(widget, spec) | ||
return inputs | ||
|
||
def handle_accept(self): | ||
if self.validate_inputs(): | ||
inputs = self.get_inputs() | ||
self.on_accept_callback(inputs) | ||
self.accept() | ||
else: | ||
# handle validation failure | ||
pass | ||
|
||
@staticmethod | ||
def validate_inputs(): | ||
# input validation happens here | ||
return True | ||
|
||
@abstractmethod | ||
def process_inputs(self, inputs: dict): | ||
""" | ||
This must be implemented by derived classes! | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from .base_dialog import BaseDialog | ||
|
||
class IndexScoreDialog(BaseDialog): | ||
def __init__(self, on_accept_callback, parent=None): | ||
input_specs = { | ||
'title': 'Index Score Configuration', | ||
'elements': [ | ||
{ | ||
'type': 'doublespinbox', | ||
'label': 'Default Value', | ||
'name': 'default_value', | ||
'min': 0.0, | ||
'max': 100.0, | ||
'decimals': 2, | ||
'default': 50.0 | ||
}, | ||
{ | ||
'type': 'spinbox', | ||
'label': 'Allowed Range', | ||
'name': 'allowed_range', | ||
'min': 1, | ||
'max': 10, | ||
'default': 5 | ||
}, | ||
# other widgettes go here | ||
] | ||
} | ||
super().__init__(input_specs, on_accept_callback, parent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from .base_dialog import BaseDialog | ||
|
||
class OSMDownloaderDialog(BaseDialog): | ||
def __init__(self, on_accept_callback, parent=None): | ||
input_specs = { | ||
'title': 'OSM Downloader', | ||
'elements': [ | ||
{ | ||
'type': 'radiobutton', | ||
'label': 'Data Source', | ||
'name': 'data_source', | ||
'options': [ | ||
{'label': 'Manual Input', 'id': 'manual', 'checked': True}, | ||
{'label': 'Download from OSM', 'id': 'osm'} | ||
] | ||
}, | ||
{ | ||
'type': 'lineedit', | ||
'label': 'OSM Query', | ||
'name': 'osm_query', | ||
'default': 'highway=primary' | ||
}, | ||
# more weedjits here | ||
] | ||
} | ||
super().__init__(input_specs, on_accept_callback, parent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .widget_factory import WidgetFactory | ||
|
||
__all__ = ['WidgetFactory'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from qgis.PyQt.QtWidgets import ( | ||
QDoubleSpinBox, QSpinBox, QLineEdit, QComboBox, QRadioButton, QButtonGroup, | ||
QFileDialog, QWidget, QHBoxLayout | ||
) | ||
from qgis.gui import QgsLayerComboBox | ||
from qgis.core import QgsMapLayer | ||
|
||
class WidgetFactory: | ||
@staticmethod | ||
def create_widget(widget_type, spec, parent): | ||
if widget_type == 'doublespinbox': | ||
widget = QDoubleSpinBox(parent) | ||
widget.setRange(spec.get('min', -1e10), spec.get('max', 1e10)) | ||
widget.setDecimals(spec.get('decimals', 2)) | ||
widget.setValue(spec.get('default', 0.0)) | ||
return widget | ||
elif widget_type == 'spinbox': | ||
widget = QSpinBox(parent) | ||
widget.setRange(spec.get('min', -1e9), spec.get('max', 1e9)) | ||
widget.setValue(spec.get('default', 0)) | ||
return widget | ||
elif widget_type == 'lineedit': | ||
widget = QLineEdit(parent) | ||
widget.setText(spec.get('default', '')) | ||
return widget | ||
elif widget_type == 'dropdown': | ||
widget = QComboBox(parent) | ||
options = spec.get('options', []) | ||
widget.addItems(options) | ||
default = spec.get('default') | ||
if default in options: | ||
widget.setCurrentText(default) | ||
elif options: | ||
widget.setCurrentText(options[0]) | ||
return widget | ||
elif widget_type == 'radiobutton': | ||
button_group = QButtonGroup(parent) | ||
layout = QHBoxLayout() | ||
container = QWidget(parent) | ||
container.setLayout(layout) | ||
for option in spec.get('options', []): | ||
rb = QRadioButton(option['label']) | ||
rb.setChecked(option.get('checked', False)) | ||
button_group.addButton(rb, id=option.get('id')) | ||
layout.addWidget(rb) | ||
container.button_group = button_group # Attach the button group for retrieval | ||
return container | ||
elif widget_type == 'layerselector': | ||
widget = QgsLayerComboBox(parent) | ||
layer_type = spec.get('layer_type', 'vector') # can be vector or raster | ||
if layer_type == 'vector': | ||
widget.setFilters(QgsMapLayer.VectorLayer) | ||
elif layer_type == 'raster': | ||
widget.setFilters(QgsMapLayer.RasterLayer) | ||
widget.setCurrentLayer(spec.get('default_layer', None)) | ||
return widget | ||
# more widgets go here | ||
else: | ||
return None | ||
|
||
@staticmethod | ||
def get_widget_value(widget, spec): | ||
widget_type = spec.get('type') | ||
if widget_type in ['doublespinbox', 'spinbox']: | ||
return widget.value() | ||
elif widget_type == 'lineedit': | ||
return widget.text() | ||
elif widget_type == 'dropdown': | ||
return widget.currentText() | ||
elif widget_type == 'radiobutton': | ||
checked_button = widget.button_group.checkedButton() | ||
return checked_button.text() if checked_button else None | ||
elif widget_type == 'layerselector': | ||
layer = widget.currentLayer() | ||
return layer.name() if layer else None | ||
else: | ||
return None |
File renamed without changes.