frame.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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(wx.Icon(os.path.join(ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  27. self._giface = giface
  28. self.panel = wx.Panel(self)
  29. self.toolbar = DataCatalogToolbar(parent = self)
  30. # workaround for http://trac.wxwidgets.org/ticket/13888
  31. if sys.platform != 'darwin':
  32. self.SetToolBar(self.toolbar)
  33. # tree
  34. self.tree = DataCatalogTree(parent=self.panel, giface=self._giface)
  35. self.tree.InitTreeItems()
  36. self.tree.ExpandCurrentMapset()
  37. # buttons
  38. self.btnClose = wx.Button(parent=self.panel, id=wx.ID_CLOSE)
  39. self.btnClose.SetToolTipString(_("Close GRASS GIS Data Catalog"))
  40. self.btnClose.SetDefault()
  41. # events
  42. self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  43. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  44. self._layout()
  45. def _layout(self):
  46. sizer = wx.BoxSizer(wx.VERTICAL)
  47. sizer.Add(self.tree, proportion=1, flag=wx.EXPAND)
  48. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  49. btnSizer.AddStretchSpacer()
  50. btnSizer.Add(self.btnClose)
  51. sizer.Add(item=btnSizer, proportion=0,
  52. flag=wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND,
  53. border=5)
  54. self.panel.SetSizer(sizer)
  55. sizer.Fit(self.panel)
  56. self.SetMinSize((400, 500))
  57. def OnCloseWindow(self, event):
  58. """Cancel button pressed"""
  59. if not isinstance(event, wx.CloseEvent):
  60. self.Destroy()
  61. event.Skip()
  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()