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