d.rast.edit.py 18 KB

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