123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- """!
- @package lmgr.giface
- @brief Layer Manager GRASS interface
- Classes:
- - giface::LayerManagerGrassInterface
- (C) 2012 by the GRASS Development Team
- This program is free software under the GNU General Public License
- (>=v2). Read the file COPYING that comes with GRASS for details.
- @author Anna Kratochvilova <kratochanna gmail.com>
- @author Vaclav Petras <wenzeslaus gmail.com>
- """
- from grass.pydispatch.signal import Signal
- class Layer(object):
- """!@implements core::giface::Layer
- @note Currently implemented without specifying the interface.
- It only provides all attributes of existing layer as used in lmgr.
- """
- def __init__(self, pydata):
- self._pydata = pydata
- def __getattr__(self, name):
- return self._pydata[0][name]
- class LayerList(object):
- """!@implements core.giface.Layer"""
- def __init__(self, tree):
- self._tree = tree
- # def __iter__(self):
- # """!Iterates over the contents of the list."""
- # for in :
- # yield
- def GetSelectedLayers(self, checkedOnly=True):
- items = self._tree.GetSelectedLayer(multi=True,
- checkedOnly=checkedOnly)
- layers = []
- for item in items:
- layer = Layer(self._tree.GetPyData(item))
- layers.append(layer)
- return layers
- def GetLayerInfo(self, layer):
- """!For compatibility only, will be removed."""
- return Layer(self._tree.GetPyData(layer))
- class LayerManagerGrassInterface(object):
- """!@implements GrassInterface"""
- def __init__(self, lmgr):
- """!Costructor is specific to the current implementation.
- Uses Layer Manager object including its private attributes.
- (It encapsulates existing Layer Manager so access to private members
- is intention.)
- """
- self.lmgr = lmgr
- # Signal when some map is created or updated by a module.
- # attributes: name: map name, ltype: map type,
- # add: if map should be added to layer tree (questionable attribute)
- self.mapCreated = Signal('LayerManagerGrassInterface.mapCreated')
- # Signal emitted to request updating of map
- self.updateMap = Signal('LayerManagerGrassInterface.updateMap')
- def RunCmd(self, *args, **kwargs):
- self.lmgr._gconsole.RunCmd(*args, **kwargs)
- def Help(self, entry):
- cmdlist = ['g.manual', 'entry=%s' % entry]
- self.RunCmd(cmdlist, compReg = False, switchPage = False)
- def WriteLog(self, text, wrap = None,
- switchPage = False, priority = 1):
- self.lmgr._gconsole.WriteLog(text = text, wrap = wrap, switchPage = switchPage,
- priority = priority)
- def WriteCmdLog(self, line, pid = None, switchPage = True):
- self.lmgr._gconsole.WriteCmdLog(line = line, pid = pid, switchPage = switchPage)
- def WriteWarning(self, line):
- self.lmgr._gconsole.WriteWarning(line = line)
- def WriteError(self, line):
- self.lmgr._gconsole.WriteError(line = line)
- def GetLayerTree(self):
- return self.lmgr.GetLayerTree()
- def GetLayerList(self):
- return LayerList(self.lmgr.GetLayerTree())
- def GetMapDisplay(self):
- return self.lmgr.GetMapDisplay(onlyCurrent=True)
- def GetAllMapDisplays(self):
- return self.lmgr.GetMapDisplay(onlyCurrent=False)
- def GetMapWindow(self):
- if self.lmgr.GetMapDisplay(onlyCurrent=True):
- return self.lmgr.GetMapDisplay(onlyCurrent=True).GetMapWindow()
- else:
- return None
- def GetProgress(self):
- return self.lmgr.goutput.GetProgressBar()
- class LayerManagerGrassInterfaceForMapDisplay(object):
- """!Provides reference only to the given layer list (according to tree),
- not to the current.
- """
- def __init__(self, giface, tree):
- """!
- @giface original grass interface
- @tree tree which will be used instead of the tree from giface
- """
- self._giface = giface
- self.tree = tree
- # Signal emitted to request updating of map
- self.updateMap = Signal('LayerManagerGrassInterfaceForMapDisplay.updateMap')
- def GetLayerTree(self):
- return self.tree
- def GetLayerList(self):
- return LayerList(self.tree)
- def GetMapWindow(self):
- return self.tree.GetMapDisplay()
- def __getattr__(self, name):
- return getattr(self._giface, name)
|