dialogs.py 25 KB

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