catalog.py 2.7 KB

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