dialogs.py 25 KB

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