Explorar o código

wxGUI/g.gui.psmap: fix using draw graphics tool on the preview page (#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>
Tomas Zigo %!s(int64=4) %!d(string=hai) anos
pai
achega
205ac15191
Modificáronse 1 ficheiros con 18 adicións e 10 borrados
  1. 18 10
      gui/wxpython/psmap/frame.py

+ 18 - 10
gui/wxpython/psmap/frame.py

@@ -202,7 +202,6 @@ class PsMapFrame(wx.Frame):
         # 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)
@@ -258,6 +257,14 @@ class PsMapFrame(wx.Frame):
                 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"""
 
@@ -796,6 +803,7 @@ class PsMapFrame(wx.Frame):
         """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.
@@ -821,6 +829,7 @@ class PsMapFrame(wx.Frame):
         """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.
@@ -846,6 +855,7 @@ class PsMapFrame(wx.Frame):
         """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.
@@ -1210,11 +1220,6 @@ class PsMapFrame(wx.Frame):
         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':
@@ -1492,24 +1497,27 @@ class PsMapBufferedWindow(wx.Window):
     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