Skip to content

Instantly share code, notes, and snippets.

@petrasovaa
Last active October 12, 2016 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrasovaa/5cfbd745363c51b63601ddf6cfd39f40 to your computer and use it in GitHub Desktop.
Save petrasovaa/5cfbd745363c51b63601ddf6cfd39f40 to your computer and use it in GitHub Desktop.
Test example of GRASS GUI plugin for drawing point with high update rate
dummy file just to have nice name on gist
<h2>DESCRIPTION</h2>
<h2>REFERENCES</h2>
<h2>SEE ALSO</h2>
<h2>AUTHOR</h2>
Anna Petrasova, <a href="http://geospatial.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>,<br>
Vaclav Petras, <a href="http://geospatial.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>
<p>
<i>Last changed: Date: 2016-02-21</i>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
from random import uniform
import grass.script as gscript
class TestPlugin(wx.Dialog):
def __init__(self, giface, parent):
wx.Dialog.__init__(self, parent, title="Plugin", style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
self.giface = giface
self.parent = parent
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.toggleBtn = wx.Button(self, wx.ID_ANY, "Start")
self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle)
self.region = gscript.region()
self.mapwindow = giface.GetMapWindow()
self.points = self.mapwindow.RegisterGraphicsToDraw(
graphicsType='point', pdc=self.mapwindow.pdcTmp,
mapCoords=True)
color = (255, 0, 0)
self.points.AddPen('pen1', wx.Pen(colour=color, width=2, style=wx.SOLID))
#self.points.AddBrush('brush1', wx.Brush(colour=color, style=wx.SOLID))
def onToggle(self, event):
btnLabel = self.toggleBtn.GetLabel()
if btnLabel == "Start":
print "starting timer..."
self.timer.Start(100)
self.toggleBtn.SetLabel("Stop")
item = self.points.AddItem(coords=[(self.region['w'] + self.region['e'])/2.,
(self.region['n'] + self.region['s'])/2.])
item.SetPropertyVal('penName', 'pen1')
else:
print "timer stopped!"
self.timer.Stop()
self.toggleBtn.SetLabel("Start")
self.points.DeleteItem(self.points.GetItem(0))
self.points.Draw()
self.mapwindow.UpdateMap(render=False)
def update(self, event):
point = self.points.GetItem(0)
x, y = point.GetCoords()
move = (self.region['n'] - self.region['s'])/50.
dx = uniform(-move, move)
dy = uniform(-move, move)
point.SetCoords([x + dx, y + dy])
self.points.Draw()
self.mapwindow.Refresh()
def main(giface=None):
dlg = TestPlugin(giface, parent=None)
dlg.Show()
if __name__ == '__main__':
gscript.parser()
main()
MODULE_TOPDIR = ../..
PGM= g.gui.draw
include $(MODULE_TOPDIR)/include/Make/Script.make
include $(MODULE_TOPDIR)/include/Make/Python.make
default: script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment