File: dialogs.py

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (613 lines) | stat: -rw-r--r-- 24,790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
"""!
@package location_wizard.dialogs

@brief Location wizard - dialogs

Classes:
 - dialogs::RegionDef
 - dialogs::TransList
 - dialogs::SelectTransformDialog

(C) 2007-2011 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Michael Barton
@author Jachym Cepicky
@author Martin Landa <landa.martin gmail.com>   
"""
import os
import sys

import wx
import wx.lib.scrolledpanel as scrolled

from core                 import globalvar
from core.gcmd            import RunCommand
from location_wizard.base import BaseClass

from grass.script import core as grass

class RegionDef(BaseClass, wx.Dialog):
    """!Page for setting default region extents and resolution
    """
    def __init__(self, parent, id = wx.ID_ANY, size = (800, 600),
                 title = _("Set default region extent and resolution"), location = None):
        wx.Dialog.__init__(self, parent, id, title, size = size)
        panel = wx.Panel(self, id = wx.ID_ANY)
        
        self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
        
        self.parent = parent
        self.location = location
        
        #
        # default values
        #
        # 2D
        self.north = 1.0
        self.south = 0.0
        self.east = 1.0
        self.west = 0.0
        self.nsres = 1.0
        self.ewres = 1.0
        # 3D
        self.top = 1.0
        self.bottom = 0.0
        #         self.nsres3 = 1.0
        #         self.ewres3 = 1.0
        self.tbres  = 1.0
        
        #
        # inputs
        #
        # 2D
        self.tnorth = self.MakeTextCtrl(text = str(self.north), size = (150, -1), parent = panel)
        self.tsouth = self.MakeTextCtrl(str(self.south), size = (150, -1), parent = panel)
        self.twest = self.MakeTextCtrl(str(self.west), size = (150, -1), parent = panel)
        self.teast = self.MakeTextCtrl(str(self.east), size = (150, -1), parent = panel)
        self.tnsres = self.MakeTextCtrl(str(self.nsres), size = (150, -1), parent = panel)
        self.tewres = self.MakeTextCtrl(str(self.ewres), size = (150, -1), parent = panel)
        
        #
        # labels
        #
        self.lrows  = self.MakeLabel(parent = panel)
        self.lcols  = self.MakeLabel(parent = panel)
        self.lcells = self.MakeLabel(parent = panel)
        
        #
        # buttons
        #
        self.bset = self.MakeButton(text = _("&Set region"), id = wx.ID_OK, parent = panel)
        self.bcancel = wx.Button(panel, id = wx.ID_CANCEL)
        self.bset.SetDefault()
        
        #
        # image
        #
        self.img = wx.Image(os.path.join(globalvar.ETCIMGDIR, "qgis_world.png"),
                            wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        
        #
        # set current working environment to PERMANENT mapset
        # in selected location in order to set default region (WIND)
        #
        envval = {}
        ret = RunCommand('g.gisenv',
                         read = True)
        if ret:
            for line in ret.splitlines():
                key, val = line.split('=')
                envval[key] = val
            self.currlocation = envval['LOCATION_NAME'].strip("';")
            self.currmapset = envval['MAPSET'].strip("';")
            if self.currlocation != self.location or self.currmapset != 'PERMANENT':
                RunCommand('g.gisenv',
                           set = 'LOCATION_NAME=%s' % self.location)
                RunCommand('g.gisenv',
                           set = 'MAPSET=PERMANENT')
        else:
            dlg = wx.MessageBox(parent = self,
                                message = _('Invalid location selected.'),
                                caption = _("Error"), style = wx.ID_OK | wx.ICON_ERROR)
            return
        
        #
        # get current region settings
        #
        region = {}
        ret = RunCommand('g.region',
                         read = True,
                         flags = 'gp3')
        if ret:
            for line in ret.splitlines():
                key, val = line.split('=')
                region[key] = float(val)
        else:
            dlg = wx.MessageBox(parent = self,
                                message = _("Invalid region"),
                                caption = _("Error"), style = wx.ID_OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return
        
        #
        # update values
        # 2D
        self.north = float(region['n'])
        self.south = float(region['s'])
        self.east = float(region['e'])
        self.west = float(region['w'])
        self.nsres = float(region['nsres'])
        self.ewres = float(region['ewres'])
        self.rows = int(region['rows'])
        self.cols = int(region['cols'])
        self.cells = int(region['cells'])
        # 3D
        self.top = float(region['t'])
        self.bottom = float(region['b'])
        #         self.nsres3 = float(region['nsres3'])
        #         self.ewres3 = float(region['ewres3'])
        self.tbres = float(region['tbres'])
        self.depth = int(region['depths'])
        self.cells3 = int(region['cells3'])
        
        #
        # 3D box collapsable
        #
        self.infoCollapseLabelExp = _("Click here to show 3D settings")
        self.infoCollapseLabelCol = _("Click here to hide 3D settings")
        self.settings3D = wx.CollapsiblePane(parent = panel,
                                             label = self.infoCollapseLabelExp,
                                             style = wx.CP_DEFAULT_STYLE |
                                             wx.CP_NO_TLW_RESIZE | wx.EXPAND)
        self.MakeSettings3DPaneContent(self.settings3D.GetPane())
        self.settings3D.Collapse(False) # FIXME
        self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSettings3DPaneChanged, self.settings3D)
        
        #
        # set current region settings
        #
        self.tnorth.SetValue(str(self.north))
        self.tsouth.SetValue(str(self.south))
        self.twest.SetValue(str(self.west))
        self.teast.SetValue(str(self.east))
        self.tnsres.SetValue(str(self.nsres))
        self.tewres.SetValue(str(self.ewres))
        self.ttop.SetValue(str(self.top))
        self.tbottom.SetValue(str(self.bottom))
        #         self.tnsres3.SetValue(str(self.nsres3))
        #         self.tewres3.SetValue(str(self.ewres3))
        self.ttbres.SetValue(str(self.tbres))
        self.lrows.SetLabel(_("Rows: %d") % self.rows)
        self.lcols.SetLabel(_("Cols: %d") % self.cols)
        self.lcells.SetLabel(_("Cells: %d") % self.cells)
        
        #
        # bindings
        #
        self.Bind(wx.EVT_BUTTON, self.OnSetButton, self.bset)
        self.Bind(wx.EVT_BUTTON, self.OnCancel, self.bcancel)
        self.tnorth.Bind(wx.EVT_TEXT,   self.OnValue)
        self.tsouth.Bind(wx.EVT_TEXT,   self.OnValue)
        self.teast.Bind(wx.EVT_TEXT,    self.OnValue)
        self.twest.Bind(wx.EVT_TEXT,    self.OnValue)
        self.tnsres.Bind(wx.EVT_TEXT,   self.OnValue)
        self.tewres.Bind(wx.EVT_TEXT,   self.OnValue)
        self.ttop.Bind(wx.EVT_TEXT,     self.OnValue)
        self.tbottom.Bind(wx.EVT_TEXT,  self.OnValue)
        #         self.tnsres3.Bind(wx.EVT_TEXT,  self.OnValue)
        #         self.tewres3.Bind(wx.EVT_TEXT,  self.OnValue)
        self.ttbres.Bind(wx.EVT_TEXT,   self.OnValue)
        
        self.__DoLayout(panel)
        self.SetMinSize(self.GetBestSize())
        self.minWindowSize = self.GetMinSize()
    
    def MakeSettings3DPaneContent(self, pane):
        """!Create 3D region settings pane"""
        border = wx.BoxSizer(wx.VERTICAL)
        gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)

        # inputs
        self.ttop = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.top),
                                size = (150, -1))
        self.tbottom = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.bottom),
                                size = (150, -1))
        self.ttbres = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.tbres),
                                size = (150, -1))
        #         self.tnsres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.nsres3),
        #                                    size = (150, -1))
        #         self.tewres3  =  wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.ewres3),
        #                                    size = (150, -1))

        #labels
        self.ldepth = wx.StaticText(parent = pane, label = _("Depth: %d") % self.depth)
        self.lcells3  =  wx.StaticText(parent = pane, label = _("3D Cells: %d") % self.cells3)

        # top
        gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Top")),
                      flag = wx.ALIGN_CENTER |
                      wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
                      pos = (0, 1))
        gridSizer.Add(item = self.ttop,
                      flag = wx.ALIGN_CENTER_HORIZONTAL |
                      wx.ALL, border = 5, pos = (1, 1))
        # bottom
        gridSizer.Add(item = wx.StaticText(parent = pane, label = _("Bottom")),
                      flag = wx.ALIGN_CENTER |
                      wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
                      pos = (0, 2))
        gridSizer.Add(item = self.tbottom,
                      flag = wx.ALIGN_CENTER_HORIZONTAL |
                      wx.ALL, border = 5, pos = (1, 2))
        # tbres
        gridSizer.Add(item = wx.StaticText(parent = pane, label = _("T-B resolution")),
                      flag = wx.ALIGN_CENTER | 
                      wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
                      pos = (0, 3))
        gridSizer.Add(item = self.ttbres,
                      flag = wx.ALIGN_CENTER_HORIZONTAL |
                      wx.ALL, border = 5, pos = (1, 3))

        # res
        #         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D N-S resolution")),
        #                       flag = wx.ALIGN_CENTER |
        #                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
        #                       pos = (2, 1))
        #         gridSizer.Add(item = self.tnsres3,
        #                       flag = wx.ALIGN_CENTER_HORIZONTAL |
        #                       wx.ALL, border = 5, pos = (3, 1))
        #         gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D E-W resolution")),
        #                       flag = wx.ALIGN_CENTER |
        #                       wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
        #                       pos = (2, 3))
        #         gridSizer.Add(item = self.tewres3,
        #                       flag = wx.ALIGN_CENTER_HORIZONTAL |
        #                       wx.ALL, border = 5, pos = (3, 3))

        # rows/cols/cells
        gridSizer.Add(item = self.ldepth,
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.ALL, border = 5, pos = (2, 1))

        gridSizer.Add(item = self.lcells3,
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.ALL, border = 5, pos = (2, 2))

        border.Add(item = gridSizer, proportion = 1,
                   flag = wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border = 5)

        pane.SetSizer(border)
        border.Fit(pane)

    def OnSettings3DPaneChanged(self, event):
        """!Collapse 3D settings box"""

        if self.settings3D.IsExpanded():
            self.settings3D.SetLabel(self.infoCollapseLabelCol)
            self.Layout()
            self.SetSize(self.GetBestSize())
            self.SetMinSize(self.GetSize())
        else:
            self.settings3D.SetLabel(self.infoCollapseLabelExp)
            self.Layout()
            self.SetSize(self.minWindowSize)
            self.SetMinSize(self.minWindowSize)

        self.SendSizeEvent()

    def __DoLayout(self, panel):
        """!Window layout"""
        frameSizer = wx.BoxSizer(wx.VERTICAL)
        gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
        settings3DSizer = wx.BoxSizer(wx.VERTICAL)
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)

        # north
        gridSizer.Add(item = self.MakeLabel(text = _("North"), parent = panel),
                      flag = wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL |
                      wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (0, 2))
        gridSizer.Add(item = self.tnorth,
                      flag = wx.ALIGN_CENTER_HORIZONTAL |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5, pos = (1, 2))
        # west
        gridSizer.Add(item = self.MakeLabel(text = _("West"), parent = panel),
                      flag = wx.ALIGN_RIGHT |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.LEFT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 0))
        gridSizer.Add(item = self.twest,
                      flag = wx.ALIGN_RIGHT |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5,  pos = (2, 1))

        gridSizer.Add(item = wx.StaticBitmap(panel, wx.ID_ANY, self.img, (-1, -1),
                                           (self.img.GetWidth(), self.img.GetHeight())),
                      flag = wx.ALIGN_CENTER |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5, pos = (2, 2))

        # east
        gridSizer.Add(item = self.teast,
                      flag = wx.ALIGN_CENTER_HORIZONTAL |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5,  pos = (2, 3))
        gridSizer.Add(item = self.MakeLabel(text = _("East"), parent = panel),
                      flag = wx.ALIGN_LEFT |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 4))
        # south
        gridSizer.Add(item = self.tsouth,
                      flag = wx.ALIGN_CENTER_HORIZONTAL |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5, pos = (3, 2))
        gridSizer.Add(item = self.MakeLabel(text = _("South"), parent = panel),
                      flag = wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL |
                      wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5, pos = (4, 2))
        # ns-res
        gridSizer.Add(item = self.MakeLabel(text = _("N-S resolution"), parent = panel),
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 1))
        gridSizer.Add(item = self.tnsres,
                      flag = wx.ALIGN_RIGHT |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5,  pos = (6, 1))
        # ew-res
        gridSizer.Add(item = self.MakeLabel(text = _("E-W resolution"), parent = panel),
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 3))
        gridSizer.Add(item = self.tewres,
                      flag = wx.ALIGN_RIGHT |
                      wx.ALIGN_CENTER_VERTICAL |
                      wx.ALL, border = 5,  pos = (6, 3))
        # rows/cols/cells
        gridSizer.Add(item = self.lrows,
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.ALL, border = 5, pos = (7, 1))

        gridSizer.Add(item = self.lcells,
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.ALL, border = 5, pos = (7, 2))

        gridSizer.Add(item = self.lcols,
                      flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
                      wx.ALL, border = 5, pos = (7, 3))

        # 3D
        settings3DSizer.Add(item = self.settings3D,
                            flag = wx.ALL,
                            border = 5)

        # buttons
        buttonSizer.Add(item = self.bcancel, proportion = 1,
                        flag = wx.ALIGN_RIGHT |
                        wx.ALIGN_CENTER_VERTICAL |
                        wx.ALL, border = 10)
        buttonSizer.Add(item = self.bset, proportion = 1,
                        flag = wx.ALIGN_CENTER |
                        wx.ALIGN_CENTER_VERTICAL |
                        wx.ALL, border = 10)

        frameSizer.Add(item = gridSizer, proportion = 1,
                       flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
        frameSizer.Add(item = settings3DSizer, proportion = 0,
                       flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
        frameSizer.Add(item = buttonSizer, proportion = 0,
                       flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)

        self.SetAutoLayout(True)
        panel.SetSizer(frameSizer)
        frameSizer.Fit(panel)
        self.Layout()

    def OnValue(self, event):
        """!Set given value"""
        try:
            if event.GetId() == self.tnorth.GetId():
                self.north = float(event.GetString())
            elif event.GetId() == self.tsouth.GetId():
                self.south = float(event.GetString())
            elif event.GetId() == self.teast.GetId():
                self.east = float(event.GetString())
            elif event.GetId() == self.twest.GetId():
                self.west = float(event.GetString())
            elif event.GetId() == self.tnsres.GetId():
                self.nsres = float(event.GetString())
            elif event.GetId() == self.tewres.GetId():
                self.ewres = float(event.GetString())
            elif event.GetId() == self.ttop.GetId():
                self.top = float(event.GetString())
            elif event.GetId() == self.tbottom.GetId():
                self.bottom = float(event.GetString())
            #             elif event.GetId() == self.tnsres3.GetId():
            #                 self.nsres3 = float(event.GetString())
            #             elif event.GetId() == self.tewres3.GetId():
            #                 self.ewres3 = float(event.GetString())
            elif event.GetId() == self.ttbres.GetId():
                self.tbres = float(event.GetString())

            self.__UpdateInfo()

        except ValueError, e:
            if len(event.GetString()) > 0 and event.GetString() != '-':
                dlg = wx.MessageBox(parent = self,
                                    message = _("Invalid value: %s") % e,
                                    caption = _("Error"),
                                    style = wx.OK | wx.ICON_ERROR)
                # reset values
                self.tnorth.SetValue(str(self.north))
                self.tsouth.SetValue(str(self.south))
                self.teast.SetValue(str(self.east))
                self.twest.SetValue(str(self.west))
                self.tnsres.SetValue(str(self.nsres))
                self.tewres.SetValue(str(self.ewres))
                self.ttop.SetValue(str(self.top))
                self.tbottom.SetValue(str(self.bottom))
                self.ttbres.SetValue(str(self.tbres))
                # self.tnsres3.SetValue(str(self.nsres3))
                # self.tewres3.SetValue(str(self.ewres3))

        event.Skip()

    def __UpdateInfo(self):
        """!Update number of rows/cols/cells"""
        self.rows = int((self.north - self.south) / self.nsres)
        self.cols = int((self.east - self.west) / self.ewres)
        self.cells = self.rows * self.cols

        self.depth = int((self.top - self.bottom) / self.tbres)
        self.cells3 = self.rows * self.cols * self.depth

        # 2D
        self.lrows.SetLabel(_("Rows: %d") % self.rows)
        self.lcols.SetLabel(_("Cols: %d") % self.cols)
        self.lcells.SetLabel(_("Cells: %d") % self.cells)
        # 3D
        self.ldepth.SetLabel(_("Depth: %d" % self.depth))
        self.lcells3.SetLabel(_("3D Cells: %d" % self.cells3))

    def OnSetButton(self, event = None):
        """!Set default region"""
        ret = RunCommand('g.region',
                         flags = 'sgpa',
                         n = self.north,
                         s = self.south,
                         e = self.east,
                         w = self.west,
                         nsres = self.nsres,
                         ewres = self.ewres,
                         t = self.top,
                         b = self.bottom,
                         tbres = self.tbres)
        if ret == 0:
            self.Destroy()

    def OnCancel(self, event):
        self.Destroy()
        
class TransList(wx.VListBox):
    """!Creates a multiline listbox for selecting datum transforms"""
        
    def OnDrawItem(self, dc, rect, n):
        if self.GetSelection() == n:
            c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
        else:
            c = self.GetForegroundColour()
        dc.SetFont(self.GetFont())
        dc.SetTextForeground(c)
        dc.DrawLabel(self._getItemText(n), rect,
                     wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

    def OnMeasureItem(self, n):
        height = 0
        if self._getItemText(n) == None:
            return
        for line in self._getItemText(n).splitlines():
            w, h = self.GetTextExtent(line)
            height += h
        return height + 5

    def _getItemText(self, item):
        global transformlist
        transitem = transformlist[item]
        if transitem.strip() !='':
            return transitem

class SelectTransformDialog(wx.Dialog):
    """!Dialog for selecting datum transformations"""
    def __init__(self, parent, transforms, title = _("Select datum transformation"),
                 pos = wx.DefaultPosition, size = wx.DefaultSize, 
                 style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):

        wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)

        global transformlist
        self.CentreOnParent()
        
        # default transform number
        self.transnum = 0
        
        panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)

        #
        # set panel sizer
        #
        panel.SetSizer(sizer)
        panel.SetupScrolling()

        #
        # dialog body
        #
        bodyBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
                               label = " %s " % _("Select from list of datum transformations"))
        bodySizer = wx.StaticBoxSizer(bodyBox)       
        
        # add no transform option
        transforms = '---\n\n0\nDo not apply any datum transformations\n\n' + transforms
        
        transformlist = transforms.split('---')
        tlistlen = len(transformlist)
        
        # calculate size for transform list
        height = 0
        width = 0
        for line in transforms.splitlines():
            w, h = self.GetTextExtent(line)
            height += h
            width = max(width, w)
            
        height = height + 5
        if height > 400: height = 400
        width = width + 5
        if width > 400: width = 400

        #
        # VListBox for displaying and selecting transformations
        #
        self.translist = TransList(panel, id = -1, size = (width, height), style = wx.SUNKEN_BORDER)
        self.translist.SetItemCount(tlistlen)
        self.translist.SetSelection(2)
        self.translist.SetFocus()
        
        self.Bind(wx.EVT_LISTBOX, self.ClickTrans, self.translist)

        bodySizer.Add(item = self.translist, proportion = 1, flag = wx.ALIGN_CENTER|wx.ALL|wx.EXPAND)

        #
        # buttons
        #
        btnsizer = wx.StdDialogButtonSizer()

        btn = wx.Button(parent = panel, id = wx.ID_OK)
        btn.SetDefault()
        btnsizer.AddButton(btn)

        btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()

        sizer.Add(item = bodySizer, proportion = 1,
                  flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)

        sizer.Add(item = btnsizer, proportion = 0,
                  flag =  wx.ALL | wx.ALIGN_RIGHT, border = 5)

        sizer.Fit(panel)

        self.SetSize(self.GetBestSize())
        self.Layout()
        
    def ClickTrans(self, event):
        """!Get the number of the datum transform to use in g.proj"""
        self.transnum = event.GetSelection()
        self.transnum = self.transnum - 1
    
    def GetTransform(self):
        """!Get the number of the datum transform to use in g.proj"""
        self.transnum = self.translist.GetSelection()
        self.transnum = self.transnum - 1
        return self.transnum