dialogs.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. """!
  2. @package location_wizard.dialogs
  3. @brief Location wizard - dialogs
  4. Classes:
  5. - dialogs::RegionDef
  6. - dialogs::TransList
  7. - dialogs::SelectTransformDialog
  8. (C) 2007-2011 by the GRASS Development Team
  9. This program is free software under the GNU General Public License
  10. (>=v2). Read the file COPYING that comes with GRASS for details.
  11. @author Michael Barton
  12. @author Jachym Cepicky
  13. @author Martin Landa <landa.martin gmail.com>
  14. """
  15. import os
  16. import sys
  17. import wx
  18. import wx.lib.scrolledpanel as scrolled
  19. if __name__ == '__main__':
  20. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  21. from core import globalvar
  22. from core.gcmd import RunCommand
  23. from location_wizard.base import BaseClass
  24. from grass.script import core as grass
  25. class RegionDef(BaseClass, wx.Dialog):
  26. """!Page for setting default region extents and resolution
  27. """
  28. def __init__(self, parent, id = wx.ID_ANY, size = (800, 600),
  29. title = _("Set default region extent and resolution"), location = None):
  30. wx.Dialog.__init__(self, parent, id, title, size = size)
  31. panel = wx.Panel(self, id = wx.ID_ANY)
  32. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  33. self.parent = parent
  34. self.location = location
  35. #
  36. # default values
  37. #
  38. # 2D
  39. self.north = 1.0
  40. self.south = 0.0
  41. self.east = 1.0
  42. self.west = 0.0
  43. self.nsres = 1.0
  44. self.ewres = 1.0
  45. # 3D
  46. self.top = 1.0
  47. self.bottom = 0.0
  48. # self.nsres3 = 1.0
  49. # self.ewres3 = 1.0
  50. self.tbres = 1.0
  51. #
  52. # inputs
  53. #
  54. # 2D
  55. self.tnorth = self.MakeTextCtrl(text = str(self.north), size = (150, -1), parent = panel)
  56. self.tsouth = self.MakeTextCtrl(str(self.south), size = (150, -1), parent = panel)
  57. self.twest = self.MakeTextCtrl(str(self.west), size = (150, -1), parent = panel)
  58. self.teast = self.MakeTextCtrl(str(self.east), size = (150, -1), parent = panel)
  59. self.tnsres = self.MakeTextCtrl(str(self.nsres), size = (150, -1), parent = panel)
  60. self.tewres = self.MakeTextCtrl(str(self.ewres), size = (150, -1), parent = panel)
  61. #
  62. # labels
  63. #
  64. self.lrows = self.MakeLabel(parent = panel)
  65. self.lcols = self.MakeLabel(parent = panel)
  66. self.lcells = self.MakeLabel(parent = panel)
  67. #
  68. # buttons
  69. #
  70. self.bset = self.MakeButton(text = _("&Set region"), id = wx.ID_OK, parent = panel)
  71. self.bcancel = wx.Button(panel, id = wx.ID_CANCEL)
  72. self.bset.SetDefault()
  73. #
  74. # image
  75. #
  76. self.img = wx.Image(os.path.join(globalvar.ETCIMGDIR, "qgis_world.png"),
  77. wx.BITMAP_TYPE_PNG).ConvertToBitmap()
  78. #
  79. # set current working environment to PERMANENT mapset
  80. # in selected location in order to set default region (WIND)
  81. #
  82. envval = {}
  83. ret = RunCommand('g.gisenv',
  84. read = True)
  85. if ret:
  86. for line in ret.splitlines():
  87. key, val = line.split('=')
  88. envval[key] = val
  89. self.currlocation = envval['LOCATION_NAME'].strip("';")
  90. self.currmapset = envval['MAPSET'].strip("';")
  91. if self.currlocation != self.location or self.currmapset != 'PERMANENT':
  92. RunCommand('g.gisenv',
  93. set = 'LOCATION_NAME=%s' % self.location)
  94. RunCommand('g.gisenv',
  95. set = 'MAPSET=PERMANENT')
  96. else:
  97. dlg = wx.MessageBox(parent = self,
  98. message = _('Invalid location selected.'),
  99. caption = _("Error"), style = wx.ID_OK | wx.ICON_ERROR)
  100. return
  101. #
  102. # get current region settings
  103. #
  104. region = {}
  105. ret = RunCommand('g.region',
  106. read = True,
  107. flags = 'gp3')
  108. if ret:
  109. for line in ret.splitlines():
  110. key, val = line.split('=')
  111. region[key] = float(val)
  112. else:
  113. dlg = wx.MessageBox(parent = self,
  114. message = _("Invalid region"),
  115. caption = _("Error"), style = wx.ID_OK | wx.ICON_ERROR)
  116. dlg.ShowModal()
  117. dlg.Destroy()
  118. return
  119. #
  120. # update values
  121. # 2D
  122. self.north = float(region['n'])
  123. self.south = float(region['s'])
  124. self.east = float(region['e'])
  125. self.west = float(region['w'])
  126. self.nsres = float(region['nsres'])
  127. self.ewres = float(region['ewres'])
  128. self.rows = int(region['rows'])
  129. self.cols = int(region['cols'])
  130. self.cells = int(region['cells'])
  131. # 3D
  132. self.top = float(region['t'])
  133. self.bottom = float(region['b'])
  134. # self.nsres3 = float(region['nsres3'])
  135. # self.ewres3 = float(region['ewres3'])
  136. self.tbres = float(region['tbres'])
  137. self.depth = int(region['depths'])
  138. self.cells3 = int(region['cells3'])
  139. #
  140. # 3D box collapsable
  141. #
  142. self.infoCollapseLabelExp = _("Click here to show 3D settings")
  143. self.infoCollapseLabelCol = _("Click here to hide 3D settings")
  144. self.settings3D = wx.CollapsiblePane(parent = panel,
  145. label = self.infoCollapseLabelExp,
  146. style = wx.CP_DEFAULT_STYLE |
  147. wx.CP_NO_TLW_RESIZE | wx.EXPAND)
  148. self.MakeSettings3DPaneContent(self.settings3D.GetPane())
  149. self.settings3D.Collapse(False) # FIXME
  150. self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSettings3DPaneChanged, self.settings3D)
  151. #
  152. # set current region settings
  153. #
  154. self.tnorth.SetValue(str(self.north))
  155. self.tsouth.SetValue(str(self.south))
  156. self.twest.SetValue(str(self.west))
  157. self.teast.SetValue(str(self.east))
  158. self.tnsres.SetValue(str(self.nsres))
  159. self.tewres.SetValue(str(self.ewres))
  160. self.ttop.SetValue(str(self.top))
  161. self.tbottom.SetValue(str(self.bottom))
  162. # self.tnsres3.SetValue(str(self.nsres3))
  163. # self.tewres3.SetValue(str(self.ewres3))
  164. self.ttbres.SetValue(str(self.tbres))
  165. self.lrows.SetLabel(_("Rows: %d") % self.rows)
  166. self.lcols.SetLabel(_("Cols: %d") % self.cols)
  167. self.lcells.SetLabel(_("Cells: %d") % self.cells)
  168. #
  169. # bindings
  170. #
  171. self.Bind(wx.EVT_BUTTON, self.OnSetButton, self.bset)
  172. self.Bind(wx.EVT_BUTTON, self.OnCancel, self.bcancel)
  173. self.tnorth.Bind(wx.EVT_TEXT, self.OnValue)
  174. self.tsouth.Bind(wx.EVT_TEXT, self.OnValue)
  175. self.teast.Bind(wx.EVT_TEXT, self.OnValue)
  176. self.twest.Bind(wx.EVT_TEXT, self.OnValue)
  177. self.tnsres.Bind(wx.EVT_TEXT, self.OnValue)
  178. self.tewres.Bind(wx.EVT_TEXT, self.OnValue)
  179. self.ttop.Bind(wx.EVT_TEXT, self.OnValue)
  180. self.tbottom.Bind(wx.EVT_TEXT, self.OnValue)
  181. # self.tnsres3.Bind(wx.EVT_TEXT, self.OnValue)
  182. # self.tewres3.Bind(wx.EVT_TEXT, self.OnValue)
  183. self.ttbres.Bind(wx.EVT_TEXT, self.OnValue)
  184. self.__DoLayout(panel)
  185. self.SetMinSize(self.GetBestSize())
  186. self.minWindowSize = self.GetMinSize()
  187. wx.CallAfter(self.settings3D.Collapse, True)
  188. def MakeSettings3DPaneContent(self, pane):
  189. """!Create 3D region settings pane"""
  190. border = wx.BoxSizer(wx.VERTICAL)
  191. gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
  192. # inputs
  193. self.ttop = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.top),
  194. size = (150, -1))
  195. self.tbottom = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.bottom),
  196. size = (150, -1))
  197. self.ttbres = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.tbres),
  198. size = (150, -1))
  199. # self.tnsres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.nsres3),
  200. # size = (150, -1))
  201. # self.tewres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.ewres3),
  202. # size = (150, -1))
  203. #labels
  204. self.ldepth = wx.StaticText(parent = pane, label = _("Depth: %d") % self.depth)
  205. self.lcells3 = wx.StaticText(parent = pane, label = _("3D Cells: %d") % self.cells3)
  206. # top
  207. gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Top")),
  208. flag = wx.ALIGN_CENTER |
  209. wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  210. pos = (0, 1))
  211. gridSizer.Add(item = self.ttop,
  212. flag = wx.ALIGN_CENTER_HORIZONTAL |
  213. wx.ALL, border = 5, pos = (1, 1))
  214. # bottom
  215. gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Bottom")),
  216. flag = wx.ALIGN_CENTER |
  217. wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  218. pos = (0, 2))
  219. gridSizer.Add(item = self.tbottom,
  220. flag = wx.ALIGN_CENTER_HORIZONTAL |
  221. wx.ALL, border = 5, pos = (1, 2))
  222. # tbres
  223. gridSizer.Add(item = wx.StaticText(parent = pane, label = _("T-B resolution")),
  224. flag = wx.ALIGN_CENTER |
  225. wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  226. pos = (0, 3))
  227. gridSizer.Add(item = self.ttbres,
  228. flag = wx.ALIGN_CENTER_HORIZONTAL |
  229. wx.ALL, border = 5, pos = (1, 3))
  230. # res
  231. # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D N-S resolution")),
  232. # flag = wx.ALIGN_CENTER |
  233. # wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  234. # pos = (2, 1))
  235. # gridSizer.Add(item = self.tnsres3,
  236. # flag = wx.ALIGN_CENTER_HORIZONTAL |
  237. # wx.ALL, border = 5, pos = (3, 1))
  238. # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D E-W resolution")),
  239. # flag = wx.ALIGN_CENTER |
  240. # wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  241. # pos = (2, 3))
  242. # gridSizer.Add(item = self.tewres3,
  243. # flag = wx.ALIGN_CENTER_HORIZONTAL |
  244. # wx.ALL, border = 5, pos = (3, 3))
  245. # rows/cols/cells
  246. gridSizer.Add(item = self.ldepth,
  247. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  248. wx.ALL, border = 5, pos = (2, 1))
  249. gridSizer.Add(item = self.lcells3,
  250. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  251. wx.ALL, border = 5, pos = (2, 2))
  252. border.Add(item = gridSizer, proportion = 1,
  253. flag = wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border = 5)
  254. pane.SetSizer(border)
  255. border.Fit(pane)
  256. def OnSettings3DPaneChanged(self, event):
  257. """!Collapse 3D settings box"""
  258. if self.settings3D.IsExpanded():
  259. self.settings3D.SetLabel(self.infoCollapseLabelCol)
  260. self.Layout()
  261. self.SetSize(self.GetBestSize())
  262. self.SetMinSize(self.GetSize())
  263. else:
  264. self.settings3D.SetLabel(self.infoCollapseLabelExp)
  265. self.Layout()
  266. self.SetSize(self.minWindowSize)
  267. self.SetMinSize(self.minWindowSize)
  268. self.SendSizeEvent()
  269. def __DoLayout(self, panel):
  270. """!Window layout"""
  271. frameSizer = wx.BoxSizer(wx.VERTICAL)
  272. gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
  273. settings3DSizer = wx.BoxSizer(wx.VERTICAL)
  274. buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
  275. # north
  276. gridSizer.Add(item = self.MakeLabel(text = _("North"), parent = panel),
  277. flag = wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL |
  278. wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (0, 2))
  279. gridSizer.Add(item = self.tnorth,
  280. flag = wx.ALIGN_CENTER_HORIZONTAL |
  281. wx.ALIGN_CENTER_VERTICAL |
  282. wx.ALL, border = 5, pos = (1, 2))
  283. # west
  284. gridSizer.Add(item = self.MakeLabel(text = _("West"), parent = panel),
  285. flag = wx.ALIGN_RIGHT |
  286. wx.ALIGN_CENTER_VERTICAL |
  287. wx.LEFT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 0))
  288. gridSizer.Add(item = self.twest,
  289. flag = wx.ALIGN_RIGHT |
  290. wx.ALIGN_CENTER_VERTICAL |
  291. wx.ALL, border = 5, pos = (2, 1))
  292. gridSizer.Add(item = wx.StaticBitmap(panel, wx.ID_ANY, self.img, (-1, -1),
  293. (self.img.GetWidth(), self.img.GetHeight())),
  294. flag = wx.ALIGN_CENTER |
  295. wx.ALIGN_CENTER_VERTICAL |
  296. wx.ALL, border = 5, pos = (2, 2))
  297. # east
  298. gridSizer.Add(item = self.teast,
  299. flag = wx.ALIGN_CENTER_HORIZONTAL |
  300. wx.ALIGN_CENTER_VERTICAL |
  301. wx.ALL, border = 5, pos = (2, 3))
  302. gridSizer.Add(item = self.MakeLabel(text = _("East"), parent = panel),
  303. flag = wx.ALIGN_LEFT |
  304. wx.ALIGN_CENTER_VERTICAL |
  305. wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 4))
  306. # south
  307. gridSizer.Add(item = self.tsouth,
  308. flag = wx.ALIGN_CENTER_HORIZONTAL |
  309. wx.ALIGN_CENTER_VERTICAL |
  310. wx.ALL, border = 5, pos = (3, 2))
  311. gridSizer.Add(item = self.MakeLabel(text = _("South"), parent = panel),
  312. flag = wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL |
  313. wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5, pos = (4, 2))
  314. # ns-res
  315. gridSizer.Add(item = self.MakeLabel(text = _("N-S resolution"), parent = panel),
  316. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  317. wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 1))
  318. gridSizer.Add(item = self.tnsres,
  319. flag = wx.ALIGN_RIGHT |
  320. wx.ALIGN_CENTER_VERTICAL |
  321. wx.ALL, border = 5, pos = (6, 1))
  322. # ew-res
  323. gridSizer.Add(item = self.MakeLabel(text = _("E-W resolution"), parent = panel),
  324. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  325. wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 3))
  326. gridSizer.Add(item = self.tewres,
  327. flag = wx.ALIGN_RIGHT |
  328. wx.ALIGN_CENTER_VERTICAL |
  329. wx.ALL, border = 5, pos = (6, 3))
  330. # rows/cols/cells
  331. gridSizer.Add(item = self.lrows,
  332. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  333. wx.ALL, border = 5, pos = (7, 1))
  334. gridSizer.Add(item = self.lcells,
  335. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  336. wx.ALL, border = 5, pos = (7, 2))
  337. gridSizer.Add(item = self.lcols,
  338. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  339. wx.ALL, border = 5, pos = (7, 3))
  340. # 3D
  341. settings3DSizer.Add(item = self.settings3D,
  342. flag = wx.ALL,
  343. border = 5)
  344. # buttons
  345. buttonSizer.Add(item = self.bcancel, proportion = 1,
  346. flag = wx.ALIGN_RIGHT |
  347. wx.ALIGN_CENTER_VERTICAL |
  348. wx.ALL, border = 10)
  349. buttonSizer.Add(item = self.bset, proportion = 1,
  350. flag = wx.ALIGN_CENTER |
  351. wx.ALIGN_CENTER_VERTICAL |
  352. wx.ALL, border = 10)
  353. frameSizer.Add(item = gridSizer, proportion = 1,
  354. flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
  355. frameSizer.Add(item = settings3DSizer, proportion = 0,
  356. flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
  357. frameSizer.Add(item = buttonSizer, proportion = 0,
  358. flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
  359. self.SetAutoLayout(True)
  360. panel.SetSizer(frameSizer)
  361. frameSizer.Fit(panel)
  362. self.Layout()
  363. def OnValue(self, event):
  364. """!Set given value"""
  365. try:
  366. if event.GetId() == self.tnorth.GetId():
  367. self.north = float(event.GetString())
  368. elif event.GetId() == self.tsouth.GetId():
  369. self.south = float(event.GetString())
  370. elif event.GetId() == self.teast.GetId():
  371. self.east = float(event.GetString())
  372. elif event.GetId() == self.twest.GetId():
  373. self.west = float(event.GetString())
  374. elif event.GetId() == self.tnsres.GetId():
  375. self.nsres = float(event.GetString())
  376. elif event.GetId() == self.tewres.GetId():
  377. self.ewres = float(event.GetString())
  378. elif event.GetId() == self.ttop.GetId():
  379. self.top = float(event.GetString())
  380. elif event.GetId() == self.tbottom.GetId():
  381. self.bottom = float(event.GetString())
  382. # elif event.GetId() == self.tnsres3.GetId():
  383. # self.nsres3 = float(event.GetString())
  384. # elif event.GetId() == self.tewres3.GetId():
  385. # self.ewres3 = float(event.GetString())
  386. elif event.GetId() == self.ttbres.GetId():
  387. self.tbres = float(event.GetString())
  388. self.__UpdateInfo()
  389. except ValueError, e:
  390. if len(event.GetString()) > 0 and event.GetString() != '-':
  391. dlg = wx.MessageBox(parent = self,
  392. message = _("Invalid value: %s") % e,
  393. caption = _("Error"),
  394. style = wx.OK | wx.ICON_ERROR)
  395. # reset values
  396. self.tnorth.SetValue(str(self.north))
  397. self.tsouth.SetValue(str(self.south))
  398. self.teast.SetValue(str(self.east))
  399. self.twest.SetValue(str(self.west))
  400. self.tnsres.SetValue(str(self.nsres))
  401. self.tewres.SetValue(str(self.ewres))
  402. self.ttop.SetValue(str(self.top))
  403. self.tbottom.SetValue(str(self.bottom))
  404. self.ttbres.SetValue(str(self.tbres))
  405. # self.tnsres3.SetValue(str(self.nsres3))
  406. # self.tewres3.SetValue(str(self.ewres3))
  407. event.Skip()
  408. def __UpdateInfo(self):
  409. """!Update number of rows/cols/cells"""
  410. self.rows = int((self.north - self.south) / self.nsres)
  411. self.cols = int((self.east - self.west) / self.ewres)
  412. self.cells = self.rows * self.cols
  413. self.depth = int((self.top - self.bottom) / self.tbres)
  414. self.cells3 = self.rows * self.cols * self.depth
  415. # 2D
  416. self.lrows.SetLabel(_("Rows: %d") % self.rows)
  417. self.lcols.SetLabel(_("Cols: %d") % self.cols)
  418. self.lcells.SetLabel(_("Cells: %d") % self.cells)
  419. # 3D
  420. self.ldepth.SetLabel(_("Depth: %d" % self.depth))
  421. self.lcells3.SetLabel(_("3D Cells: %d" % self.cells3))
  422. def OnSetButton(self, event = None):
  423. """!Set default region"""
  424. ret = RunCommand('g.region',
  425. flags = 'sgpa',
  426. n = self.north,
  427. s = self.south,
  428. e = self.east,
  429. w = self.west,
  430. nsres = self.nsres,
  431. ewres = self.ewres,
  432. t = self.top,
  433. b = self.bottom,
  434. tbres = self.tbres)
  435. if ret == 0:
  436. self.Destroy()
  437. def OnCancel(self, event):
  438. self.Destroy()
  439. class TransList(wx.VListBox):
  440. """!Creates a multiline listbox for selecting datum transforms"""
  441. def OnDrawItem(self, dc, rect, n):
  442. if self.GetSelection() == n:
  443. c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
  444. else:
  445. c = self.GetForegroundColour()
  446. dc.SetFont(self.GetFont())
  447. dc.SetTextForeground(c)
  448. dc.DrawLabel(self._getItemText(n), rect,
  449. wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
  450. def OnMeasureItem(self, n):
  451. height = 0
  452. if self._getItemText(n) == None:
  453. return
  454. for line in self._getItemText(n).splitlines():
  455. w, h = self.GetTextExtent(line)
  456. height += h
  457. return height + 5
  458. def _getItemText(self, item):
  459. global transformlist
  460. transitem = transformlist[item]
  461. if transitem.strip() !='':
  462. return transitem
  463. class SelectTransformDialog(wx.Dialog):
  464. """!Dialog for selecting datum transformations"""
  465. def __init__(self, parent, transforms, title = _("Select datum transformation"),
  466. pos = wx.DefaultPosition, size = wx.DefaultSize,
  467. style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
  468. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  469. global transformlist
  470. self.CentreOnParent()
  471. # default transform number
  472. self.transnum = 0
  473. panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
  474. sizer = wx.BoxSizer(wx.VERTICAL)
  475. #
  476. # set panel sizer
  477. #
  478. panel.SetSizer(sizer)
  479. panel.SetupScrolling()
  480. #
  481. # dialog body
  482. #
  483. bodyBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  484. label = " %s " % _("Select from list of datum transformations"))
  485. bodySizer = wx.StaticBoxSizer(bodyBox)
  486. # add no transform option
  487. transforms = '---\n\n0\nDo not apply any datum transformations\n\n' + transforms
  488. transformlist = transforms.split('---')
  489. tlistlen = len(transformlist)
  490. # calculate size for transform list
  491. height = 0
  492. width = 0
  493. for line in transforms.splitlines():
  494. w, h = self.GetTextExtent(line)
  495. height += h
  496. width = max(width, w)
  497. height = height + 5
  498. if height > 400: height = 400
  499. width = width + 5
  500. if width > 400: width = 400
  501. #
  502. # VListBox for displaying and selecting transformations
  503. #
  504. self.translist = TransList(panel, id = -1, size = (width, height), style = wx.SUNKEN_BORDER)
  505. self.translist.SetItemCount(tlistlen)
  506. self.translist.SetSelection(2)
  507. self.translist.SetFocus()
  508. self.Bind(wx.EVT_LISTBOX, self.ClickTrans, self.translist)
  509. bodySizer.Add(item = self.translist, proportion = 1, flag = wx.ALIGN_CENTER|wx.ALL|wx.EXPAND)
  510. #
  511. # buttons
  512. #
  513. btnsizer = wx.StdDialogButtonSizer()
  514. btn = wx.Button(parent = panel, id = wx.ID_OK)
  515. btn.SetDefault()
  516. btnsizer.AddButton(btn)
  517. btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
  518. btnsizer.AddButton(btn)
  519. btnsizer.Realize()
  520. sizer.Add(item = bodySizer, proportion = 1,
  521. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  522. sizer.Add(item = btnsizer, proportion = 0,
  523. flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
  524. sizer.Fit(panel)
  525. self.SetSize(self.GetBestSize())
  526. self.Layout()
  527. def ClickTrans(self, event):
  528. """!Get the number of the datum transform to use in g.proj"""
  529. self.transnum = event.GetSelection()
  530. self.transnum = self.transnum - 1
  531. def GetTransform(self):
  532. """!Get the number of the datum transform to use in g.proj"""
  533. self.transnum = self.translist.GetSelection()
  534. self.transnum = self.transnum - 1
  535. return self.transnum
  536. def testRegionDef():
  537. import sys
  538. import gettext
  539. import wx.lib.inspection
  540. import grass.script as grass
  541. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  542. app = wx.PySimpleApp()
  543. dlg = RegionDef(None, location = grass.gisenv()["LOCATION_NAME"])
  544. dlg.Show()
  545. wx.lib.inspection.InspectionTool().Show()
  546. app.MainLoop()
  547. if __name__ == '__main__':
  548. testRegionDef()