dialogs.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. from core import globalvar
  20. from core.gcmd import RunCommand
  21. from location_wizard.base import BaseClass
  22. from grass.script import core as grass
  23. class RegionDef(BaseClass, wx.Frame):
  24. """!Page for setting default region extents and resolution
  25. """
  26. def __init__(self, parent, id = wx.ID_ANY,
  27. title = _("Set default region extent and resolution"), location = None):
  28. wx.Frame.__init__(self, parent, id, title, size = (650,300))
  29. panel = wx.Panel(self, id = wx.ID_ANY)
  30. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, '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.ETCIMGDIR, "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. def MakeSettings3DPaneContent(self, pane):
  186. """!Create 3D region settings pane"""
  187. border = wx.BoxSizer(wx.VERTICAL)
  188. gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
  189. # inputs
  190. self.ttop = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.top),
  191. size = (150, -1))
  192. self.tbottom = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.bottom),
  193. size = (150, -1))
  194. self.ttbres = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.tbres),
  195. size = (150, -1))
  196. # self.tnsres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.nsres3),
  197. # size = (150, -1))
  198. # self.tewres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.ewres3),
  199. # size = (150, -1))
  200. #labels
  201. self.ldepth = wx.StaticText(parent = pane, label = _("Depth: %d") % self.depth)
  202. self.lcells3 = wx.StaticText(parent = pane, label = _("3D Cells: %d") % self.cells3)
  203. # top
  204. gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Top")),
  205. flag = wx.ALIGN_CENTER |
  206. wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  207. pos = (0, 1))
  208. gridSizer.Add(item = self.ttop,
  209. flag = wx.ALIGN_CENTER_HORIZONTAL |
  210. wx.ALL, border = 5, pos = (1, 1))
  211. # bottom
  212. gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Bottom")),
  213. flag = wx.ALIGN_CENTER |
  214. wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  215. pos = (0, 2))
  216. gridSizer.Add(item = self.tbottom,
  217. flag = wx.ALIGN_CENTER_HORIZONTAL |
  218. wx.ALL, border = 5, pos = (1, 2))
  219. # tbres
  220. gridSizer.Add(item = wx.StaticText(parent = pane, label = _("T-B resolution")),
  221. flag = wx.ALIGN_CENTER |
  222. wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  223. pos = (0, 3))
  224. gridSizer.Add(item = self.ttbres,
  225. flag = wx.ALIGN_CENTER_HORIZONTAL |
  226. wx.ALL, border = 5, pos = (1, 3))
  227. # res
  228. # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D N-S resolution")),
  229. # flag = wx.ALIGN_CENTER |
  230. # wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  231. # pos = (2, 1))
  232. # gridSizer.Add(item = self.tnsres3,
  233. # flag = wx.ALIGN_CENTER_HORIZONTAL |
  234. # wx.ALL, border = 5, pos = (3, 1))
  235. # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D E-W resolution")),
  236. # flag = wx.ALIGN_CENTER |
  237. # wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
  238. # pos = (2, 3))
  239. # gridSizer.Add(item = self.tewres3,
  240. # flag = wx.ALIGN_CENTER_HORIZONTAL |
  241. # wx.ALL, border = 5, pos = (3, 3))
  242. # rows/cols/cells
  243. gridSizer.Add(item = self.ldepth,
  244. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  245. wx.ALL, border = 5, pos = (2, 1))
  246. gridSizer.Add(item = self.lcells3,
  247. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  248. wx.ALL, border = 5, pos = (2, 2))
  249. border.Add(item = gridSizer, proportion = 1,
  250. flag = wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border = 5)
  251. pane.SetSizer(border)
  252. border.Fit(pane)
  253. def OnSettings3DPaneChanged(self, event):
  254. """!Collapse 3D settings box"""
  255. if self.settings3D.IsExpanded():
  256. self.settings3D.SetLabel(self.infoCollapseLabelCol)
  257. self.Layout()
  258. self.SetSize(self.GetBestSize())
  259. self.SetMinSize(self.GetSize())
  260. else:
  261. self.settings3D.SetLabel(self.infoCollapseLabelExp)
  262. self.Layout()
  263. self.SetSize(self.minWindowSize)
  264. self.SetMinSize(self.minWindowSize)
  265. self.SendSizeEvent()
  266. def __DoLayout(self, panel):
  267. """!Window layout"""
  268. frameSizer = wx.BoxSizer(wx.VERTICAL)
  269. gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
  270. settings3DSizer = wx.BoxSizer(wx.VERTICAL)
  271. buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
  272. # north
  273. gridSizer.Add(item = self.MakeLabel(text = _("North"), parent = panel),
  274. flag = wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL |
  275. wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (0, 2))
  276. gridSizer.Add(item = self.tnorth,
  277. flag = wx.ALIGN_CENTER_HORIZONTAL |
  278. wx.ALIGN_CENTER_VERTICAL |
  279. wx.ALL, border = 5, pos = (1, 2))
  280. # west
  281. gridSizer.Add(item = self.MakeLabel(text = _("West"), parent = panel),
  282. flag = wx.ALIGN_RIGHT |
  283. wx.ALIGN_CENTER_VERTICAL |
  284. wx.LEFT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 0))
  285. gridSizer.Add(item = self.twest,
  286. flag = wx.ALIGN_RIGHT |
  287. wx.ALIGN_CENTER_VERTICAL |
  288. wx.ALL, border = 5, pos = (2, 1))
  289. gridSizer.Add(item = wx.StaticBitmap(panel, wx.ID_ANY, self.img, (-1, -1),
  290. (self.img.GetWidth(), self.img.GetHeight())),
  291. flag = wx.ALIGN_CENTER |
  292. wx.ALIGN_CENTER_VERTICAL |
  293. wx.ALL, border = 5, pos = (2, 2))
  294. # east
  295. gridSizer.Add(item = self.teast,
  296. flag = wx.ALIGN_CENTER_HORIZONTAL |
  297. wx.ALIGN_CENTER_VERTICAL |
  298. wx.ALL, border = 5, pos = (2, 3))
  299. gridSizer.Add(item = self.MakeLabel(text = _("East"), parent = panel),
  300. flag = wx.ALIGN_LEFT |
  301. wx.ALIGN_CENTER_VERTICAL |
  302. wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 4))
  303. # south
  304. gridSizer.Add(item = self.tsouth,
  305. flag = wx.ALIGN_CENTER_HORIZONTAL |
  306. wx.ALIGN_CENTER_VERTICAL |
  307. wx.ALL, border = 5, pos = (3, 2))
  308. gridSizer.Add(item = self.MakeLabel(text = _("South"), parent = panel),
  309. flag = wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL |
  310. wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5, pos = (4, 2))
  311. # ns-res
  312. gridSizer.Add(item = self.MakeLabel(text = _("N-S resolution"), parent = panel),
  313. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  314. wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 1))
  315. gridSizer.Add(item = self.tnsres,
  316. flag = wx.ALIGN_RIGHT |
  317. wx.ALIGN_CENTER_VERTICAL |
  318. wx.ALL, border = 5, pos = (6, 1))
  319. # ew-res
  320. gridSizer.Add(item = self.MakeLabel(text = _("E-W resolution"), parent = panel),
  321. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  322. wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 3))
  323. gridSizer.Add(item = self.tewres,
  324. flag = wx.ALIGN_RIGHT |
  325. wx.ALIGN_CENTER_VERTICAL |
  326. wx.ALL, border = 5, pos = (6, 3))
  327. # rows/cols/cells
  328. gridSizer.Add(item = self.lrows,
  329. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  330. wx.ALL, border = 5, pos = (7, 1))
  331. gridSizer.Add(item = self.lcells,
  332. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  333. wx.ALL, border = 5, pos = (7, 2))
  334. gridSizer.Add(item = self.lcols,
  335. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
  336. wx.ALL, border = 5, pos = (7, 3))
  337. # 3D
  338. settings3DSizer.Add(item = self.settings3D,
  339. flag = wx.ALL,
  340. border = 5)
  341. # buttons
  342. buttonSizer.Add(item = self.bcancel, proportion = 1,
  343. flag = wx.ALIGN_RIGHT |
  344. wx.ALIGN_CENTER_VERTICAL |
  345. wx.ALL, border = 10)
  346. buttonSizer.Add(item = self.bset, proportion = 1,
  347. flag = wx.ALIGN_CENTER |
  348. wx.ALIGN_CENTER_VERTICAL |
  349. wx.ALL, border = 10)
  350. frameSizer.Add(item = gridSizer, proportion = 1,
  351. flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
  352. frameSizer.Add(item = settings3DSizer, proportion = 0,
  353. flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
  354. frameSizer.Add(item = buttonSizer, proportion = 0,
  355. flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
  356. self.SetAutoLayout(True)
  357. panel.SetSizer(frameSizer)
  358. frameSizer.Fit(panel)
  359. self.Layout()
  360. def OnValue(self, event):
  361. """!Set given value"""
  362. try:
  363. if event.GetId() == self.tnorth.GetId():
  364. self.north = float(event.GetString())
  365. elif event.GetId() == self.tsouth.GetId():
  366. self.south = float(event.GetString())
  367. elif event.GetId() == self.teast.GetId():
  368. self.east = float(event.GetString())
  369. elif event.GetId() == self.twest.GetId():
  370. self.west = float(event.GetString())
  371. elif event.GetId() == self.tnsres.GetId():
  372. self.nsres = float(event.GetString())
  373. elif event.GetId() == self.tewres.GetId():
  374. self.ewres = float(event.GetString())
  375. elif event.GetId() == self.ttop.GetId():
  376. self.top = float(event.GetString())
  377. elif event.GetId() == self.tbottom.GetId():
  378. self.bottom = float(event.GetString())
  379. # elif event.GetId() == self.tnsres3.GetId():
  380. # self.nsres3 = float(event.GetString())
  381. # elif event.GetId() == self.tewres3.GetId():
  382. # self.ewres3 = float(event.GetString())
  383. elif event.GetId() == self.ttbres.GetId():
  384. self.tbres = float(event.GetString())
  385. self.__UpdateInfo()
  386. except ValueError, e:
  387. if len(event.GetString()) > 0 and event.GetString() != '-':
  388. dlg = wx.MessageBox(parent = self,
  389. message = _("Invalid value: %s") % e,
  390. caption = _("Error"),
  391. style = wx.OK | wx.ICON_ERROR)
  392. # reset values
  393. self.tnorth.SetValue(str(self.north))
  394. self.tsouth.SetValue(str(self.south))
  395. self.teast.SetValue(str(self.east))
  396. self.twest.SetValue(str(self.west))
  397. self.tnsres.SetValue(str(self.nsres))
  398. self.tewres.SetValue(str(self.ewres))
  399. self.ttop.SetValue(str(self.top))
  400. self.tbottom.SetValue(str(self.bottom))
  401. self.ttbres.SetValue(str(self.tbres))
  402. # self.tnsres3.SetValue(str(self.nsres3))
  403. # self.tewres3.SetValue(str(self.ewres3))
  404. event.Skip()
  405. def __UpdateInfo(self):
  406. """!Update number of rows/cols/cells"""
  407. self.rows = int((self.north - self.south) / self.nsres)
  408. self.cols = int((self.east - self.west) / self.ewres)
  409. self.cells = self.rows * self.cols
  410. self.depth = int((self.top - self.bottom) / self.tbres)
  411. self.cells3 = self.rows * self.cols * self.depth
  412. # 2D
  413. self.lrows.SetLabel(_("Rows: %d") % self.rows)
  414. self.lcols.SetLabel(_("Cols: %d") % self.cols)
  415. self.lcells.SetLabel(_("Cells: %d") % self.cells)
  416. # 3D
  417. self.ldepth.SetLabel(_("Depth: %d" % self.depth))
  418. self.lcells3.SetLabel(_("3D Cells: %d" % self.cells3))
  419. def OnSetButton(self, event = None):
  420. """!Set default region"""
  421. ret = RunCommand('g.region',
  422. flags = 'sgpa',
  423. n = self.north,
  424. s = self.south,
  425. e = self.east,
  426. w = self.west,
  427. nsres = self.nsres,
  428. ewres = self.ewres,
  429. t = self.top,
  430. b = self.bottom,
  431. tbres = self.tbres)
  432. if ret == 0:
  433. self.Destroy()
  434. def OnCancel(self, event):
  435. self.Destroy()
  436. class TransList(wx.VListBox):
  437. """!Creates a multiline listbox for selecting datum transforms"""
  438. def OnDrawItem(self, dc, rect, n):
  439. if self.GetSelection() == n:
  440. c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
  441. else:
  442. c = self.GetForegroundColour()
  443. dc.SetFont(self.GetFont())
  444. dc.SetTextForeground(c)
  445. dc.DrawLabel(self._getItemText(n), rect,
  446. wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
  447. def OnMeasureItem(self, n):
  448. height = 0
  449. if self._getItemText(n) == None:
  450. return
  451. for line in self._getItemText(n).splitlines():
  452. w, h = self.GetTextExtent(line)
  453. height += h
  454. return height + 5
  455. def _getItemText(self, item):
  456. global transformlist
  457. transitem = transformlist[item]
  458. if transitem.strip() !='':
  459. return transitem
  460. class SelectTransformDialog(wx.Dialog):
  461. """!Dialog for selecting datum transformations"""
  462. def __init__(self, parent, transforms, title = _("Select datum transformation"),
  463. pos = wx.DefaultPosition, size = wx.DefaultSize,
  464. style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
  465. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  466. global transformlist
  467. self.CentreOnParent()
  468. # default transform number
  469. self.transnum = 0
  470. panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
  471. sizer = wx.BoxSizer(wx.VERTICAL)
  472. #
  473. # set panel sizer
  474. #
  475. panel.SetSizer(sizer)
  476. panel.SetupScrolling()
  477. #
  478. # dialog body
  479. #
  480. bodyBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  481. label = " %s " % _("Select from list of datum transformations"))
  482. bodySizer = wx.StaticBoxSizer(bodyBox)
  483. # add no transform option
  484. transforms = '---\n\n0\nDo not apply any datum transformations\n\n' + transforms
  485. transformlist = transforms.split('---')
  486. tlistlen = len(transformlist)
  487. # calculate size for transform list
  488. height = 0
  489. width = 0
  490. for line in transforms.splitlines():
  491. w, h = self.GetTextExtent(line)
  492. height += h
  493. width = max(width, w)
  494. height = height + 5
  495. if height > 400: height = 400
  496. width = width + 5
  497. if width > 400: width = 400
  498. #
  499. # VListBox for displaying and selecting transformations
  500. #
  501. self.translist = TransList(panel, id = -1, size = (width, height), style = wx.SUNKEN_BORDER)
  502. self.translist.SetItemCount(tlistlen)
  503. self.translist.SetSelection(2)
  504. self.translist.SetFocus()
  505. self.Bind(wx.EVT_LISTBOX, self.ClickTrans, self.translist)
  506. bodySizer.Add(item = self.translist, proportion = 1, flag = wx.ALIGN_CENTER|wx.ALL|wx.EXPAND)
  507. #
  508. # buttons
  509. #
  510. btnsizer = wx.StdDialogButtonSizer()
  511. btn = wx.Button(parent = panel, id = wx.ID_OK)
  512. btn.SetDefault()
  513. btnsizer.AddButton(btn)
  514. btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
  515. btnsizer.AddButton(btn)
  516. btnsizer.Realize()
  517. sizer.Add(item = bodySizer, proportion = 1,
  518. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  519. sizer.Add(item = btnsizer, proportion = 0,
  520. flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
  521. sizer.Fit(panel)
  522. self.SetSize(self.GetBestSize())
  523. self.Layout()
  524. def ClickTrans(self, event):
  525. """!Get the number of the datum transform to use in g.proj"""
  526. self.transnum = event.GetSelection()
  527. self.transnum = self.transnum - 1
  528. def GetTransform(self):
  529. """!Get the number of the datum transform to use in g.proj"""
  530. self.transnum = self.translist.GetSelection()
  531. self.transnum = self.transnum - 1
  532. return self.transnum