2 @package location_wizard.dialogs
4 @brief Location wizard - dialogs
9 - dialogs::SelectTransformDialog
11 (C) 2007-2011 by the GRASS Development Team
13 This program is free software under the GNU General Public License
14 (>=v2). Read the file COPYING that comes with GRASS for details.
16 @author Michael Barton
17 @author Jachym Cepicky
18 @author Martin Landa <landa.martin gmail.com>
24 import wx.lib.scrolledpanel
as scrolled
26 from core
import globalvar
33 """!Page for setting default region extents and resolution
35 def __init__(self, parent, id = wx.ID_ANY, size = (800, 600),
36 title = _(
"Set default region extent and resolution"), location =
None):
37 wx.Dialog.__init__(self, parent, id, title, size = size)
38 panel = wx.Panel(self, id = wx.ID_ANY)
40 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
'grass.ico'), wx.BITMAP_TYPE_ICO))
66 self.
tnorth = self.MakeTextCtrl(text = str(self.
north), size = (150, -1), parent = panel)
67 self.
tsouth = self.MakeTextCtrl(str(self.
south), size = (150, -1), parent = panel)
68 self.
twest = self.MakeTextCtrl(str(self.
west), size = (150, -1), parent = panel)
69 self.
teast = self.MakeTextCtrl(str(self.
east), size = (150, -1), parent = panel)
70 self.
tnsres = self.MakeTextCtrl(str(self.
nsres), size = (150, -1), parent = panel)
71 self.
tewres = self.MakeTextCtrl(str(self.
ewres), size = (150, -1), parent = panel)
76 self.
lrows = self.MakeLabel(parent = panel)
77 self.
lcols = self.MakeLabel(parent = panel)
78 self.
lcells = self.MakeLabel(parent = panel)
83 self.
bset = self.MakeButton(text = _(
"&Set region"), id = wx.ID_OK, parent = panel)
84 self.
bcancel = wx.Button(panel, id = wx.ID_CANCEL)
85 self.bset.SetDefault()
90 self.
img = wx.Image(os.path.join(globalvar.ETCIMGDIR,
"qgis_world.png"),
91 wx.BITMAP_TYPE_PNG).ConvertToBitmap()
101 for line
in ret.splitlines():
102 key, val = line.split(
'=')
108 set =
'LOCATION_NAME=%s' % self.
location)
110 set =
'MAPSET=PERMANENT')
112 dlg = wx.MessageBox(parent = self,
113 message = _(
'Invalid location selected.'),
114 caption = _(
"Error"), style = wx.ID_OK | wx.ICON_ERROR)
125 for line
in ret.splitlines():
126 key, val = line.split(
'=')
127 region[key] = float(val)
129 dlg = wx.MessageBox(parent = self,
130 message = _(
"Invalid region"),
131 caption = _(
"Error"), style = wx.ID_OK | wx.ICON_ERROR)
139 self.
north = float(region[
'n'])
140 self.
south = float(region[
's'])
141 self.
east = float(region[
'e'])
142 self.
west = float(region[
'w'])
143 self.
nsres = float(region[
'nsres'])
144 self.
ewres = float(region[
'ewres'])
145 self.
rows = int(region[
'rows'])
146 self.
cols = int(region[
'cols'])
149 self.
top = float(region[
't'])
150 self.
bottom = float(region[
'b'])
153 self.
tbres = float(region[
'tbres'])
164 style = wx.CP_DEFAULT_STYLE |
165 wx.CP_NO_TLW_RESIZE | wx.EXPAND)
167 self.settings3D.Collapse(
False)
173 self.tnorth.SetValue(str(self.
north))
174 self.tsouth.SetValue(str(self.
south))
175 self.twest.SetValue(str(self.
west))
176 self.teast.SetValue(str(self.
east))
177 self.tnsres.SetValue(str(self.
nsres))
178 self.tewres.SetValue(str(self.
ewres))
179 self.ttop.SetValue(str(self.
top))
180 self.tbottom.SetValue(str(self.
bottom))
183 self.ttbres.SetValue(str(self.
tbres))
184 self.lrows.SetLabel(_(
"Rows: %d") % self.
rows)
185 self.lcols.SetLabel(_(
"Cols: %d") % self.
cols)
186 self.lcells.SetLabel(_(
"Cells: %d") % self.
cells)
193 self.tnorth.Bind(wx.EVT_TEXT, self.
OnValue)
194 self.tsouth.Bind(wx.EVT_TEXT, self.
OnValue)
195 self.teast.Bind(wx.EVT_TEXT, self.
OnValue)
196 self.twest.Bind(wx.EVT_TEXT, self.
OnValue)
197 self.tnsres.Bind(wx.EVT_TEXT, self.
OnValue)
198 self.tewres.Bind(wx.EVT_TEXT, self.
OnValue)
199 self.ttop.Bind(wx.EVT_TEXT, self.
OnValue)
200 self.tbottom.Bind(wx.EVT_TEXT, self.
OnValue)
203 self.ttbres.Bind(wx.EVT_TEXT, self.
OnValue)
206 self.SetMinSize(self.GetBestSize())
210 """!Create 3D region settings pane"""
211 border = wx.BoxSizer(wx.VERTICAL)
212 gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
215 self.
ttop = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.
top),
217 self.
tbottom = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.
bottom),
219 self.
ttbres = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.
tbres),
227 self.
ldepth = wx.StaticText(parent = pane, label = _(
"Depth: %d") % self.
depth)
228 self.
lcells3 = wx.StaticText(parent = pane, label = _(
"3D Cells: %d") % self.
cells3)
231 gridSizer.Add(item = wx.StaticText(parent = pane, label = _(
"Top")),
232 flag = wx.ALIGN_CENTER |
233 wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
235 gridSizer.Add(item = self.
ttop,
236 flag = wx.ALIGN_CENTER_HORIZONTAL |
237 wx.ALL, border = 5, pos = (1, 1))
239 gridSizer.Add(item = wx.StaticText(parent = pane, label = _(
"Bottom")),
240 flag = wx.ALIGN_CENTER |
241 wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
243 gridSizer.Add(item = self.
tbottom,
244 flag = wx.ALIGN_CENTER_HORIZONTAL |
245 wx.ALL, border = 5, pos = (1, 2))
247 gridSizer.Add(item = wx.StaticText(parent = pane, label = _(
"T-B resolution")),
248 flag = wx.ALIGN_CENTER |
249 wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
251 gridSizer.Add(item = self.
ttbres,
252 flag = wx.ALIGN_CENTER_HORIZONTAL |
253 wx.ALL, border = 5, pos = (1, 3))
272 gridSizer.Add(item = self.
ldepth,
273 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
274 wx.ALL, border = 5, pos = (2, 1))
276 gridSizer.Add(item = self.
lcells3,
277 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
278 wx.ALL, border = 5, pos = (2, 2))
280 border.Add(item = gridSizer, proportion = 1,
281 flag = wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border = 5)
283 pane.SetSizer(border)
287 """!Collapse 3D settings box"""
289 if self.settings3D.IsExpanded():
292 self.SetSize(self.GetBestSize())
293 self.SetMinSize(self.GetSize())
302 def __DoLayout(self, panel):
304 frameSizer = wx.BoxSizer(wx.VERTICAL)
305 gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
306 settings3DSizer = wx.BoxSizer(wx.VERTICAL)
307 buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
310 gridSizer.Add(item = self.MakeLabel(text = _(
"North"), parent = panel),
311 flag = wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL |
312 wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (0, 2))
313 gridSizer.Add(item = self.
tnorth,
314 flag = wx.ALIGN_CENTER_HORIZONTAL |
315 wx.ALIGN_CENTER_VERTICAL |
316 wx.ALL, border = 5, pos = (1, 2))
318 gridSizer.Add(item = self.MakeLabel(text = _(
"West"), parent = panel),
319 flag = wx.ALIGN_RIGHT |
320 wx.ALIGN_CENTER_VERTICAL |
321 wx.LEFT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 0))
322 gridSizer.Add(item = self.
twest,
323 flag = wx.ALIGN_RIGHT |
324 wx.ALIGN_CENTER_VERTICAL |
325 wx.ALL, border = 5, pos = (2, 1))
327 gridSizer.Add(item = wx.StaticBitmap(panel, wx.ID_ANY, self.
img, (-1, -1),
328 (self.img.GetWidth(), self.img.GetHeight())),
329 flag = wx.ALIGN_CENTER |
330 wx.ALIGN_CENTER_VERTICAL |
331 wx.ALL, border = 5, pos = (2, 2))
334 gridSizer.Add(item = self.
teast,
335 flag = wx.ALIGN_CENTER_HORIZONTAL |
336 wx.ALIGN_CENTER_VERTICAL |
337 wx.ALL, border = 5, pos = (2, 3))
338 gridSizer.Add(item = self.MakeLabel(text = _(
"East"), parent = panel),
339 flag = wx.ALIGN_LEFT |
340 wx.ALIGN_CENTER_VERTICAL |
341 wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 4))
343 gridSizer.Add(item = self.
tsouth,
344 flag = wx.ALIGN_CENTER_HORIZONTAL |
345 wx.ALIGN_CENTER_VERTICAL |
346 wx.ALL, border = 5, pos = (3, 2))
347 gridSizer.Add(item = self.MakeLabel(text = _(
"South"), parent = panel),
348 flag = wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL |
349 wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5, pos = (4, 2))
351 gridSizer.Add(item = self.MakeLabel(text = _(
"N-S resolution"), parent = panel),
352 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
353 wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 1))
354 gridSizer.Add(item = self.
tnsres,
355 flag = wx.ALIGN_RIGHT |
356 wx.ALIGN_CENTER_VERTICAL |
357 wx.ALL, border = 5, pos = (6, 1))
359 gridSizer.Add(item = self.MakeLabel(text = _(
"E-W resolution"), parent = panel),
360 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
361 wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 3))
362 gridSizer.Add(item = self.
tewres,
363 flag = wx.ALIGN_RIGHT |
364 wx.ALIGN_CENTER_VERTICAL |
365 wx.ALL, border = 5, pos = (6, 3))
367 gridSizer.Add(item = self.
lrows,
368 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
369 wx.ALL, border = 5, pos = (7, 1))
371 gridSizer.Add(item = self.
lcells,
372 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
373 wx.ALL, border = 5, pos = (7, 2))
375 gridSizer.Add(item = self.
lcols,
376 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
377 wx.ALL, border = 5, pos = (7, 3))
385 buttonSizer.Add(item = self.
bcancel, proportion = 1,
386 flag = wx.ALIGN_RIGHT |
387 wx.ALIGN_CENTER_VERTICAL |
389 buttonSizer.Add(item = self.
bset, proportion = 1,
390 flag = wx.ALIGN_CENTER |
391 wx.ALIGN_CENTER_VERTICAL |
394 frameSizer.Add(item = gridSizer, proportion = 1,
395 flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
396 frameSizer.Add(item = settings3DSizer, proportion = 0,
397 flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
398 frameSizer.Add(item = buttonSizer, proportion = 0,
399 flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
401 self.SetAutoLayout(
True)
402 panel.SetSizer(frameSizer)
403 frameSizer.Fit(panel)
407 """!Set given value"""
409 if event.GetId() == self.tnorth.GetId():
410 self.
north = float(event.GetString())
411 elif event.GetId() == self.tsouth.GetId():
412 self.
south = float(event.GetString())
413 elif event.GetId() == self.teast.GetId():
414 self.
east = float(event.GetString())
415 elif event.GetId() == self.twest.GetId():
416 self.
west = float(event.GetString())
417 elif event.GetId() == self.tnsres.GetId():
418 self.
nsres = float(event.GetString())
419 elif event.GetId() == self.tewres.GetId():
420 self.
ewres = float(event.GetString())
421 elif event.GetId() == self.ttop.GetId():
422 self.
top = float(event.GetString())
423 elif event.GetId() == self.tbottom.GetId():
424 self.
bottom = float(event.GetString())
429 elif event.GetId() == self.ttbres.GetId():
430 self.
tbres = float(event.GetString())
434 except ValueError, e:
435 if len(event.GetString()) > 0
and event.GetString() !=
'-':
436 dlg = wx.MessageBox(parent = self,
437 message = _(
"Invalid value: %s") % e,
438 caption = _(
"Error"),
439 style = wx.OK | wx.ICON_ERROR)
441 self.tnorth.SetValue(str(self.
north))
442 self.tsouth.SetValue(str(self.
south))
443 self.teast.SetValue(str(self.
east))
444 self.twest.SetValue(str(self.
west))
445 self.tnsres.SetValue(str(self.
nsres))
446 self.tewres.SetValue(str(self.
ewres))
447 self.ttop.SetValue(str(self.
top))
448 self.tbottom.SetValue(str(self.
bottom))
449 self.ttbres.SetValue(str(self.
tbres))
455 def __UpdateInfo(self):
456 """!Update number of rows/cols/cells"""
465 self.lrows.SetLabel(_(
"Rows: %d") % self.
rows)
466 self.lcols.SetLabel(_(
"Cols: %d") % self.
cols)
467 self.lcells.SetLabel(_(
"Cells: %d") % self.
cells)
469 self.ldepth.SetLabel(_(
"Depth: %d" % self.
depth))
470 self.lcells3.SetLabel(_(
"3D Cells: %d" % self.
cells3))
473 """!Set default region"""
492 """!Creates a multiline listbox for selecting datum transforms"""
495 if self.GetSelection() == n:
496 c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
498 c = self.GetForegroundColour()
499 dc.SetFont(self.GetFont())
500 dc.SetTextForeground(c)
502 wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
509 w, h = self.GetTextExtent(line)
513 def _getItemText(self, item):
515 transitem = transformlist[item]
516 if transitem.strip() !=
'':
520 """!Dialog for selecting datum transformations"""
521 def __init__(self, parent, transforms, title = _(
"Select datum transformation"),
522 pos = wx.DefaultPosition, size = wx.DefaultSize,
523 style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
525 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
528 self.CentreOnParent()
533 panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
534 sizer = wx.BoxSizer(wx.VERTICAL)
539 panel.SetSizer(sizer)
540 panel.SetupScrolling()
545 bodyBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
546 label =
" %s " % _(
"Select from list of datum transformations"))
547 bodySizer = wx.StaticBoxSizer(bodyBox)
550 transforms =
'---\n\n0\nDo not apply any datum transformations\n\n' + transforms
552 transformlist = transforms.split(
'---')
553 tlistlen = len(transformlist)
558 for line
in transforms.splitlines():
559 w, h = self.GetTextExtent(line)
561 width =
max(width, w)
564 if height > 400: height = 400
566 if width > 400: width = 400
572 self.translist.SetItemCount(tlistlen)
573 self.translist.SetSelection(2)
574 self.translist.SetFocus()
578 bodySizer.Add(item = self.
translist, proportion = 1, flag = wx.ALIGN_CENTER|wx.ALL|wx.EXPAND)
583 btnsizer = wx.StdDialogButtonSizer()
585 btn = wx.Button(parent = panel, id = wx.ID_OK)
587 btnsizer.AddButton(btn)
589 btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
590 btnsizer.AddButton(btn)
593 sizer.Add(item = bodySizer, proportion = 1,
594 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
596 sizer.Add(item = btnsizer, proportion = 0,
597 flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
601 self.SetSize(self.GetBestSize())
605 """!Get the number of the datum transform to use in g.proj"""
606 self.
transnum = event.GetSelection()
610 """!Get the number of the datum transform to use in g.proj"""
611 self.
transnum = self.translist.GetSelection()
def __DoLayout
Window layout.
def OnValue
Set given value.
Location wizard - base classes.
def MakeSettings3DPaneContent
Create 3D region settings pane.
Creates a multiline listbox for selecting datum transforms.
Page for setting default region extents and resolution.
def OnSetButton
Set default region.
def OnSettings3DPaneChanged
Collapse 3D settings box.
def __UpdateInfo
Update number of rows/cols/cells.
def RunCommand
Run GRASS command.