d.rast.edit.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. #!/usr/bin/env python3
  2. ############################################################################
  3. #
  4. # MODULE: d.rast.edit
  5. # AUTHOR(S): Glynn Clements <glynn@gclements.plus.com>
  6. # COPYRIGHT: (C) 2007,2008,2009 Glynn Clements
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # /
  19. #%module
  20. #% description: Edits cell values in a raster map.
  21. #% keyword: display
  22. #% keyword: editing
  23. #% keyword: raster
  24. #%end
  25. #%option G_OPT_R_INPUT
  26. #%end
  27. #%option G_OPT_R_OUTPUT
  28. #%end
  29. #%option G_OPT_R_INPUT
  30. #% key: aspect
  31. #% required: no
  32. #% description: Name of input aspect raster map
  33. #%end
  34. #%option
  35. #% key: width
  36. #% type: integer
  37. #% required: no
  38. #% multiple: no
  39. #% description: Width of display canvas
  40. #% answer: 640
  41. #%end
  42. #%option
  43. #% key: height
  44. #% type: integer
  45. #% required: no
  46. #% multiple: no
  47. #% description: Height of display canvas
  48. #% answer: 480
  49. #%end
  50. #%option
  51. #% key: size
  52. #% type: integer
  53. #% required: no
  54. #% multiple: no
  55. #% description: Minimum size of each cell
  56. #% answer: 12
  57. #%end
  58. #%option
  59. #% key: rows
  60. #% type: integer
  61. #% required: no
  62. #% multiple: no
  63. #% description: Maximum number of rows to load
  64. #% answer: 100
  65. #%end
  66. #%option
  67. #% key: cols
  68. #% type: integer
  69. #% required: no
  70. #% multiple: no
  71. #% description: Maximum number of columns to load
  72. #% answer: 100
  73. #%end
  74. import sys
  75. import math
  76. import atexit
  77. import grass.script as grass
  78. try:
  79. import wx
  80. except ImportError:
  81. # ensure that --help, --interface-description etc work even without wx
  82. if __name__ == "__main__":
  83. if len(sys.argv) == 2:
  84. arg = sys.argv[1]
  85. if arg[0:2] == '--' or arg in ["help", "-help"]:
  86. grass.parser()
  87. # Either we didn't call g.parser, or it returned
  88. # At this point, there's nothing to be done except re-raise the exception
  89. raise
  90. wind_keys = {
  91. 'north': ('n', float),
  92. 'south': ('s', float),
  93. 'east': ('e', float),
  94. 'west': ('w', float),
  95. 'nsres': ('nsres', float),
  96. 'ewres': ('ewres', float),
  97. 'rows': ('rows', int),
  98. 'cols': ('cols', int),
  99. }
  100. gray12_bits = '\x00\x00\x22\x22\x00\x00\x88\x88\x00\x00\x22\x22\x00\x00\x88\x88\x00\x00\x22\x22\x00\x00\x88\x88\x00\x00\x22\x22\x00\x00\x88\x88'
  101. def run(cmd, **kwargs):
  102. grass.run_command(cmd, quiet=True, **kwargs)
  103. class OverviewCanvas(wx.ScrolledWindow):
  104. def __init__(self, app, parent):
  105. wx.ScrolledWindow.__init__(self, parent)
  106. self.app = app
  107. self.width = app.total['cols']
  108. self.height = app.total['rows']
  109. self.SetVirtualSize((self.width, self.height))
  110. self.SetScrollRate(1, 1)
  111. self.Bind(wx.EVT_LEFT_DOWN, self.OnMouse)
  112. self.Bind(wx.EVT_MOTION, self.OnMouse)
  113. self.Bind(wx.EVT_LEFT_UP, self.OnMouse)
  114. self.Bind(wx.EVT_PAINT, self.OnPaint)
  115. run('r.out.ppm', input=app.inmap, output=app.tempfile)
  116. self.image = wx.BitmapFromImage(wx.Image(app.tempfile))
  117. grass.try_remove(app.tempfile)
  118. app.force_window()
  119. def OnPaint(self, ev):
  120. x0 = self.app.origin_x
  121. y0 = self.app.origin_y
  122. dx = self.app.cols
  123. dy = self.app.rows
  124. dc = wx.PaintDC(self)
  125. self.DoPrepareDC(dc)
  126. src = wx.MemoryDC()
  127. src.SelectObjectAsSource(self.image)
  128. dc.Blit(0, 0, self.width, self.height, src, 0, 0)
  129. src.SelectObjectAsSource(wx.NullBitmap)
  130. dc.SetPen(wx.Pen('red', style=wx.LONG_DASH))
  131. dc.SetBrush(wx.Brush('black', style=wx.TRANSPARENT))
  132. dc.DrawRectangle(x0, y0, dx, dy)
  133. dc.SetBrush(wx.NullBrush)
  134. dc.SetPen(wx.NullPen)
  135. def OnMouse(self, ev):
  136. if ev.Moving():
  137. return
  138. x = ev.GetX()
  139. y = ev.GetY()
  140. (x, y) = self.CalcUnscrolledPosition(x, y)
  141. self.set_window(x, y)
  142. if ev.ButtonUp():
  143. self.app.change_window()
  144. def set_window(self, x, y):
  145. self.app.origin_x = x - app.cols / 2
  146. self.app.origin_y = y - app.rows / 2
  147. self.app.force_window()
  148. self.Refresh()
  149. class OverviewWindow(wx.Frame):
  150. def __init__(self, app):
  151. wx.Frame.__init__(
  152. self,
  153. None,
  154. title="d.rast.edit overview (%s)" %
  155. app.inmap)
  156. self.app = app
  157. self.canvas = OverviewCanvas(app, parent=self)
  158. self.Bind(wx.EVT_CLOSE, self.OnClose)
  159. def OnClose(self, ev):
  160. self.app.finalize()
  161. class Canvas(wx.ScrolledWindow):
  162. def __init__(self, app, parent):
  163. wx.ScrolledWindow.__init__(self, parent)
  164. self.app = app
  165. self.size = app.size
  166. w = app.cols * self.size
  167. h = app.rows * self.size
  168. self.SetVirtualSize((w, h))
  169. self.SetVirtualSizeHints(50, 50)
  170. self.SetScrollRate(1, 1)
  171. self.Bind(wx.EVT_LEFT_DOWN, self.OnMouse)
  172. self.Bind(wx.EVT_RIGHT_DOWN, self.OnMouse)
  173. self.Bind(wx.EVT_MOTION, self.OnMouse)
  174. self.Bind(wx.EVT_PAINT, self.OnPaint2)
  175. self.row = 0
  176. self.col = 0
  177. self.gray12 = wx.BitmapFromBits(gray12_bits, 16, 16)
  178. def OnMouse(self, ev):
  179. oldrow = self.row
  180. oldcol = self.col
  181. x = ev.GetX()
  182. y = ev.GetY()
  183. (x, y) = self.CalcUnscrolledPosition(x, y)
  184. col = x / self.size
  185. row = y / self.size
  186. self.row = row
  187. self.col = col
  188. if ev.Moving():
  189. self.refresh_cell(oldrow, oldcol)
  190. self.refresh_cell(row, col)
  191. elif ev.ButtonDown(wx.MOUSE_BTN_LEFT):
  192. self.cell_set()
  193. elif ev.ButtonDown(wx.MOUSE_BTN_RIGHT):
  194. self.cell_get()
  195. def paint_cell(self, dc, r, c):
  196. if r < 0 or r >= self.app.rows or c < 0 or c >= self.app.cols:
  197. return
  198. val = self.app.values[r][c]
  199. if val is None:
  200. fill = 'black'
  201. stipple = self.gray12
  202. else:
  203. fill = self.app.get_color(val)
  204. stipple = None
  205. if r == self.row and c == self.col:
  206. outline = 'red'
  207. elif self.app.changed[r][c]:
  208. outline = 'white'
  209. else:
  210. outline = 'black'
  211. dc.SetPen(wx.Pen(outline))
  212. if stipple:
  213. brush = wx.Brush(fill, style=wx.STIPPLE)
  214. brush.SetStipple(stipple)
  215. else:
  216. brush = wx.Brush(fill, style=wx.SOLID)
  217. x0 = c * self.size + 1
  218. x1 = x0 + self.size - 1
  219. y0 = r * self.size + 1
  220. y1 = y0 + self.size - 1
  221. dc.SetBrush(brush)
  222. dc.DrawRectangle(x0, y0, x1 - x0, y1 - y0)
  223. dc.SetPen(wx.NullPen)
  224. dc.SetBrush(wx.NullBrush)
  225. if not self.app.angles:
  226. return
  227. if self.app.angles[r][c] == '*':
  228. return
  229. cx = (x0 + x1) / 2
  230. cy = (y0 + y1) / 2
  231. a = math.radians(float(self.app.angles[r][c]))
  232. dx = math.cos(a) * self.size / 2
  233. dy = -math.sin(a) * self.size / 2
  234. x0 = cx - dx
  235. y0 = cy - dy
  236. x1 = cx + dx
  237. y1 = cy + dy
  238. dx, dy = x1 - x0, y1 - y0
  239. px, py = -dy, dx
  240. r, g, b = wx.NamedColor(fill)
  241. if r + g + b > 384:
  242. line = 'black'
  243. else:
  244. line = 'white'
  245. dc.SetPen(wx.Pen(line))
  246. dc.DrawLine(x0, y0, x1, y1)
  247. dc.DrawLine(x1, y1, x1 + px / 6 - dx / 3, y1 + py / 6 - dy / 3)
  248. dc.DrawLine(x1, y1, x1 - px / 6 - dx / 3, y1 - py / 6 - dy / 3)
  249. dc.SetPen(wx.NullPen)
  250. def paint_rect(self, dc, x, y, w, h):
  251. c0 = (x + 0) / self.size
  252. c1 = (x + w + 1) / self.size
  253. r0 = (y + 0) / self.size
  254. r1 = (y + h + 1) / self.size
  255. for r in range(r0, r1 + 1):
  256. for c in range(c0, c1 + 1):
  257. self.paint_cell(dc, r, c)
  258. def OnPaint(self, ev):
  259. dc = wx.PaintDC(self)
  260. self.DoPrepareDC(dc)
  261. for r in range(self.app.rows):
  262. for c in range(self.app.cols):
  263. self.paint_cell(dc, r, c)
  264. def OnPaint2(self, ev):
  265. dc = wx.PaintDC(self)
  266. self.DoPrepareDC(dc)
  267. it = wx.RegionIterator(self.GetUpdateRegion())
  268. while it.HaveRects():
  269. x = it.GetX()
  270. y = it.GetY()
  271. w = it.GetW()
  272. h = it.GetH()
  273. (x, y) = self.CalcUnscrolledPosition(x, y)
  274. self.paint_rect(dc, x, y, w, h)
  275. it.Next()
  276. def cell_enter(self):
  277. if not self.row or not self.col:
  278. return
  279. self.app.update_status(self.row, self.col)
  280. def cell_leave(self):
  281. self.app.clear_status()
  282. def cell_get(self):
  283. self.app.brush = self.app.values[self.row][self.col]
  284. self.app.frame.brush_update()
  285. def cell_set(self):
  286. self.app.values[self.row][self.col] = self.app.brush
  287. self.app.changed[self.row][self.col] = True
  288. self.refresh_cell(self.row, self.col)
  289. def refresh_cell(self, row, col):
  290. x = col * self.size
  291. y = row * self.size
  292. (x, y) = self.CalcScrolledPosition(x, y)
  293. self.RefreshRect((x, y, self.size, self.size))
  294. class ColorPanel(wx.Panel):
  295. def __init__(self, **kwargs):
  296. wx.Panel.__init__(self, **kwargs)
  297. self.SetBackgroundStyle(wx.BG_STYLE_COLOUR)
  298. self.stipple = wx.BitmapFromBits(gray12_bits, 16, 16)
  299. self.null_bg = True
  300. self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
  301. def OnErase(self, ev):
  302. self.ClearBackground()
  303. if not self.null_bg:
  304. return
  305. dc = ev.GetDC()
  306. if not dc:
  307. dc = wx.ClientDC(self)
  308. brush = wx.Brush('black', style=wx.STIPPLE)
  309. brush.SetStipple(self.stipple)
  310. dc.SetBackground(brush)
  311. dc.Clear()
  312. dc.SetBackground(wx.NullBrush)
  313. def SetNullBackgroundColour(self):
  314. wx.Panel.SetBackgroundColour(self, 'gray')
  315. self.null_bg = True
  316. def SetBackgroundColour(self, color):
  317. wx.Panel.SetBackgroundColour(self, color)
  318. self.null_bg = False
  319. class MainWindow(wx.Frame):
  320. def __init__(self, app):
  321. wx.Frame.__init__(self, None, title="d.rast.edit (%s)" % app.inmap)
  322. self.app = app
  323. self.Bind(wx.EVT_CLOSE, self.OnClose)
  324. filemenu = wx.Menu()
  325. filemenu.Append(wx.ID_SAVE, "&Save", "Save changes")
  326. filemenu.Append(wx.ID_EXIT, "E&xit", "Terminate the program")
  327. menubar = wx.MenuBar()
  328. menubar.Append(filemenu, "&File")
  329. self.SetMenuBar(menubar)
  330. wx.EVT_MENU(self, wx.ID_SAVE, self.OnSave)
  331. wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
  332. sizer = wx.BoxSizer(orient=wx.VERTICAL)
  333. self.canvas = Canvas(app, parent=self)
  334. si = sizer.Add(self.canvas, proportion=1, flag=wx.EXPAND)
  335. tools = wx.BoxSizer(wx.HORIZONTAL)
  336. l = wx.StaticText(parent=self, label='New Value:')
  337. tools.Add(l, flag=wx.ALIGN_CENTER_VERTICAL)
  338. tools.AddSpacer(5)
  339. self.newval = wx.TextCtrl(parent=self, style=wx.TE_PROCESS_ENTER)
  340. tools.Add(self.newval, flag=wx.ALIGN_CENTER_VERTICAL)
  341. l = wx.StaticText(parent=self, label='Color:')
  342. tools.Add(l, flag=wx.ALIGN_CENTER_VERTICAL)
  343. tools.AddSpacer(5)
  344. self.color = ColorPanel(parent=self, size=(30, 5))
  345. tools.Add(self.color, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  346. self.Bind(wx.EVT_TEXT_ENTER, self.OnReturn, source=self.newval)
  347. sizer.AddSizer(tools, proportion=0, flag=wx.EXPAND)
  348. self.SetSizerAndFit(sizer)
  349. self.SetSize((app.width, app.height))
  350. self.status = self.CreateStatusBar(6)
  351. self.brush_update()
  352. def OnSave(self, ev):
  353. self.app.save_map()
  354. def OnExit(self, ev):
  355. self.Close(True)
  356. def OnClose(self, ev):
  357. self.app.finalize()
  358. def OnReturn(self, ev):
  359. self.app.brush = self.newval.GetValue()
  360. if self.app.brush != '*' and self.app.brush.strip('0123456789') != '':
  361. self.app.brush = '*'
  362. self.brush_update()
  363. def update_status(self):
  364. for i, key in enumerate(['row', 'col', 'x', 'y', 'value', 'aspect']):
  365. s = "%s%s: %s" % (key[0].upper(), key[1:], self.app.status[key])
  366. self.status.SetStatusText(s, i)
  367. def clear_status(self):
  368. for key in self.status:
  369. self.status[key] = ''
  370. def brush_update(self):
  371. self.newval.ChangeValue(self.app.brush)
  372. if self.app.brush == '*':
  373. self.color.SetNullBackgroundColour()
  374. else:
  375. self.color.SetBackgroundColour(self.app.get_color(self.app.brush))
  376. self.color.Refresh()
  377. class Application(wx.App):
  378. def __init__(self, options):
  379. self.options = options
  380. wx.App.__init__(self)
  381. def initialize(self):
  382. grass.use_temp_region()
  383. run('g.region', raster=self.inmap)
  384. reg = grass.region()
  385. for k, f in wind_keys.values():
  386. self.total[k] = (f)(reg[k])
  387. if self.cols > self.total['cols']:
  388. self.cols = self.total['cols']
  389. if self.rows > self.total['rows']:
  390. self.rows = self.total['rows']
  391. tempbase = grass.tempfile()
  392. grass.try_remove(tempbase)
  393. self.tempfile = tempbase + '.ppm'
  394. self.tempmap = 'tmp.d.rast.edit'
  395. atexit.register(self.cleanup)
  396. run('g.copy', raster=(self.inmap, self.outmap), overwrite=True)
  397. run('r.colors', map=self.outmap, rast=self.inmap)
  398. def cleanup(self):
  399. grass.try_remove(self.tempfile)
  400. run('g.remove', flags='f', type='raster', name=self.tempmap)
  401. def finalize(self):
  402. self.save_map()
  403. sys.exit(0)
  404. def save_map(self):
  405. p = grass.feed_command(
  406. 'r.in.ascii',
  407. input='-',
  408. output=self.tempmap,
  409. quiet=True,
  410. overwrite=True)
  411. outf = p.stdin
  412. outf.write("north: %f\n" % self.wind['n'])
  413. outf.write("south: %f\n" % self.wind['s'])
  414. outf.write("east: %f\n" % self.wind['e'])
  415. outf.write("west: %f\n" % self.wind['w'])
  416. outf.write("rows: %d\n" % self.wind['rows'])
  417. outf.write("cols: %d\n" % self.wind['cols'])
  418. outf.write("null: *\n")
  419. for row in range(self.wind['rows']):
  420. for col in range(self.wind['cols']):
  421. if col > 0:
  422. outf.write(" ")
  423. val = self.values[row][col]
  424. if val and self.changed[row][col]:
  425. outf.write("%s" % val)
  426. else:
  427. outf.write('*')
  428. outf.write("\n")
  429. outf.close()
  430. p.wait()
  431. run('g.region', raster=self.inmap)
  432. run('r.patch',
  433. input=(self.tempmap,
  434. self.outmap),
  435. output=self.outmap,
  436. overwrite=True)
  437. run('r.colors', map=self.outmap, rast=self.inmap)
  438. run('g.remove', flags='f', type='raster', name=self.tempmap)
  439. def read_header(self, infile):
  440. wind = {}
  441. for i in range(6):
  442. line = infile.readline().rstrip('\r\n')
  443. f = line.split(':')
  444. key = f[0]
  445. val = f[1].strip()
  446. (k, f) = wind_keys[key]
  447. wind[k] = (f)(val)
  448. return wind
  449. def read_data(self, infile):
  450. values = []
  451. for row in range(self.wind['rows']):
  452. line = infile.readline().rstrip('\r\n')
  453. values.append(line.split())
  454. return values
  455. def load_map(self):
  456. run('g.region', **self.wind)
  457. p = grass.pipe_command('r.out.ascii', input=self.inmap, quiet=True)
  458. self.wind = self.read_header(p.stdout)
  459. self.values = self.read_data(p.stdout)
  460. self.changed = [[False for c in row] for row in self.values]
  461. p.wait()
  462. self.clear_changes()
  463. run('r.out.ppm', input=self.inmap, output=self.tempfile)
  464. colorimg = wx.Image(self.tempfile)
  465. grass.try_remove(self.tempfile)
  466. for row in range(self.wind['rows']):
  467. for col in range(self.wind['cols']):
  468. val = self.values[row][col]
  469. if val in self.colors:
  470. continue
  471. r = colorimg.GetRed(col, row)
  472. g = colorimg.GetGreen(col, row)
  473. b = colorimg.GetBlue(col, row)
  474. color = "#%02x%02x%02x" % (r, g, b)
  475. self.colors[val] = color
  476. colorimg.Destroy()
  477. def load_aspect(self):
  478. if not self.aspect:
  479. return
  480. p = grass.pipe_command('r.out.ascii', input=self.aspect, quiet=True)
  481. self.read_header(p.stdout)
  482. self.angles = self.read_data(p.stdout)
  483. p.wait()
  484. def clear_changes(self):
  485. for row in range(self.wind['rows']):
  486. for col in range(self.wind['cols']):
  487. self.changed[row][col] = 0
  488. def update_window(self):
  489. x0 = self.origin_x
  490. y0 = self.origin_y
  491. x1 = x0 + self.cols
  492. y1 = y0 + self.rows
  493. self.wind['n'] = self.total['n'] - y0 * self.total['nsres']
  494. self.wind['s'] = self.total['n'] - y1 * self.total['nsres']
  495. self.wind['w'] = self.total['w'] + x0 * self.total['ewres']
  496. self.wind['e'] = self.total['w'] + x1 * self.total['ewres']
  497. self.wind['rows'] = self.rows
  498. self.wind['cols'] = self.cols
  499. def change_window(self):
  500. self.save_map()
  501. self.update_window()
  502. self.load_map()
  503. self.load_aspect()
  504. self.refresh_canvas()
  505. def force_window(self):
  506. if self.origin_x < 0:
  507. self.origin_x = 0
  508. if self.origin_x > self.total['cols'] - self.cols:
  509. self.origin_x = self.total['cols'] - self.cols
  510. if self.origin_y < 0:
  511. self.origin_y = 0
  512. if self.origin_y > self.total['rows'] - self.rows:
  513. self.origin_y = self.total['rows'] - self.rows
  514. def update_status(self, row, col):
  515. self.status['row'] = row
  516. self.status['col'] = col
  517. self.status['x'] = self.wind[
  518. 'e'] + (col + 0.5) * (self.wind['e'] - self.wind['w']) / self.wind['cols']
  519. self.status['y'] = self.wind[
  520. 'n'] - (row + 0.5) * (self.wind['n'] - self.wind['s']) / self.wind['rows']
  521. self.status['value'] = self.values[row][col]
  522. if self.angles:
  523. self.status['aspect'] = self.angles[row][col]
  524. def force_color(val):
  525. run('g.region', rows=1, cols=1)
  526. run('r.mapcalc', expression="%s = %d" % (self.tempmap, val))
  527. run('r.colors', map=self.tempmap, rast=self.inmap)
  528. run('r.out.ppm', input=self.tempmap, out=self.tempfile)
  529. run('g.remove', flags='f', type='raster', name=self.tempmap)
  530. tempimg = wx.Image(self.tempfile)
  531. grass.try_remove(self.tempfile)
  532. rgb = tempimg.get(0, 0)
  533. color = "#%02x%02x%02x" % rgb
  534. self.colors[val] = color
  535. tempimg.delete()
  536. def get_color(self, val):
  537. if val not in self.colors:
  538. try:
  539. self.force_color(val)
  540. except:
  541. self.colors[val] = "#ffffff"
  542. return self.colors[val]
  543. def refresh_canvas(self):
  544. self.frame.canvas.Refresh()
  545. def make_ui(self):
  546. self.frame = MainWindow(self)
  547. self.SetTopWindow(self.frame)
  548. self.frame.Show()
  549. self.overview = OverviewWindow(self)
  550. self.overview.Show()
  551. def OnInit(self):
  552. self.outmap = self.options['output']
  553. self.inmap = self.options['input']
  554. self.aspect = self.options['aspect']
  555. self.width = int(self.options['width'])
  556. self.height = int(self.options['height'])
  557. self.size = int(self.options['size'])
  558. self.rows = int(self.options['rows'])
  559. self.cols = int(self.options['cols'])
  560. self.status = {
  561. 'row': '',
  562. 'col': '',
  563. 'x': '',
  564. 'y': '',
  565. 'value': '',
  566. 'aspect': ''
  567. }
  568. self.values = None
  569. self.changed = None
  570. self.angles = None
  571. self.colors = {}
  572. self.brush = '*'
  573. self.origin_x = 0
  574. self.origin_y = 0
  575. self.wind = {}
  576. self.total = {}
  577. self.initialize()
  578. self.update_window()
  579. self.make_ui()
  580. self.load_map()
  581. self.load_aspect()
  582. self.refresh_canvas()
  583. return True
  584. if __name__ == "__main__":
  585. options, flags = grass.parser()
  586. app = Application(options)
  587. app.MainLoop()