Skip to content

Commit

Permalink
black + isort
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha committed Nov 10, 2024
1 parent 164ba58 commit 662bf69
Show file tree
Hide file tree
Showing 24 changed files with 704 additions and 607 deletions.
1 change: 1 addition & 0 deletions BivariateRenderer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ def classFactory(iface): # pylint: disable=invalid-name
"""
#
from .bivariate_renderer_plugin import BivariateRendererPlugin

return BivariateRendererPlugin(iface)
11 changes: 4 additions & 7 deletions BivariateRenderer/bivariate_renderer_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
from qgis.core import QgsApplication
from qgis.gui import QgsGui

from .renderer.bivariate_renderer_metadata import BivariateRendererMetadata

from .bivariate_renderer_provider import BivariateRendererProvider
from .layoutitems.layout_item import BivariateRendererLayoutItemMetadata
from .layoutitems.layout_item_widget import BivariateRendererLayoutItemGuiMetadata
from .bivariate_renderer_provider import BivariateRendererProvider
from .renderer.bivariate_renderer_metadata import BivariateRendererMetadata


class BivariateRendererPlugin:
Expand All @@ -45,17 +44,15 @@ def __init__(self, iface):
self.bivariate_renderer_layout_item_metadata = BivariateRendererLayoutItemMetadata()

# TODO disconnect
QgsApplication.layoutItemRegistry().addLayoutItemType(
self.bivariate_renderer_layout_item_metadata)
QgsApplication.layoutItemRegistry().addLayoutItemType(self.bivariate_renderer_layout_item_metadata)

def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""

QgsApplication.rendererRegistry().addRenderer(self.bivariate_renderer_metadata)

# TODO disconnect
QgsGui.layoutItemGuiRegistry().addLayoutItemGuiMetadata(
self.bivariate_renderer_layout_item_gui_metadata)
QgsGui.layoutItemGuiRegistry().addLayoutItemGuiMetadata(self.bivariate_renderer_layout_item_gui_metadata)

self.initProcessing()

Expand Down
4 changes: 2 additions & 2 deletions BivariateRenderer/bivariate_renderer_provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path

from qgis.core import QgsProcessingProvider
from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsProcessingProvider
from BivariateRenderer.tools.tool_calculate_categories import CalculateCategoriesAlgorithm


Expand Down Expand Up @@ -33,7 +33,7 @@ def id(self):
string should be a unique, short, character only string, eg "qgis" or
"gdal". This string should not be localised.
"""
return 'bivariatepolygonrenderer'
return "bivariatepolygonrenderer"

def name(self):
"""
Expand Down
21 changes: 13 additions & 8 deletions BivariateRenderer/colormixing/color_mixing_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def name(self) -> str:

def mix_colors(self, color1: QColor, color2: QColor) -> QColor:

return QColor(int((color1.red() + color2.red()) / 2),
int((color1.green() + color2.green()) / 2),
int((color1.blue() + color2.blue()) / 2))
return QColor(
int((color1.red() + color2.red()) / 2),
int((color1.green() + color2.green()) / 2),
int((color1.blue() + color2.blue()) / 2),
)


class ColorMixingMethodDarken(ColorMixingMethod):
Expand All @@ -39,8 +41,9 @@ def name(self) -> str:

def mix_colors(self, color1: QColor, color2: QColor) -> QColor:

return QColor(min(color1.red(), color2.red()), min(color1.green(), color2.green()),
min(color1.blue(), color2.blue()))
return QColor(
min(color1.red(), color2.red()), min(color1.green(), color2.green()), min(color1.blue(), color2.blue())
)


class ColorMixingMethodMultiply(ColorMixingMethod):
Expand All @@ -53,6 +56,8 @@ def name(self) -> str:

def mix_colors(self, color1: QColor, color2: QColor) -> QColor:

return QColor(int((color1.redF() * color2.redF()) * 255),
int((color1.greenF() * color2.greenF()) * 255),
int((color1.blueF() * color2.blueF()) * 255))
return QColor(
int((color1.redF() * color2.redF()) * 255),
int((color1.greenF() * color2.greenF()) * 255),
int((color1.blueF() * color2.blueF()) * 255),
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import List, Optional

from ..utils import Singleton
from .color_mixing_method import (ColorMixingMethodDirect, ColorMixingMethodDarken,
ColorMixingMethod, ColorMixingMethodMultiply)
from .color_mixing_method import (
ColorMixingMethod,
ColorMixingMethodDarken,
ColorMixingMethodDirect,
ColorMixingMethodMultiply,
)


class ColorMixingMethodsRegister(metaclass=Singleton):
Expand Down
24 changes: 16 additions & 8 deletions BivariateRenderer/colorramps/color_ramps_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
from qgis.PyQt.QtGui import QIcon

from ..utils import Singleton
from .bivariate_color_ramp import (BivariateColorRamp, BivariateColorRampBlueGreen,
BivariateColorRampCyanBrow, BivariateColorRampCyanViolet,
BivariateColorRampGreenPink, BivariateColorRampGreenPurple,
BivariateColorRampLigthYellowPurple,
BivariateColorRampOrangeBlue, BivariateColorRampOrangePurple,
BivariateColorRampPinkBlue, BivariateColorRampTurquoiseGold,
BivariateColorRampVioletBlue, BivariateColorRampYellowBlue)
from .bivariate_color_ramp import (
BivariateColorRamp,
BivariateColorRampBlueGreen,
BivariateColorRampCyanBrow,
BivariateColorRampCyanViolet,
BivariateColorRampGreenPink,
BivariateColorRampGreenPurple,
BivariateColorRampLigthYellowPurple,
BivariateColorRampOrangeBlue,
BivariateColorRampOrangePurple,
BivariateColorRampPinkBlue,
BivariateColorRampTurquoiseGold,
BivariateColorRampVioletBlue,
BivariateColorRampYellowBlue,
)


class BivariateColorRampsRegister(metaclass=Singleton):
Expand All @@ -27,7 +35,7 @@ class BivariateColorRampsRegister(metaclass=Singleton):
BivariateColorRampPinkBlue(),
BivariateColorRampTurquoiseGold(),
BivariateColorRampVioletBlue(),
BivariateColorRampYellowBlue()
BivariateColorRampYellowBlue(),
]

@property
Expand Down
88 changes: 44 additions & 44 deletions BivariateRenderer/layoutitems/layout_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def __init__(self, layout: QgsLayout):
self.ticks_use_category_midpoints = False

self.symbol_rectangle_without_values = load_symbol_xml(
Path(__file__).parent.parent / "data" / "empty_rectangle_fill_symbol.xml")
Path(__file__).parent.parent / "data" / "empty_rectangle_fill_symbol.xml"
)

self.replace_rectangle_without_values = False
self.use_rectangle_without_values_color_from_legend = False
Expand Down Expand Up @@ -147,7 +148,9 @@ def to_legend_renderer(self) -> LegendRenderer:
legend_render.use_category_midpoints = self.ticks_use_category_midpoints

legend_render.replace_rectangle_without_values = self.replace_rectangle_without_values
legend_render.use_rectangle_without_values_color_from_legend = self.use_rectangle_without_values_color_from_legend
legend_render.use_rectangle_without_values_color_from_legend = (
self.use_rectangle_without_values_color_from_legend
)
legend_render.symbol_rectangle_without_values = self.symbol_rectangle_without_values

return legend_render
Expand All @@ -162,36 +165,30 @@ def draw(self, context: QgsLayoutItemRenderContext) -> None:

if self.renderer:

legend_render.render_legend(render_context, item_size.width(), item_size.height(),
self.renderer)
legend_render.render_legend(render_context, item_size.width(), item_size.height(), self.renderer)

def writePropertiesToElement(self, bivariate_legend_element: QDomElement, doc: QDomDocument,
context: QgsReadWriteContext) -> bool:
def writePropertiesToElement(
self, bivariate_legend_element: QDomElement, doc: QDomDocument, context: QgsReadWriteContext
) -> bool:

bivariate_legend_element.setAttribute("axis_x_name", self.text_axis_x)
bivariate_legend_element.setAttribute("axis_y_name", self.text_axis_y)

bivariate_legend_element.setAttribute("legend_rotated", str(self.legend_rotated))
bivariate_legend_element.setAttribute("draw_axes_text", str(self.add_axes_texts))
bivariate_legend_element.setAttribute("draw_axes_arrow", str(self.add_axes_arrows))
bivariate_legend_element.setAttribute("draw_axes_values_texts",
str(self.add_axes_values_texts))
bivariate_legend_element.setAttribute("draw_axes_values_texts", str(self.add_axes_values_texts))
bivariate_legend_element.setAttribute("y_axis_rotation", str(self.y_axis_rotation))
bivariate_legend_element.setAttribute("ticks_x_precision", str(self.ticks_x_precision))
bivariate_legend_element.setAttribute("ticks_y_precision", str(self.ticks_y_precision))
bivariate_legend_element.setAttribute("space_above_ticks", str(self.space_above_ticks))
bivariate_legend_element.setAttribute("ticks_use_category_midpoints",
str(self.ticks_use_category_midpoints))

bivariate_legend_element.setAttribute("draw_colors_separators",
str(self.add_colors_separators))
bivariate_legend_element.setAttribute("color_separator_width",
str(self.color_separator_width))
bivariate_legend_element.setAttribute("color_separator_color",
self.color_separator_color.name())

bivariate_legend_element.setAttribute("arrows_common_start_point",
str(self.arrows_common_start_point))
bivariate_legend_element.setAttribute("ticks_use_category_midpoints", str(self.ticks_use_category_midpoints))

bivariate_legend_element.setAttribute("draw_colors_separators", str(self.add_colors_separators))
bivariate_legend_element.setAttribute("color_separator_width", str(self.color_separator_width))
bivariate_legend_element.setAttribute("color_separator_color", self.color_separator_color.name())

bivariate_legend_element.setAttribute("arrows_common_start_point", str(self.arrows_common_start_point))
bivariate_legend_element.setAttribute("arrow_width", str(self.arrow_width))

line_symbol = doc.createElement("lineSymbol")
Expand All @@ -214,16 +211,14 @@ def writePropertiesToElement(self, bivariate_legend_element: QDomElement, doc: Q

bivariate_legend_element.appendChild(text_axes_values_format)

bivariate_legend_element.setAttribute("replace_empty_rectangles",
str(self.replace_rectangle_without_values))
bivariate_legend_element.setAttribute("replace_empty_rectangles", str(self.replace_rectangle_without_values))
bivariate_legend_element.setAttribute(
"empty_rectangle_use_legend_color",
str(self.use_rectangle_without_values_color_from_legend))
"empty_rectangle_use_legend_color", str(self.use_rectangle_without_values_color_from_legend)
)

empty_polygon_symbol_elem = doc.createElement("emptyPolygonSymbol")

symbol_elem = QgsSymbolLayerUtils.saveSymbol("", self.symbol_rectangle_without_values, doc,
context)
symbol_elem = QgsSymbolLayerUtils.saveSymbol("", self.symbol_rectangle_without_values, doc, context)

empty_polygon_symbol_elem.appendChild(symbol_elem)

Expand All @@ -234,8 +229,9 @@ def writePropertiesToElement(self, bivariate_legend_element: QDomElement, doc: Q

return True

def readPropertiesFromElement(self, element: QDomElement, document: QDomDocument,
context: QgsReadWriteContext) -> bool:
def readPropertiesFromElement(
self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext
) -> bool:

if self.linked_layer:
self.layer = None
Expand Down Expand Up @@ -270,8 +266,7 @@ def readPropertiesFromElement(self, element: QDomElement, document: QDomDocument
self.ticks_y_precision = int(element.attribute("ticks_y_precision"))

self.space_above_ticks = int(element.attribute("space_above_ticks"))
self.ticks_use_category_midpoints = element.attribute(
"ticks_use_category_midpoints") == "True"
self.ticks_use_category_midpoints = element.attribute("ticks_use_category_midpoints") == "True"

self.legend_rotated = element.attribute("legend_rotated") == "True"

Expand All @@ -298,10 +293,10 @@ def readPropertiesFromElement(self, element: QDomElement, document: QDomDocument
self.color_separator_width = int(element.attribute("color_separator_width"))
self.color_separator_color = QColor(element.attribute("color_separator_color"))

self.replace_rectangle_without_values = element.attribute(
"replace_empty_rectangles") == "True"
self.use_rectangle_without_values_color_from_legend = element.attribute(
"empty_rectangle_use_legend_color") == "True"
self.replace_rectangle_without_values = element.attribute("replace_empty_rectangles") == "True"
self.use_rectangle_without_values_color_from_legend = (
element.attribute("empty_rectangle_use_legend_color") == "True"
)

empty_polygon_symbol_elem = element.firstChildElement("emptyPolygonSymbol")

Expand All @@ -325,8 +320,9 @@ def set_y_axis_rotation(self, rotation: float) -> None:

self.refresh()

def set_axis_texts_settings(self, draw: bool, text_format: QgsTextFormat, axis_x_text: str,
axis_y_text: str) -> None:
def set_axis_texts_settings(
self, draw: bool, text_format: QgsTextFormat, axis_x_text: str, axis_y_text: str
) -> None:
self.text_format = text_format
self.add_axes_texts = draw
self.text_axis_x = axis_x_text
Expand All @@ -343,8 +339,15 @@ def are_labels_default(self) -> bool:

return self.text_axis_x == "Axis X" and self.text_axis_y == "Axis Y"

def set_ticks_settings(self, draw: bool, text_format: QgsTextFormat, use_midpoint: bool,
axis_x_precision: int, axis_y_precision: int, space_above: int) -> None:
def set_ticks_settings(
self,
draw: bool,
text_format: QgsTextFormat,
use_midpoint: bool,
axis_x_precision: int,
axis_y_precision: int,
space_above: int,
) -> None:
self.add_axes_values_texts = draw
self.text_values_format = text_format
self.ticks_use_category_midpoints = use_midpoint
Expand All @@ -361,17 +364,15 @@ def set_color_separator_settings(self, draw: bool, color: QColor, width: float)

self.refresh()

def set_arrows_settings(self, draw: bool, line_format: QgsLineSymbol, use_common_point: bool,
width: float) -> None:
def set_arrows_settings(self, draw: bool, line_format: QgsLineSymbol, use_common_point: bool, width: float) -> None:
self.add_axes_arrows = draw
self.arrows_common_start_point = use_common_point
self.arrow_width = width
self.line_format = line_format.clone()

self.refresh()

def set_rectangle_without_values_settings(self, use: bool, symbol: QgsFillSymbol,
color_from_legend: bool) -> None:
def set_rectangle_without_values_settings(self, use: bool, symbol: QgsFillSymbol, color_from_legend: bool) -> None:

self.symbol_rectangle_without_values = symbol
self.replace_rectangle_without_values = use
Expand Down Expand Up @@ -415,8 +416,7 @@ def beginCommand(self, commandText: str, command) -> None:
class BivariateRendererLayoutItemMetadata(QgsLayoutItemAbstractMetadata):

def __init__(self):
super().__init__(IDS.plot_item_bivariate_renderer_legend,
Texts.plot_item_bivariate_renderer)
super().__init__(IDS.plot_item_bivariate_renderer_legend, Texts.plot_item_bivariate_renderer)

def createItem(self, layout):
return BivariateRendererLayoutItem(layout)
Loading

0 comments on commit 662bf69

Please sign in to comment.