Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI: remove deprecated methods from MapDisplay #1729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gui/wxpython/core/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import os
import sys

import grass.script as grass

Expand Down Expand Up @@ -141,6 +142,10 @@ def WriteError(self, text):
"""Writes error message for the user."""
raise NotImplementedError()

def GetLog(self, err=False):
"""Returns file-like object for writing."""
raise NotImplementedError()

def GetLayerTree(self):
"""Returns LayerManager's tree GUI object.
.. note::
Expand Down Expand Up @@ -313,6 +318,11 @@ def _write(self, function, text):
function(text)
os.environ["GRASS_MESSAGE_FORMAT"] = orig

def GetLog(self, err=False):
if err:
return sys.stdout
return sys.stderr

def GetLayerList(self):
return []

Expand Down
14 changes: 1 addition & 13 deletions gui/wxpython/gcp/mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def AddToolbar(self, name):
"""
# default toolbar
if name == "map":
self.toolbars["map"] = MapToolbar(self, self._toolSwitcher)
self.toolbars["map"] = MapToolbar(self, self._toolSwitcher, self._giface)

self._mgr.AddPane(
self.toolbars["map"],
Expand Down Expand Up @@ -563,18 +563,6 @@ def OnZoomMenu(self, event):
self.PopupMenu(zoommenu)
zoommenu.Destroy()

def IsStandalone(self):
"""Check if Map display is standalone"""
# we do not know and we do not care, so always False
return True

def GetLayerManager(self):
"""Get reference to Layer Manager

:return: always None
"""
return None

def GetSrcWindow(self):
return self.SrcMapWindow

Expand Down
4 changes: 0 additions & 4 deletions gui/wxpython/gui_core/mapdisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ def StatusbarEnableLongHelp(self, enable=True):
for toolbar in six.itervalues(self.toolbars):
toolbar.EnableLongHelp(enable)

def IsStandalone(self):
"""Check if map frame is standalone"""
raise NotImplementedError("IsStandalone")

def OnRender(self, event):
"""Re-render map composition (each map layer)"""
raise NotImplementedError("OnRender")
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/iclass/digit.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def GetCategoryColor(self, cat):
class IClassVDigit(IVDigit):
"""Class similar to IVDigit but specialized for wxIClass."""

def __init__(self, mapwindow):
IVDigit.__init__(self, mapwindow, driver=IClassDisplayDriver)
def __init__(self, giface, mapwindow):
IVDigit.__init__(self, giface, mapwindow, driver=IClassDisplayDriver)
self._settings["closeBoundary"] = True # snap to the first node

def _getNewFeaturesLayer(self):
Expand Down
22 changes: 10 additions & 12 deletions gui/wxpython/iclass/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import grass.script as grass

from mapdisp import statusbar as sb
from mapdisp.main import StandaloneMapDisplayGrassInterface
from mapwin.buffered import BufferedMapWindow
from vdigit.toolbars import VDigitToolbar
from gui_core.mapdisp import DoubleMapFrame
Expand Down Expand Up @@ -105,7 +106,10 @@ def __init__(
secondMap=Map(),
**kwargs,
)
self._giface = giface
if giface:
self.giface = giface
else:
self.giface = StandaloneMapDisplayGrassInterface(self)
self.tree = None
self.mapWindowProperties = MapWindowProperties()
self.mapWindowProperties.setValuesFromUserSettings()
Expand All @@ -114,13 +118,13 @@ def __init__(

self.firstMapWindow = IClassVDigitWindow(
parent=self,
giface=self._giface,
giface=self.giface,
properties=self.mapWindowProperties,
map=self.firstMap,
)
self.secondMapWindow = BufferedMapWindow(
parent=self,
giface=self._giface,
giface=self.giface,
properties=self.mapWindowProperties,
Map=self.secondMap,
)
Expand Down Expand Up @@ -218,9 +222,7 @@ def __init__(
self.dialogs["category"] = None

# PyPlot init
self.plotPanel = PlotPanel(
self, giface=self._giface, stats_data=self.stats_data
)
self.plotPanel = PlotPanel(self, giface=self.giface, stats_data=self.stats_data)

self._addPanes()
self._mgr.Update()
Expand Down Expand Up @@ -258,7 +260,7 @@ def _cleanup(self):

def OnHelp(self, event):
"""Show help page"""
self._giface.Help(entry="wxGUI.iclass")
self.giface.Help(entry="wxGUI.iclass")

def _getTempVectorName(self):
"""Return new name for temporary vector map (training areas)"""
Expand Down Expand Up @@ -389,7 +391,7 @@ def AddToolbar(self, name):
toolSwitcher=self._toolSwitcher,
MapWindow=self.GetFirstWindow(),
digitClass=IClassVDigit,
giface=self._giface,
giface=self.giface,
tools=[
"addArea",
"moveVertex",
Expand Down Expand Up @@ -485,10 +487,6 @@ def _addPaneMapWindow(self, name, position):
.Position(position),
)

def IsStandalone(self):
"""Check if Map display is standalone"""
return True

def OnUpdateActive(self, event):
"""
.. todo::
Expand Down
8 changes: 3 additions & 5 deletions gui/wxpython/iclass/g.gui.iclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def main():
set_gui_path()

from core.settings import UserSettings
from core.giface import StandaloneGrassInterface
from iclass.frame import IClassMapFrame

group_name = subgroup_name = map_name = trainingmap_name = None
Expand Down Expand Up @@ -105,21 +104,20 @@ def main():
app = wx.App()

# show main frame
giface = StandaloneGrassInterface()
frame = IClassMapFrame(
parent=None,
giface=giface,
giface=None,
title=_("Supervised Classification Tool - GRASS GIS"),
)
if not flags["m"]:
frame.CenterOnScreen()
if group_name:
frame.SetGroup(group_name, subgroup_name)
if map_name:
giface.WriteLog(_("Loading raster map <%s>...") % map_name)
frame.giface.WriteLog(_("Loading raster map <%s>...") % map_name)
frame.trainingMapManager.AddLayer(map_name)
if trainingmap_name:
giface.WriteLog(_("Loading training map <%s>...") % trainingmap_name)
frame.giface.WriteLog(_("Loading training map <%s>...") % trainingmap_name)
frame.ImportAreas(trainingmap_name)

frame.Show()
Expand Down
14 changes: 1 addition & 13 deletions gui/wxpython/image2target/ii2t_mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def AddToolbar(self, name):
"""
# default toolbar
if name == "map":
self.toolbars["map"] = MapToolbar(self, self._toolSwitcher)
self.toolbars["map"] = MapToolbar(self, self._toolSwitcher, self._giface)

self._mgr.AddPane(
self.toolbars["map"],
Expand Down Expand Up @@ -563,18 +563,6 @@ def OnZoomMenu(self, event):
self.PopupMenu(zoommenu)
zoommenu.Destroy()

def IsStandalone(self):
"""Check if Map display is standalone"""
# we do not know and we do not care, so always False
return True

def GetLayerManager(self):
"""Get reference to Layer Manager

:return: always None
"""
return None

def GetSrcWindow(self):
return self.SrcMapWindow

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ def OnIClass(self, event=None, cmd=None):
)
return

win = IClassMapFrame(parent=self, giface=self._giface)
win = IClassMapFrame(parent=self)
win.CentreOnScreen()

win.Show()
Expand Down
3 changes: 3 additions & 0 deletions gui/wxpython/lmgr/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def WriteWarning(self, text):
def WriteError(self, text):
self.lmgr._gconsole.WriteError(text=text)

def GetLog(self, err=False):
return self.lmgr._gconsole.GetLog(err=err)

def GetLayerTree(self):
return self.lmgr.GetLayerTree()

Expand Down
89 changes: 27 additions & 62 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ def _addToolbarVDigit(self):
giface=self._giface,
)
self.toolbars["vdigit"].quitDigitizer.connect(self.QuitVDigit)

def openATM(selection):
self._layerManager.OnShowAttributeTable(None, selection=selection)

self.toolbars["vdigit"].openATM.connect(
lambda selection: openATM(selection)
)
self.Map.layerAdded.connect(self._updateVDigitLayers)
self.MapWindowVDigit.SetToolbar(self.toolbars["vdigit"])

Expand Down Expand Up @@ -587,7 +594,9 @@ def Disable3dMode(self):
self.toolbars["map"].combo.Delete(1)

def RemoveNviz(self):
"""Restore 2D view"""
"""Restore 2D view. Can be called even if 3D is not active."""
if not self.IsPaneShown("3d"):
return
try:
self.toolbars["map"].RemoveTool(self.toolbars["map"].rotate)
self.toolbars["map"].RemoveTool(self.toolbars["map"].flyThrough)
Expand Down Expand Up @@ -648,7 +657,9 @@ def AddToolbar(self, name, fixed=False):
# default toolbar
if name == "map":
if "map" not in self.toolbars:
self.toolbars["map"] = MapToolbar(self, toolSwitcher=self._toolSwitcher)
self.toolbars["map"] = MapToolbar(
self, toolSwitcher=self._toolSwitcher, giface=self._giface
)

self._mgr.AddPane(
self.toolbars["map"],
Expand Down Expand Up @@ -1024,8 +1035,7 @@ def CleanUp(self):
maplayer = self.toolbars["vdigit"].GetLayer()
if maplayer:
self.toolbars["vdigit"].OnExit()
if self.IsPaneShown("3d"):
self.RemoveNviz()
self.RemoveNviz()
if hasattr(self, "rdigit") and self.rdigit:
self.rdigit.CleanUp()
if self.dialogs["vnet"]:
Expand Down Expand Up @@ -1548,11 +1558,7 @@ def OnZoomToMap(self, event):
NULLs) or vector map.
"""
Debug.msg(3, "MapFrame.OnZoomToMap()")
layers = None
if self.IsStandalone():
layers = self.MapWindow.GetMap().GetListOfLayers(active=False)

self.MapWindow.ZoomToMap(layers=layers)
self.MapWindow.ZoomToMap(layers=None)

def OnZoomToRaster(self, event):
"""Set display extents to match selected raster map (ignore NULLs)"""
Expand Down Expand Up @@ -1640,41 +1646,6 @@ def SetProperties(
self.mapWindowProperties.alignExtent = alignExtent
self.mapWindowProperties.resolution = constrainRes

def IsStandalone(self):
"""Check if Map display is standalone

.. deprecated:: 7.0
"""
# TODO: once it is removed from 2 places in vdigit it can be deleted
# here and also in base class and other classes in the tree (hopefully)
# and one place here still uses IsStandalone
Debug.msg(
1,
"MapFrame.IsStandalone(): Method IsStandalone is"
"deprecated, use some general approach instead such as"
" Signals or giface",
)
if self._layerManager:
return False

return True

def GetLayerManager(self):
"""Get reference to Layer Manager

:return: window reference
:return: None (if standalone)

.. deprecated:: 7.0
"""
Debug.msg(
1,
"MapFrame.GetLayerManager(): Method GetLayerManager is"
"deprecated, use some general approach instead such as"
" Signals or giface",
)
return self._layerManager

def GetMapToolbar(self):
"""Returns toolbar with zooming tools"""
return self.toolbars["map"] if "map" in self.toolbars else None
Expand Down Expand Up @@ -1785,25 +1756,19 @@ def _updateRDigitLayers(self, layer):
def QuitRDigit(self):
"""Calls digitizer cleanup, removes digitizer object and disconnects
signals from Map."""
if not self.IsStandalone():
self.rdigit.CleanUp()
# disconnect updating layers
self.GetMap().layerAdded.disconnect(self._updateRDigitLayers)
self.GetMap().layerRemoved.disconnect(self._updateRDigitLayers)
self.GetMap().layerChanged.disconnect(self._updateRDigitLayers)
self._toolSwitcher.toggleToolChanged.disconnect(
self.toolbars["rdigit"].CheckSelectedTool,
)
self.rdigit.CleanUp()
# disconnect updating layers
self.GetMap().layerAdded.disconnect(self._updateRDigitLayers)
self.GetMap().layerRemoved.disconnect(self._updateRDigitLayers)
self.GetMap().layerChanged.disconnect(self._updateRDigitLayers)
self._toolSwitcher.toggleToolChanged.disconnect(
self.toolbars["rdigit"].CheckSelectedTool,
)

self.RemoveToolbar("rdigit", destroy=True)
self.rdigit = None
else:
self.Close()
self.RemoveToolbar("rdigit", destroy=True)
self.rdigit = None

def QuitVDigit(self):
"""Quit VDigit"""
if not self.IsStandalone():
# disable the toolbar
self.RemoveToolbar("vdigit", destroy=True)
else:
self.Close()
# disable the toolbar
self.RemoveToolbar("vdigit", destroy=True)
9 changes: 8 additions & 1 deletion gui/wxpython/mapdisp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def GetLayerByData(self, key, value):
return None


class DMonGrassInterface(StandaloneGrassInterface):
class StandaloneMapDisplayGrassInterface(StandaloneGrassInterface):
"""@implements GrassInterface"""

def __init__(self, mapframe):
Expand All @@ -457,6 +457,13 @@ def GetProgress(self):
return self._mapframe.GetProgressBar()


class DMonGrassInterface(StandaloneMapDisplayGrassInterface):
"""@implements GrassInterface"""

def __init__(self, mapframe):
StandaloneMapDisplayGrassInterface.__init__(self, mapframe)


class DMonFrame(MapFrame):
def OnZoomToMap(self, event):
layers = self.MapWindow.GetMap().GetListOfLayers()
Expand Down
Loading