From 508e68f39cbbe6a536918e223b99f6c8c2da749c Mon Sep 17 00:00:00 2001 From: mshukun Date: Fri, 30 Aug 2024 15:41:10 -0400 Subject: [PATCH 01/12] Remove unused variables and lines from files in the `gcp` directory --- gui/wxpython/gcp/g.gui.gcp.py | 2 +- gui/wxpython/gcp/manager.py | 8 ++------ gui/wxpython/gcp/mapdisplay.py | 2 -- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/gui/wxpython/gcp/g.gui.gcp.py b/gui/wxpython/gcp/g.gui.gcp.py index 32ef2c4fc0d..12f0a152090 100755 --- a/gui/wxpython/gcp/g.gui.gcp.py +++ b/gui/wxpython/gcp/g.gui.gcp.py @@ -65,7 +65,7 @@ def main(): app = wx.App() - wizard = GCPWizard(parent=None, giface=StandaloneGrassInterface()) + GCPWizard(parent=None, giface=StandaloneGrassInterface()) app.MainLoop() diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index ac006a95cbf..c6c9a36554d 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -1826,7 +1826,7 @@ def OnGeorect(self, event): else: flags = "a" - busy = wx.BusyInfo(_("Rectifying images, please wait..."), parent=self) + wx.BusyInfo(_("Rectifying images, please wait..."), parent=self) wx.GetApp().Yield() ret, msg = RunCommand( @@ -1886,7 +1886,7 @@ def OnGeorect(self, event): ) ret = msg = "" - busy = wx.BusyInfo( + wx.BusyInfo( _("Rectifying vector map <%s>, please wait...") % vect, parent=self ) wx.GetApp().Yield() @@ -2028,7 +2028,6 @@ def OnGROrder(self, event): elif self.gr_order == 2: minNumOfItems = 6 - diff = 6 - numOfItems # self.SetStatusText( # _('Insufficient points, 6+ points needed for 2nd order')) @@ -2331,7 +2330,6 @@ def OnZoomToTarget(self, event): def OnZoomMenuGCP(self, event): """Popup Zoom menu""" - point = wx.GetMousePosition() zoommenu = Menu() # Add items to the menu @@ -3433,7 +3431,6 @@ def UpdateSettings(self): srcrenderVector = False tgtrender = False tgtrenderVector = False - reload_target = False if self.new_src_map != src_map: # remove old layer layers = self.parent.grwiz.SrcMap.GetListOfLayers() @@ -3471,7 +3468,6 @@ def UpdateSettings(self): del layers[0] layers = self.parent.grwiz.TgtMap.GetListOfLayers() # self.parent.grwiz.TgtMap.DeleteAllLayers() - reload_target = True tgt_map["raster"] = self.new_tgt_map["raster"] tgt_map["vector"] = self.new_tgt_map["vector"] diff --git a/gui/wxpython/gcp/mapdisplay.py b/gui/wxpython/gcp/mapdisplay.py index 13872b807cf..66daa70d2ca 100644 --- a/gui/wxpython/gcp/mapdisplay.py +++ b/gui/wxpython/gcp/mapdisplay.py @@ -484,7 +484,6 @@ def PrintMenu(self, event): """ Print options and output menu for map display """ - point = wx.GetMousePosition() printmenu = Menu() # Add items to the menu setup = wx.MenuItem(printmenu, wx.ID_ANY, _("Page setup")) @@ -528,7 +527,6 @@ def SaveDisplayRegion(self, event): def OnZoomMenu(self, event): """Popup Zoom menu""" - point = wx.GetMousePosition() zoommenu = Menu() # Add items to the menu From f19ef2358019ac366e23f1de3b6ca2ad1608f184 Mon Sep 17 00:00:00 2001 From: mshukun Date: Fri, 30 Aug 2024 15:54:56 -0400 Subject: [PATCH 02/12] Replace `pylint: disable=W0612` with `noqa: F841` --- gui/wxpython/gui_core/treeview.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/gui/wxpython/gui_core/treeview.py b/gui/wxpython/gui_core/treeview.py index 4c20885599c..784f0c5320d 100644 --- a/gui/wxpython/gui_core/treeview.py +++ b/gui/wxpython/gui_core/treeview.py @@ -303,17 +303,13 @@ def main(): root = tree.root n1 = tree.AppendNode(parent=root, data={"label": "node1"}) n2 = tree.AppendNode(parent=root, data={"label": "node2"}) - n3 = tree.AppendNode(parent=root, data={"label": "node3"}) # pylint: disable=W0612 + n3 = tree.AppendNode(parent=root, data={"label": "node3"}) # noqa: F841 n11 = tree.AppendNode(parent=n1, data={"label": "node11", "xxx": "A"}) - n12 = tree.AppendNode( - parent=n1, data={"label": "node12", "xxx": "B"} - ) # pylint: disable=W0612 - n21 = tree.AppendNode( - parent=n2, data={"label": "node21", "xxx": "A"} - ) # pylint: disable=W0612 - n111 = tree.AppendNode( + n12 = tree.AppendNode(parent=n1, data={"label": "node12", "xxx": "B"}) # noqa: F841 + n21 = tree.AppendNode(parent=n2, data={"label": "node21", "xxx": "A"}) # noqa: F841 + n111 = tree.AppendNode( # noqa: F841 parent=n11, data={"label": "node111", "xxx": "A"} - ) # pylint: disable=W0612 + ) app = wx.App() frame = TreeFrame(model=tree) From 2d4664c1e777bef818fe336734f2a7e89cfe1c73 Mon Sep 17 00:00:00 2001 From: mshukun Date: Fri, 30 Aug 2024 15:58:31 -0400 Subject: [PATCH 03/12] Delete multiple lines to fix F841 --- gui/wxpython/gui_core/gselect.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gui/wxpython/gui_core/gselect.py b/gui/wxpython/gui_core/gselect.py index 7dc51b75935..9a16c36e08e 100644 --- a/gui/wxpython/gui_core/gselect.py +++ b/gui/wxpython/gui_core/gselect.py @@ -1373,12 +1373,6 @@ def Insert(self, group): """Insert subgroups for defined group""" if not group: return - gisenv = gs.gisenv() - try: - name, mapset = group.split("@", 1) - except ValueError: - name = group - mapset = gisenv["MAPSET"] mlist = RunCommand("i.group", group=group, read=True, flags="sg").splitlines() try: From a9287affbb0b373b38bdf787cc31123b7d39efad Mon Sep 17 00:00:00 2001 From: mshukun Date: Fri, 30 Aug 2024 16:55:03 -0400 Subject: [PATCH 04/12] Delete unused variables and lines to fix F841 --- gui/wxpython/gui_core/dialogs.py | 2 +- gui/wxpython/gui_core/forms.py | 3 --- gui/wxpython/gui_core/goutput.py | 2 +- gui/wxpython/gui_core/menu.py | 2 +- gui/wxpython/gui_core/preferences.py | 2 -- gui/wxpython/gui_core/prompt.py | 4 ++-- gui/wxpython/gui_core/pystc.py | 1 - gui/wxpython/gui_core/widgets.py | 2 +- 8 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gui/wxpython/gui_core/dialogs.py b/gui/wxpython/gui_core/dialogs.py index c31939312a7..e8f84bd5ba5 100644 --- a/gui/wxpython/gui_core/dialogs.py +++ b/gui/wxpython/gui_core/dialogs.py @@ -180,7 +180,7 @@ def OnLocation(self, event): dbase = grass.gisenv()["GISDBASE"] self.element2.UpdateItems(dbase=dbase, location=location) self.element2.SetSelection(0) - mapset = self.element2.GetStringSelection() + self.element2.GetStringSelection() def GetValues(self): """Get location, mapset""" diff --git a/gui/wxpython/gui_core/forms.py b/gui/wxpython/gui_core/forms.py index 4ff6f0ee0ee..8ecc4feb995 100644 --- a/gui/wxpython/gui_core/forms.py +++ b/gui/wxpython/gui_core/forms.py @@ -307,8 +307,6 @@ def run(self): pTable = self.task.get_param( "dbtable", element="element", raiseError=False ) - if pTable: - table = pTable.get("value", "") if name == "LayerSelect": # determine format @@ -1546,7 +1544,6 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar if value: selection.SetValue(value) - formatSelector = True # A gselect.Select is a combobox with two children: a textctl # and a popupwindow; we target the textctl here textWin = selection.GetTextCtrl() diff --git a/gui/wxpython/gui_core/goutput.py b/gui/wxpython/gui_core/goutput.py index 6aca497f365..34515f407aa 100644 --- a/gui/wxpython/gui_core/goutput.py +++ b/gui/wxpython/gui_core/goutput.py @@ -620,7 +620,7 @@ def AddStyledMessage(self, message, style=None): self.linePos -= 1 else: if c == "\r": - pos = self.GetCurLine()[1] + self.GetCurLine()[1] # self.SetCurrentPos(pos) else: self.SetCurrentPos(self.linePos) diff --git a/gui/wxpython/gui_core/menu.py b/gui/wxpython/gui_core/menu.py index 71d6d153f8b..b4985c9e8f4 100644 --- a/gui/wxpython/gui_core/menu.py +++ b/gui/wxpython/gui_core/menu.py @@ -144,7 +144,7 @@ def OnMenuHighlight(self, event): id = event.GetMenuId() item = self.FindItemById(id) if item: - help = item.GetHelp() + item.GetHelp() # but in this case just call Skip so the default is done event.Skip() diff --git a/gui/wxpython/gui_core/preferences.py b/gui/wxpython/gui_core/preferences.py index 3c3df8e8e42..c2020b2ffba 100644 --- a/gui/wxpython/gui_core/preferences.py +++ b/gui/wxpython/gui_core/preferences.py @@ -2021,8 +2021,6 @@ def OnCheckColorTable(self, event): def OnLoadEpsgCodes(self, event): """Load EPSG codes from the file""" - win = self.FindWindowById(self.winId["projection:statusbar:projFile"]) - path = win.GetValue() epsgCombo = self.FindWindowById(self.winId["projection:statusbar:epsg"]) wx.BeginBusyCursor() try: diff --git a/gui/wxpython/gui_core/prompt.py b/gui/wxpython/gui_core/prompt.py index 6ac9219f827..efec2622494 100644 --- a/gui/wxpython/gui_core/prompt.py +++ b/gui/wxpython/gui_core/prompt.py @@ -511,7 +511,7 @@ def OnChar(self, event): # complete command after pressing '.' if event.GetKeyCode() == 46: self.autoCompList = [] - entry = self.GetTextLeft() + self.GetTextLeft() self.InsertText(pos, ".") self.CharRight() self.toComplete = self.EntityToComplete() @@ -538,7 +538,7 @@ def OnChar(self, event): or event.GetKeyCode() == wx.WXK_SUBTRACT ): self.autoCompList = [] - entry = self.GetTextLeft() + self.GetTextLeft() self.InsertText(pos, "-") self.CharRight() self.toComplete = self.EntityToComplete() diff --git a/gui/wxpython/gui_core/pystc.py b/gui/wxpython/gui_core/pystc.py index a1dfc543320..d2df651a387 100644 --- a/gui/wxpython/gui_core/pystc.py +++ b/gui/wxpython/gui_core/pystc.py @@ -98,7 +98,6 @@ def __init__(self, parent, id=wx.ID_ANY, statusbar=None): 9, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL ) face = font.GetFaceName() - size = font.GetPointSize() # setting the monospace here to not mess with the rest of the code # TODO: review the whole styling diff --git a/gui/wxpython/gui_core/widgets.py b/gui/wxpython/gui_core/widgets.py index 035c70e6fbd..0ec50553114 100644 --- a/gui/wxpython/gui_core/widgets.py +++ b/gui/wxpython/gui_core/widgets.py @@ -170,7 +170,7 @@ def InsertPage(self, *args, **kwargs): self.classObject.InsertPage(self.widget, *args, **kwargs) except ( TypeError - ) as e: # documentation says 'index', but certain versions of wx require 'n' + ): # documentation says 'index', but certain versions of wx require 'n' kwargs["n"] = kwargs["index"] del kwargs["index"] self.classObject.InsertPage(self.widget, *args, **kwargs) From 37f4c3af05aa3b1d1377f60e403fe596cc2e1ff5 Mon Sep 17 00:00:00 2001 From: mshukun Date: Fri, 30 Aug 2024 16:55:33 -0400 Subject: [PATCH 05/12] Update `.flake8` according to F841 fixes --- .flake8 | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.flake8 b/.flake8 index 573debabe1c..83d5e6251ae 100644 --- a/.flake8 +++ b/.flake8 @@ -58,17 +58,14 @@ per-file-ignores = gui/wxpython/dbmgr/manager.py: E722 gui/wxpython/dbmgr/vinfo.py: F841 gui/wxpython/docs/wxgui_sphinx/conf.py: E402, W291 - gui/wxpython/gcp/g.gui.gcp.py: F841 - gui/wxpython/gcp/manager.py: F841, E722 - gui/wxpython/gcp/mapdisplay.py: F841 - gui/wxpython/gui_core/*: F841, E266, E722 - gui/wxpython/gui_core/dialogs.py: E722, F841 - gui/wxpython/gui_core/forms.py: E722, F841 + gui/wxpython/gcp/manager.py: E722 + gui/wxpython/gui_core/*: E266, E722 + gui/wxpython/gui_core/dialogs.py: E722 + gui/wxpython/gui_core/forms.py: E722 gui/wxpython/gui_core/ghelp.py: E722 - gui/wxpython/gui_core/gselect.py: F841, E266, E722 - gui/wxpython/gui_core/preferences.py: E266, F841 - gui/wxpython/gui_core/treeview.py: F841 - gui/wxpython/gui_core/widgets.py: F841, E722, E266 + gui/wxpython/gui_core/gselect.py: E266, E722 + gui/wxpython/gui_core/preferences.py: E266 + gui/wxpython/gui_core/widgets.py: E722, E266 gui/wxpython/image2target/*: F841, E722, E265 gui/wxpython/image2target/g.gui.image2target.py: E501, E265, F841 gui/wxpython/iscatt/*: F841, E722, F405, F403 From b46a6433ac53de4251a0833a55bb89a8aff5cd43 Mon Sep 17 00:00:00 2001 From: mshukun Date: Thu, 5 Sep 2024 16:53:29 -0400 Subject: [PATCH 06/12] Replace `busy = wx.BusyInfo` variable assignment with `with wx.BusyInfo()` as suggested --- gui/wxpython/gcp/manager.py | 62 +++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index c6c9a36554d..2d89d8312cc 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -1826,23 +1826,21 @@ def OnGeorect(self, event): else: flags = "a" - wx.BusyInfo(_("Rectifying images, please wait..."), parent=self) - wx.GetApp().Yield() - - ret, msg = RunCommand( - "i.rectify", - parent=self, - getErrorMsg=True, - quiet=True, - group=self.xygroup, - extension=self.extension, - order=self.gr_order, - method=self.gr_method, - flags=flags, - overwrite=overwrite, - ) + with wx.BusyInfo(_("Rectifying images, please wait..."), parent=self): + wx.GetApp().Yield() - del busy + ret, msg = RunCommand( + "i.rectify", + parent=self, + getErrorMsg=True, + quiet=True, + group=self.xygroup, + extension=self.extension, + order=self.gr_order, + method=self.gr_method, + flags=flags, + overwrite=overwrite, + ) # provide feedback on failure if ret != 0: @@ -1886,24 +1884,22 @@ def OnGeorect(self, event): ) ret = msg = "" - wx.BusyInfo( + with wx.BusyInfo( _("Rectifying vector map <%s>, please wait...") % vect, parent=self - ) - wx.GetApp().Yield() - - ret, msg = RunCommand( - "v.rectify", - parent=self, - getErrorMsg=True, - quiet=True, - input=vect, - output=self.outname, - group=self.xygroup, - order=self.gr_order, - overwrite=overwrite, - ) - - del busy + ): + wx.GetApp().Yield() + + ret, msg = RunCommand( + "v.rectify", + parent=self, + getErrorMsg=True, + quiet=True, + input=vect, + output=self.outname, + group=self.xygroup, + order=self.gr_order, + overwrite=overwrite, + ) # provide feedback on failure if ret != 0: From 9db45fc5f3865127fd00c957f51064c8e26ff27a Mon Sep 17 00:00:00 2001 From: mshukun Date: Thu, 5 Sep 2024 17:02:01 -0400 Subject: [PATCH 07/12] Remove `OnMenuHighlight` method and call as suggested --- gui/wxpython/gui_core/menu.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/gui/wxpython/gui_core/menu.py b/gui/wxpython/gui_core/menu.py index b4985c9e8f4..de6b49b7e93 100644 --- a/gui/wxpython/gui_core/menu.py +++ b/gui/wxpython/gui_core/menu.py @@ -68,8 +68,6 @@ def _createMenu(self, node): self._createMenuItem(menu, label=child.label, **data) - self.parent.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.OnMenuHighlight) - return menu def _createMenuItem( @@ -136,19 +134,6 @@ def GetCmd(self): """ return self.menucmd - def OnMenuHighlight(self, event): - """ - Default menu help handler - """ - # Show how to get menu item info from this event handler - id = event.GetMenuId() - item = self.FindItemById(id) - if item: - item.GetHelp() - - # but in this case just call Skip so the default is done - event.Skip() - class Menu(MenuBase, wx.MenuBar): def __init__(self, parent, model, class_handler=None): From eab6816dfd22c3c700771ec8779269684b5fcbfa Mon Sep 17 00:00:00 2001 From: mshukun Date: Thu, 5 Sep 2024 17:02:55 -0400 Subject: [PATCH 08/12] Remove `self.GetCurLine()[1]` as suggested --- gui/wxpython/gui_core/goutput.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gui/wxpython/gui_core/goutput.py b/gui/wxpython/gui_core/goutput.py index 34515f407aa..3c8927f2233 100644 --- a/gui/wxpython/gui_core/goutput.py +++ b/gui/wxpython/gui_core/goutput.py @@ -619,11 +619,7 @@ def AddStyledMessage(self, message, style=None): if c == "\b": self.linePos -= 1 else: - if c == "\r": - self.GetCurLine()[1] - # self.SetCurrentPos(pos) - else: - self.SetCurrentPos(self.linePos) + self.SetCurrentPos(self.linePos) self.ReplaceSelection(c) self.linePos = self.GetCurrentPos() if c != " ": From f7d9124cafa7e4e5df0a638fb18d3c88512ca3b5 Mon Sep 17 00:00:00 2001 From: mshukun Date: Thu, 5 Sep 2024 17:03:34 -0400 Subject: [PATCH 09/12] Remove `self.GetTextLeft` as suggested --- gui/wxpython/gui_core/prompt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/wxpython/gui_core/prompt.py b/gui/wxpython/gui_core/prompt.py index efec2622494..4eba75c4016 100644 --- a/gui/wxpython/gui_core/prompt.py +++ b/gui/wxpython/gui_core/prompt.py @@ -511,7 +511,6 @@ def OnChar(self, event): # complete command after pressing '.' if event.GetKeyCode() == 46: self.autoCompList = [] - self.GetTextLeft() self.InsertText(pos, ".") self.CharRight() self.toComplete = self.EntityToComplete() From ec10aa37814a88ae836140866cb85d41914c9759 Mon Sep 17 00:00:00 2001 From: mshukun Date: Thu, 5 Sep 2024 17:06:48 -0400 Subject: [PATCH 10/12] Suppress F841 using both Flake8 and Pylint --- gui/wxpython/gui_core/treeview.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gui/wxpython/gui_core/treeview.py b/gui/wxpython/gui_core/treeview.py index 784f0c5320d..b5ee50a7822 100644 --- a/gui/wxpython/gui_core/treeview.py +++ b/gui/wxpython/gui_core/treeview.py @@ -303,11 +303,17 @@ def main(): root = tree.root n1 = tree.AppendNode(parent=root, data={"label": "node1"}) n2 = tree.AppendNode(parent=root, data={"label": "node2"}) - n3 = tree.AppendNode(parent=root, data={"label": "node3"}) # noqa: F841 + n3 = tree.AppendNode( # noqa: F841 # pylint: disable=W0612 + parent=root, data={"label": "node3"} + ) n11 = tree.AppendNode(parent=n1, data={"label": "node11", "xxx": "A"}) - n12 = tree.AppendNode(parent=n1, data={"label": "node12", "xxx": "B"}) # noqa: F841 - n21 = tree.AppendNode(parent=n2, data={"label": "node21", "xxx": "A"}) # noqa: F841 - n111 = tree.AppendNode( # noqa: F841 + n12 = tree.AppendNode( # noqa: F841 # pylint: disable=W0612 + parent=n1, data={"label": "node12", "xxx": "B"} + ) + n21 = tree.AppendNode( # noqa: F841 # pylint: disable=W0612 + parent=n2, data={"label": "node21", "xxx": "A"} + ) + n111 = tree.AppendNode( # noqa: F841 # pylint: disable=W0612 parent=n11, data={"label": "node111", "xxx": "A"} ) From d0d7448de13ef74bed684f54fa2b19f32dd3c59d Mon Sep 17 00:00:00 2001 From: mshukun Date: Thu, 5 Sep 2024 17:08:47 -0400 Subject: [PATCH 11/12] Remove `self.element2.GetStringSelection()` as suggested --- gui/wxpython/gui_core/dialogs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/wxpython/gui_core/dialogs.py b/gui/wxpython/gui_core/dialogs.py index e8f84bd5ba5..f7c7711cadf 100644 --- a/gui/wxpython/gui_core/dialogs.py +++ b/gui/wxpython/gui_core/dialogs.py @@ -180,7 +180,6 @@ def OnLocation(self, event): dbase = grass.gisenv()["GISDBASE"] self.element2.UpdateItems(dbase=dbase, location=location) self.element2.SetSelection(0) - self.element2.GetStringSelection() def GetValues(self): """Get location, mapset""" From f12a14e065ebb9cc84b2786ac3e18ca5ddd7b0be Mon Sep 17 00:00:00 2001 From: Makiko Shukunobe Date: Wed, 18 Sep 2024 11:28:14 -0400 Subject: [PATCH 12/12] Remove "GetTextLeft" as suggested --- gui/wxpython/gui_core/prompt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/wxpython/gui_core/prompt.py b/gui/wxpython/gui_core/prompt.py index 4eba75c4016..6734de169a9 100644 --- a/gui/wxpython/gui_core/prompt.py +++ b/gui/wxpython/gui_core/prompt.py @@ -537,7 +537,6 @@ def OnChar(self, event): or event.GetKeyCode() == wx.WXK_SUBTRACT ): self.autoCompList = [] - self.GetTextLeft() self.InsertText(pos, "-") self.CharRight() self.toComplete = self.EntityToComplete()