Skip to content

Commit 30b9fd6

Browse files
author
Axel Hörteborn
committed
Update with isoxml tasks
1 parent d3be56e commit 30b9fd6

51 files changed

Lines changed: 6269 additions & 37 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ connection_data.ini
5959
zip_build/
6060
tests/test_data/TaskPotatis/*
6161
tests/__pycache__/*
62+
63+
# Meta data XML files (contain personal data)
64+
# Use *.xml.template files as starting point
65+
support_scripts/pyagriculture/meta_data/*.xml
66+
!support_scripts/pyagriculture/meta_data/*.xml.template
67+
iso_standarder/*

GeoDataFarm.py

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
else:
3939
sys.path.append('/usr/lib/qgis')
4040
sys.path.append('/usr/share/qgis/python/plugins')
41-
from qgis.core import QgsApplication
41+
from qgis.core import QgsApplication, QgsMessageLog, Qgis
4242

4343
from qgis.PyQt.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
4444
from qgis.PyQt.QtWidgets import QAction, QMessageBox, QApplication, QListWidgetItem
@@ -80,6 +80,7 @@
8080
from .support_scripts.multiedit import MultiEdit
8181
from .support_scripts.populate_lists import Populate
8282
from .support_scripts.rescale_values import RescaleValues
83+
from .support_scripts.pyagriculture.generate_taskdata_commands import GenerateTaskCommands
8384

8485
class GeoDataFarm:
8586
"""QGIS Plugin Implementation."""
@@ -102,7 +103,19 @@ def __init__(self: Self, iface: "pytest_qgis.qgis_interface.QgisInterface", test
102103
translate = TR()
103104
self.tr = translate.tr
104105
# initialize locale
105-
locale = QSettings().value('locale/userLocale')[0:2]
106+
# QSettings().value('locale/userLocale') may be None in test environments
107+
if test_mode:
108+
locale = 'en'
109+
else:
110+
locale_val = QSettings().value('locale/userLocale')
111+
if isinstance(locale_val, str) and len(locale_val) >= 2:
112+
locale = locale_val[0:2]
113+
else:
114+
try:
115+
locale = str(locale_val)[0:2]
116+
except Exception:
117+
locale = 'en'
118+
106119
locale_path = os.path.join(
107120
self.plugin_dir,
108121
'i18n',
@@ -120,6 +133,8 @@ def __init__(self: Self, iface: "pytest_qgis.qgis_interface.QgisInterface", test
120133
self.menu = self.tr(u'&GeoFarm')
121134
self.toolbar = self.iface.addToolBar(u'GeoDataFarm')
122135
self.toolbar.setObjectName(u'GeoDataFarm')
136+
# Track whether GUI (menu/toolbar) has been initialized
137+
self.gui_initialized = False
123138
self.tsk_mngr = QgsApplication.taskManager()
124139

125140
#print "** INITIALIZING GeoDataFarm"
@@ -146,6 +161,8 @@ def __init__(self: Self, iface: "pytest_qgis.qgis_interface.QgisInterface", test
146161
self.guide = None
147162
self.test_mode = test_mode
148163
self.find_iso_field = None
164+
# helper for opening generate dialogs/widgets
165+
self.generate_commands = GenerateTaskCommands(self)
149166

150167
# noinspection PyMethodMayBeStatic
151168

@@ -220,6 +237,8 @@ def initGui(self):
220237
text=self.tr(u'GeoDataFarm'),
221238
callback=self.run,
222239
parent=self.iface.mainWindow())
240+
# plugin action is added here.
241+
self.gui_initialized = True
223242

224243
def onClosePlugin(self):
225244
"""Cleanup necessary items here when plugin dock_widget is closed"""
@@ -238,6 +257,19 @@ def unload(self):
238257
# remove the toolbar
239258
del self.toolbar
240259

260+
def _log_exception(self, message: str, exception: Exception) -> None:
261+
"""Log an exception with context information."""
262+
import traceback
263+
tb = traceback.format_exc()
264+
info = "Please send this information to geodatafarm@gmail.com to improve the plugin."
265+
QgsMessageLog.logMessage(f"{info}\n{message}\n{exception}\n{tb}", "GeoDataFarm", Qgis.Info)
266+
self.iface.messageBar().pushMessage(
267+
"GeoDataFarm",
268+
"A new log entry was added. Open the GeoDataFarm tab for details.",
269+
level=Qgis.Info
270+
)
271+
272+
241273
# Functions create specific for GeoDataFarm-----------------------------
242274
def add_selected_tables(self):
243275
"""Adds a layer for each "parameter" of all selected tables"""
@@ -431,6 +463,34 @@ def run_interpolate_harvest(self):
431463
cta = ConvertToAreas(self)
432464
cta.run()
433465

466+
def _get_generate_tab(self):
467+
"""Get the 'Generate ISO XMLs' tab."""
468+
dock = self.dock_widget
469+
return getattr(dock, 'tab_generate_isoxml', None) or getattr(dock, 'tab_17', None)
470+
471+
def open_generate_menu(self):
472+
"""Show the Generate ISO XMLs tab."""
473+
tab = self._get_generate_tab()
474+
if tab is None:
475+
return
476+
477+
# Select the tab if possible
478+
try:
479+
tab_widget = getattr(self.dock_widget, 'tabWidget', None)
480+
if tab_widget:
481+
idx = tab_widget.indexOf(tab)
482+
if idx != -1:
483+
tab_widget.setCurrentIndex(idx)
484+
except Exception as e:
485+
self._log_exception("Failed to select tab", e)
486+
487+
# Show dock
488+
try:
489+
self.dock_widget.show()
490+
self.dock_widget.raise_()
491+
except Exception as e:
492+
self._log_exception("Failed to show dock", e)
493+
434494
def set_buttons(self: Self) -> None:
435495
"""Since most functions are dependent on that a database connections
436496
exist the buttons are set when a connection is set. If new connections
@@ -481,7 +541,15 @@ def set_buttons(self: Self) -> None:
481541
self.dock_widget.PBHvInterpolateData.clicked.connect(self.run_interpolate_harvest)
482542

483543
def run(self: Self, test_mode: bool=False) -> None:
544+
print("he2j3")
484545
"""Run method that loads and starts the plugin"""
546+
# Ensure GUI items are initialized (useful when calling `run()` directly)
547+
if not getattr(self, 'gui_initialized', False):
548+
try:
549+
self.initGui()
550+
except Exception:
551+
# best-effort: if initGui fails (e.g., headless tests), continue
552+
pass
485553
icon_path = ':/plugins/GeoDataFarm/img/icon.png'
486554
if not self.pluginIsActive:
487555
self.pluginIsActive = True
@@ -494,6 +562,15 @@ def run(self: Self, test_mode: bool=False) -> None:
494562
if self.dock_widget is None:
495563
# Create the dock_widget (after translation) and keep reference
496564
self.dock_widget = GeoDataFarmDockWidget()
565+
566+
# Set the parent_gdf reference for GenerateTaskDataWidget
567+
if hasattr(self.dock_widget, 'generate_taskdata_widget'):
568+
self.dock_widget.generate_taskdata_widget.parent_gdf = self
569+
570+
# Set the parent_gdf reference for GenerateIsoxmlController
571+
if hasattr(self.dock_widget, 'generate_isoxml_controller'):
572+
self.dock_widget.generate_isoxml_controller.parent_gdf = self
573+
497574
img = QImage(icon_path)
498575

499576
if hasattr(QtCore.Qt, "AspectRatioMode"): # Qt6+
@@ -509,6 +586,8 @@ def run(self: Self, test_mode: bool=False) -> None:
509586
self.dock_widget.LIcon.setPixmap(pimg)
510587
if self.get_database_connection():
511588
self.set_buttons()
589+
# Setup the Generate ISO XMLs tab (buttons, tables)
590+
# Removed: _setup_generate_isoxml_tab() - now using promoted widget in UI
512591
self.dock_widget.PBAddNewFarm.clicked.connect(self.clicked_create_farm)
513592
self.dock_widget.PBConnect2Farm.clicked.connect(self.connect_to_farm)
514593
try:

0 commit comments

Comments
 (0)