frame.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. """
  2. @package datacatalog::frame
  3. @brief Data catalog frame class
  4. Classes:
  5. - datacatalog::DataCatalogFrame
  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 (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.globalvar import ICONDIR
  17. from core.gcmd import RunCommand, GMessage
  18. from datacatalog.tree import DataCatalogTree
  19. from datacatalog.toolbars import DataCatalogToolbar
  20. from gui_core.wrap import Button
  21. class DataCatalogFrame(wx.Frame):
  22. """Frame for testing purposes only."""
  23. def __init__(self, parent, giface=None):
  24. wx.Frame.__init__(self, parent=parent,
  25. title=_('GRASS GIS Data Catalog'))
  26. self.SetName("DataCatalog")
  27. self.SetIcon(
  28. wx.Icon(
  29. os.path.join(
  30. ICONDIR,
  31. 'grass.ico'),
  32. wx.BITMAP_TYPE_ICO))
  33. self._giface = giface
  34. self.panel = wx.Panel(self)
  35. self.toolbar = DataCatalogToolbar(parent=self)
  36. # workaround for http://trac.wxwidgets.org/ticket/13888
  37. if sys.platform != 'darwin':
  38. self.SetToolBar(self.toolbar)
  39. # tree
  40. self.tree = DataCatalogTree(parent=self.panel, giface=self._giface)
  41. self.tree.ReloadTreeItems()
  42. # buttons
  43. self.btnClose = Button(parent=self.panel, id=wx.ID_CLOSE)
  44. self.btnClose.SetToolTip(_("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(btnSizer, proportion=0,
  57. flag=wx.ALL | 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. def OnReloadCurrentMapset(self, event):
  71. """Reload current mapset tree only"""
  72. self.tree.ReloadCurrentMapset()
  73. def OnAddGrassDB(self, event):
  74. """Add grass database"""
  75. dlg = wx.DirDialog(self, _("Choose GRASS data directory:"),
  76. os.getcwd(), wx.DD_DEFAULT_STYLE)
  77. if dlg.ShowModal() == wx.ID_OK:
  78. grassdatabase = dlg.GetPath()
  79. self.tree.InsertGrassDb(name=grassdatabase)
  80. dlg.Destroy()
  81. def OnCreateMapset(self, event):
  82. """Create new mapset in current location"""
  83. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  84. self.tree.CreateMapset(db_node, loc_node)
  85. def OnCreateLocation(self, event):
  86. """Create new location"""
  87. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  88. self.tree.CreateLocation(db_node)
  89. def OnDownloadLocation(self, event):
  90. """Download location online"""
  91. db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
  92. self.tree.DownloadLocation(db_node)
  93. def SetRestriction(self, restrict):
  94. """Allow editing other mapsets or restrict editing to current mapset"""
  95. self.tree.SetRestriction(restrict)
  96. def Filter(self, text):
  97. self.tree.Filter(text=text)