Skip to content

Commit

Permalink
style: run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
merydian authored and koebi committed Nov 29, 2024
1 parent 344d661 commit 6a717df
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 70 deletions.
13 changes: 9 additions & 4 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
)

from ORStools import (
RESOURCE_PREFIX,
PLUGIN_NAME,
DEFAULT_COLOR,
__version__,
Expand Down Expand Up @@ -166,9 +165,13 @@ def initGui(self) -> None:
self.iface.mainWindow(),
),
# About dialog
QAction(gui.GuiUtils.get_icon("icon_about.png"), self.tr("About"), self.iface.mainWindow()),
QAction(
gui.GuiUtils.get_icon("icon_about.png"), self.tr("About"), self.iface.mainWindow()
),
# Help page
QAction(gui.GuiUtils.get_icon("icon_help.png"), self.tr("Help"), self.iface.mainWindow()),
QAction(
gui.GuiUtils.get_icon("icon_help.png"), self.tr("Help"), self.iface.mainWindow()
),
]

# Create menu
Expand Down Expand Up @@ -439,7 +442,9 @@ def run_gui_control(self) -> None:
def tr(self, string: str) -> str:
return QCoreApplication.translate(str(self.__class__.__name__), string)

MAIN_WIDGET, _ = uic.loadUiType(gui.GuiUtils.get_ui_file_path('ORStoolsDialogUI.ui'))

MAIN_WIDGET, _ = uic.loadUiType(gui.GuiUtils.get_ui_file_path("ORStoolsDialogUI.ui"))


class ORStoolsDialog(QDialog, MAIN_WIDGET):
"""Define the custom behaviour of Dialog"""
Expand Down
3 changes: 2 additions & 1 deletion ORStools/gui/ORStoolsDialogConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

from ORStools.utils import configmanager, gui

CONFIG_WIDGET, _ = uic.loadUiType(gui.GuiUtils.get_ui_file_path('ORStoolsDialogConfigUI.ui'))
CONFIG_WIDGET, _ = uic.loadUiType(gui.GuiUtils.get_ui_file_path("ORStoolsDialogConfigUI.ui"))


class ORStoolsDialogConfigMain(QDialog, CONFIG_WIDGET):
"""Builds provider config dialog."""
Expand Down
4 changes: 1 addition & 3 deletions ORStools/proc/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

from qgis.core import QgsProcessingProvider

from qgis.PyQt.QtGui import QIcon

from ORStools import RESOURCE_PREFIX, PLUGIN_NAME, __version__
from ORStools import PLUGIN_NAME, __version__
from .directions_lines_proc import ORSDirectionsLinesAlgo
from .directions_points_layer_proc import ORSDirectionsPointsLayerAlgo
from .directions_points_layers_proc import ORSDirectionsPointsLayersAlgo
Expand All @@ -42,7 +41,6 @@
from ORStools.utils.gui import GuiUtils



class ORStoolsProvider(QgsProcessingProvider):
def __init__(self):
QgsProcessingProvider.__init__(self)
Expand Down
100 changes: 38 additions & 62 deletions ORStools/utils/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@
(at your option) any later version.
"""

__author__ = '(C) 2018 by Nyall Dawson'
__date__ = '20/04/2018'
__copyright__ = 'Copyright 2018, North Road'
__author__ = "(C) 2018 by Nyall Dawson"
__date__ = "20/04/2018"
__copyright__ = "Copyright 2018, North Road"
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
__revision__ = "$Format:%H$"

import math
import os
import re
from typing import (
Optional,
Union
)
from typing import Optional, Union

from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import (
Expand All @@ -30,18 +27,13 @@
QPixmap,
QFontDatabase,
QColor,
QPainter
QPainter,
)
from qgis.PyQt.QtSvg import QSvgRenderer
from qgis.PyQt.QtWidgets import (
QMenu
)
from qgis.core import (
Qgis
)
from qgis.PyQt.QtWidgets import QMenu
from qgis.core import Qgis
from qgis.utils import iface

from ORStools import RESOURCE_PREFIX
from ORStools.utils import logger

FONT_FAMILIES = ""
Expand Down Expand Up @@ -80,9 +72,9 @@ class GuiUtils:
APPLICATION_FONT_MAP = {}

@staticmethod
def set_link_color(html: str,
wrap_color=True,
color: Optional[Union[QColor, str]] = None) -> str:
def set_link_color(
html: str, wrap_color=True, color: Optional[Union[QColor, str]] = None
) -> str:
"""
Adds style tags to links in a HTML string for the standard link color
"""
Expand All @@ -92,13 +84,10 @@ def set_link_color(html: str,
else:
color_string = color.name()
else:
color_string = 'rgba(0,0,0,.3)'
res = re.sub(r'(<a href.*?)>',
r'\1 style="color: {};">'.format(color_string),
html)
color_string = "rgba(0,0,0,.3)"
res = re.sub(r"(<a href.*?)>", r'\1 style="color: {};">'.format(color_string), html)
if wrap_color:
res = '<span style="color: {};">{}</span>'.format(color_string,
res)
res = '<span style="color: {};">{}</span>'.format(color_string, res)
return res

@staticmethod
Expand All @@ -121,14 +110,10 @@ def get_icon_svg(icon: str) -> str:
:param icon: icon name (svg file name)
:return: icon svg path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'gui/img',
icon)
path = os.path.join(os.path.dirname(__file__), "..", "gui/img", icon)
logger.log(path)
if not os.path.exists(path):
return ''
return ""

return path

Expand All @@ -139,21 +124,21 @@ def get_icon_pixmap(icon: str) -> QPixmap:
:param icon: icon name (png file name)
:return: icon png path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'icons',
icon)
path = os.path.join(os.path.dirname(__file__), "..", "icons", icon)
if not os.path.exists(path):
return QPixmap()

im = QImage(path)
return QPixmap.fromImage(im)

@staticmethod
def get_svg_as_image(icon: str, width: int, height: int,
background_color: Optional[QColor] = None,
device_pixel_ratio: float = 1) -> QImage:
def get_svg_as_image(
icon: str,
width: int,
height: int,
background_color: Optional[QColor] = None,
device_pixel_ratio: float = 1,
) -> QImage:
"""
Returns an SVG returned as an image
"""
Expand All @@ -162,18 +147,17 @@ def get_svg_as_image(icon: str, width: int, height: int,
return QImage()

renderer = QSvgRenderer(path)
image = QImage(int(width * device_pixel_ratio),
int(height * device_pixel_ratio),
QImage.Format_ARGB32)
image = QImage(
int(width * device_pixel_ratio), int(height * device_pixel_ratio), QImage.Format_ARGB32
)
image.setDevicePixelRatio(device_pixel_ratio)
if not background_color:
image.fill(Qt.transparent)
else:
image.fill(background_color)

painter = QPainter(image)
painter.scale(1 / device_pixel_ratio,
1 / device_pixel_ratio)
painter.scale(1 / device_pixel_ratio, 1 / device_pixel_ratio)
renderer.render(painter)
painter.end()

Expand All @@ -186,11 +170,7 @@ def get_ui_file_path(file: str) -> str:
:param file: file name (uifile name)
:return: ui file path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'gui',
file)
path = os.path.join(os.path.dirname(__file__), "..", "gui", file)
if not os.path.exists(path):
return path

Expand All @@ -203,17 +183,18 @@ def scale_icon_size(standard_size: int) -> int:
"""
fm = QFontMetrics((QFont()))
scale = 1.1 * standard_size / 24.0
return int(math.floor(max(Qgis.UI_SCALE_FACTOR * fm.height() * scale,
float(standard_size))))
return int(
math.floor(max(Qgis.UI_SCALE_FACTOR * fm.height() * scale, float(standard_size)))
)

@staticmethod
def get_default_font() -> QFont:
"""
Returns the best font match for the Koordinates default font
families which is available on the system
"""
for family in FONT_FAMILIES.split(','):
family_cleaned = re.match(r'^\s*\'?(.*?)\'?\s*$', family).group(1)
for family in FONT_FAMILIES.split(","):
family_cleaned = re.match(r"^\s*\'?(.*?)\'?\s*$", family).group(1)
font = QFont(family_cleaned)
if font.exactMatch():
return font
Expand All @@ -227,13 +208,9 @@ def get_font_path(font: str) -> str:
:param font: font name
:return: font file path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'fonts',
font)
path = os.path.join(os.path.dirname(__file__), "..", "fonts", font)
if not os.path.exists(path):
return ''
return ""

return path

Expand Down Expand Up @@ -267,9 +244,8 @@ def get_project_import_export_menu() -> Optional[QMenu]:
pass

project_menu = iface.projectMenu()
matches = [m for m in project_menu.children()
if m.objectName() == 'menuImport_Export']
matches = [m for m in project_menu.children() if m.objectName() == "menuImport_Export"]
if matches:
return matches[0]

return None
return None

0 comments on commit 6a717df

Please sign in to comment.