Skip to content

Commit

Permalink
Merge pull request #7 from JanCaha/refactor_ramps
Browse files Browse the repository at this point in the history
Refactor ramps
  • Loading branch information
JanCaha authored Nov 10, 2024
2 parents e26fa1f + 46c06f9 commit ed99920
Show file tree
Hide file tree
Showing 50 changed files with 1,337 additions and 1,131 deletions.
60 changes: 52 additions & 8 deletions .github/workflows/test_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,68 @@ on:
- "tests/**"
- ".github/workflows/test_plugin.yaml"

env:
DEBIAN_FRONTEND: noninteractive
QT_QPA_PLATFORM: offscreen
XDG_RUNTIME_DIR: /tmp
PYTHONPATH: /usr/share/qgis/python/plugins:/usr/share/qgis/python:./qgis-plugin-bivariate-renderer

jobs:

Tests-plugin-BivariateRenderer:

runs-on: ubuntu-latest

container: cahik/vscode-ubuntu-qgis-testing:v2
runs-on: ubuntu-24.04

steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Print dir
run: dir
- name: Prepare QGIS
run: |
sudo gpg -k && \
KEYRING=/usr/share/keyrings/qgis-archive-keyring.gpg && \
wget -O $KEYRING https://download.qgis.org/downloads/qgis-archive-keyring.gpg && \
sudo touch /etc/apt/sources.list.d/qgis.sources && \
echo 'Types: deb deb-src' | sudo tee -a /etc/apt/sources.list.d/qgis.sources && \
echo 'URIs: https://qgis.org/ubuntugis' | sudo tee -a /etc/apt/sources.list.d/qgis.sources && \
echo 'Suites: '$(lsb_release -c -s) | sudo tee -a /etc/apt/sources.list.d/qgis.sources && \
echo 'Architectures: '$(dpkg --print-architecture) | sudo tee -a /etc/apt/sources.list.d/qgis.sources && \
echo 'Components: main' | sudo tee -a /etc/apt/sources.list.d/qgis.sources && \
echo 'Signed-By: '$KEYRING | sudo tee -a /etc/apt/sources.list.d/qgis.sources && \
LASTSUPPORTED=focal && \
KEYRING=/usr/share/keyrings/ubuntugis-archive-keyring.gpg && \
sudo gpg --no-default-keyring --keyring $KEYRING --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 6B827C12C2D425E227EDCA75089EBE08314DF160 && \
sudo touch /etc/apt/sources.list.d/ubuntugis-unstable.sources && \
echo 'Types: deb deb-src' | sudo tee -a /etc/apt/sources.list.d/ubuntugis-unstable.sources && \
echo 'URIs:https://ppa.launchpadcontent.net/ubuntugis/ubuntugis-unstable/ubuntu' | sudo tee -a /etc/apt/sources.list.d/ubuntugis-unstable.sources && \
echo 'Suites: '$(lsb_release -c -s)| sudo tee -a /etc/apt/sources.list.d/ubuntugis-unstable.sources && \
echo 'Architectures: '$(dpkg --print-architecture) | sudo tee -a /etc/apt/sources.list.d/ubuntugis-unstable.sources && \
echo 'Components: main' | sudo tee -a /etc/apt/sources.list.d/ubuntugis-unstable.sources && \
echo 'Signed-By: '$KEYRING | sudo tee -a /etc/apt/sources.list.d/ubuntugis-unstable.sources
- name: Install
run: |
sudo apt-get update && \
sudo apt-get -y -q install --no-install-recommends wget software-properties-common build-essential ca-certificates python3-pip dialog apt-utils && \
sudo apt -y -q install qgis qgis-dev qgis-plugin-grass
- name: Install Python packages
run: |
pip install --no-cache-dir pytest pytest-qgis pytest-cov pillow flake8 mypy pycodestyle pb_tool pytest-qt pixelmatch --break-system-packages
- name: Print Dir
run: |
ls -la
- name: Run tests
run: |
PYTHONPATH=$PYTHONPATH:./qgis-plugin-bivariate-renderer
pytest tests --cov=BivariateRenderer --cov-report=term-missing:skip-covered -rP -vv -s --ignore=tests/tests_visual_result_generation
pytest tests --cov=BivariateRenderer --cov-report=term-missing:skip-covered -rP -vv -s --ignore=tests/tests_visual_result_generation
- name: Upload Artifact
if: failure()
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: artifacts
path: /tmp/images_diff
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

35 changes: 7 additions & 28 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,16 @@
"**/.pytest_cache": true,
"**/.mypy_cache": true
},
"python.analysis.extraPaths": [
"/usr/share/qgis/python/plugins",
"/usr/share/qgis/python"
],
"python.linting.pycodestyleEnabled": true,
"python.linting.pycodestyleArgs": [
"--max-line-length=160",
"--ignore=W293,W504"
],
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length=160",
"--ignore=W293,W504"
],
"python.linting.mypyEnabled": true,
"python.linting.mypyArgs": [
"--follow-imports=silent",
"--ignore-missing-imports",
"--show-column-numbers",
"--no-pretty",
"--no-strict-optional"
],
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
"--style",
"{based_on_style: google, indent_width: 4, column_limit=99}"
],
"svg.preview.background": "custom",
"python.testing.pytestArgs": [
"tests",
"-rP"
],
"python.testing.pytestEnabled": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
},
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"label": "Run Pytest image generation",
"type": "shell",
"command": "BIVARIATE_GENERATE=True pytest tests/tests_visual_result_generation -rP -vv -s",
"command": "BIVARIATE_GENERATE=True QT_QPA_PLATFORM=offscreen pytest tests/tests_visual_result_generation -rP -vv -s",
"group": {
"kind": "test",
"isDefault": false
Expand Down
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
Loading

0 comments on commit ed99920

Please sign in to comment.