frame.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """
  2. @package datacatalog::frame
  3. @brief Data catalog frame class
  4. Classes:
  5. - datacatalog::DataCatalogFrame
  6. (C) 2014-2016 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 (original author)
  11. @author Martin Landa <landa.martin gmail.com> (various improvements)
  12. """
  13. import os
  14. import sys
  15. import wx
  16. from core.utils import _
  17. from core.globalvar import ICONDIR
  18. from datacatalog.tree import DataCatalogTree
  19. from datacatalog.toolbars import DataCatalogToolbar
  20. class DataCatalogFrame(wx.Frame):
  21. """Frame for testing purposes only."""
  22. def __init__(self, parent, giface=None):
  23. wx.Frame.__init__(self, parent=parent,
  24. title=_('GRASS GIS Data Catalog'))
  25. self.SetName("DataCatalog")
  26. self.SetIcon(
  27. wx.Icon(
  28. os.path.join(
  29. ICONDIR,
  30. 'grass.ico'),
  31. wx.BITMAP_TYPE_ICO))
  32. self._giface = giface
  33. self.panel = wx.Panel(self)
  34. self.toolbar = DataCatalogToolbar(parent=self)
  35. # workaround for http://trac.wxwidgets.org/ticket/13888
  36. if sys.platform != 'darwin':
  37. self.SetToolBar(self.toolbar)
  38. # tree
  39. self.tree = DataCatalogTree(parent=self.panel, giface=self._giface)
  40. self.tree.InitTreeItems()
  41. self.tree.ExpandCurrentMapset()
  42. # buttons
  43. self.btnClose = wx.Button(parent=self.panel, id=wx.ID_CLOSE)
  44. self.btnClose.SetToolTipString(_("Close GRASS GIS Data Catalog"))
  45. self.btnClose.SetDefault()
  46. # events
  47. self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  48. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  49. self._layout()
  50. def _layout(self):
  51. sizer = wx.BoxSizer(wx.VERTICAL)
  52. sizer.Add(self.tree, proportion=1, flag=wx.EXPAND)
  53. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  54. btnSizer.AddStretchSpacer()
  55. btnSizer.Add(self.btnClose)
  56. sizer.Add(item=btnSizer, proportion=0,
  57. flag=wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND,
  58. border=5)
  59. self.panel.SetSizer(sizer)
  60. sizer.Fit(self.panel)
  61. self.SetMinSize((400, 500))
  62. def OnCloseWindow(self, event):
  63. """Cancel button pressed"""
  64. if not isinstance(event, wx.CloseEvent):
  65. self.Destroy()
  66. event.Skip()
  67. def OnReloadTree(self, event):
  68. """Reload whole tree"""
  69. self.tree.ReloadTreeItems()
  70. self.tree.ExpandCurrentMapset()
  71. def OnReloadCurrentMapset(self, event):
  72. """Reload current mapset tree only"""
  73. self.tree.ReloadCurrentMapset()
  74. def SetRestriction(self, restrict):
  75. """Allow editing other mapsets or restrict editing to current mapset"""
  76. self.tree.SetRestriction(restrict)