class DataCatalogFrame(wx.Frame): """Frame for testing purposes only.""" def __init__(self, parent, giface=None): wx.Frame.__init__(self, parent=parent, title=_('GRASS GIS Data Catalog (experimetal)')) self.SetName("DataCatalog") self.SetIcon( wx.Icon(os.path.join(ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self._giface = giface self.panel = wx.Panel(self) # tree self.tree = DataCatalogTree(parent=self.panel, giface=self._giface) self.tree.InitTreeItems() self.tree.ExpandCurrentMapset() # buttons self.btnClose = wx.Button(parent=self.panel, id=wx.ID_CLOSE) self.btnClose.SetToolTipString(_("Close GRASS GIS Data Catalog")) self.btnClose.SetDefault() # events self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self._layout() def _layout(self): sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.tree, proportion=1, flag=wx.EXPAND) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.AddStretchSpacer() btnSizer.Add(self.btnClose) sizer.Add(item=btnSizer, proportion=0, flag=wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND, border=5) self.panel.SetSizer(sizer) sizer.Fit(self.panel) self.SetMinSize((400, 500)) def OnCloseWindow(self, event): """Cancel button pressed""" if not isinstance(event, wx.CloseEvent): self.Destroy() event.Skip()
class DataCatalogFrame(wx.Frame): """Frame for testing purposes only.""" def __init__(self, parent, giface=None): wx.Frame.__init__(self, parent=parent, title=_('GRASS GIS Data Catalog')) self.SetName("DataCatalog") self.SetIcon( wx.Icon(os.path.join(ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self._giface = giface self.panel = wx.Panel(self) self.toolbar = DataCatalogToolbar(parent=self) # workaround for http://trac.wxwidgets.org/ticket/13888 if sys.platform != 'darwin': self.SetToolBar(self.toolbar) # tree self.tree = DataCatalogTree(parent=self.panel, giface=self._giface) self.tree.InitTreeItems() self.tree.ExpandCurrentMapset() self.tree.changeMapset.connect( lambda mapset: self.ChangeLocationMapset(location=None, mapset=mapset)) self.tree.changeLocation.connect( lambda mapset, location: self.ChangeLocationMapset( location=location, mapset=mapset)) # buttons self.btnClose = wx.Button(parent=self.panel, id=wx.ID_CLOSE) self.btnClose.SetToolTipString(_("Close GRASS GIS Data Catalog")) self.btnClose.SetDefault() # events self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self._layout() def _layout(self): sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.tree, proportion=1, flag=wx.EXPAND) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.AddStretchSpacer() btnSizer.Add(self.btnClose) sizer.Add(btnSizer, proportion=0, flag=wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND, border=5) self.panel.SetSizer(sizer) sizer.Fit(self.panel) self.SetMinSize((400, 500)) def OnCloseWindow(self, event): """Cancel button pressed""" if not isinstance(event, wx.CloseEvent): self.Destroy() event.Skip() def OnReloadTree(self, event): """Reload whole tree""" self.tree.ReloadTreeItems() self.tree.ExpandCurrentMapset() def OnReloadCurrentMapset(self, event): """Reload current mapset tree only""" self.tree.ReloadCurrentMapset() def SetRestriction(self, restrict): """Allow editing other mapsets or restrict editing to current mapset""" self.tree.SetRestriction(restrict) def ChangeLocationMapset(self, mapset, location=None): """Change mapset or location""" if location: if RunCommand('g.mapset', parent=self, location=location, mapset=mapset) == 0: GMessage(parent=self, message=_("Current location is <%(loc)s>.\n" "Current mapset is <%(mapset)s>.") % { 'loc': location, 'mapset': mapset }) else: if RunCommand('g.mapset', parent=self, mapset=mapset) == 0: GMessage(parent=self, message=_("Current mapset is <%s>.") % mapset) def Filter(self, text): self.tree.Filter(text=text)
class DataCatalogFrame(wx.Frame): """Frame for testing purposes only.""" def __init__(self, parent, giface=None): wx.Frame.__init__(self, parent=parent, title=_('GRASS GIS Data Catalog')) self.SetName("DataCatalog") self.SetIcon( wx.Icon(os.path.join(ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self._giface = giface self.panel = wx.Panel(self) self.toolbar = DataCatalogToolbar(parent=self) # workaround for http://trac.wxwidgets.org/ticket/13888 if sys.platform != 'darwin': self.SetToolBar(self.toolbar) # tree self.tree = DataCatalogTree(parent=self.panel, giface=self._giface) self.tree.InitTreeItems() self.tree.UpdateCurrentDbLocationMapsetNode() self.tree.ExpandCurrentMapset() self.tree.changeMapset.connect( lambda mapset: self.ChangeDbLocationMapset(location=None, mapset=mapset)) self.tree.changeLocation.connect( lambda mapset, location, dbase: self.ChangeDbLocationMapset( dbase=dbase, location=location, mapset=mapset)) # buttons self.btnClose = Button(parent=self.panel, id=wx.ID_CLOSE) self.btnClose.SetToolTip(_("Close GRASS GIS Data Catalog")) self.btnClose.SetDefault() # events self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self._layout() def _layout(self): sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.tree, proportion=1, flag=wx.EXPAND) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.AddStretchSpacer() btnSizer.Add(self.btnClose) sizer.Add(btnSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5) self.panel.SetSizer(sizer) sizer.Fit(self.panel) self.SetMinSize((400, 500)) def OnCloseWindow(self, event): """Cancel button pressed""" if not isinstance(event, wx.CloseEvent): self.Destroy() event.Skip() def OnReloadTree(self, event): """Reload whole tree""" self.tree.ReloadTreeItems() self.tree.ExpandCurrentMapset() def OnReloadCurrentMapset(self, event): """Reload current mapset tree only""" self.tree.ReloadCurrentMapset() def OnAddGrassDB(self, event): """Add an existing grass database""" dlg = wx.DirDialog(self, _("Choose GRASS data directory:"), os.getcwd(), wx.DD_DEFAULT_STYLE) if dlg.ShowModal() == wx.ID_OK: grassdatabase = dlg.GetPath() self.tree.InsertGrassDb(name=grassdatabase) dlg.Destroy() def OnCreateMapset(self, event): """Create new mapset in current location""" db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode( ) self.tree.CreateMapset(db_node, loc_node) def OnCreateLocation(self, event): """Create new location""" db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode( ) self.tree.CreateLocation(db_node) def OnDownloadLocation(self, event): """Download location online""" db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode( ) self.tree.DownloadLocation(db_node) def SetRestriction(self, restrict): """Allow editing other mapsets or restrict editing to current mapset""" self.tree.SetRestriction(restrict) def ChangeDbLocationMapset(self, mapset, location=None, dbase=None): """Change mapset, location or db""" if dbase: if RunCommand('g.mapset', parent=self, location=location, mapset=mapset, dbase=dbase) == 0: GMessage(parent=self, message=_("Current GRASS database is <%(dbase)s>.\n" "Current location is <%(loc)s>.\n" "Current mapset is <%(mapset)s>.") % { 'dbase': dbase, 'loc': location, 'mapset': mapset }) elif location: if RunCommand('g.mapset', parent=self, location=location, mapset=mapset) == 0: GMessage(parent=self, message=_("Current location is <%(loc)s>.\n" "Current mapset is <%(mapset)s>.") % { 'loc': location, 'mapset': mapset }) else: if RunCommand('g.mapset', parent=self, mapset=mapset) == 0: GMessage(parent=self, message=_("Current mapset is <%s>.") % mapset) def Filter(self, text): self.tree.Filter(text=text)