Skip to content

Commit

Permalink
Merge branch 'main' into small-MASK-to-mask-replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix authored Jan 28, 2025
2 parents b7364e9 + 8ea57d6 commit c56b193
Show file tree
Hide file tree
Showing 34 changed files with 782 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# renovate: datasource=pypi depName=bandit
BANDIT_VERSION: "1.8.2"
# renovate: datasource=pypi depName=ruff
RUFF_VERSION: "0.9.2"
RUFF_VERSION: "0.9.3"

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.9.2
rev: v0.9.3
hooks:
# Run the linter.
- id: ruff
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/animation/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
HashCmds,
)
from animation.data import AnimationData
from itertools import starmap


class AnimationController(wx.EvtHandler):
Expand Down Expand Up @@ -369,7 +368,7 @@ def _updateAnimations(self, activeIndices, mapNamesDict=None):
if anim.viewMode == "3d":
regions = [None] * len(regions)
self.animations[i].SetFrames(
list(starmap(HashCmds, zip(anim.cmdMatrix, regions)))
list(map(HashCmds, anim.cmdMatrix, regions))
)
self.animations[i].SetActive(True)
else:
Expand Down
26 changes: 23 additions & 3 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import time
import traceback
from threading import Thread
from typing import TYPE_CHECKING, TextIO
from typing import TYPE_CHECKING, AnyStr, TextIO, overload

import wx
from core.debug import Debug
Expand All @@ -59,7 +59,17 @@
from io import TextIOWrapper


def DecodeString(string):
@overload
def DecodeString(string: AnyStr) -> AnyStr | str:
pass


@overload
def DecodeString(string: None) -> None:
pass


def DecodeString(string: AnyStr | None) -> AnyStr | str | None:
"""Decode string using system encoding
:param string: string to be decoded
Expand All @@ -75,7 +85,17 @@ def DecodeString(string):
return string


def EncodeString(string):
@overload
def EncodeString(string: str) -> bytes | str:
pass


@overload
def EncodeString(string: None) -> None:
pass


def EncodeString(string: str | None) -> bytes | str | None:
"""Return encoded string using system locales
:param string: string to be encoded
Expand Down
19 changes: 13 additions & 6 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@author Jachym Cepicky
"""

from __future__ import annotations

import os
import sys
import platform
Expand All @@ -21,6 +23,8 @@
import inspect
import operator
from string import digits
from typing import TYPE_CHECKING


from grass.script import core as grass
from grass.script import task as gtask
Expand All @@ -31,6 +35,11 @@
from core.globalvar import wxPythonPhoenix


if TYPE_CHECKING:
import wx
import PIL.Image


def cmp(a, b):
"""cmp function"""
return (a > b) - (a < b)
Expand Down Expand Up @@ -862,12 +871,10 @@ def StoreEnvVariable(key, value=None, envFile=None):
return
expCmd = "set" if windows else "export"

for key, value in environ.items():
fd.write("%s %s=%s\n" % (expCmd, key, value))
fd.writelines("%s %s=%s\n" % (expCmd, key, value) for key, value in environ.items())

# write also skipped lines
for line in lineSkipped:
fd.write(line + os.linesep)
fd.writelines(line + os.linesep for line in lineSkipped)

fd.close()

Expand Down Expand Up @@ -1011,7 +1018,7 @@ def GetGEventAttribsForHandler(method, event):
return kwargs, missing_args


def PilImageToWxImage(pilImage, copyAlpha=True):
def PilImageToWxImage(pilImage: PIL.Image.Image, copyAlpha: bool = True) -> wx.Image:
"""Convert PIL image to wx.Image
Based on http://wiki.wxpython.org/WorkingWithImages
Expand Down Expand Up @@ -1040,7 +1047,7 @@ def PilImageToWxImage(pilImage, copyAlpha=True):
return wxImage


def autoCropImageFromFile(filename):
def autoCropImageFromFile(filename) -> wx.Image:
"""Loads image from file and crops it automatically.
If PIL is not installed, it does not crop it.
Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ def SetSrcEnv(self, location, mapset):

try:
f = open(self.source_gisrc, mode="w")
for line in self.gisrc_dict.items():
f.write(line[0] + ": " + line[1] + "\n")
f.writelines(
line[0] + ": " + line[1] + "\n" for line in self.gisrc_dict.items()
)
finally:
f.close()

Expand Down Expand Up @@ -2769,8 +2770,7 @@ def MakeVGroup(self):

f = open(self.vgrpfile, mode="w")
try:
for vect in vgrouplist:
f.write(vect + "\n")
f.writelines(vect + "\n" for vect in vgrouplist)
finally:
f.close()

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ def WriteModelFile(self, filename):
try:
mfile = open(filename, "w")
tmpfile.seek(0)
for line in tmpfile.readlines():
mfile.write(line)
mfile.writelines(tmpfile.readlines())
except OSError:
wx.MessageBox(
parent=self,
Expand Down
18 changes: 10 additions & 8 deletions gui/wxpython/gui_core/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@author Anna Petrasova <kratochanna gmail.com>
"""

from __future__ import annotations

import sys
import wx
import wx.lib.agw.floatspin as fs
Expand Down Expand Up @@ -80,7 +82,7 @@ def convertToInt(argsOrKwargs, roundVal=False):
return result


def IsDark():
def IsDark() -> bool:
"""Detects if used theme is dark.
Wraps wx method for different versions."""

Expand All @@ -96,25 +98,25 @@ def luminance(c):
return luminance(fg) - luminance(bg) > 0.2


def BitmapFromImage(image, depth=-1):
def BitmapFromImage(image: wx.Image, depth=-1) -> wx.Bitmap:
if wxPythonPhoenix:
return wx.Bitmap(img=image, depth=depth)
return wx.BitmapFromImage(image, depth=depth)


def ImageFromBitmap(bitmap):
def ImageFromBitmap(bitmap: wx.Bitmap) -> wx.Image:
if wxPythonPhoenix:
return bitmap.ConvertToImage()
return wx.ImageFromBitmap(bitmap)


def EmptyBitmap(width, height, depth=-1):
def EmptyBitmap(width, height, depth=-1) -> wx.Bitmap:
if wxPythonPhoenix:
return wx.Bitmap(width=width, height=height, depth=depth)
return wx.EmptyBitmap(width=width, height=height, depth=depth)


def EmptyImage(width, height, clear=True):
def EmptyImage(width, height, clear=True) -> wx.Image:
if wxPythonPhoenix:
return wx.Image(width=width, height=height, clear=clear)
return wx.EmptyImage(width=width, height=height, clear=clear)
Expand Down Expand Up @@ -680,17 +682,17 @@ def __init__(self, *args, **kwargs):
kwargs = convertToInt(argsOrKwargs=kwargs)
wx.Rect.__init__(self, *args, **kwargs)

def ContainsXY(self, x, y):
def ContainsXY(self, x: float, y: float) -> bool:
if wxPythonPhoenix:
return wx.Rect.Contains(self, x=int(x), y=int(y))
return wx.Rect.ContainsXY(self, int(x), int(y))

def ContainsRect(self, rect):
def ContainsRect(self, rect: wx.Rect) -> bool:
if wxPythonPhoenix:
return wx.Rect.Contains(self, rect=rect)
return wx.Rect.ContainsRect(self, rect)

def OffsetXY(self, dx, dy):
def OffsetXY(self, dx: float, dy: float) -> wx.Rect:
if wxPythonPhoenix:
return wx.Rect.Offset(self, int(dx), int(dy))
return wx.Rect.OffsetXY(self, int(dx), int(dy))
Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ def SetSrcEnv(self, location, mapset):

try:
f = open(self.source_gisrc, mode="w")
for line in self.gisrc_dict.items():
f.write(line[0] + ": " + line[1] + "\n")
f.writelines(
line[0] + ": " + line[1] + "\n" for line in self.gisrc_dict.items()
)
finally:
f.close()

Expand Down Expand Up @@ -2709,8 +2710,7 @@ def MakeVGroup(self):

f = open(self.vgrpfile, mode="w")
try:
for vect in vgrouplist:
f.write(vect + "\n")
f.writelines(vect + "\n" for vect in vgrouplist)
finally:
f.close()

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/lmgr/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ def SaveToFile(self, filename):
try:
mfile = open(filename, "wb")
tmpfile.seek(0)
for line in tmpfile.readlines():
mfile.write(line)
mfile.writelines(tmpfile.readlines())
except OSError:
GError(
parent=self.lmgr,
Expand Down
39 changes: 20 additions & 19 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,30 @@
from typing import TYPE_CHECKING

from core import globalvar

# isort: split
import wx
import wx.aui

from mapdisp.toolbars import MapToolbar, NvizIcons
from mapdisp.gprint import PrintOptions
from core.gcmd import GError, GMessage, RunCommand
from core.utils import ListOfCatsToRange, GetLayerNameFromCmd
from gui_core.dialogs import GetImageHandlers, ImageSizeDialog
from core.debug import Debug
from core.gcmd import GError, GMessage, RunCommand
from core.giface import Notification
from core.settings import UserSettings
from gui_core.mapdisp import SingleMapPanel, FrameMixin
from gui_core.query import QueryDialog, PrepareQueryResults
from core.utils import GetLayerNameFromCmd, ListOfCatsToRange
from gui_core.dialogs import GetImageHandlers, ImageSizeDialog
from gui_core.forms import GUI
from gui_core.mapdisp import FrameMixin, SingleMapPanel
from gui_core.query import PrepareQueryResults, QueryDialog
from gui_core.vselect import VectorSelectBase, VectorSelectHighlighter
from gui_core.wrap import Menu
from main_window.page import MainPageBase
from mapdisp import statusbar as sb
from mapdisp.gprint import PrintOptions
from mapdisp.toolbars import MapToolbar, NvizIcons
from mapwin.analysis import (
MeasureAreaController,
MeasureDistanceController,
ProfileController,
)
from mapwin.buffered import BufferedMapWindow
from mapwin.decorations import (
ArrowController,
Expand All @@ -49,17 +61,6 @@
LegendController,
LegendVectController,
)
from mapwin.analysis import (
MeasureAreaController,
MeasureDistanceController,
ProfileController,
)
from gui_core.forms import GUI
from core.giface import Notification
from gui_core.vselect import VectorSelectBase, VectorSelectHighlighter
from gui_core.wrap import Menu
from mapdisp import statusbar as sb
from main_window.page import MainPageBase

import grass.script as gs
from grass.pydispatch.signal import Signal
Expand Down
Loading

0 comments on commit c56b193

Please sign in to comment.