Skip to content

Commit

Permalink
Merge pull request #296 from osundwajeff/move-to-geest-core
Browse files Browse the repository at this point in the history
Move to geest/core
  • Loading branch information
osundwajeff authored Sep 21, 2024
2 parents b54b13a + dfa6350 commit 04d9923
Show file tree
Hide file tree
Showing 69 changed files with 204 additions and 1,649 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black-python-code-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "./src/qgis_gender_indicator_tool"
src: "./geest"
4 changes: 2 additions & 2 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import typer

LOCAL_ROOT_DIR = Path(__file__).parent.resolve()
SRC_NAME = "qgis_gender_indicator_tool"
SRC_NAME = "geest"
PACKAGE_NAME = SRC_NAME.replace("_", "")
TEST_FILES = ["test", "test_suite.py", "docker-compose.yml", "scripts"]
app = typer.Typer()
Expand Down Expand Up @@ -245,7 +245,7 @@ def copy_source_files(
"""
output_directory.mkdir(parents=True, exist_ok=True)
for child in (LOCAL_ROOT_DIR / "src" / SRC_NAME).iterdir():
for child in (LOCAL_ROOT_DIR / SRC_NAME).iterdir():
if child.name != "__pycache__":
target_path = output_directory / child.name
handler = shutil.copytree if child.is_dir() else shutil.copy
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
qgis-testing-environment:
image: ${IMAGE}:${QGIS_VERSION_TAG}
volumes:
- ./build/qgis_gender_indicator_tool:/tests_directory:rw
- ./build/geest:/tests_directory:rw
environment:
QGIS_VERSION_TAG: "${QGIS_VERSION_TAG}"
WITH_PYTHON_PEP: "${WITH_PYTHON_PEP}"
Expand Down
28 changes: 15 additions & 13 deletions geest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
from qgis.PyQt.QtWidgets import QMessageBox, QPushButton, QAction, QDockWidget
from qgis.core import Qgis

#from .geest import Geest
#from .core import RenderQueue, setting
from .core import setting #, JSONValidator
# from .geest import Geest
# from .core import RenderQueue, setting
from .core import setting # , JSONValidator
from .utilities import resources_path
from .gui import GeestOptionsFactory, GeestDock

Expand All @@ -46,26 +46,29 @@ class GeestPlugin:
def __init__(self, iface):
self.iface = iface

#self.render_queue: Optional[RenderQueue] = None
# self.render_queue: Optional[RenderQueue] = None
self.run_action: Optional[QAction] = None
self.debug_action: Optional[QAction] = None
self.options_factory = None

def initGui(self): # pylint: disable=missing-function-docstring

#self.render_queue = RenderQueue()
# self.render_queue = RenderQueue()
icon = QIcon(resources_path("resources", "geest-main.svg"))

# Validate our json schema first
#validator = JSONValidator('resources/schema.json', 'resources/model.json')
#validator.validate_json()
# validator = JSONValidator('resources/schema.json', 'resources/model.json')
# validator.validate_json()

self.run_action = QAction(icon, "GEEST", self.iface.mainWindow())
self.run_action.triggered.connect(self.run)
self.iface.addToolBarIcon(self.run_action)
self.dock_widget = GeestDock(parent=self.iface.mainWindow(), json_file=resources_path("resources", "model.json"))
self.dock_widget = GeestDock(
parent=self.iface.mainWindow(),
json_file=resources_path("resources", "model.json"),
)
self.dock_widget.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
#self.dock_widget.setWidget(Geest(self.iface.mainWindow(), self.iface))
# self.dock_widget.setWidget(Geest(self.iface.mainWindow(), self.iface))
self.dock_widget.setFloating(False)
self.dock_widget.setFeatures(QDockWidget.DockWidgetMovable)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dock_widget)
Expand All @@ -85,7 +88,7 @@ def initGui(self): # pylint: disable=missing-function-docstring
debug_env = int(os.getenv("GEEST_DEBUG", 0))
if debug_env:
self.debug()

self.options_factory = GeestOptionsFactory()
self.iface.registerOptionsWidgetFactory(self.options_factory)

Expand Down Expand Up @@ -125,9 +128,8 @@ def run(self):
"""
# Create the settings dialog
self.iface.showOptionsDialog(
parent=self.iface.mainWindow(),
currentPage='geest')

parent=self.iface.mainWindow(), currentPage="geest"
)

def display_information_message_bar(
self,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions geest/gui/geest_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(self, parent=None):
"""
QgsOptionsPageWidget.__init__(self, parent)
self.setupUi(self)
# We need this so we can open the settings to our own
# We need this so we can open the settings to our own
# page from the plugin button bar.
self.setObjectName('geest')
self.setObjectName("geest")
# The maximum number of concurrent threads to allow
# during rendering. Probably setting to the same number
# of CPU cores you have would be a good conservative approach
Expand All @@ -41,8 +41,8 @@ def __init__(self, parent=None):
if edit_mode:
self.edit_mode_checkbox.setChecked(True)
else:
self.edit_mode_checkbox.setChecked(False)
self.edit_mode_checkbox.setChecked(False)

# This is intended for developers to attach to the plugin using a
# remote debugger so that they can step through the code. Do not
# enable it if you do not have a remote debugger set up as it will
Expand All @@ -69,12 +69,12 @@ def apply(self):
key="render_thread_pool_size",
value=self.spin_thread_pool_size.value(),
)

if self.edit_mode_checkbox.isChecked():
set_setting(key="edit_mode", value=1)
else:
set_setting(key="edit_mode", value=0)
set_setting(key="edit_mode", value=0)

if self.debug_mode_checkbox.isChecked():
set_setting(key="debug_mode", value=1)
else:
Expand Down
13 changes: 6 additions & 7 deletions geest/gui/geest_treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,19 @@ def setData(self, index, value, role=Qt.EditRole):

def flags(self, index):
"""Allow editing of the name and weighting columns."""
#Override the flags method to allow specific columns to be editable.

# Override the flags method to allow specific columns to be editable.

if not index.isValid():
return Qt.NoItemFlags

item = index.internalPointer()
# For example, only allow editing for the first and second columns
if index.column() == 0 or index.column() == 1:
return Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled

return Qt.ItemIsSelectable | Qt.ItemIsEnabled


return Qt.ItemIsSelectable | Qt.ItemIsEnabled

def update_font_color(self, item, color):
"""Update the font color of an item."""
item.font_color = color
Expand Down
4 changes: 3 additions & 1 deletion geest/gui/toggle_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def paintEvent(self, event):

# Background color based on state
if self.checked:
painter.setBrush(QColor("#002244")) # Active state color (blue) from WB Style Guide
painter.setBrush(
QColor("#002244")
) # Active state color (blue) from WB Style Guide
else:
painter.setBrush(QColor("#ADB5BD")) # Inactive state color (gray)

Expand Down
45 changes: 30 additions & 15 deletions geest/gui/tree_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import json
import os
from .geest_treeview import CustomTreeView, JsonTreeModel
from .setup_panel import SetupPanel
from .setup_panel import SetupPanel
from .layer_detail_dialog import LayerDetailDialog
from geest.utilities import resources_path
from geest.core import set_setting, setting


class TreePanel(QWidget):
def __init__(self, parent=None, json_file=None):
super().__init__(parent)
Expand All @@ -40,7 +41,7 @@ def __init__(self, parent=None, json_file=None):
else:
self.json_data = {"dimensions": []}

# Create a CustomTreeView widget to handle editing and reverts
# Create a CustomTreeView widget to handle editing and reverts
self.treeView = CustomTreeView()
self.treeView.setDragDropMode(QTreeView.InternalMove)
self.treeView.setDefaultDropAction(Qt.MoveAction)
Expand Down Expand Up @@ -93,7 +94,7 @@ def __init__(self, parent=None, json_file=None):
self.prepare_button = QPushButton("▶️ Prepare")
self.prepare_button.clicked.connect(self.process_leaves)
movie.start()

# Add Edit Toggle checkbox
self.edit_toggle = QCheckBox("Edit")
self.edit_toggle.setChecked(False)
Expand All @@ -102,8 +103,8 @@ def __init__(self, parent=None, json_file=None):
if edit_mode:
self.edit_toggle.setVisible(True)
else:
self.edit_toggle.setVisible(False)
self.edit_toggle.setVisible(False)

button_bar.addWidget(self.add_dimension_button)
button_bar.addStretch()

Expand All @@ -115,7 +116,7 @@ def __init__(self, parent=None, json_file=None):
button_bar.addWidget(self.edit_toggle) # Add the edit toggle
layout.addLayout(button_bar)
self.setLayout(layout)

def edit(self, index, trigger, event):
"""
Override the edit method to enable editing only on the column that was clicked.
Expand Down Expand Up @@ -239,16 +240,17 @@ def show_layer_properties(self, item):

# Create and show the LayerDetailDialog
dialog = LayerDetailDialog(
layer_name, layer_data, item, editing=editing, parent=self)
layer_name, layer_data, item, editing=editing, parent=self
)

# Connect the dialog's dataUpdated signal to handle data updates
def update_layer_data(updated_data):
# Update the layer data in the item (column 4)
item.setData(3, updated_data)

# Check if the layer name has changed, and if so, update it in column 0
if updated_data.get('name', layer_name) != layer_name:
item.setData(0, updated_data.get('name', layer_name))
if updated_data.get("name", layer_name) != layer_name:
item.setData(0, updated_data.get("name", layer_name))

# Connect the signal emitted from the dialog to update the item
dialog.dataUpdated.connect(update_layer_data)
Expand All @@ -273,7 +275,7 @@ def process_leaves(self):
"""
This function processes all nodes in the QTreeView that have the 'layer' role.
It iterates over the entire tree, collecting nodes with the 'layer' role, and
processes each one by showing an animated icon, waiting for 2 seconds, and
processes each one by showing an animated icon, waiting for 2 seconds, and
then removing the animation.
"""
model = self.treeView.model() # Get the model from the tree_view
Expand Down Expand Up @@ -302,7 +304,7 @@ def collect_layer_nodes(self, model, parent_index, layer_nodes):
item = parent_index.internalPointer()

# If the item is a 'layer', add it to the list of nodes to process
if item and getattr(item, 'role', None) == 'layer':
if item and getattr(item, "role", None) == "layer":
layer_nodes.append(parent_index)

# Process all child items recursively
Expand All @@ -329,9 +331,17 @@ def process_each_layer(self, layer_nodes, index):
second_column_index = model.index(node_index.row(), 1, node_index.parent())

# Set an animated icon (using a QLabel and QMovie to simulate animation)
movie = QMovie(resources_path("resources", "throbber.gif")) # Use a valid path to an animated gif
row_height = self.treeView.rowHeight(node_index) # Get the height of the current row
movie.setScaledSize(movie.currentPixmap().size().scaled(row_height, row_height, Qt.KeepAspectRatio))
movie = QMovie(
resources_path("resources", "throbber.gif")
) # Use a valid path to an animated gif
row_height = self.treeView.rowHeight(
node_index
) # Get the height of the current row
movie.setScaledSize(
movie.currentPixmap()
.size()
.scaled(row_height, row_height, Qt.KeepAspectRatio)
)

label = QLabel()
label.setMovie(movie)
Expand All @@ -341,7 +351,12 @@ def process_each_layer(self, layer_nodes, index):
self.treeView.setIndexWidget(second_column_index, label)

# Wait for 2 seconds to simulate processing
QTimer.singleShot(2000, lambda: self.finish_processing(second_column_index, layer_nodes, index, movie))
QTimer.singleShot(
2000,
lambda: self.finish_processing(
second_column_index, layer_nodes, index, movie
),
)

def finish_processing(self, second_column_index, layer_nodes, index, movie):
"""
Expand Down
Loading

0 comments on commit 04d9923

Please sign in to comment.