GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
location_wizard/dialogs.py
Go to the documentation of this file.
00001 """!
00002 @package location_wizard.dialogs
00003 
00004 @brief Location wizard - dialogs
00005 
00006 Classes:
00007  - dialogs::RegionDef
00008  - dialogs::TransList
00009  - dialogs::SelectTransformDialog
00010 
00011 (C) 2007-2011 by the GRASS Development Team
00012 
00013 This program is free software under the GNU General Public License
00014 (>=v2). Read the file COPYING that comes with GRASS for details.
00015 
00016 @author Michael Barton
00017 @author Jachym Cepicky
00018 @author Martin Landa <landa.martin gmail.com>   
00019 """
00020 import os
00021 import sys
00022 
00023 import wx
00024 import wx.lib.scrolledpanel as scrolled
00025 
00026 from core                 import globalvar
00027 from core.gcmd            import RunCommand
00028 from location_wizard.base import BaseClass
00029 
00030 from grass.script import core as grass
00031 
00032 class RegionDef(BaseClass, wx.Frame):
00033     """!Page for setting default region extents and resolution
00034     """
00035     def __init__(self, parent, id = wx.ID_ANY,
00036                  title = _("Set default region extent and resolution"), location = None):
00037         wx.Frame.__init__(self, parent, id, title, size = (650,300))
00038         panel = wx.Panel(self, id = wx.ID_ANY)
00039         
00040         self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
00041         
00042         self.parent = parent
00043         self.location = location
00044         
00045         #
00046         # default values
00047         #
00048         # 2D
00049         self.north = 1.0
00050         self.south = 0.0
00051         self.east = 1.0
00052         self.west = 0.0
00053         self.nsres = 1.0
00054         self.ewres = 1.0
00055         # 3D
00056         self.top = 1.0
00057         self.bottom = 0.0
00058         #         self.nsres3 = 1.0
00059         #         self.ewres3 = 1.0
00060         self.tbres  = 1.0
00061         
00062         #
00063         # inputs
00064         #
00065         # 2D
00066         self.tnorth = self.MakeTextCtrl(text = str(self.north), size = (150, -1), parent = panel)
00067         self.tsouth = self.MakeTextCtrl(str(self.south), size = (150, -1), parent = panel)
00068         self.twest = self.MakeTextCtrl(str(self.west), size = (150, -1), parent = panel)
00069         self.teast = self.MakeTextCtrl(str(self.east), size = (150, -1), parent = panel)
00070         self.tnsres = self.MakeTextCtrl(str(self.nsres), size = (150, -1), parent = panel)
00071         self.tewres = self.MakeTextCtrl(str(self.ewres), size = (150, -1), parent = panel)
00072         
00073         #
00074         # labels
00075         #
00076         self.lrows  = self.MakeLabel(parent = panel)
00077         self.lcols  = self.MakeLabel(parent = panel)
00078         self.lcells = self.MakeLabel(parent = panel)
00079         
00080         #
00081         # buttons
00082         #
00083         self.bset = self.MakeButton(text = _("&Set region"), id = wx.ID_OK, parent = panel)
00084         self.bcancel = wx.Button(panel, id = wx.ID_CANCEL)
00085         self.bset.SetDefault()
00086         
00087         #
00088         # image
00089         #
00090         self.img = wx.Image(os.path.join(globalvar.ETCIMGDIR, "qgis_world.png"),
00091                             wx.BITMAP_TYPE_PNG).ConvertToBitmap()
00092         
00093         #
00094         # set current working environment to PERMANENT mapset
00095         # in selected location in order to set default region (WIND)
00096         #
00097         envval = {}
00098         ret = RunCommand('g.gisenv',
00099                          read = True)
00100         if ret:
00101             for line in ret.splitlines():
00102                 key, val = line.split('=')
00103                 envval[key] = val
00104             self.currlocation = envval['LOCATION_NAME'].strip("';")
00105             self.currmapset = envval['MAPSET'].strip("';")
00106             if self.currlocation != self.location or self.currmapset != 'PERMANENT':
00107                 RunCommand('g.gisenv',
00108                            set = 'LOCATION_NAME=%s' % self.location)
00109                 RunCommand('g.gisenv',
00110                            set = 'MAPSET=PERMANENT')
00111         else:
00112             dlg = wx.MessageBox(parent = self,
00113                                 message = _('Invalid location selected.'),
00114                                 caption = _("Error"), style = wx.ID_OK | wx.ICON_ERROR)
00115             return
00116         
00117         #
00118         # get current region settings
00119         #
00120         region = {}
00121         ret = RunCommand('g.region',
00122                          read = True,
00123                          flags = 'gp3')
00124         if ret:
00125             for line in ret.splitlines():
00126                 key, val = line.split('=')
00127                 region[key] = float(val)
00128         else:
00129             dlg = wx.MessageBox(parent = self,
00130                                 message = _("Invalid region"),
00131                                 caption = _("Error"), style = wx.ID_OK | wx.ICON_ERROR)
00132             dlg.ShowModal()
00133             dlg.Destroy()
00134             return
00135         
00136         #
00137         # update values
00138         # 2D
00139         self.north = float(region['n'])
00140         self.south = float(region['s'])
00141         self.east = float(region['e'])
00142         self.west = float(region['w'])
00143         self.nsres = float(region['nsres'])
00144         self.ewres = float(region['ewres'])
00145         self.rows = int(region['rows'])
00146         self.cols = int(region['cols'])
00147         self.cells = int(region['cells'])
00148         # 3D
00149         self.top = float(region['t'])
00150         self.bottom = float(region['b'])
00151         #         self.nsres3 = float(region['nsres3'])
00152         #         self.ewres3 = float(region['ewres3'])
00153         self.tbres = float(region['tbres'])
00154         self.depth = int(region['depths'])
00155         self.cells3 = int(region['cells3'])
00156         
00157         #
00158         # 3D box collapsable
00159         #
00160         self.infoCollapseLabelExp = _("Click here to show 3D settings")
00161         self.infoCollapseLabelCol = _("Click here to hide 3D settings")
00162         self.settings3D = wx.CollapsiblePane(parent = panel,
00163                                              label = self.infoCollapseLabelExp,
00164                                              style = wx.CP_DEFAULT_STYLE |
00165                                              wx.CP_NO_TLW_RESIZE | wx.EXPAND)
00166         self.MakeSettings3DPaneContent(self.settings3D.GetPane())
00167         self.settings3D.Collapse(False) # FIXME
00168         self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSettings3DPaneChanged, self.settings3D)
00169         
00170         #
00171         # set current region settings
00172         #
00173         self.tnorth.SetValue(str(self.north))
00174         self.tsouth.SetValue(str(self.south))
00175         self.twest.SetValue(str(self.west))
00176         self.teast.SetValue(str(self.east))
00177         self.tnsres.SetValue(str(self.nsres))
00178         self.tewres.SetValue(str(self.ewres))
00179         self.ttop.SetValue(str(self.top))
00180         self.tbottom.SetValue(str(self.bottom))
00181         #         self.tnsres3.SetValue(str(self.nsres3))
00182         #         self.tewres3.SetValue(str(self.ewres3))
00183         self.ttbres.SetValue(str(self.tbres))
00184         self.lrows.SetLabel(_("Rows: %d") % self.rows)
00185         self.lcols.SetLabel(_("Cols: %d") % self.cols)
00186         self.lcells.SetLabel(_("Cells: %d") % self.cells)
00187         
00188         #
00189         # bindings
00190         #
00191         self.Bind(wx.EVT_BUTTON, self.OnSetButton, self.bset)
00192         self.Bind(wx.EVT_BUTTON, self.OnCancel, self.bcancel)
00193         self.tnorth.Bind(wx.EVT_TEXT,   self.OnValue)
00194         self.tsouth.Bind(wx.EVT_TEXT,   self.OnValue)
00195         self.teast.Bind(wx.EVT_TEXT,    self.OnValue)
00196         self.twest.Bind(wx.EVT_TEXT,    self.OnValue)
00197         self.tnsres.Bind(wx.EVT_TEXT,   self.OnValue)
00198         self.tewres.Bind(wx.EVT_TEXT,   self.OnValue)
00199         self.ttop.Bind(wx.EVT_TEXT,     self.OnValue)
00200         self.tbottom.Bind(wx.EVT_TEXT,  self.OnValue)
00201         #         self.tnsres3.Bind(wx.EVT_TEXT,  self.OnValue)
00202         #         self.tewres3.Bind(wx.EVT_TEXT,  self.OnValue)
00203         self.ttbres.Bind(wx.EVT_TEXT,   self.OnValue)
00204         
00205         self.__DoLayout(panel)
00206         self.SetMinSize(self.GetBestSize())
00207         self.minWindowSize = self.GetMinSize()
00208     
00209     def MakeSettings3DPaneContent(self, pane):
00210         """!Create 3D region settings pane"""
00211         border = wx.BoxSizer(wx.VERTICAL)
00212         gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
00213 
00214         # inputs
00215         self.ttop = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.top),
00216                                 size = (150, -1))
00217         self.tbottom = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.bottom),
00218                                 size = (150, -1))
00219         self.ttbres = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.tbres),
00220                                 size = (150, -1))
00221         #         self.tnsres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.nsres3),
00222         #                                    size = (150, -1))
00223         #         self.tewres3  =  wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.ewres3),
00224         #                                    size = (150, -1))
00225 
00226         #labels
00227         self.ldepth = wx.StaticText(parent = pane, label = _("Depth: %d") % self.depth)
00228         self.lcells3  =  wx.StaticText(parent = pane, label = _("3D Cells: %d") % self.cells3)
00229 
00230         # top
00231         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Top")),
00232                       flag = wx.ALIGN_CENTER |
00233                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
00234                       pos = (0, 1))
00235         gridSizer.Add(item = self.ttop,
00236                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00237                       wx.ALL, border = 5, pos = (1, 1))
00238         # bottom
00239         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Bottom")),
00240                       flag = wx.ALIGN_CENTER |
00241                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
00242                       pos = (0, 2))
00243         gridSizer.Add(item = self.tbottom,
00244                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00245                       wx.ALL, border = 5, pos = (1, 2))
00246         # tbres
00247         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("T-B resolution")),
00248                       flag = wx.ALIGN_CENTER | 
00249                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
00250                       pos = (0, 3))
00251         gridSizer.Add(item = self.ttbres,
00252                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00253                       wx.ALL, border = 5, pos = (1, 3))
00254 
00255         # res
00256         #         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D N-S resolution")),
00257         #                       flag = wx.ALIGN_CENTER |
00258         #                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
00259         #                       pos = (2, 1))
00260         #         gridSizer.Add(item = self.tnsres3,
00261         #                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00262         #                       wx.ALL, border = 5, pos = (3, 1))
00263         #         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D E-W resolution")),
00264         #                       flag = wx.ALIGN_CENTER |
00265         #                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
00266         #                       pos = (2, 3))
00267         #         gridSizer.Add(item = self.tewres3,
00268         #                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00269         #                       wx.ALL, border = 5, pos = (3, 3))
00270 
00271         # rows/cols/cells
00272         gridSizer.Add(item = self.ldepth,
00273                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00274                       wx.ALL, border = 5, pos = (2, 1))
00275 
00276         gridSizer.Add(item = self.lcells3,
00277                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00278                       wx.ALL, border = 5, pos = (2, 2))
00279 
00280         border.Add(item = gridSizer, proportion = 1,
00281                    flag = wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border = 5)
00282 
00283         pane.SetSizer(border)
00284         border.Fit(pane)
00285 
00286     def OnSettings3DPaneChanged(self, event):
00287         """!Collapse 3D settings box"""
00288 
00289         if self.settings3D.IsExpanded():
00290             self.settings3D.SetLabel(self.infoCollapseLabelCol)
00291             self.Layout()
00292             self.SetSize(self.GetBestSize())
00293             self.SetMinSize(self.GetSize())
00294         else:
00295             self.settings3D.SetLabel(self.infoCollapseLabelExp)
00296             self.Layout()
00297             self.SetSize(self.minWindowSize)
00298             self.SetMinSize(self.minWindowSize)
00299 
00300         self.SendSizeEvent()
00301 
00302     def __DoLayout(self, panel):
00303         """!Window layout"""
00304         frameSizer = wx.BoxSizer(wx.VERTICAL)
00305         gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
00306         settings3DSizer = wx.BoxSizer(wx.VERTICAL)
00307         buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
00308 
00309         # north
00310         gridSizer.Add(item = self.MakeLabel(text = _("North"), parent = panel),
00311                       flag = wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL |
00312                       wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (0, 2))
00313         gridSizer.Add(item = self.tnorth,
00314                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00315                       wx.ALIGN_CENTER_VERTICAL |
00316                       wx.ALL, border = 5, pos = (1, 2))
00317         # west
00318         gridSizer.Add(item = self.MakeLabel(text = _("West"), parent = panel),
00319                       flag = wx.ALIGN_RIGHT |
00320                       wx.ALIGN_CENTER_VERTICAL |
00321                       wx.LEFT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 0))
00322         gridSizer.Add(item = self.twest,
00323                       flag = wx.ALIGN_RIGHT |
00324                       wx.ALIGN_CENTER_VERTICAL |
00325                       wx.ALL, border = 5,  pos = (2, 1))
00326 
00327         gridSizer.Add(item = wx.StaticBitmap(panel, wx.ID_ANY, self.img, (-1, -1),
00328                                            (self.img.GetWidth(), self.img.GetHeight())),
00329                       flag = wx.ALIGN_CENTER |
00330                       wx.ALIGN_CENTER_VERTICAL |
00331                       wx.ALL, border = 5, pos = (2, 2))
00332 
00333         # east
00334         gridSizer.Add(item = self.teast,
00335                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00336                       wx.ALIGN_CENTER_VERTICAL |
00337                       wx.ALL, border = 5,  pos = (2, 3))
00338         gridSizer.Add(item = self.MakeLabel(text = _("East"), parent = panel),
00339                       flag = wx.ALIGN_LEFT |
00340                       wx.ALIGN_CENTER_VERTICAL |
00341                       wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 4))
00342         # south
00343         gridSizer.Add(item = self.tsouth,
00344                       flag = wx.ALIGN_CENTER_HORIZONTAL |
00345                       wx.ALIGN_CENTER_VERTICAL |
00346                       wx.ALL, border = 5, pos = (3, 2))
00347         gridSizer.Add(item = self.MakeLabel(text = _("South"), parent = panel),
00348                       flag = wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL |
00349                       wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5, pos = (4, 2))
00350         # ns-res
00351         gridSizer.Add(item = self.MakeLabel(text = _("N-S resolution"), parent = panel),
00352                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00353                       wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 1))
00354         gridSizer.Add(item = self.tnsres,
00355                       flag = wx.ALIGN_RIGHT |
00356                       wx.ALIGN_CENTER_VERTICAL |
00357                       wx.ALL, border = 5,  pos = (6, 1))
00358         # ew-res
00359         gridSizer.Add(item = self.MakeLabel(text = _("E-W resolution"), parent = panel),
00360                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00361                       wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 3))
00362         gridSizer.Add(item = self.tewres,
00363                       flag = wx.ALIGN_RIGHT |
00364                       wx.ALIGN_CENTER_VERTICAL |
00365                       wx.ALL, border = 5,  pos = (6, 3))
00366         # rows/cols/cells
00367         gridSizer.Add(item = self.lrows,
00368                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00369                       wx.ALL, border = 5, pos = (7, 1))
00370 
00371         gridSizer.Add(item = self.lcells,
00372                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00373                       wx.ALL, border = 5, pos = (7, 2))
00374 
00375         gridSizer.Add(item = self.lcols,
00376                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
00377                       wx.ALL, border = 5, pos = (7, 3))
00378 
00379         # 3D
00380         settings3DSizer.Add(item = self.settings3D,
00381                             flag = wx.ALL,
00382                             border = 5)
00383 
00384         # buttons
00385         buttonSizer.Add(item = self.bcancel, proportion = 1,
00386                         flag = wx.ALIGN_RIGHT |
00387                         wx.ALIGN_CENTER_VERTICAL |
00388                         wx.ALL, border = 10)
00389         buttonSizer.Add(item = self.bset, proportion = 1,
00390                         flag = wx.ALIGN_CENTER |
00391                         wx.ALIGN_CENTER_VERTICAL |
00392                         wx.ALL, border = 10)
00393 
00394         frameSizer.Add(item = gridSizer, proportion = 1,
00395                        flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
00396         frameSizer.Add(item = settings3DSizer, proportion = 0,
00397                        flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
00398         frameSizer.Add(item = buttonSizer, proportion = 0,
00399                        flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
00400 
00401         self.SetAutoLayout(True)
00402         panel.SetSizer(frameSizer)
00403         frameSizer.Fit(panel)
00404         self.Layout()
00405 
00406     def OnValue(self, event):
00407         """!Set given value"""
00408         try:
00409             if event.GetId() == self.tnorth.GetId():
00410                 self.north = float(event.GetString())
00411             elif event.GetId() == self.tsouth.GetId():
00412                 self.south = float(event.GetString())
00413             elif event.GetId() == self.teast.GetId():
00414                 self.east = float(event.GetString())
00415             elif event.GetId() == self.twest.GetId():
00416                 self.west = float(event.GetString())
00417             elif event.GetId() == self.tnsres.GetId():
00418                 self.nsres = float(event.GetString())
00419             elif event.GetId() == self.tewres.GetId():
00420                 self.ewres = float(event.GetString())
00421             elif event.GetId() == self.ttop.GetId():
00422                 self.top = float(event.GetString())
00423             elif event.GetId() == self.tbottom.GetId():
00424                 self.bottom = float(event.GetString())
00425             #             elif event.GetId() == self.tnsres3.GetId():
00426             #                 self.nsres3 = float(event.GetString())
00427             #             elif event.GetId() == self.tewres3.GetId():
00428             #                 self.ewres3 = float(event.GetString())
00429             elif event.GetId() == self.ttbres.GetId():
00430                 self.tbres = float(event.GetString())
00431 
00432             self.__UpdateInfo()
00433 
00434         except ValueError, e:
00435             if len(event.GetString()) > 0 and event.GetString() != '-':
00436                 dlg = wx.MessageBox(parent = self,
00437                                     message = _("Invalid value: %s") % e,
00438                                     caption = _("Error"),
00439                                     style = wx.OK | wx.ICON_ERROR)
00440                 # reset values
00441                 self.tnorth.SetValue(str(self.north))
00442                 self.tsouth.SetValue(str(self.south))
00443                 self.teast.SetValue(str(self.east))
00444                 self.twest.SetValue(str(self.west))
00445                 self.tnsres.SetValue(str(self.nsres))
00446                 self.tewres.SetValue(str(self.ewres))
00447                 self.ttop.SetValue(str(self.top))
00448                 self.tbottom.SetValue(str(self.bottom))
00449                 self.ttbres.SetValue(str(self.tbres))
00450                 # self.tnsres3.SetValue(str(self.nsres3))
00451                 # self.tewres3.SetValue(str(self.ewres3))
00452 
00453         event.Skip()
00454 
00455     def __UpdateInfo(self):
00456         """!Update number of rows/cols/cells"""
00457         self.rows = int((self.north - self.south) / self.nsres)
00458         self.cols = int((self.east - self.west) / self.ewres)
00459         self.cells = self.rows * self.cols
00460 
00461         self.depth = int((self.top - self.bottom) / self.tbres)
00462         self.cells3 = self.rows * self.cols * self.depth
00463 
00464         # 2D
00465         self.lrows.SetLabel(_("Rows: %d") % self.rows)
00466         self.lcols.SetLabel(_("Cols: %d") % self.cols)
00467         self.lcells.SetLabel(_("Cells: %d") % self.cells)
00468         # 3D
00469         self.ldepth.SetLabel(_("Depth: %d" % self.depth))
00470         self.lcells3.SetLabel(_("3D Cells: %d" % self.cells3))
00471 
00472     def OnSetButton(self, event = None):
00473         """!Set default region"""
00474         ret = RunCommand('g.region',
00475                          flags = 'sgpa',
00476                          n = self.north,
00477                          s = self.south,
00478                          e = self.east,
00479                          w = self.west,
00480                          nsres = self.nsres,
00481                          ewres = self.ewres,
00482                          t = self.top,
00483                          b = self.bottom,
00484                          tbres = self.tbres)
00485         if ret == 0:
00486             self.Destroy()
00487 
00488     def OnCancel(self, event):
00489         self.Destroy()
00490         
00491 class TransList(wx.VListBox):
00492     """!Creates a multiline listbox for selecting datum transforms"""
00493         
00494     def OnDrawItem(self, dc, rect, n):
00495         if self.GetSelection() == n:
00496             c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
00497         else:
00498             c = self.GetForegroundColour()
00499         dc.SetFont(self.GetFont())
00500         dc.SetTextForeground(c)
00501         dc.DrawLabel(self._getItemText(n), rect,
00502                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
00503 
00504     def OnMeasureItem(self, n):
00505         height = 0
00506         if self._getItemText(n) == None:
00507             return
00508         for line in self._getItemText(n).splitlines():
00509             w, h = self.GetTextExtent(line)
00510             height += h
00511         return height + 5
00512 
00513     def _getItemText(self, item):
00514         global transformlist
00515         transitem = transformlist[item]
00516         if transitem.strip() !='':
00517             return transitem
00518 
00519 class SelectTransformDialog(wx.Dialog):
00520     """!Dialog for selecting datum transformations"""
00521     def __init__(self, parent, transforms, title = _("Select datum transformation"),
00522                  pos = wx.DefaultPosition, size = wx.DefaultSize, 
00523                  style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
00524 
00525         wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
00526 
00527         global transformlist
00528         self.CentreOnParent()
00529         
00530         # default transform number
00531         self.transnum = 0
00532         
00533         panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
00534         sizer = wx.BoxSizer(wx.VERTICAL)
00535 
00536         #
00537         # set panel sizer
00538         #
00539         panel.SetSizer(sizer)
00540         panel.SetupScrolling()
00541 
00542         #
00543         # dialog body
00544         #
00545         bodyBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
00546                                label = " %s " % _("Select from list of datum transformations"))
00547         bodySizer = wx.StaticBoxSizer(bodyBox)       
00548         
00549         # add no transform option
00550         transforms = '---\n\n0\nDo not apply any datum transformations\n\n' + transforms
00551         
00552         transformlist = transforms.split('---')
00553         tlistlen = len(transformlist)
00554         
00555         # calculate size for transform list
00556         height = 0
00557         width = 0
00558         for line in transforms.splitlines():
00559             w, h = self.GetTextExtent(line)
00560             height += h
00561             width = max(width, w)
00562             
00563         height = height + 5
00564         if height > 400: height = 400
00565         width = width + 5
00566         if width > 400: width = 400
00567 
00568         #
00569         # VListBox for displaying and selecting transformations
00570         #
00571         self.translist = TransList(panel, id = -1, size = (width, height), style = wx.SUNKEN_BORDER)
00572         self.translist.SetItemCount(tlistlen)
00573         self.translist.SetSelection(2)
00574         self.translist.SetFocus()
00575         
00576         self.Bind(wx.EVT_LISTBOX, self.ClickTrans, self.translist)
00577 
00578         bodySizer.Add(item = self.translist, proportion = 1, flag = wx.ALIGN_CENTER|wx.ALL|wx.EXPAND)
00579 
00580         #
00581         # buttons
00582         #
00583         btnsizer = wx.StdDialogButtonSizer()
00584 
00585         btn = wx.Button(parent = panel, id = wx.ID_OK)
00586         btn.SetDefault()
00587         btnsizer.AddButton(btn)
00588 
00589         btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
00590         btnsizer.AddButton(btn)
00591         btnsizer.Realize()
00592 
00593         sizer.Add(item = bodySizer, proportion = 1,
00594                   flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
00595 
00596         sizer.Add(item = btnsizer, proportion = 0,
00597                   flag =  wx.ALL | wx.ALIGN_RIGHT, border = 5)
00598 
00599         sizer.Fit(panel)
00600 
00601         self.SetSize(self.GetBestSize())
00602         self.Layout()
00603         
00604     def ClickTrans(self, event):
00605         """!Get the number of the datum transform to use in g.proj"""
00606         self.transnum = event.GetSelection()
00607         self.transnum = self.transnum - 1
00608     
00609     def GetTransform(self):
00610         """!Get the number of the datum transform to use in g.proj"""
00611         self.transnum = self.translist.GetSelection()
00612         self.transnum = self.transnum - 1
00613         return self.transnum