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

F841 fixes #18

Merged
merged 15 commits into from
Oct 18, 2024
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
6 changes: 2 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ per-file-ignores =
gui/scripts/d.wms.py: E501
gui/wxpython/image2target/g.gui.image2target.py: E501
gui/wxpython/modules/*: F841, E722
gui/wxpython/nviz/*: F841, E266, E722, F403, F405
gui/wxpython/nviz/*: E266, E722, F403, F405
gui/wxpython/photo2image/*: F841, E722, E265
gui/wxpython/photo2image/g.gui.photo2image.py: E501, F841
gui/wxpython/psmap/*: F841, E266, E722, F405, F403
gui/wxpython/psmap/*: F841, E266, E722
gui/wxpython/vdigit/*: F841, E722, F405, F403
gui/wxpython/vnet/*: F841
gui/wxpython/wxgui.py: F841
gui/wxpython/animation/g.gui.animation.py: E501
gui/wxpython/tplot/frame.py: F841, E722
gui/wxpython/tplot/g.gui.tplot.py: E501
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# renovate: datasource=pypi depName=bandit
BANDIT_VERSION: "1.7.10"
# renovate: datasource=pypi depName=ruff
RUFF_VERSION: "0.6.9"
RUFF_VERSION: "0.7.0"

runs-on: ${{ matrix.os }}
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.9
rev: v0.7.0
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
pytest
];

LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";

shellHook = ''
function dev-help {
echo -e "\nWelcome to a GRASS development environment !"
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import inspect
import operator
from string import digits

from grass.script import core as grass
from grass.script import task as gtask
Expand Down Expand Up @@ -936,7 +937,7 @@ def SetAddOnPath(addonPath=None, key="PATH"):


def color_resolve(color):
if len(color) > 0 and color[0] in "0123456789":
if len(color) > 0 and color[0] in digits:
rgb = tuple(map(int, color.split(":")))
label = color
else:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gmodeler/g.gui.gmodeler.html
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ <h2>SEE ALSO</h2>

<p>
See also selected user models available from
<a href="https://grass.osgeo.org/grass78/manuals/addons/">GRASS Addons repository</a>.
<a href="https://grass.osgeo.org/grass8/manuals/addons/">GRASS Addons repository</a>.

<p>
See also
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/gui_core/goutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import textwrap
from string import digits

import wx
from wx import stc
Expand Down Expand Up @@ -624,7 +625,7 @@ def AddStyledMessage(self, message, style=None):
self.linePos = self.GetCurrentPos()
if c != " ":
last_c = c
if last_c not in ("0123456789"):
if last_c not in (digits):
self.AddTextWrapped("\n", wrap=None)
self.linePos = -1
else:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def GetMenuCmd(self, event):
layer = self.GetLayerTree().layer_selected
name = self.GetLayerTree().GetLayerInfo(layer, key="maplayer").name
type = self.GetLayerTree().GetLayerInfo(layer, key="type")
except AttributeError:
except (AttributeError, TypeError):
layer = None

if layer and len(cmdlist) == 1: # only if no parameters given
Expand Down Expand Up @@ -1183,7 +1183,7 @@ def OnVDigit(self, event):
# available only for vector map layers
try:
mapLayer = tree.GetLayerInfo(layer, key="maplayer")
except AttributeError:
except (AttributeError, TypeError):
mapLayer = None

if not mapLayer or mapLayer.GetType() != "vector":
Expand Down Expand Up @@ -1860,7 +1860,7 @@ def OnShowAttributeTable(self, event, selection=None):
# available only for vector map layers
try:
maptype = tree.GetLayerInfo(layer, key="maplayer").type
except AttributeError:
except (AttributeError, TypeError):
maptype = None

if not maptype or maptype != "vector":
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ def OnDeleteLayer(self, event):
try:
if self.GetLayerInfo(item, key="type") != "group":
self.Map.DeleteLayer(self.GetLayerInfo(item, key="maplayer"))
except AttributeError:
except (AttributeError, TypeError):
pass

# redraw map if auto-rendering is enabled
Expand Down Expand Up @@ -2399,7 +2399,7 @@ def __FindSubItemByName(self, item, value):
while item and item.IsOk():
try:
itemLayer = self.GetLayerInfo(item, key="maplayer")
except KeyError:
except (KeyError, TypeError):
return None

if itemLayer and value == itemLayer.GetName():
Expand Down
20 changes: 14 additions & 6 deletions gui/wxpython/lmgr/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,20 @@ def CreateRecentFilesMenu(self, menu=None):
:return None
"""
if menu:
file_menu = menu.GetMenu(
menuIndex=menu.FindMenu(title=_("File")),
)
workspace_item = file_menu.FindItem(
id=file_menu.FindItem(itemString=_("Workspace")),
)[0]
menu_index = menu.FindMenu(_("File"))
if menu_index == wx.NOT_FOUND:
# try untranslated version
menu_index = menu.FindMenu("File")
if menu_index == wx.NOT_FOUND:
return
file_menu = menu.GetMenu(menu_index)
workspace_index = file_menu.FindItem(_("Workspace"))
if workspace_index == wx.NOT_FOUND:
workspace_index = file_menu.FindItem("Workspace")
if workspace_index == wx.NOT_FOUND:
return
workspace_item = file_menu.FindItemById(workspace_index)

self._recent_files = RecentFilesMenu(
app_name="main",
parent_menu=workspace_item.GetSubMenu(),
Expand Down
11 changes: 7 additions & 4 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,9 +1604,12 @@ def __init__(self, wizard, parent):
self, data=None, columns=[_("Code"), _("Description"), _("Parameters")]
)

# epsg.io hyperlink
# A hyperlink to a CRS database (PROJ related)
self.tlink = HyperlinkCtrl(
self, id=wx.ID_ANY, label="epsg.io", url="https://epsg.io/"
self,
id=wx.ID_ANY,
label="spatialreference.org",
url="https://spatialreference.org/",
)
self.tlink.SetNormalColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
self.tlink.SetVisitedColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
Expand Down Expand Up @@ -1688,14 +1691,14 @@ def EnableNext(self, enable=True):
def OnTextChange(self, event):
value = self.searchb.GetValue()
if value == "":
self.tlink.SetURL("https://epsg.io/")
self.tlink.SetURL("https://spatialreference.org/")
self.epsgcode = None
self.epsgdesc = self.epsgparams = ""
self.searchb.ChangeValue("")
self.OnBrowseCodes(None)
self.EnableNext(False)
else:
self.tlink.SetURL(str("https://epsg.io/?q={0}".format(value)))
self.tlink.SetURL(f"https://spatialreference.org/ref/?&search={value}")
data = self.epsglist.Search(index=[0, 1, 2], pattern=value, firstOnly=False)
if data:
index = 0
Expand Down
1 change: 0 additions & 1 deletion gui/wxpython/modules/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ def SaveToFile(self, event):

def PrintMenu(self, event):
"""Print options and output menu"""
point = wx.GetMousePosition()
printmenu = Menu()
# Add items to the menu
setup = wx.MenuItem(printmenu, id=wx.ID_ANY, text=_("Page setup"))
Expand Down
58 changes: 47 additions & 11 deletions gui/wxpython/modules/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

@author Martin Landa <landa.martin gmail.com>
@author Anna Kratochvilova <kratochanna gmail.com> (GroupDialog, SymbolDialog)
@author William Welch <ww.dev icloud.com> (commands running queue)
"""

import os
from collections import deque

from pathlib import Path

Expand Down Expand Up @@ -60,6 +62,8 @@ def __init__(

self.commandId = -1 # id of running command

self._commands_running = deque()

wx.Dialog.__init__(
self, parent, id, title, style=style, name="MultiImportDialog"
)
Expand Down Expand Up @@ -122,16 +126,17 @@ def __init__(
# buttons
#
# cancel
self._DEFAULT_CLOSE_BTN_TEXT = _("Close dialog")
self.btn_close = CloseButton(parent=self.panel)
self.btn_close.SetToolTip(_("Close dialog"))
self.btn_close.SetToolTip(_(self._DEFAULT_CLOSE_BTN_TEXT))
self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
# run
self.btn_run = Button(parent=self.panel, id=wx.ID_OK, label=_("&Import"))
self.btn_run.SetToolTip(_("Import selected layers"))
self.btn_run.SetDefault()
self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)

self.Bind(wx.EVT_CLOSE, lambda evt: self.Destroy())
self.Bind(wx.EVT_CLOSE, self._handleCloseEvent)

self.notebook = GNotebook(parent=self, style=globalvar.FNPageDStyle)

Expand Down Expand Up @@ -270,6 +275,33 @@ def _validateOutputMapName(self):
return False
return True

def _handleCloseEvent(self, event: wx.CloseEvent):
if event.CanVeto() and len(self._commands_running) > 0:
# prevent dialog close while async commands are running
event.Veto()
return
self.Destroy()

def _addToCommandQueue(self):
self._commands_running.append(True)

# disable the dialog close button
self.btn_close.SetToolTip(
_("Dialog cannot be closed while command is running.")
)
self.btn_close.Disable()

def _removeFromCommandQueue(self):
try:
self._commands_running.pop()
except IndexError:
pass
finally:
if len(self._commands_running) == 0:
# enable the dialog close button
self.btn_close.Enable()
self.btn_close.SetToolTip(self._DEFAULT_CLOSE_BTN_TEXT)

def OnClose(self, event=None):
"""Close dialog"""
self.Close()
Expand Down Expand Up @@ -461,7 +493,6 @@ def OnRun(self, event):
dsn = self.dsnInput.GetDsn()
if not dsn:
return
ext = self.dsnInput.GetFormatExt()

for layer, output, listId in data:
userData = {}
Expand Down Expand Up @@ -519,6 +550,7 @@ def OnRun(self, event):
):
cmd.append("--overwrite")

self._addToCommandQueue()
# run in Layer Manager
self._giface.RunCmd(
cmd, onDone=self.OnCmdDone, userData=userData, addLayer=False
Expand All @@ -527,9 +559,11 @@ def OnRun(self, event):
def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, "AddLayers"):
self._removeFromCommandQueue()
return

self.AddLayers(event.returncode, event.cmd, event.userData)
self._removeFromCommandQueue()

if event.returncode == 0 and self.closeOnFinish.IsChecked():
self.Close()
Expand Down Expand Up @@ -613,7 +647,7 @@ def OnRun(self, event):
return

if not data:
GMessage(_("No layers selected. Operation canceled."), parent=self)
GMessage(parent=self, message=_("No layers selected. Operation canceled."))
return

if not self._validateOutputMapName():
Expand Down Expand Up @@ -644,13 +678,7 @@ def OnRun(self, event):
if ext and layer.rfind(ext) > -1:
layer = layer.replace("." + ext, "")
if "|" in layer:
layer, geometry = layer.split("|", 1)
else:
geometry = None

# TODO: v.import has no geometry option
# if geometry:
# cmd.append('geometry=%s' % geometry)
layer = layer.split("|", 1)[0]

cmd = self.getSettingsPageCmd()
cmd.append("input=%s" % dsn)
Expand All @@ -670,6 +698,7 @@ def OnRun(self, event):
):
cmd.append("--overwrite")

self._addToCommandQueue()
# run in Layer Manager
self._giface.RunCmd(
cmd, onDone=self.OnCmdDone, userData=userData, addLayer=False
Expand All @@ -678,10 +707,13 @@ def OnRun(self, event):
def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, "AddLayers"):
self._removeFromCommandQueue()
return

self.AddLayers(event.returncode, event.cmd, event.userData)

self._removeFromCommandQueue()

if self.popOGR:
os.environ.pop("GRASS_VECTOR_OGR")

Expand Down Expand Up @@ -880,16 +912,20 @@ def OnRun(self, event):
):
cmd.append("--overwrite")

self._commands_running.append(True)
# run in Layer Manager
self._giface.RunCmd(cmd, onDone=self.OnCmdDone, addLayer=False)

def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, "AddLayers"):
self._removeFromCommandQueue()
return

self.AddLayers(event.returncode, event.cmd)

self._removeFromCommandQueue()

if self.closeOnFinish.IsChecked():
self.Close()

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/mapsets_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def main():
app = wx.App()
wx.App()

dlg = MapsetAccess(parent=None)
dlg.CenterOnScreen()
Expand Down
Loading
Loading