[GRASS-SVN] r35117 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Dec 30 12:36:21 EST 2008
Author: cmbarton
Date: 2008-12-30 12:36:21 -0500 (Tue, 30 Dec 2008)
New Revision: 35117
Modified:
grass/branches/develbranch_6/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/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2008-12-30 10:31:02 UTC (rev 35116)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2008-12-30 17:36:21 UTC (rev 35117)
@@ -128,7 +128,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)
@@ -169,7 +170,8 @@
pass
def GetSelectedLayer(self, type='layer'):
- """Get selected layer from layer tree
+ """
+ Get selected layer from layer tree
@param type 'item' / 'layer' / 'nviz'
@@ -808,7 +810,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).
@@ -835,7 +838,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)
@@ -886,30 +890,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'
@@ -961,7 +963,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
@@ -1040,38 +1043,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)
@@ -1082,35 +1057,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)
@@ -1131,7 +1079,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
@@ -1368,8 +1387,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()
@@ -1674,8 +1695,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):
@@ -1722,7 +1743,7 @@
self.parent.OnAddBarscale(None)
elif self.dragid == 1:
self.parent.OnAddLegend(None)
-
+
event.Skip()
def OnRightDown(self, event):
@@ -1937,7 +1958,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:
@@ -2000,7 +2023,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
@@ -2341,8 +2366,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
@@ -2398,8 +2424,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()
@@ -2449,7 +2474,9 @@
dlg.Destroy()
def SaveRegion(self, wind):
- """Save region settings"""
+ """
+ Save region settings
+ """
new = self.Map.AlignResolution()
cmdRegion = ["g.region",
@@ -2571,7 +2598,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,
@@ -2875,7 +2902,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()
@@ -2959,7 +2988,9 @@
self.StatusbarUpdate()
def OnPointer(self, event):
- """Pointer button clicked"""
+ """
+ Pointer button clicked
+ """
if self.toolbars['map']:
if event:
self.toolbars['map'].OnTool(event)
@@ -3073,12 +3104,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 = []
@@ -3090,18 +3125,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:
@@ -3259,8 +3300,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))
@@ -3297,12 +3338,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
@@ -3325,7 +3362,7 @@
def OnCloseWindow(self, event):
"""
- Window closed
+ Window closed.
Also close associated layer tree page
"""
pgnum = None
@@ -3859,6 +3896,7 @@
ctrltxt = _("scale object"))
self.dialogs['barscale'].Show()
+ self.MapWindow.mouse['use'] = 'pointer'
def OnAddLegend(self, event):
"""
@@ -3886,6 +3924,7 @@
ctrltxt = _("legend object"))
self.dialogs['legend'].Show()
+ self.MapWindow.mouse['use'] = 'pointer'
def OnAddText(self, event):
"""
@@ -3928,6 +3967,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