catalog.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. """
  2. @package datacatalog::catalog
  3. @brief Data catalog
  4. Classes:
  5. - datacatalog::DataCatalog
  6. (C) 2014-2018 by Tereza Fiedlerova, and the GRASS Development Team
  7. This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. @author Tereza Fiedlerova
  11. @author Linda Kladivova l.kladivova@seznam.cz
  12. """
  13. import wx
  14. import os
  15. from core.debug import Debug
  16. from datacatalog.tree import DataCatalogTree
  17. from datacatalog.toolbars import DataCatalogToolbar
  18. from gui_core.infobar import InfoBar
  19. from datacatalog.infomanager import DataCatalogInfoManager
  20. from gui_core.wrap import Menu
  21. from gui_core.forms import GUI
  22. from grass.pydispatch.signal import Signal
  23. from grass.grassdb.checks import is_current_mapset_in_demolocation
  24. class DataCatalog(wx.Panel):
  25. """Data catalog panel"""
  26. def __init__(self, parent, giface=None, id=wx.ID_ANY,
  27. title=_("Data catalog"), name='catalog', **kwargs):
  28. """Panel constructor """
  29. self.showNotification = Signal('DataCatalog.showNotification')
  30. self.parent = parent
  31. self.baseTitle = title
  32. self.giface = giface
  33. wx.Panel.__init__(self, parent=parent, id=id, **kwargs)
  34. self.SetName("DataCatalog")
  35. Debug.msg(1, "DataCatalog.__init__()")
  36. # toolbar
  37. self.toolbar = DataCatalogToolbar(parent=self)
  38. # tree with layers
  39. self.tree = DataCatalogTree(self, giface=giface)
  40. self.tree.showNotification.connect(self.showNotification)
  41. # infobar for data catalog
  42. self.infoBar = InfoBar(self)
  43. # infobar manager for data catalog
  44. self.infoManager = DataCatalogInfoManager(infobar=self.infoBar,
  45. giface=self.giface)
  46. self.tree.showImportDataInfo.connect(self.showImportDataInfo)
  47. # some layout
  48. self._layout()
  49. # show data structure infobar for first-time user with proper layout
  50. if is_current_mapset_in_demolocation():
  51. wx.CallLater(2000, self.showDataStructureInfo)
  52. def _layout(self):
  53. """Do layout"""
  54. sizer = wx.BoxSizer(wx.VERTICAL)
  55. sizer.Add(self.toolbar, proportion=0, flag=wx.EXPAND)
  56. sizer.Add(self.infoBar, proportion=0, flag=wx.EXPAND)
  57. sizer.Add(self.tree.GetControl(), proportion=1, flag=wx.EXPAND)
  58. self.SetAutoLayout(True)
  59. self.SetSizer(sizer)
  60. self.Fit()
  61. self.Layout()
  62. def showDataStructureInfo(self):
  63. self.infoManager.ShowDataStructureInfo(self.OnCreateLocation)
  64. def showImportDataInfo(self):
  65. self.infoManager.ShowImportDataInfo(self.OnImportOgrLayers, self.OnImportGdalLayers)
  66. def LoadItems(self):
  67. self.tree.ReloadTreeItems()
  68. def OnReloadTree(self, event):
  69. """Reload whole tree"""
  70. self.LoadItems()
  71. def OnReloadCurrentMapset(self, event):
  72. """Reload current mapset tree only"""
  73. self.tree.ReloadCurrentMapset()
  74. def OnAddGrassDB(self, event):
  75. """Add grass database"""
  76. dlg = wx.DirDialog(self, _("Choose GRASS data directory:"),
  77. os.getcwd(), wx.DD_DEFAULT_STYLE)
  78. if dlg.ShowModal() == wx.ID_OK:
  79. grassdatabase = dlg.GetPath()
  80. self.tree.InsertGrassDb(name=grassdatabase)
  81. dlg.Destroy()
  82. def OnCreateMapset(self, event):
  83. """Create new mapset in current location"""
  84. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  85. self.tree.CreateMapset(db_node, loc_node)
  86. def OnCreateLocation(self, event):
  87. """Create new location"""
  88. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  89. self.tree.CreateLocation(db_node)
  90. def OnDownloadLocation(self, event):
  91. """Download location to current grass database"""
  92. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  93. self.tree.DownloadLocation(db_node)
  94. def OnImportGdalLayers(self, event):
  95. """Convert multiple GDAL layers to GRASS raster map layers"""
  96. from modules.import_export import GdalImportDialog
  97. dlg = GdalImportDialog(parent=self, giface=self.giface)
  98. dlg.CentreOnScreen()
  99. dlg.Show()
  100. def OnImportOgrLayers(self, event):
  101. """Convert multiple OGR layers to GRASS vector map layers"""
  102. from modules.import_export import OgrImportDialog
  103. dlg = OgrImportDialog(parent=self, giface=self.giface)
  104. dlg.CentreOnScreen()
  105. dlg.Show()
  106. def OnLinkGdalLayers(self, event):
  107. """Link multiple GDAL layers to GRASS raster map layers"""
  108. from modules.import_export import GdalImportDialog
  109. dlg = GdalImportDialog(parent=self, giface=self.giface, link=True)
  110. dlg.CentreOnScreen()
  111. dlg.Show()
  112. def OnLinkOgrLayers(self, event):
  113. """Links multiple OGR layers to GRASS vector map layers"""
  114. from modules.import_export import OgrImportDialog
  115. dlg = OgrImportDialog(parent=self, giface=self.giface, link=True)
  116. dlg.CentreOnScreen()
  117. dlg.Show()
  118. def OnRasterOutputFormat(self, event):
  119. """Set raster output format handler"""
  120. from modules.import_export import GdalOutputDialog
  121. dlg = GdalOutputDialog(parent=self, ogr=False)
  122. dlg.CentreOnScreen()
  123. dlg.Show()
  124. def OnVectorOutputFormat(self, event):
  125. """Set vector output format handler"""
  126. from modules.import_export import GdalOutputDialog
  127. dlg = GdalOutputDialog(parent=self, ogr=True)
  128. dlg.CentreOnScreen()
  129. dlg.Show()
  130. def GuiParseCommand(self, cmd):
  131. """Generic handler"""
  132. GUI(parent=self, giface=self.giface).ParseCommand(cmd=[cmd])
  133. def OnMoreOptions(self, event):
  134. self.giface.Help(entry="topic_import")
  135. def SetRestriction(self, restrict):
  136. """Allow editing other mapsets or restrict editing to current mapset"""
  137. self.tree.SetRestriction(restrict)
  138. def Filter(self, text, element=None):
  139. self.tree.Filter(text=text, element=element)
  140. def OnImportMenu(self, event):
  141. """Create popup menu for other import options"""
  142. # create submenu
  143. subMenu = Menu()
  144. subitem = wx.MenuItem(subMenu, wx.ID_ANY, _("Link external raster data [r.external]"))
  145. subMenu.AppendItem(subitem)
  146. self.Bind(wx.EVT_MENU, self.OnLinkGdalLayers, subitem)
  147. subitem = wx.MenuItem(subMenu, wx.ID_ANY, _("Link external vector data [v.external]"))
  148. subMenu.AppendItem(subitem)
  149. self.Bind(wx.EVT_MENU, self.OnLinkOgrLayers, subitem)
  150. subMenu.AppendSeparator()
  151. subitem = wx.MenuItem(subMenu, wx.ID_ANY, _("Set raster output format [r.external.out]"))
  152. subMenu.AppendItem(subitem)
  153. self.Bind(wx.EVT_MENU, self.OnRasterOutputFormat, subitem)
  154. subitem = wx.MenuItem(subMenu, wx.ID_ANY, _("Set vector output format [v.external.out]"))
  155. subMenu.AppendItem(subitem)
  156. self.Bind(wx.EVT_MENU, self.OnVectorOutputFormat, subitem)
  157. # create menu
  158. menu = Menu()
  159. item = wx.MenuItem(menu, wx.ID_ANY, _("Unpack GRASS raster map [r.unpack]"))
  160. menu.AppendItem(item)
  161. self.Bind(wx.EVT_MENU, lambda evt: self.GuiParseCommand('r.unpack'), item)
  162. item = wx.MenuItem(menu, wx.ID_ANY, _("Unpack GRASS vector map [v.unpack]"))
  163. menu.AppendItem(item)
  164. self.Bind(wx.EVT_MENU, lambda evt: self.GuiParseCommand('v.unpack'), item)
  165. menu.AppendSeparator()
  166. item = wx.MenuItem(menu, wx.ID_ANY, _("Create raster map from x,y,z data [r.in.xyz]"))
  167. menu.AppendItem(item)
  168. self.Bind(wx.EVT_MENU, lambda evt: self.GuiParseCommand('r.in.xyz'), item)
  169. item = wx.MenuItem(menu, wx.ID_ANY, _("Create vector map from x,y,z data [v.in.ascii]"))
  170. menu.AppendItem(item)
  171. self.Bind(wx.EVT_MENU, lambda evt: self.GuiParseCommand('v.in.ascii'), item)
  172. menu.AppendSeparator()
  173. menu.AppendMenu(wx.ID_ANY, _("Link external data"), subMenu)
  174. menu.AppendSeparator()
  175. item = wx.MenuItem(menu, wx.ID_ANY, _("More options..."))
  176. menu.AppendItem(item)
  177. self.Bind(wx.EVT_MENU, self.OnMoreOptions, item)
  178. self.PopupMenu(menu)
  179. menu.Destroy()