dialogs.py 25 KB

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