dialogs.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # -*- coding: utf-8 -*-
  2. """
  3. @package datacatalog.dialogs
  4. @brief Dialogs used in data catalog
  5. Classes:
  6. - dialogs::CatalogReprojectionDialog
  7. (C) 2016 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Anna Petrasova <kratochanna gmail.com>
  11. """
  12. import wx
  13. import grass.script as gscript
  14. from grass.script import task as gtask
  15. from gui_core.forms import CmdPanel
  16. from core.giface import Notification
  17. class CatalogReprojectionDialog(wx.Dialog):
  18. """ """
  19. def __init__(self, parent, giface, inputGisdbase, inputLocation, inputMapset, inputLayer,
  20. outputGisdbase, outputLocation, outputMapset, etype,
  21. id=wx.ID_ANY, title=_("Reprojection"),
  22. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  23. self.parent = parent # GMFrame
  24. self._giface = giface # used to add layers
  25. wx.Dialog.__init__(self, parent, id, title, style=style,
  26. name="ReprojectionDialog")
  27. self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
  28. self.iGisdbase = inputGisdbase
  29. self.iLocation = inputLocation
  30. self.iMapset = inputMapset
  31. self.iLayer = inputLayer
  32. self.oGisdbase = outputGisdbase
  33. self.oLocation = outputLocation
  34. self.oMapset = outputMapset
  35. self.etype = etype
  36. self._blackList = {
  37. 'enabled': True,
  38. 'items': {
  39. 'r.proj': {
  40. 'params': ['location', 'mapset', 'input', 'dbase'],
  41. 'flags': ['l']},
  42. 'v.proj': {
  43. 'params': ['location', 'mapset', 'input', 'dbase'],
  44. 'flags': ['l']}}}
  45. if self.etype == 'raster':
  46. grass_task = gtask.parse_interface('r.proj', blackList=self._blackList)
  47. elif self.etype == 'vector':
  48. grass_task = gtask.parse_interface('v.proj', blackList=self._blackList)
  49. self.settingsPanel = CmdPanel(parent=self, giface=self._giface, task=grass_task, frame=None)
  50. self.closeOnFinished = wx.CheckBox(self.panel, label=_("Close dialog on finish"))
  51. #
  52. # buttons
  53. #
  54. # cancel
  55. self.btn_close = wx.Button(parent=self.panel, id=wx.ID_CLOSE)
  56. self.btn_close.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
  57. # run
  58. self.btn_run = wx.Button(
  59. parent=self.panel,
  60. id=wx.ID_OK,
  61. label=_("Reproject"))
  62. if self.etype == 'raster':
  63. self.btn_run.SetToolTipString(_("Reproject raster"))
  64. elif self.etype == 'vector':
  65. self.btn_run.SetToolTipString(_("Reproject vector"))
  66. self.btn_run.SetDefault()
  67. self.btn_run.Bind(wx.EVT_BUTTON, self.OnReproject)
  68. self.doLayout()
  69. def doLayout(self):
  70. """Do layout"""
  71. dialogSizer = wx.BoxSizer(wx.VERTICAL)
  72. dialogSizer.Add(wx.StaticText(self.panel, label=_("The copied layer needs to be reprojected:")),
  73. flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5)
  74. dialogSizer.Add(self.settingsPanel, proportion=1,
  75. flag=wx.ALL | wx.EXPAND, border=5)
  76. dialogSizer.Add(self.closeOnFinished, flag=wx.ALL | wx.EXPAND, border=5)
  77. #
  78. # buttons
  79. #
  80. btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL)
  81. btnsizer.Add(self.btn_close, proportion=0,
  82. flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER,
  83. border=10)
  84. btnsizer.Add(self.btn_run, proportion=0,
  85. flag=wx.RIGHT | wx.ALIGN_CENTER,
  86. border=10)
  87. dialogSizer.Add(
  88. btnsizer,
  89. proportion=0,
  90. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  91. border=5)
  92. self.panel.SetSizer(dialogSizer)
  93. dialogSizer.Fit(self.panel)
  94. self.Layout()
  95. # sizing not working properly
  96. self.SetMinSize(self.GetBestSize())
  97. def getSettingsPageCmd(self):
  98. return self.settingsPanel.createCmd(
  99. ignoreErrors=True, ignoreRequired=True)
  100. def OnReproject(self, event):
  101. cmd = self.getSettingsPageCmd()
  102. cmd.append('dbase=' + self.iGisdbase)
  103. cmd.append('location=' + self.iLocation)
  104. cmd.append('mapset=' + self.iMapset)
  105. cmd.append('input=' + self.iLayer)
  106. self.tmpfile, env = gscript.create_environment(self.oGisdbase, self.oLocation, self.oMapset)
  107. self._giface.RunCmd(cmd, env=env,
  108. onDone=self.OnDone, userData=None,
  109. notification=Notification.MAKE_VISIBLE)
  110. def OnDone(self, event):
  111. gscript.try_remove(self.tmpfile)
  112. if self.closeOnFinished.IsChecked() and event.returncode == 0:
  113. self.Close()