[GRASS-SVN] r30477 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 5 06:22:56 EST 2008
Author: martinl
Date: 2008-03-05 06:22:56 -0500 (Wed, 05 Mar 2008)
New Revision: 30477
Modified:
grass/trunk/gui/wxpython/gui_modules/mapdisp.py
grass/trunk/gui/wxpython/gui_modules/toolbars.py
Log:
wxGUI: (vdigit) * draw box in map canvas only if left mouse button is pressed
* (move line/vertex) avoid position displacement on left/right mouse button pressed
* choose poiter tool from map toolbar by default (digit toolbar created or tool selected)
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-03-05 09:56:00 UTC (rev 30476)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-03-05 11:22:56 UTC (rev 30477)
@@ -865,7 +865,9 @@
# dragging anything else - rubber band box or line
else:
self.mouse['end'] = event.GetPositionTuple()[:]
- self.MouseDraw(pdc=self.pdcTmp)
+ if event.LeftIsDown():
+ # draw box only when left mouse button is pressed
+ self.MouseDraw(pdc=self.pdcTmp)
# double click
elif event.ButtonDClick():
@@ -1199,7 +1201,13 @@
pos2 = self.Pixel2Cell(self.mouse['end'])
if hasattr(self, "moveBegin"):
- self.moveCoords = pos2
+ if len(digitClass.driver.GetSelected()) == 0:
+ self.moveCoords = pos2
+ else:
+ dx = pos2[0] - pos1[0]
+ dy = pos2[1] - pos1[1]
+ self.moveCoords = (self.moveCoords[0] + dx,
+ self.moveCoords[1] + dy)
# eliminate initial mouse moving efect
self.mouse['begin'] = self.mouse['end']
@@ -1271,12 +1279,16 @@
else:
# -> moveLine || deleteLine, etc. (select by point/box)
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
+ if digitToolbar.action == 'moveLine' and \
+ len(digitClass.driver.GetSelected()) > 0:
+ nselected = 0
+ else:
+ nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
+ digitClass.GetSelectType())
+ if nselected == 0:
+ if digitClass.driver.SelectLineByPoint(pos1,
+ digitClass.GetSelectType()) is not None:
+ nselected = 1
if nselected > 0:
if digitToolbar.action in ["moveLine", "moveVertex"]:
@@ -1447,6 +1459,29 @@
r.Inflate(4,4)
self.RefreshRect(r, False)
+ digitToolbar = self.parent.digittoolbar
+ if digitToolbar:
+ digitClass = self.parent.digit
+ # digitization tool (confirm action)
+ if digitToolbar.action in ["moveLine", "moveVertex"] and \
+ hasattr(self, "moveBegin"):
+
+ pTo = self.Pixel2Cell(event.GetPositionTuple())
+ pFrom = self.moveCoords
+ move = (pTo[0]-pFrom[0], pTo[1]-pFrom[1])
+
+ if digitToolbar.action == "moveLine":
+ # move line
+ digitClass.MoveSelectedLines(move)
+ elif digitToolbar.action == "moveVertex":
+ # move vertex
+ digitClass.MoveSelectedVertex(pFrom,
+ move)
+
+ del self.moveBegin
+ del self.moveCoords
+ del self.moveIds
+
event.Skip()
def OnRightUp(self, event):
@@ -1513,24 +1548,6 @@
elif digitToolbar.action == "deleteLine":
# -> delete selected vector features
digitClass.DeleteSelectedLines()
- elif digitToolbar.action in ["moveLine", "moveVertex"] and \
- hasattr(self, "moveBegin"):
-
- pTo = self.Pixel2Cell(event.GetPositionTuple())
- pFrom = self.moveCoords
- move = (pTo[0]-pFrom[0], pTo[1]-pFrom[1])
-
- if digitToolbar.action == "moveLine":
- # move line
- digitClass.MoveSelectedLines(move)
- elif digitToolbar.action == "moveVertex":
- # move vertex
- digitClass.MoveSelectedVertex(pFrom,
- move)
-
- del self.moveBegin
- del self.moveCoords
- del self.moveIds
elif digitToolbar.action == "splitLine":
# split line
digitClass.SplitLine(self.Pixel2Cell(self.mouse['begin']))
Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py 2008-03-05 09:56:00 UTC (rev 30476)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py 2008-03-05 11:22:56 UTC (rev 30477)
@@ -37,11 +37,17 @@
pass
def InitToolbar(self, parent, toolbar, toolData):
- """Initialize toolbar, i.e. add tools to the toolbar"""
+ """Initialize toolbar, i.e. add tools to the toolbar
+ @return list of ids (of added tools)
+ """
+
+ ids = []
for tool in toolData:
- self.CreateTool(parent, toolbar, *tool)
+ ids.append(self.CreateTool(parent, toolbar, *tool))
+ return ids
+
def ToolbarData(self):
"""Toolbar data"""
@@ -49,18 +55,24 @@
def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
shortHelp, longHelp, handler):
- """Add tool to the toolbar"""
+ """Add tool to the toolbar
+ @return id of tool
+ """
+
bmpDisabled=wx.NullBitmap
+ id = wx.NewId()
if label:
- tool = toolbar.AddLabelTool(wx.ID_ANY, label, bitmap,
+ tool = toolbar.AddLabelTool(id, label, bitmap,
bmpDisabled, kind,
shortHelp, longHelp)
parent.Bind(wx.EVT_TOOL, handler, tool)
else: # add separator
toolbar.AddSeparator()
+ return id
+
class MapToolbar(AbstractToolbar):
"""
Main Map Display toolbar
@@ -73,8 +85,8 @@
self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
- self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
-
+ self.pointerId = self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())[4]
+
# optional tools
self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value='Tools',
choices=['Digitize'], style=wx.CB_READONLY, size=(90, -1))
@@ -84,7 +96,7 @@
# realize the toolbar
self.toolbar.Realize()
-
+
def ToolbarData(self):
"""Toolbar data"""
@@ -252,7 +264,8 @@
self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
self.toolbar[row].SetToolBitmapSize(wx.Size(24,24))
-
+ self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
+
# create toolbar
if self.numOfRows == 1:
rowdata=None
@@ -267,6 +280,9 @@
for row in range(0, self.numOfRows):
self.toolbar[row].Realize()
+ # toogle to pointer by default
+ self.OnTool(None)
+
def ToolbarData(self, row=None):
"""
Toolbar data
@@ -343,6 +359,14 @@
return data
+ def OnTool(self, event):
+ """Tool selected -> toggle tool to pointer"""
+ id = self.parent.maptoolbar.pointerId
+ self.parent.maptoolbar.toolbar.ToggleTool(id, True)
+ self.parent.maptoolbar.mapdisplay.OnPointer(event)
+ if event:
+ event.Skip()
+
def OnAddPoint(self, event):
"""Add point to the vector map Laier"""
Debug.msg (2, "DigitToolbar.OnAddPoint()")
More information about the grass-commit
mailing list