[GRASS-SVN] r35118 -
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Dec 30 12:41:16 EST 2008
Author: cmbarton
Date: 2008-12-30 12:41:16 -0500 (Tue, 30 Dec 2008)
New Revision: 35118
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py
Log:
Fixed bug that caused freezing or display corruption when dragging an overlay (scale, legend, text). Also some code cleanup.
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py 2008-12-30 17:36:21 UTC (rev 35117)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py 2008-12-30 17:41:16 UTC (rev 35118)
@@ -127,7 +127,8 @@
sys.exit()
class MapWindow(object):
- """Abstract map window class
+ """
+ Abstract map window class
Parent for BufferedWindow class (2D display mode) and
GLWindow (3D display mode)
@@ -168,7 +169,8 @@
pass
def GetSelectedLayer(self, type='layer'):
- """Get selected layer from layer tree
+ """
+ Get selected layer from layer tree
@param type 'item' / 'layer' / 'nviz'
@@ -807,7 +809,8 @@
return True
def DrawCompRegionExtent(self):
- """Draw computational region extent in the display
+ """
+ Draw computational region extent in the display
Display region is drawn as a blue box inside the computational region,
computational region inside a display region as a red box).
@@ -834,7 +837,8 @@
self.DrawLines(pdc=self.pdcDec, polycoords=self.regionCoords)
def IsInRegion(self, region, refRegion):
- """Test if 'region' is inside of 'refRegion'
+ """
+ Test if 'region' is inside of 'refRegion'
@param region input region
@param refRegion reference region (e.g. computational region)
@@ -885,30 +889,28 @@
"""
Drag an overlay decoration item
"""
- Debug.msg (5, "BufferedWindow.DragItem(): id=%d" % \
- id)
+ if id == 99: return
+ Debug.msg (5, "BufferedWindow.DragItem(): id=%d" % id)
x, y = self.lastpos
dx = event.GetX() - x
dy = event.GetY() - y
self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
r = self.pdc.GetIdBounds(id)
- if self.dragid > 100: # text dragging
+ if id > 100: # text dragging
rtop = (r[0],r[1]-r[3],r[2],r[3])
r = r.Union(rtop)
rleft = (r[0]-r[2],r[1],r[2],r[3])
r = r.Union(rleft)
self.pdc.TranslateId(id, dx, dy)
+
r2 = self.pdc.GetIdBounds(id)
+ if id > 100: # text
+ self.textdict[id]['coords'] = r2
r = r.Union(r2)
r.Inflate(4,4)
-
- self.Update()
self.RefreshRect(r, False)
self.lastpos = (event.GetX(), event.GetY())
-
- if id > 100: # text
- self.textdict[id]['coords'] = r2
-
+
def MouseDraw(self, pdc=None, begin=None, end=None):
"""
Mouse box or line from 'begin' to 'end'
@@ -960,7 +962,8 @@
self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=mousecoords)
def DrawLines(self, pdc=None, polycoords=None):
- """Draw polyline in PseudoDC
+ """
+ Draw polyline in PseudoDC
Set self.pline to wx.NEW_ID + 1
@@ -1039,38 +1042,10 @@
### if self.redrawAll is False:
### self.redrawAll = True
- wheel = event.GetWheelRotation()
# zoom with mouse wheel
- if wheel != 0:
- self.processMouse = False
- current = event.GetPositionTuple()[:]
- Debug.msg (5, "BufferedWindow.MouseAction(): wheel=%d" % wheel)
- # zoom 1/2 of the screen, centered to current mouse position (TODO: settings)
- begin = (current[0] - self.Map.width / 4,
- current[1] - self.Map.height / 4)
- end = (current[0] + self.Map.width / 4,
- current[1] + self.Map.height / 4)
-
- if wheel > 0:
- zoomtype = 1
- else:
- zoomtype = -1
-
- # zoom
- self.Zoom(begin, end, zoomtype)
-
- # redraw map
- self.UpdateMap()
-
- ### self.OnPaint(None)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- self.Refresh()
+ if event.GetWheelRotation() != 0:
+ self.OnMouseWheel(event)
- self.processMouse = True
-
# left mouse button pressed
elif event.LeftDown():
self.OnLeftDown(event)
@@ -1081,35 +1056,8 @@
# dragging
elif event.Dragging():
- Debug.msg (5, "BufferedWindow.MouseAction(): Dragging")
- current = event.GetPositionTuple()[:]
- previous = self.mouse['begin']
- move = (current[0] - previous[0],
- current[1] - previous[1])
+ self.OnDragging(event)
- digitToolbar = self.parent.toolbars['vdigit']
-
- # dragging or drawing box with left button
- if self.mouse['use'] == 'pan':
- self.DragMap(move)
-
- # dragging decoration overlay item
- elif (self.mouse['use'] == 'pointer' and not digitToolbar) and \
- self.dragid != None and \
- self.dragid != 99:
- self.DragItem(self.dragid, event)
-
- # dragging anything else - rubber band box or line
- else:
- self.mouse['end'] = event.GetPositionTuple()[:]
- digitClass = self.parent.digit
- if event.LeftIsDown() and not \
- (digitToolbar and \
- digitToolbar.GetAction() in ("moveLine",) and \
- digitClass.driver.GetSelected() > 0):
- # draw box only when left mouse button is pressed
- self.MouseDraw(pdc=self.pdcTmp)
-
# double click
elif event.ButtonDClick():
self.OnButtonDClick(event)
@@ -1130,7 +1078,78 @@
self.OnMouseMoving(event)
event.Skip()
+
+ def OnMouseWheel(self, event):
+ """
+ Mouse wheel moved
+ """
+ self.processMouse = False
+ current = event.GetPositionTuple()[:]
+ wheel = event.GetWheelRotation()
+ Debug.msg (5, "BufferedWindow.MouseAction(): wheel=%d" % wheel)
+ # zoom 1/2 of the screen, centered to current mouse position (TODO: settings)
+ begin = (current[0] - self.Map.width / 4,
+ current[1] - self.Map.height / 4)
+ end = (current[0] + self.Map.width / 4,
+ current[1] + self.Map.height / 4)
+ if wheel > 0:
+ zoomtype = 1
+ else:
+ zoomtype = -1
+
+ # zoom
+ self.Zoom(begin, end, zoomtype)
+
+ # redraw map
+ self.UpdateMap()
+
+ ### self.OnPaint(None)
+
+ # update statusbar
+ self.parent.StatusbarUpdate()
+
+ self.Refresh()
+ self.processMouse = True
+ event.Skip()
+
+ def OnDragging(self, event):
+ """
+ Mouse dragging with left button down
+ """
+ Debug.msg (5, "BufferedWindow.MouseAction(): Dragging")
+ current = event.GetPositionTuple()[:]
+ previous = self.mouse['begin']
+ move = (current[0] - previous[0],
+ current[1] - previous[1])
+
+ digitToolbar = self.parent.toolbars['vdigit']
+
+ # dragging or drawing box with left button
+ if self.mouse['use'] == 'pan':
+ self.DragMap(move)
+
+ # dragging decoration overlay item
+ elif (self.mouse['use'] == 'pointer' and
+ not digitToolbar and
+ self.dragid != None):
+ self.DragItem(self.dragid, event)
+
+ # dragging anything else - rubber band box or line
+ else:
+ if (self.mouse['use'] == 'pointer' and
+ not digitToolbar): return
+ self.mouse['end'] = event.GetPositionTuple()[:]
+ digitClass = self.parent.digit
+ if (event.LeftIsDown() and
+ not (digitToolbar and
+ digitToolbar.GetAction() in ("moveLine",) and
+ digitClass.driver.GetSelected() > 0)):
+ # draw box only when left mouse button is pressed
+ self.MouseDraw(pdc=self.pdcTmp)
+
+ event.Skip()
+
def OnLeftDown(self, event):
"""
Left mouse button pressed
@@ -1367,8 +1386,10 @@
self.lastpos = self.mouse['begin']
idlist = self.pdc.FindObjects(x=self.lastpos[0], y=self.lastpos[1],
radius=self.hitradius)
- if idlist != []:
- self.dragid = idlist[0]
+
+ if 99 in idlist: idlist.remove(99)
+ if idlist != [] :
+ self.dragid = idlist[0] #drag whatever is on top
event.Skip()
@@ -1673,8 +1694,8 @@
self.overlays[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
self.dragid = None
self.currtxtid = None
- self.Update()
-
+ self.UpdateMap(render=True)
+
event.Skip()
def OnButtonDClick(self, event):
@@ -1721,7 +1742,7 @@
self.parent.OnAddBarscale(None)
elif self.dragid == 1:
self.parent.OnAddLegend(None)
-
+
event.Skip()
def OnRightDown(self, event):
@@ -1936,7 +1957,9 @@
event.Skip()
def OnMiddleDown(self, event):
- """Middle mouse button pressed"""
+ """
+ Middle mouse button pressed
+ """
digitToolbar = self.parent.toolbars['vdigit']
# digitization tool
if self.mouse["use"] == "pointer" and digitToolbar:
@@ -1999,7 +2022,9 @@
self.redrawAll = True
def OnMouseMoving(self, event):
- """Motion event and no mouse buttons were pressed"""
+ """
+ Motion event and no mouse buttons were pressed
+ """
digitToolbar = self.parent.toolbars['vdigit']
if self.mouse["use"] == "pointer" and digitToolbar:
digitClass = self.parent.digit
@@ -2340,8 +2365,9 @@
self.parent.StatusbarUpdate()
def ZoomToDefault(self, event):
- """Set display geometry to match default
- region settings"""
+ """
+ Set display geometry to match default region settings
+ """
self.Map.region = self.Map.GetRegion(default=True)
self.Map.AdjustRegion() # aling region extent to the display
@@ -2397,8 +2423,7 @@
wind = dlg.wind
- p = gcmd.Command (["g.region",
- "-ugp", "region=%s" % wind])
+ p = gcmd.Command (["g.region", "-ugp", "region=%s" % wind])
if p.returncode == 0:
output = p.ReadStdOutput()
@@ -2448,7 +2473,9 @@
dlg.Destroy()
def SaveRegion(self, wind):
- """Save region settings"""
+ """
+ Save region settings
+ """
new = self.Map.AlignResolution()
cmdRegion = ["g.region",
@@ -2570,7 +2597,7 @@
self.statusbar.SetStatusWidths([-5, -2, -1])
self.toggleStatus = wx.Choice(self.statusbar, wx.ID_ANY,
choices = globalvar.MAP_DISPLAY_STATUSBAR_MODE)
- self.toggleStatus.SetSelection(UserSettings.Get(group='display', key='statusbarMode', subkey='selection'))
+ self.toggleStatus.SetSelection(UserSettings.Get(group='display', key='statusbarMode', subkey='selection'))
self.statusbar.Bind(wx.EVT_CHOICE, self.OnToggleStatus, self.toggleStatus)
# auto-rendering checkbox
self.autoRender = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
@@ -2874,7 +2901,9 @@
# self.Map.SetRegion() # adjust region to match display window
def OnUpdateProgress(self, event):
- """Update progress bar info"""
+ """
+ Update progress bar info
+ """
self.onRenderGauge.SetValue(event.value)
event.Skip()
@@ -2958,7 +2987,9 @@
self.StatusbarUpdate()
def OnPointer(self, event):
- """Pointer button clicked"""
+ """
+ Pointer button clicked
+ """
if self.toolbars['map']:
if event:
self.toolbars['map'].OnTool(event)
@@ -3072,12 +3103,16 @@
# event.Skip()
def OnToggleRender(self, event):
- """Enable/disable auto-rendering"""
+ """
+ Enable/disable auto-rendering
+ """
if self.autoRender.GetValue():
self.OnRender(None)
def OnToggleShowRegion(self, event):
- """Show/Hide extent in map canvas"""
+ """
+ Show/Hide extent in map canvas
+ """
if self.showRegion.GetValue():
# show extent
self.MapWindow.regionCoords = []
@@ -3089,18 +3124,24 @@
self.OnRender(None)
def OnToggleResolution(self, event):
- """Use resolution of computation region settings
- for redering image instead of display resolution"""
+ """
+ Use resolution of computation region settings
+ for redering image instead of display resolution
+ """
# redraw map if auto-rendering is enabled
if self.autoRender.GetValue():
self.OnRender(None)
def OnToggleStatus(self, event):
- """Toggle status text"""
+ """
+ Toggle status text
+ """
self.StatusbarUpdate()
def OnChangeMapScale(self, event):
- """Map scale changed by user"""
+ """
+ Map scale changed by user
+ """
scale = event.GetString()
try:
@@ -3258,8 +3299,8 @@
else: # choice || auto-rendering
x, y = rect.x, rect.y - 1
w, h = rect.width, rect.height + 2
- if idx == 2:
- x += 5
+ if idx == 2:
+ x += 5
win.SetPosition((x, y))
win.SetSize((w, h))
@@ -3296,12 +3337,8 @@
def PrintMenu(self, event):
"""
- Print map display
+ Print options and output menu for map display
"""
-
- """
- Print options and output menu
- """
point = wx.GetMousePosition()
printmenu = wx.Menu()
# Add items to the menu
@@ -3324,7 +3361,7 @@
def OnCloseWindow(self, event):
"""
- Window closed
+ Window closed.
Also close associated layer tree page
"""
pgnum = None
@@ -3858,6 +3895,7 @@
ctrltxt = _("scale object"))
self.dialogs['barscale'].Show()
+ self.MapWindow.mouse['use'] = 'pointer'
def OnAddLegend(self, event):
"""
@@ -3885,6 +3923,7 @@
ctrltxt = _("legend object"))
self.dialogs['legend'].Show()
+ self.MapWindow.mouse['use'] = 'pointer'
def OnAddText(self, event):
"""
@@ -3927,6 +3966,8 @@
drawid=id, pdctype='text', coords=coords)
self.MapWindow.UpdateMap(render=False, renderVector=False)
+
+ self.MapWindow.mouse['use'] = 'pointer'
def GetOptData(self, dcmd, type, params, propwin):
"""
More information about the grass-commit
mailing list