Skip to content

Commit

Permalink
wxGUI/gmodeler: fix r.what module query map coordinate (#3593)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi authored May 17, 2024
1 parent d505efb commit bbc3d9b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
11 changes: 8 additions & 3 deletions gui/wxpython/gmodeler/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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),
Expand Down
14 changes: 4 additions & 10 deletions gui/wxpython/gmodeler/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 14 additions & 3 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -3630,6 +3637,7 @@ def __init__(
self,
parent,
model,
giface,
params,
id=wx.ID_ANY,
title=_("Model parameters"),
Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit bbc3d9b

Please sign in to comment.