From bbc3d9bb2347bd3a421145e7bf7c430a8fc13338 Mon Sep 17 00:00:00 2001 From: Tomas Zigo <50632337+tmszi@users.noreply.github.com> Date: Fri, 17 May 2024 17:54:47 +0200 Subject: [PATCH] wxGUI/gmodeler: fix r.what module query map coordinate (#3593) --- gui/wxpython/gmodeler/canvas.py | 11 ++++++++--- gui/wxpython/gmodeler/giface.py | 14 ++++---------- gui/wxpython/gmodeler/model.py | 17 ++++++++++++++--- gui/wxpython/gmodeler/panels.py | 13 +++++++++---- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/gui/wxpython/gmodeler/canvas.py b/gui/wxpython/gmodeler/canvas.py index 00a71fadc7c..9742df75d73 100644 --- a/gui/wxpython/gmodeler/canvas.py +++ b/gui/wxpython/gmodeler/canvas.py @@ -44,8 +44,9 @@ class ModelCanvas(ogl.ShapeCanvas): """Canvas where model is drawn""" - def __init__(self, parent): + def __init__(self, parent, giface): self.parent = parent + self._giface = giface ogl.OGLInitialize() ogl.ShapeCanvas.__init__(self, parent) @@ -121,11 +122,12 @@ def GetShapesSelected(self): class ModelEvtHandler(ogl.ShapeEvtHandler): """Model event handler class""" - def __init__(self, log, frame): + def __init__(self, log, frame, giface): ogl.ShapeEvtHandler.__init__(self) self.log = log self.frame = frame self.x = self.y = None + self._giface = giface def OnLeftClick(self, x, y, keys=0, attachment=0): """Left mouse button pressed -> select item & update statusbar""" @@ -185,7 +187,10 @@ def OnProperties(self, event=None): gmodule = GUI( parent=self.frame, show=True, - giface=GraphicalModelerGrassInterface(self.frame.GetModel()), + giface=GraphicalModelerGrassInterface( + model=self.frame.GetModel(), + giface=self._giface, + ), ) gmodule.ParseCommand( shape.GetLog(string=False), diff --git a/gui/wxpython/gmodeler/giface.py b/gui/wxpython/gmodeler/giface.py index 68d4b333880..22331fcfef1 100644 --- a/gui/wxpython/gmodeler/giface.py +++ b/gui/wxpython/gmodeler/giface.py @@ -20,21 +20,15 @@ class GraphicalModelerGrassInterface: """@implements core::giface::GrassInterface""" - def __init__(self, model): + def __init__(self, model, giface): self._model = model + self._giface = giface # Signal emitted to request updating of map (TODO) self.updateMap = Signal("GraphicalModelerGrassInterface.updateMap") - def GetLayerTree(self): - return None - def GetLayerList(self, prompt): return self._model.GetMaps(prompt) - def GetMapDisplay(self): - """ - ..todo:: - implement connection with mapdisplay - """ - return None + def __getattr__(self, name): + return getattr(self._giface, name) diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py index 00f670d20cb..0c2d62e006c 100644 --- a/gui/wxpython/gmodeler/model.py +++ b/gui/wxpython/gmodeler/model.py @@ -68,7 +68,11 @@ class Model: """Class representing the model""" - def __init__(self, canvas=None): + def __init__( + self, + giface, + canvas=None, + ): self.items = list() # list of ordered items (action/loop/condition) # model properties @@ -82,6 +86,7 @@ def __init__(self, canvas=None): self.variablesParams = dict() self.canvas = canvas + self._giface = giface def GetCanvas(self): """Get canvas or None""" @@ -663,7 +668,9 @@ def Run(self, log, onDone, parent=None): params = self.Parameterize() delInterData = False if params: - dlg = ModelParamDialog(parent=parent, model=self, params=params) + dlg = ModelParamDialog( + parent=parent, model=self, params=params, giface=self._giface + ) dlg.CenterOnParent() ret = dlg.ShowModal() @@ -3630,6 +3637,7 @@ def __init__( self, parent, model, + giface, params, id=wx.ID_ANY, title=_("Model parameters"), @@ -3639,6 +3647,7 @@ def __init__( """Model parameters dialog""" self.parent = parent self._model = model + self._giface = giface self.params = params self.tasks = list() # list of tasks/pages @@ -3727,7 +3736,9 @@ def _createPage(self, name, params): parent=self, id=wx.ID_ANY, task=task, - giface=GraphicalModelerGrassInterface(self._model), + giface=GraphicalModelerGrassInterface( + model=self._model, giface=self._giface + ), ) self.tasks.append(task) diff --git a/gui/wxpython/gmodeler/panels.py b/gui/wxpython/gmodeler/panels.py index 7a2762ab4ce..7585cf3adbc 100644 --- a/gui/wxpython/gmodeler/panels.py +++ b/gui/wxpython/gmodeler/panels.py @@ -139,13 +139,13 @@ def __init__( self.notebook = GNotebook(parent=self, style=globalvar.FNPageDStyle) - self.canvas = ModelCanvas(self) + self.canvas = ModelCanvas(self, giface=self._giface) self.canvas.SetBackgroundColour( wx.SystemSettings().GetColour(wx.SYS_COLOUR_WINDOW) ) self.canvas.SetCursor(self.cursors["default"]) - self.model = Model(self.canvas) + self.model = Model(giface=self._giface, canvas=self.canvas) self.variablePanel = VariablePanel(parent=self) @@ -218,7 +218,9 @@ def _layout(self): def _addEvent(self, item): """Add event to item""" - evthandler = ModelEvtHandler(self.statusbar, self) + evthandler = ModelEvtHandler( + log=self.statusbar, frame=self, giface=self._giface + ) evthandler.SetShape(item) evthandler.SetPreviousHandler(item.GetEventHandler()) item.SetEventHandler(evthandler) @@ -1115,7 +1117,10 @@ def OnAddAction(self, event): gmodule = GUI( parent=self, show=True, - giface=GraphicalModelerGrassInterface(self.model), + giface=GraphicalModelerGrassInterface( + model=self.model, + giface=self._giface, + ), ) gmodule.ParseCommand( action.GetLog(string=False),