Skip to content

Commit

Permalink
wxGUI/mapdisp: it is also possible to remove the MASK interactively (#…
Browse files Browse the repository at this point in the history
…1176)

With left mouse click on the MASK button widget inside statusbar.
  • Loading branch information
tmszi committed Dec 7, 2021
1 parent 400bef3 commit 596f2b0
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions gui/wxpython/mapdisp/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from core import utils
from core.gcmd import RunCommand
from core.settings import UserSettings
from gui_core.wrap import StaticText, TextCtrl
from gui_core.wrap import Button, TextCtrl

from grass.script import core as grass

Expand Down Expand Up @@ -283,7 +283,6 @@ def Reposition(self):
wWin = rect.width - 6
if idx == 2: # mask
x += 5
y += 4
elif idx == 3: # render
x += 5
win.SetPosition((x, y))
Expand Down Expand Up @@ -894,14 +893,20 @@ def Update(self):


class SbMask(SbItem):
"""StaticText to show whether mask is activated."""
"""Button to show whether mask is activated and remove mask with
left mouse click
"""

def __init__(self, mapframe, statusbar, position=0):
SbItem.__init__(self, mapframe, statusbar, position)
self.name = "mask"

self.widget = StaticText(parent=self.statusbar, id=wx.ID_ANY, label=_("MASK"))
self.widget = Button(
parent=self.statusbar, id=wx.ID_ANY, label=_("MASK"), style=wx.NO_BORDER
)
self.widget.Bind(wx.EVT_BUTTON, self.OnRemoveMask)
self.widget.SetForegroundColour(wx.Colour(255, 0, 0))
self.widget.SetToolTip(tip=_("Left mouse click to remove the MASK"))
self.widget.Hide()

def Update(self):
Expand All @@ -912,6 +917,24 @@ def Update(self):
else:
self.Hide()

def OnRemoveMask(self, event):
if grass.find_file(
name="MASK", element="cell", mapset=grass.gisenv()["MAPSET"]
)["name"]:

dlg = wx.MessageDialog(
self.mapFrame,
message=_("Are you sure that you want to remove the MASK?"),
caption=_("Remove MASK"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if dlg.ShowModal() != wx.ID_YES:
dlg.Destroy()
return
RunCommand("r.mask", flags="r")
self.Hide()
self.mapFrame.OnRender(event=None)


class SbTextItem(SbItem):
"""Base class for items without widgets.
Expand Down

0 comments on commit 596f2b0

Please sign in to comment.