catalog.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. """
  12. import wx
  13. import os
  14. from core.debug import Debug
  15. from datacatalog.tree import DataCatalogTree
  16. from datacatalog.toolbars import DataCatalogToolbar
  17. from gui_core.infobar import InfoBar
  18. from datacatalog.infomanager import DataCatalogInfoManager
  19. from grass.pydispatch.signal import Signal
  20. from grass.grassdb.checks import is_current_mapset_in_demolocation
  21. class DataCatalog(wx.Panel):
  22. """Data catalog panel"""
  23. def __init__(self, parent, giface=None, id=wx.ID_ANY,
  24. title=_("Data catalog"), name='catalog', **kwargs):
  25. """Panel constructor """
  26. self.showNotification = Signal('DataCatalog.showNotification')
  27. self.parent = parent
  28. self.baseTitle = title
  29. self.giface = giface
  30. wx.Panel.__init__(self, parent=parent, id=id, **kwargs)
  31. self.SetName("DataCatalog")
  32. Debug.msg(1, "DataCatalog.__init__()")
  33. # toolbar
  34. self.toolbar = DataCatalogToolbar(parent=self)
  35. # tree with layers
  36. self.tree = DataCatalogTree(self, giface=giface)
  37. self.tree.showNotification.connect(self.showNotification)
  38. # infobar for data catalog
  39. self.infoBar = InfoBar(self)
  40. # infobar manager for data catalog
  41. self.infoManager = DataCatalogInfoManager(infobar=self.infoBar,
  42. giface=self.giface)
  43. # some layout
  44. self._layout()
  45. # show data structure infobar for first-time user with proper layout
  46. if is_current_mapset_in_demolocation():
  47. wx.CallLater(2000, self.showDataStructureInfo)
  48. def _layout(self):
  49. """Do layout"""
  50. sizer = wx.BoxSizer(wx.VERTICAL)
  51. sizer.Add(self.toolbar, proportion=0, flag=wx.EXPAND)
  52. sizer.Add(self.infoBar, proportion=0, flag=wx.EXPAND)
  53. sizer.Add(self.tree.GetControl(), proportion=1, flag=wx.EXPAND)
  54. self.SetAutoLayout(True)
  55. self.SetSizer(sizer)
  56. self.Fit()
  57. self.Layout()
  58. def showDataStructureInfo(self):
  59. self.infoManager.ShowDataStructureInfo(self.OnCreateLocation)
  60. def LoadItems(self):
  61. self.tree.ReloadTreeItems()
  62. def OnReloadTree(self, event):
  63. """Reload whole tree"""
  64. self.LoadItems()
  65. def OnReloadCurrentMapset(self, event):
  66. """Reload current mapset tree only"""
  67. self.tree.ReloadCurrentMapset()
  68. def OnAddGrassDB(self, event):
  69. """Add grass database"""
  70. dlg = wx.DirDialog(self, _("Choose GRASS data directory:"),
  71. os.getcwd(), wx.DD_DEFAULT_STYLE)
  72. if dlg.ShowModal() == wx.ID_OK:
  73. grassdatabase = dlg.GetPath()
  74. self.tree.InsertGrassDb(name=grassdatabase)
  75. dlg.Destroy()
  76. def OnCreateMapset(self, event):
  77. """Create new mapset in current location"""
  78. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  79. self.tree.CreateMapset(db_node, loc_node)
  80. def OnCreateLocation(self, event):
  81. """Create new location"""
  82. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  83. self.tree.CreateLocation(db_node)
  84. def OnDownloadLocation(self, event):
  85. """Download location to current grass database"""
  86. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  87. self.tree.DownloadLocation(db_node)
  88. def SetRestriction(self, restrict):
  89. """Allow editing other mapsets or restrict editing to current mapset"""
  90. self.tree.SetRestriction(restrict)
  91. def Filter(self, text):
  92. self.tree.Filter(text=text)