Adding hand tool icon in Toolbar for moving the view
authorlaurent
Wed, 12 Oct 2011 15:08:47 +0200
changeset 575 a7c706b9492e
parent 574 8c525217ef1f
child 576 3f2024f30553
Adding hand tool icon in Toolbar for moving the view
Images/icons.svg
Images/move.png
PLCOpenEditor.py
Viewer.py
graphics/GraphicCommons.py
--- a/Images/icons.svg	Tue Oct 11 12:08:55 2011 +0200
+++ b/Images/icons.svg	Wed Oct 12 15:08:47 2011 +0200
@@ -662,9 +662,9 @@
      borderopacity="1.0"
      inkscape:pageopacity="0"
      inkscape:pageshadow="2"
-     inkscape:zoom="8"
-     inkscape:cx="264.59165"
-     inkscape:cy="46.838908"
+     inkscape:zoom="11.313708"
+     inkscape:cx="477.40877"
+     inkscape:cy="-82.224917"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      width="16px"
@@ -674,16 +674,18 @@
      gridtolerance="10"
      showguides="true"
      inkscape:guide-bbox="true"
-     inkscape:window-width="1623"
-     inkscape:window-height="998"
-     inkscape:window-x="52"
-     inkscape:window-y="47"
-     inkscape:window-maximized="0">
+     inkscape:window-width="1920"
+     inkscape:window-height="1056"
+     inkscape:window-x="0"
+     inkscape:window-y="24"
+     inkscape:window-maximized="1">
     <inkscape:grid
        type="xygrid"
        id="grid2410"
        visible="true"
-       enabled="true" />
+       enabled="true"
+       empspacing="5"
+       snapvisiblegridlinesonly="true" />
   </sodipodi:namedview>
   <metadata
      id="metadata7">
@@ -2867,5 +2869,29 @@
          d="M 11,7 11,11 8,9 11.516466,17 15,9 12,11 12,7 z"
          style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none" />
     </g>
+    <rect
+       style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+       id="move"
+       width="24"
+       height="24"
+       x="420"
+       y="92"
+       inkscape:label="#rect3636" />
+    <text
+       id="text3741-2"
+       y="87"
+       x="416"
+       style="font-size:4.49727678px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans"
+       xml:space="preserve"><tspan
+         y="87"
+         x="416"
+         id="tspan3743-5"
+         sodipodi:role="line">%%move%%</tspan></text>
+    <path
+       id="rect4019-0"
+       style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.04667795;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline"
+       d="m 422.51945,108.09999 0,-3.69999 c 0,-1.10799 0.58266,-2 1.69064,-2 1.108,0 1.30076,0.58603 1.30076,0.95332 l 0,4.94668 c 0,-4.53334 0,-5.76667 0,-10.3 0,-1.108 1.00248,-1.999999 2.11049,-1.999999 1.108,0 1.90765,0.892006 1.9116,1.999999 l 0,6.19293 0,-7.79293 c 0,-1.107998 0.9804,-1.999999 2.0884,-1.999999 1.108,0 1.9116,0.957418 1.9116,2.065417 0,0 0,8.704682 0,7.596682 l 0,-6.0621 c 0,-1.108 0.9804,-1.999999 2.0884,-1.999999 1.108,0 1.91162,0.891999 1.91162,1.999999 0,0 0,8.14719 0,7.03918 l 0,-3.72334 c 0,-1.10799 0.98038,-1.999996 2.08838,-1.999996 1.10802,0 1.91161,0.892006 1.91161,1.999996 l 0,4.68416 c 0,0 0,3.59999 -0.79999,6 -4.82135,2 -11.28619,2 -16.12285,0 -1.02363,-0.38443 -2.09065,-1.59999 -2.09066,-3.90001 z"
+       inkscape:connector-curvature="0"
+       sodipodi:nodetypes="csssccsscsscssscsssscccc" />
   </g>
 </svg>
Binary file Images/move.png has changed
--- a/PLCOpenEditor.py	Tue Oct 11 12:08:55 2011 +0200
+++ b/PLCOpenEditor.py	Wed Oct 12 15:08:47 2011 +0200
@@ -154,8 +154,8 @@
  ID_PLCOPENEDITORTOOLBARBRANCH, ID_PLCOPENEDITORTOOLBARINITIALSTEP,
  ID_PLCOPENEDITORTOOLBARSTEP, ID_PLCOPENEDITORTOOLBARTRANSITION,
  ID_PLCOPENEDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITORTOOLBARDIVERGENCE,
- ID_PLCOPENEDITORTOOLBARJUMP,
-] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(17)]
+ ID_PLCOPENEDITORTOOLBARJUMP, ID_PLCOPENEDITORTOOLBARMOTION, 
+] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(18)]
 
 # Define behaviour of each Toolbar item according to current POU body type 
 # Informations meaning are in this order:
@@ -167,6 +167,9 @@
 #  - Item tooltip text
 ToolBarItems = {
     "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
+              ID_PLCOPENEDITORTOOLBARMOTION, "OnMotionTool",
+              "move.png", _("Move the view")),
+             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
               ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool",
               "add_comment.png", _("Create a new comment")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
@@ -178,7 +181,10 @@
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
               ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", 
               "add_connection.png", _("Create a new connection"))],
-    "LD"  : [(True, FREEDRAWING_MODE, 
+    "LD"  : [((True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
+              ID_PLCOPENEDITORTOOLBARMOTION, "OnMotionTool",
+              "move.png", _("Move the view")),
+             True, FREEDRAWING_MODE, 
               ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", 
               "add_comment.png", _("Create a new comment")),
              (True, FREEDRAWING_MODE, 
@@ -205,7 +211,10 @@
              (True, FREEDRAWING_MODE, 
               ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", 
               "add_connection.png", _("Create a new connection"))],
-    "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
+    "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
+              ID_PLCOPENEDITORTOOLBARMOTION, "OnMotionTool",
+              "move.png", _("Move the view")),
+             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
               ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", 
               "add_comment.png", _("Create a new comment")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
@@ -595,8 +604,8 @@
                   wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, _("Select an object"))
             self.ToolBar.Realize()
             
-            self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
-                  id=ID_PLCOPENEDITORTOOLBARSELECTION)
+        self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
+              id=ID_PLCOPENEDITORTOOLBARSELECTION)
         
         self.VariablePanelIndexer = VariablePanelIndexer(self.BottomNoteBook, self)
         self.BottomNoteBook.AddPage(self.VariablePanelIndexer, _("Variables"))
@@ -2083,43 +2092,42 @@
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION)
-        event.Skip()
+    
+    def OnMotionTool(self, event):
+        selected = self.TabsOpened.GetSelection()
+        if selected != -1:
+            self.TabsOpened.GetPage(selected).SetMode(MODE_MOTION)
     
     def OnCommentTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT)
-        event.Skip()
     
     def OnVariableTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE)
-        event.Skip()
     
     def OnBlockTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARBLOCK)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK)
-        event.Skip()
         
     def OnConnectionTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION)
-        event.Skip()
-
+    
     def OnPowerRailTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL)
-        event.Skip()
-
+    
     def OnRungTool(self, event):
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
@@ -2142,20 +2150,17 @@
                 self.TabsOpened.GetPage(selected).SetMode(MODE_CONTACT)
             else:
                 self.TabsOpened.GetPage(selected).AddLadderContact()
-        event.Skip()
     
     def OnBranchTool(self, event): 
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).AddLadderBranch()
-        event.Skip()    
     
     def OnInitialStepTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP)
-        event.Skip()
     
     def OnStepTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
@@ -2166,8 +2171,7 @@
                 self.TabsOpened.GetPage(selected).SetMode(MODE_STEP)
             else:
                 self.TabsOpened.GetPage(selected).AddStep()
-        event.Skip()
-
+    
     def OnActionBlockTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
             self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK)
@@ -2177,15 +2181,13 @@
                 self.TabsOpened.GetPage(selected).SetMode(MODE_ACTION)
             else:
                 self.TabsOpened.GetPage(selected).AddStepAction()
-        event.Skip()
-
+    
     def OnTransitionTool(self, event):
         self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION)
-        event.Skip()
-
+    
     def OnDivergenceTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
             self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE)
@@ -2195,7 +2197,6 @@
                 self.TabsOpened.GetPage(selected).SetMode(MODE_DIVERGENCE)
             else:
                 self.TabsOpened.GetPage(selected).AddDivergence()
-        event.Skip()
     
     def OnJumpTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
@@ -2206,8 +2207,7 @@
                 self.TabsOpened.GetPage(selected).SetMode(MODE_JUMP)
             else:
                 self.TabsOpened.GetPage(selected).AddJump()
-        event.Skip()
-
+    
 
 #-------------------------------------------------------------------------------
 #                         Add Project Elements Functions
--- a/Viewer.py	Tue Oct 11 12:08:55 2011 +0200
+++ b/Viewer.py	Wed Oct 12 15:08:47 2011 +0200
@@ -533,10 +533,11 @@
         self.RefreshHighlightsTimer.Stop()
     
     def SetCurrentCursor(self, cursor):
-        global CURSORS
-        if self.CurrentCursor != cursor:
-            self.CurrentCursor = cursor
-            self.SetCursor(CURSORS[cursor])
+        if self.Mode != MODE_MOTION:
+            global CURSORS
+            if self.CurrentCursor != cursor:
+                self.CurrentCursor = cursor
+                self.SetCursor(CURSORS[cursor])
     
     def GetScrolledRect(self, rect):
         rect.x, rect.y = self.CalcScrolledPosition(int(rect.x * self.ViewScale[0]), 
@@ -729,7 +730,9 @@
     
     # Changes Viewer mode
     def SetMode(self, mode):
-        if self.Mode != mode or mode == MODE_SELECTION:
+        if self.Mode != mode or mode == MODE_SELECTION:    
+            if self.Mode == MODE_MOTION:
+                wx.CallAfter(self.SetCursor, wx.NullCursor)
             self.Mode = mode
             self.SavedMode = False
         else:
@@ -738,7 +741,10 @@
         if self.Mode != MODE_SELECTION and self.SelectedElement:
             self.SelectedElement.SetSelected(False)
             self.SelectedElement = None
-    
+        if self.Mode == MODE_MOTION:
+            wx.CallAfter(self.SetCursor, wx.StockCursor(wx.CURSOR_HAND))
+            self.SavedMode = True
+        
     # Return current drawing mode
     def GetDrawingMode(self):
         return self.ParentWindow.GetDrawingMode()
@@ -1393,6 +1399,9 @@
                            MODE_STEP, MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION]:
             self.rubberBand.Reset()
             self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
+        elif self.Mode == MODE_MOTION:
+            self.StartMousePos = event.GetPosition()
+            self.StartScreenPos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
         event.Skip()
 
     def OnViewerLeftUp(self, event):
@@ -1469,6 +1478,9 @@
                 else:
                     self.SelectedElement.OnLeftUp(event, dc, self.Scaling)
                 wx.CallAfter(self.SetCurrentCursor, 0)
+        elif self.Mode == MODE_MOTION:
+            self.StartMousePos = None
+            self.StartScreenPos = None
         if self.Mode != MODE_SELECTION and not self.SavedMode:
             wx.CallAfter(self.ParentWindow.ResetCurrentMode)
         event.Skip()
@@ -1541,7 +1553,7 @@
         refresh = False
         dc = self.GetLogicalDC()
         pos = GetScaledEventPosition(event, dc, self.Scaling)
-        if event.MiddleIsDown():
+        if event.MiddleIsDown() or self.Mode == MODE_MOTION:
             if self.StartMousePos is not None and self.StartScreenPos is not None:
                 new_pos = event.GetPosition()
                 xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
@@ -1608,7 +1620,8 @@
         event.Skip()
 
     def OnLeaveViewer(self, event):
-        self.StartMousePos = None
+        if self.StartScreenPos is None:
+            self.StartMousePos = None
         if self.SelectedElement is not None and self.SelectedElement.GetDragging():
             event.Skip()
         elif self.HighlightedElement is not None:
--- a/graphics/GraphicCommons.py	Tue Oct 11 12:08:55 2011 +0200
+++ b/graphics/GraphicCommons.py	Wed Oct 12 15:08:47 2011 +0200
@@ -83,7 +83,7 @@
 # Contants for defining which mode is selected for each view 
 [MODE_SELECTION, MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, 
  MODE_COIL, MODE_CONTACT, MODE_POWERRAIL, MODE_INITIALSTEP, MODE_STEP, 
- MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION] = range(14)
+ MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION, MODE_MOTION] = range(15)
 
 # Contants for defining alignment types for graphic group 
 [ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM] = range(6)