Skip to content

Commit

Permalink
wxGUI/g.gui.psmap: fix using draw graphics tool on the preview page (#…
Browse files Browse the repository at this point in the history
…1057)

Allow switching to preview page in drawing modes (add point/line/rectangle and add map frame) but disable certain mouse events when preview is selected. Switch to draft page when on preview and draw tool is selected.

Co-authored-by: Anna Petrasova <kratochanna@gmail.com>
  • Loading branch information
tmszi and petrasovaa committed Nov 22, 2020
1 parent a92f411 commit 205ac15
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def __init__(self, parent=None, id=wx.ID_ANY,
# workaround for http://trac.wxwidgets.org/ticket/13628
self.SetSize(self.GetBestSize())

self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Bind(EVT_CMD_DONE, self.OnCmdDone)
Expand Down Expand Up @@ -258,6 +257,14 @@ def _checkMapFrameExists(self, type_id):
return False
return True

def _switchToPage(self, page_index=0):
"""Switch to page (default to Draft page)
:param int page_index: page index where you want to switch
"""
self.book.SetSelection(page_index)
self.currentPage = page_index

def InstructionFile(self):
"""Creates mapping instructions"""

Expand Down Expand Up @@ -796,6 +803,7 @@ def OnAddPoint(self, event):
"""Add point action selected"""
self.mouse["use"] = "addPoint"
self.canvas.SetCursor(self.cursors["cross"])
self._switchToPage()

def AddPoint(self, id=None, coordinates=None):
"""Add point and open property dialog.
Expand All @@ -821,6 +829,7 @@ def OnAddLine(self, event):
"""Add line action selected"""
self.mouse["use"] = "addLine"
self.canvas.SetCursor(self.cursors["cross"])
self._switchToPage()

def AddLine(self, id=None, coordinates=None):
"""Add line and open property dialog.
Expand All @@ -846,6 +855,7 @@ def OnAddRectangle(self, event):
"""Add rectangle action selected"""
self.mouse["use"] = "addRectangle"
self.canvas.SetCursor(self.cursors["cross"])
self._switchToPage()

def AddRectangle(self, id=None, coordinates=None):
"""Add rectangle and open property dialog.
Expand Down Expand Up @@ -1210,11 +1220,6 @@ def OnPageChanged(self, event):
else:
self.SetStatusText('')

def OnPageChanging(self, event):
"""Flatnotebook page is changing"""
if self.currentPage == 0 and self.mouse['use'] == 'addMap':
event.Veto()

def OnHelp(self, event):
"""Show help"""
if self.parent and self.parent.GetName() == 'LayerManager':
Expand Down Expand Up @@ -1492,24 +1497,27 @@ def OnPaint(self, event):
def MouseActions(self, event):
"""Mouse motion and button click notifier
"""
disable = self.preview and self.mouse['use'] in ('pointer', 'resize',
'addMap', 'addPoint',
'addLine', 'addRectangle')
# zoom with mouse wheel
if event.GetWheelRotation() != 0:
self.OnMouseWheel(event)

# left mouse button pressed
elif event.LeftDown():
elif event.LeftDown() and not disable:
self.OnLeftDown(event)

# left mouse button released
elif event.LeftUp():
elif event.LeftUp() and not disable:
self.OnLeftUp(event)

# dragging
elif event.Dragging():
elif event.Dragging() and not disable:
self.OnDragging(event)

# double click
elif event.ButtonDClick():
elif event.ButtonDClick() and not disable:
self.OnButtonDClick(event)

# middle mouse button pressed
Expand Down

0 comments on commit 205ac15

Please sign in to comment.