Skip to content

Commit

Permalink
wxGUI/digitizer: fix digitizer - VDigitToolbar.OnTool method was not …
Browse files Browse the repository at this point in the history
…called (#3027)

Co-authored-by: Tomas Zigo <tomas.zigo@slovanet.sk>
  • Loading branch information
petrasovaa and tmszi committed Jun 21, 2023
1 parent 8a9e840 commit 84fc38f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 44 deletions.
114 changes: 74 additions & 40 deletions gui/wxpython/vdigit/mapwindow.py
Expand Up @@ -136,86 +136,120 @@ def OnKeyDown(self, event):
shift = event.ShiftDown()
kc = event.GetKeyCode()

tools = {
ord("P"): {
"event": wx.CommandEvent(id=self.toolbar.addPoint),
default_tools = {
"addPoint": {
"evt": True,
"ord": ord("P"),
"tool": self.toolbar.OnAddPoint,
},
ord("L"): {
"event": wx.CommandEvent(id=self.toolbar.addLine),
"addLine": {
"evt": True,
"ord": ord("L"),
"tool": self.toolbar.OnAddLine,
},
ord("A"): {
"event": wx.CommandEvent(id=self.toolbar.addArea),
"addArea": {
"evt": True,
"ord": ord("A"),
"tool": self.toolbar.OnAddArea,
},
ord("B"): {
"event": None,
"addBoundary": {
"evt": False,
"ord": ord("B"),
"tool": self.toolbar.OnAddBoundary,
},
ord("C"): {
"event": None,
"addCentroid": {
"evt": False,
"ord": ord("C"),
"tool": self.toolbar.OnAddCentroid,
},
ord("V"): {
"event": wx.CommandEvent(id=self.toolbar.addVertex),
"addVertex": {
"evt": True,
"ord": ord("V"),
"tool": self.toolbar.OnAddVertex,
},
ord("X"): {
"event": wx.CommandEvent(id=self.toolbar.removeVertex),
"removeVertex": {
"evt": True,
"ord": ord("X"),
"tool": self.toolbar.OnRemoveVertex,
},
ord("G"): {
"event": wx.CommandEvent(id=self.toolbar.moveVertex),
"moveVertex": {
"evt": True,
"ord": ord("G"),
"tool": self.toolbar.OnMoveVertex,
},
ord("D"): {
"event": wx.CommandEvent(id=self.toolbar.deleteLine),
"deleteLine": {
"evt": True,
"ord": ord("D"),
"tool": self.toolbar.OnDeleteLine,
},
ord("F"): {
"event": wx.CommandEvent(id=self.toolbar.deleteArea),
"deleteArea": {
"evt": True,
"ord": ord("F"),
"tool": self.toolbar.OnDeleteArea,
},
ord("E"): {
"event": wx.CommandEvent(id=self.toolbar.editLine),
"editLine": {
"evt": True,
"ord": ord("E"),
"tool": self.toolbar.OnEditLine,
},
ord("M"): {
"event": wx.CommandEvent(id=self.toolbar.moveLine),
"moveLine": {
"evt": True,
"ord": ord("M"),
"tool": self.toolbar.OnMoveLine,
},
ord("J"): {
"event": wx.CommandEvent(id=self.toolbar.displayCats),
"displayCats": {
"evt": True,
"ord": ord("J"),
"tool": self.toolbar.OnDisplayCats,
},
ord("K"): {
"event": wx.CommandEvent(id=self.toolbar.displayAttr),
"displayAttr": {
"evt": True,
"ord": ord("K"),
"tool": self.toolbar.OnDisplayAttr,
},
ord("Z"): {
"event": wx.CommandEvent(id=self.toolbar.undo),
"undo": {
"evt": True,
"ord": ord("Z"),
"tool": self.toolbar.OnUndo,
},
ord("Y"): {
"event": wx.CommandEvent(id=self.toolbar.redo),
"redo": {
"evt": True,
"ord": ord("Y"),
"tool": self.toolbar.OnRedo,
},
ord("T"): {
"event": wx.CommandEvent(id=self.toolbar.settings),
"settings": {
"evt": True,
"ord": ord("T"),
"tool": self.toolbar.OnSettings,
},
ord("H"): {
"event": wx.CommandEvent(id=self.toolbar.help),
"help": {
"evt": True,
"ord": ord("H"),
"tool": self.toolbar.OnHelp,
},
ord("Q"): {
"event": wx.CommandEvent(id=self.toolbar.quit),
"quit": {
"evt": True,
"ord": ord("Q"),
"tool": self.toolbar.OnExit,
},
}

# Custom vdigit tools if VDigitToolbar class tool param arg was defined
actual_tools = {}
for tool in default_tools:
# custom tools, e.g. in g.gui.iclass
if self.toolbar.tools and tool not in self.toolbar.tools:
continue
event = None
if default_tools[tool]["evt"] and hasattr(self.toolbar, tool):
event = wx.CommandEvent(id=getattr(self.toolbar, tool))
actual_tools[default_tools[tool]["ord"]] = {
"event": event,
"tool": default_tools[tool]["tool"],
}

if not shift:
tool = tools.get(kc)
tool = actual_tools.get(kc)
if tool:
event = self.toolbar.OnTool(tool["event"])
tool["tool"](event)
Expand Down
12 changes: 8 additions & 4 deletions gui/wxpython/vdigit/toolbars.py
Expand Up @@ -54,6 +54,9 @@ def __init__(self, parent, toolSwitcher, MapWindow, digitClass, giface, tools=[]
self.editingStopped.connect(layerTree.StopEditing)
self.editingBgMap.connect(layerTree.SetBgMapForEditing)

# replace OnTool from controller
self.controller.OnTool = self.OnTool

# bind events
self.Bind(wx.EVT_SHOW, self.OnShow)

Expand Down Expand Up @@ -446,14 +449,15 @@ def OnTool(self, event):
3,
f"VDigitToolbar.OnTool(): id = {event.GetId() if event else event}",
)
if self.toolSwitcher and event:
self.toolSwitcher.ToolChanged(event.GetId())

# set cursor
self.MapWindow.SetNamedCursor("cross")
self.MapWindow.mouse["box"] = "point"
self.MapWindow.mouse["use"] = "pointer"

aId = self.action.get("id", -1)
if event:
BaseToolbar.OnTool(self, event)

# clear tmp canvas
if self.action["id"] != aId or aId == -1:
Expand All @@ -467,8 +471,8 @@ def OnTool(self, event):
if self.action["id"] == -1:
self.action = {"desc": "", "type": "", "id": -1}

# set focus
self.MapWindow.SetFocus()
if event:
event.Skip()

def OnAddPoint(self, event):
"""Add point to the vector map Laier"""
Expand Down

0 comments on commit 84fc38f

Please sign in to comment.