Skip to content

Commit

Permalink
Merge branch 'main' into d_rast_edit-MASK-to-mask
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasovaa authored Jan 28, 2025
2 parents a42ffaa + 71410de commit b623221
Show file tree
Hide file tree
Showing 40 changed files with 953 additions and 362 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ per-file-ignores =
gui/wxpython/image2target/g.gui.image2target.py: E501
gui/wxpython/photo2image/g.gui.photo2image.py: E501
gui/wxpython/psmap/*: E501
gui/wxpython/vdigit/*: F405, F403
gui/wxpython/animation/g.gui.animation.py: E501
gui/wxpython/tplot/g.gui.tplot.py: E501
gui/wxpython/iclass/g.gui.iclass.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 @@ -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
80 changes: 79 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/emacs.desktop
*~
*.lock
!flake.lock
*.pyc
Expand Down Expand Up @@ -68,3 +67,82 @@ lib/*/latex/
.coverage
.coverage.*
coverage.xml

# Created by https://www.toptal.com/developers/gitignore/api/windows,linux,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,macos

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos
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
Loading

0 comments on commit b623221

Please sign in to comment.