catalog.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.gthread import gThread
  15. from core.debug import Debug
  16. from datacatalog.tree import DataCatalogTree
  17. from datacatalog.toolbars import DataCatalogToolbar
  18. from grass.pydispatch.signal import Signal
  19. class DataCatalog(wx.Panel):
  20. """Data catalog panel"""
  21. def __init__(self, parent, giface=None, id=wx.ID_ANY,
  22. title=_("Data catalog"), name='catalog', **kwargs):
  23. """Panel constructor """
  24. self.showNotification = Signal('DataCatalog.showNotification')
  25. self.changeMapset = Signal('DataCatalog.changeMapset')
  26. self.changeLocation = Signal('DataCatalog.changeLocation')
  27. self.parent = parent
  28. self.baseTitle = title
  29. wx.Panel.__init__(self, parent=parent, id=id, **kwargs)
  30. self.SetName("DataCatalog")
  31. Debug.msg(1, "DataCatalog.__init__()")
  32. # toolbar
  33. self.toolbar = DataCatalogToolbar(parent=self)
  34. # tree with layers
  35. self.tree = DataCatalogTree(self, giface=giface)
  36. self.thread = gThread()
  37. self._loaded = False
  38. self.tree.showNotification.connect(self.showNotification)
  39. self.tree.changeMapset.connect(self.changeMapset)
  40. self.tree.changeLocation.connect(self.changeLocation)
  41. # some layout
  42. self._layout()
  43. def _layout(self):
  44. """Do layout"""
  45. sizer = wx.BoxSizer(wx.VERTICAL)
  46. sizer.Add(self.toolbar, proportion=0,
  47. flag=wx.EXPAND)
  48. sizer.Add(self.tree.GetControl(), proportion=1,
  49. flag=wx.EXPAND)
  50. self.SetAutoLayout(True)
  51. self.SetSizer(sizer)
  52. self.Layout()
  53. def LoadItems(self):
  54. if self._loaded:
  55. return
  56. self.thread.Run(callable=self.tree.InitTreeItems,
  57. ondone=lambda event: self.LoadItemsDone())
  58. def LoadItemsDone(self):
  59. self._loaded = True
  60. self.tree.UpdateCurrentDbLocationMapsetNode()
  61. self.tree.ExpandCurrentMapset()
  62. def OnReloadTree(self, event):
  63. """Reload whole tree"""
  64. self.tree.ReloadTreeItems()
  65. self.tree.ExpandCurrentMapset()
  66. def OnReloadCurrentMapset(self, event):
  67. """Reload current mapset tree only"""
  68. self.tree.ReloadCurrentMapset()
  69. def OnAddGrassDB(self, event):
  70. """Add an existing grass database"""
  71. dlg = wx.DirDialog(self, _("Choose GRASS data directory:"),
  72. os.getcwd(), wx.DD_DEFAULT_STYLE)
  73. if dlg.ShowModal() == wx.ID_OK:
  74. grassdatabase = dlg.GetPath()
  75. self.tree.InsertGrassDb(name=grassdatabase)
  76. dlg.Destroy()
  77. def SetRestriction(self, restrict):
  78. """Allow editing other mapsets or restrict editing to current mapset"""
  79. self.tree.SetRestriction(restrict)
  80. def Filter(self, text):
  81. self.tree.Filter(text=text)