Skip to content

Commit

Permalink
Fix #108
Browse files Browse the repository at this point in the history
  • Loading branch information
hypsug0 committed Feb 8, 2024
1 parent 2f5d052 commit a42afa6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 51 deletions.
86 changes: 36 additions & 50 deletions plugin_qgis_lpo/action_scripts/csv_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#####################################################

import os
import re
import webbrowser
from typing import Dict

Expand All @@ -27,6 +26,27 @@
QVBoxLayout,
)

LR_COLORS = {
"EX": "000000",
"EW": "3d1851",
"RE": "5b1a62",
"CR": "d20019",
"EN": "fabf00",
"VU": "ffed00",
"NT": "faf2c7",
"LC": "78b747",
"DD": "d4d4d4",
}


def wc_hex_is_light(color):
"""Set font color depending on fill darkness"""
red = int(color[0:2], 16)
green = int(color[2:4], 16)
blue = int(color[4:6], 16)
brightness = ((red * 299) + (green * 587) + (blue * 114)) / 1000
return "000000" if brightness > 155 else "ffffff"


class SuccessDialog(QDialog):
def __init__(self):
Expand Down Expand Up @@ -59,6 +79,7 @@ def __init__(self):
# Récupération de la couche
layer_id = "[%@layer_id%]"
layer = QgsProject().instance().mapLayer(layer_id)

# Ajout de l'entête
fields = layer.fields()
fields_row = []
Expand All @@ -77,7 +98,6 @@ def __init__(self):
feature_row.append(feature[attribute])
# print(feature_row)
ws.append(feature_row)

#####################################################
# >> 3 - Mise en forme du fichier #
#####################################################
Expand All @@ -98,55 +118,23 @@ def __init__(self):

# >> 3.2 - Couleur sur les cases de type statut

# >> Définition du style
blackFill = PatternFill(start_color="000000", end_color="000000", fill_type="solid")
purpleFill = PatternFill(start_color="3d1851", end_color="3d1851", fill_type="solid")
lpurpleFill = PatternFill(start_color="5b1a62", end_color="5b1a62", fill_type="solid")
redFill = PatternFill(start_color="d20019", end_color="d20019", fill_type="solid")
orangeFill = PatternFill(start_color="fabf00", end_color="fabf00", fill_type="solid")
yellowFill = PatternFill(start_color="ffed00", end_color="ffed00", fill_type="solid")
beigeFill = PatternFill(start_color="faf2c7", end_color="faf2c7", fill_type="solid")
greenFill = PatternFill(start_color="78b747", end_color="78b747", fill_type="solid")
grey2Fill = PatternFill(start_color="d4d4d4", end_color="d4d4d4", fill_type="solid")


# >> Définition de la fonction d'application des couleurs selon le statut
def color_statut_style(x):
for cell in ws[x]:
if re.match("EX", cell.value):
cell.fill = blackFill
elif re.match("EW", cell.value):
cell.fill = purpleFill
elif re.match("RE", cell.value):
cell.fill = lpurpleFill
elif re.match("CR", cell.value):
cell.fill = redFill
elif re.match("EN", cell.value):
cell.fill = orangeFill
elif re.match("VU", cell.value):
cell.fill = yellowFill
elif re.match("NT", cell.value):
cell.fill = beigeFill
elif re.match("LC", cell.value):
cell.fill = greenFill
elif re.match("DD", cell.value):
cell.fill = grey2Fill
"""set RedList color style"""
for lr_cell in ws[x]:
if lr_cell.value in LR_COLORS.keys():
color = LR_COLORS[lr_cell.value]
lr_cell.fill = PatternFill(
start_color=color, end_color=color, fill_type="solid"
)
lr_cell.font = Font(color=wc_hex_is_light(color))


# >> Recherche des colonnes de type statut
# Rechercher la colonne "LR France", "LR Rhône-Alpes", "LR Auvergne" # d'autres colonnes à prévoir
for col in ws["1:1"]:
if col.value == "LR France":
# Si on trouve une colonne référente alors :
range_statut = col
ref_statut = range_statut.column_letter + ":" + range_statut.column_letter
color_statut_style(ref_statut)
elif col.value == "LR Rhône-Alpes":
# Si on trouve une colonne référente alors :
range_statut = col
ref_statut = range_statut.column_letter + ":" + range_statut.column_letter
color_statut_style(ref_statut)
elif col.value == "LR Auvergne":
if col.value.startswith("LR "):
# Si on trouve une colonne référente alors :
range_statut = col
ref_statut = range_statut.column_letter + ":" + range_statut.column_letter
Expand All @@ -155,11 +143,9 @@ def color_statut_style(x):
# >> 3.3 - Style général des colonnes

# >> Mise en gras des noms de colonnes
col_name_font = Font(bold=True, italic=False, vertAlign=None, color="ffffff", size=12)
blueLPO = PatternFill(start_color="0076bd", end_color="0076bd", fill_type="solid")
for cell in ws["1:1"]:
cell.font = col_name_font
cell.fill = blueLPO
cell.font = Font(bold=True, italic=False, vertAlign=None, color="ffffff", size=12)
cell.fill = PatternFill(start_color="0076bd", end_color="0076bd", fill_type="solid")

# >> Mise en forme de la largeur des colonnes
dims: Dict[str, int] = {}
Expand All @@ -180,9 +166,9 @@ def color_statut_style(x):
# Définition d'une fonction qui parcourt les cellules et applique le style de bordure choisie
def set_border(ws, cell_range):
border = Border(bottom=Side(border_style="thin", color="0076bd"))
for row in ws[cell_range]:
for cell in row:
cell.border = border
for line in ws[cell_range]:
for rcell in line:
rcell.border = border


# Obtenir les dimensions du tableau
Expand Down
2 changes: 1 addition & 1 deletion plugin_qgis_lpo/processing/summary_table_per_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(self) -> None:
synthese AS (
SELECT DISTINCT
d.cd_ref
, vn_id
, array_to_string(vn_id,', ') as vn_id
, nom_rang AS "Rang"
, d.groupe_taxo AS "Groupe taxo"
, nom_vern AS "Nom vernaculaire"
Expand Down

0 comments on commit a42afa6

Please sign in to comment.