catalog.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. """
  2. @package datacatalog::catalog
  3. @brief Data catalog
  4. Classes:
  5. - datacatalog::DataCatalog
  6. (C) 2014 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 core.utils import _
  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.ExpandCurrentMapset()
  61. def OnReloadTree(self, event):
  62. """Reload whole tree"""
  63. self.tree.ReloadTreeItems()
  64. self.tree.ExpandCurrentMapset()
  65. def OnReloadCurrentMapset(self, event):
  66. """Reload current mapset tree only"""
  67. self.tree.ReloadCurrentMapset()
  68. def SetRestriction(self, restrict):
  69. """Allow editing other mapsets or restrict editing to current mapset"""
  70. self.tree.SetRestriction(restrict)
  71. def Filter(self, text):
  72. self.tree.Filter(text=text)