d.rast.edit.py 18 KB

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