Skip to content

Commit 596f2b0

Browse files
authored
wxGUI/mapdisp: it is also possible to remove the MASK interactively (#1176)
With left mouse click on the MASK button widget inside statusbar.
1 parent 400bef3 commit 596f2b0

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

gui/wxpython/mapdisp/statusbar.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from core import utils
3838
from core.gcmd import RunCommand
3939
from core.settings import UserSettings
40-
from gui_core.wrap import StaticText, TextCtrl
40+
from gui_core.wrap import Button, TextCtrl
4141

4242
from grass.script import core as grass
4343

@@ -283,7 +283,6 @@ def Reposition(self):
283283
wWin = rect.width - 6
284284
if idx == 2: # mask
285285
x += 5
286-
y += 4
287286
elif idx == 3: # render
288287
x += 5
289288
win.SetPosition((x, y))
@@ -894,14 +893,20 @@ def Update(self):
894893

895894

896895
class SbMask(SbItem):
897-
"""StaticText to show whether mask is activated."""
896+
"""Button to show whether mask is activated and remove mask with
897+
left mouse click
898+
"""
898899

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

903-
self.widget = StaticText(parent=self.statusbar, id=wx.ID_ANY, label=_("MASK"))
904+
self.widget = Button(
905+
parent=self.statusbar, id=wx.ID_ANY, label=_("MASK"), style=wx.NO_BORDER
906+
)
907+
self.widget.Bind(wx.EVT_BUTTON, self.OnRemoveMask)
904908
self.widget.SetForegroundColour(wx.Colour(255, 0, 0))
909+
self.widget.SetToolTip(tip=_("Left mouse click to remove the MASK"))
905910
self.widget.Hide()
906911

907912
def Update(self):
@@ -912,6 +917,24 @@ def Update(self):
912917
else:
913918
self.Hide()
914919

920+
def OnRemoveMask(self, event):
921+
if grass.find_file(
922+
name="MASK", element="cell", mapset=grass.gisenv()["MAPSET"]
923+
)["name"]:
924+
925+
dlg = wx.MessageDialog(
926+
self.mapFrame,
927+
message=_("Are you sure that you want to remove the MASK?"),
928+
caption=_("Remove MASK"),
929+
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
930+
)
931+
if dlg.ShowModal() != wx.ID_YES:
932+
dlg.Destroy()
933+
return
934+
RunCommand("r.mask", flags="r")
935+
self.Hide()
936+
self.mapFrame.OnRender(event=None)
937+
915938

916939
class SbTextItem(SbItem):
917940
"""Base class for items without widgets.

0 commit comments

Comments
 (0)