1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
|
# coding:utf-8
#version 3.x python
# ---------------------------------------------------------
# Modules
# ---------------------------------------------------------
import sys
import os.path
from os import path
from tkinter import *
from tkinter.ttk import *
def TABLES(Liste_Full, Liste_Somme, Liste_Indices_Finaux, Nom_Rec, Liste_Ajouts1, Liste_Ajouts2, Liste_Ajouts3, Liste_Ajouts4, Liste_Ajouts5, Liste_Ajouts6, Liste_Ajouts7, Liste_Ajouts8, Qt_TT_Recette, prix):
print("\n" + "<--- Liste des information nécessaire pour le PDF_Build --->")
print("<---> Nom_Recette ", Nom_Rec.get())
print("<---> Liste_Full ", Liste_Full)
print("<---> Liste_Somme ", Liste_Somme)
print("<---> Liste_Indices_Finaux ", Liste_Indices_Finaux)
print("<---> Liste_Ajouts1 ", Liste_Ajouts1)
print("<---> Liste_Ajouts2 ", Liste_Ajouts2)
print("<---> Liste_Ajouts3 ", Liste_Ajouts3)
print("<---> Liste_Ajouts4 ", Liste_Ajouts4)
print("<---> Liste_Ajouts5 ", Liste_Ajouts5)
print("<---> Liste_Ajouts6 ", Liste_Ajouts6)
print("<---> Liste_Ajouts7 ", Liste_Ajouts7)
print("<---> Liste_Ajouts8 ", Liste_Ajouts8)
print("<---> Poids Recette ", Qt_TT_Recette)
print("<---> Prix Recette ", prix)
print("\n")
# Référence les HV sans Prix
HV_NoPrix = []
HV_NoPrix[:] = []
for u in range(0, len(Liste_Full)):
# print("HV", Liste_Full[u][0], " Prix", Liste_Full[u][24])
if Liste_Full[u][24] == 0:
HV_NoPrix.append(Liste_Full[u][0])
# print("HV_NoPrix - Huile sans prix", HV_NoPrix) # ex : ['Babassu', 'Arachide', 'Amande douce']
Liste_HV_wo_Price = StringVar()
Liste_HV_wo_Price = ""
for u in range(0, len(HV_NoPrix)):
Liste_HV_wo_Price = Liste_HV_wo_Price + " " + HV_NoPrix[u]
# print("Liste_HV_wo_Price", Liste_HV_wo_Price)
HV_NoPrix[:] = []
# Encapsulation des Liste_AjoutsX dans Listes_Ajouts_Full
# Enregistre le nombre d'éléments de chaque Liste_AjoutsX
Compteur = 0 # Compteur le Nb de Liste_AjoutsX non vide
Elements = [] # Contient le Nb Items de chaque Liste_AjoutsX
Element_Ligne1 =[] # Contient le Nb Items sur les 4 premières Liste_AjoutsX constituant la Ligne 1
Element_Ligne2 = [] # Contient le Nb Items sur les 4 premières Liste_AjoutsX constituant la Ligne 2
Listes_Ajouts_Full =[]
if len(Liste_Ajouts1) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts1)
# print("Listes_Ajouts_Full - Liste_Ajouts1", Listes_Ajouts_Full)
if len(Liste_Ajouts1) > 0:
Elements.append(len(Liste_Ajouts1))
Compteur = Compteur + 1
if len(Liste_Ajouts2) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts2)
# print("Listes_Ajouts_Full - Liste_Ajouts2", Listes_Ajouts_Full)
if len(Liste_Ajouts2) > 0:
Elements.append(len(Liste_Ajouts2))
Compteur = Compteur + 1
if len(Liste_Ajouts3) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts3)
# print("Listes_Ajouts_Full - Liste_Ajouts3", Listes_Ajouts_Full)
if len(Liste_Ajouts3) > 0:
Elements.append(len(Liste_Ajouts3))
Compteur = Compteur + 1
if len(Liste_Ajouts4) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts4)
# print("Listes_Ajouts_Full - Liste_Ajouts4", Listes_Ajouts_Full)
if len(Liste_Ajouts4) > 0:
Elements.append(len(Liste_Ajouts4))
Compteur = Compteur + 1
if len(Liste_Ajouts5) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts5)
# print("Listes_Ajouts_Full - Liste_Ajouts5", Listes_Ajouts_Full)
if len(Liste_Ajouts5) > 0:
Elements.append(len(Liste_Ajouts5))
Compteur = Compteur + 1
if len(Liste_Ajouts6) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts6)
# print("Listes_Ajouts_Full - Liste_Ajouts6", Listes_Ajouts_Full)
if len(Liste_Ajouts6) > 0:
Elements.append(len(Liste_Ajouts6))
Compteur = Compteur + 1
if len(Liste_Ajouts7) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts7)
# print("Listes_Ajouts_Full - Liste_Ajouts7", Listes_Ajouts_Full)
if len(Liste_Ajouts7) > 0:
Elements.append(len(Liste_Ajouts7))
Compteur = Compteur + 1
if len(Liste_Ajouts8) != 0:
Listes_Ajouts_Full.append(Liste_Ajouts8)
# print("Listes_Ajouts_Full - Liste_Ajouts8", Listes_Ajouts_Full)
if len(Liste_Ajouts8) > 0:
Elements.append(len(Liste_Ajouts8))
Compteur = Compteur + 1
# print("len(Listes_Ajouts_Full) -- Listes_Ajouts_Full", len(Listes_Ajouts_Full), " ", Listes_Ajouts_Full)
# for u in range(0, len(Listes_Ajouts_Full)):
# for z in range(0, len(Listes_Ajouts_Full[u])):
# print("Listes_Ajouts_Full[", u, "][", z, "]", Listes_Ajouts_Full[u][z])
# Regroupe le Nb Item par tranche de 4 colonnes pour chaque ligne d'affichage
# print("Elements", Elements)
# print("Compteur", Compteur)
if len(Elements) <= 4:
for i in range(0, Compteur):
Element_Ligne1.append(Elements[i])
# print("Element_Ligne1 -- <= 4", Element_Ligne1)
max_Ligne1 = IntVar()
if Element_Ligne1 == []:
max_Ligne1 = 0
if Element_Ligne1 != []:
max_Ligne1 = max(Element_Ligne1) - 1
# print("max_Ligne1", max_Ligne1)
if len(Elements) >= 4:
for i in range(0, 4):
Element_Ligne1.append(Elements[i])
# print("Element_Ligne1 -- >= 4", Element_Ligne1)
max_Ligne1 = IntVar()
max_Ligne1 = max(Element_Ligne1) - 1
# print("max_Ligne1", max_Ligne1)
Solde_Compteur = Compteur - (Compteur - 4)
# print("Solde_Compteur", Solde_Compteur)
for j in range(Solde_Compteur, Compteur):
Element_Ligne2.append(Elements[j])
# print("Element_Ligne2 -- >= 4", Element_Ligne2)
max_Ligne2 = IntVar()
if Element_Ligne2 == []:
max_Ligne2 = 0
if Element_Ligne2 != []:
max_Ligne2 = max(Element_Ligne2) - 1
# print("max_Ligne2", max_Ligne2)
# ===================
# --- Création PDF ---
# ===================
import reportlab
#
from reportlab.lib import colors
from reportlab.pdfgen import canvas
from reportlab.platypus import Paragraph, Table, TableStyle, Frame, Image, ParagraphAndImage
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import mm
# Format de la feuille
from reportlab.lib.pagesizes import landscape
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
# modif du calcul du chemin du répertoire "fonts"
if getattr(sys, 'frozen', False):
folder = os.path.join(sys._MEIPASS, "fonts") # programma traité par pyinstaller
else:
folder = os.path.join(os.path.dirname(reportlab.__file__), 'fonts') # programme non traité
# Chargement des Polices de caractères
TTF_File1 = os.path.join(folder, 'verdana.ttf')
pdfmetrics.registerFont(TTFont("Verdana", TTF_File1))
TTF_File2 = os.path.join(folder, 'verdanab.ttf')
pdfmetrics.registerFont(TTFont("Verdana-Bold", TTF_File2))
TTF_File3 = os.path.join(folder, 'verdanai.ttf')
pdfmetrics.registerFont(TTFont("Verdana-Italic", TTF_File3))
TTF_File4 = os.path.join(folder, 'verdanaz.ttf')
pdfmetrics.registerFont(TTFont("Verdana-BoldItalic", TTF_File4))
#
TTF_File5 = os.path.join(folder, 'arabtype.ttf')
pdfmetrics.registerFont(TTFont("arabtype", TTF_File5))
#
TTF_File6 = os.path.join(folder, 'THSarabun.ttf')
pdfmetrics.registerFont(TTFont("THSarabun", TTF_File6))
TTF_File7 = os.path.join(folder, 'THSarabun Bold.ttf')
pdfmetrics.registerFont(TTFont("THSarabun-Bold", TTF_File7))
TTF_File8 = os.path.join(folder, 'THSarabun Italic.ttf')
pdfmetrics.registerFont(TTFont("THSarabun-italic", TTF_File8))
TTF_File9 = os.path.join(folder, 'THSarabun Bold Italic.ttf')
pdfmetrics.registerFont(TTFont("THSarabun-BoldItalic", TTF_File9))
# ===================
# ------- Styles TitreX_X -------
# ===================
# alignmemt -- Valeur : 0 Gauche -- 1 Centrer -- 2 Droite --
st_Titre = ParagraphStyle(
name='Normal',
fontName='Verdana-Bold',
fontSize=8,
textColor='blue'
)
st_Titre_Ajouts = ParagraphStyle(
name='Normal',
alignment=0,
fontName='Verdana-Bold',
fontSize=8,
textColor='blue'
)
# ===============================
# ------- Nom Fichier Cible PDF & Titre PAGE -------
# ===============================
# Identifie PID du processus ...
os.system("tasklist | findstr /I Acrobat.exe")
os.system("tasklist | findstr /I AcroRd32.exe")
# Tue le processus ...
os.system("taskkill /f /im Acrobat.exe") # Acrobat Reader
os.system("taskkill /f /im AcroRd32.exe") # Acrobat Reader
# ------- Dossier Cible & Nom fichier PDF -------
Dossier_Cible = 'Recettes'
Nom_File = Nom_Rec.get() + ".pdf"
# Vérifie la présence du dossier cible
try:
os.makedirs(Dossier_Cible)
print("Directory ", Dossier_Cible, " Created ")
except FileExistsError:
print("Directory ", Dossier_Cible, " already exists")
# Ecriture du fichier cible
pdf = canvas.Canvas(Dossier_Cible + "/" + Nom_File, pagesize=landscape(A4))
# ------- Nom Recette -------
flow_Ligne1 = []
styles = getSampleStyleSheet()
stl_Recette_EU = ParagraphStyle(
name='Normal',
alignment=1,
fontName='Verdana-Bold',
fontSize=24,
textColor="#7E2300",
)
stl_Recette_TH = ParagraphStyle(
name='Normal',
alignment=1,
fontName='THSarabun-Bold',
fontSize=24,
textColor="#7E2300",
)
stl_Recette_AR = ParagraphStyle(
name='Normal',
alignment=1,
fontName='arabtype',
fontSize=24,
textColor="#7E2300",
)
# Identification de la langue utilisée pour le titre de la recette puis orientation vers la bon style
# from langdetect import detect # Détecte la langue d'un texte, d'une variable string
# Titre_Recette = ""
# lang_Nom_Rec = detect(Nom_Rec.get()) # detect la langue utilisée pour le titre
# print("lang_Nom_Rec", lang_Nom_Rec, type(lang_Nom_Rec))
# if lang_Nom_Rec == "it":
Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_EU)
# if lang_Nom_Rec == "th":
# Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_TH)
# if lang_Nom_Rec == "ar":
# Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_AR)
# print("Titre de la recette", Titre_Recette)
'''
Titre de la recette Paragraph(
'caseSensitive': 1
'encoding': 'utf8'
'text': 'Nouveau Nom Recette Test - Coincoin - 20.06.2020'
'frags': [ParaFrag(__tag__='para', bold=1, fontName='Verdana-Bold', fontSize=24, greek=0, italic=1, link=[], rise=0, text='Nouveau Nom Recette Test - Coincoin - 20.06.2020', textColor='#7E2300', us_lines=[])]
'style': <ParagraphStyle 'Normal'>
'bulletText': None
'debug': 0
) #Paragraph
'''
flow_Ligne1.append(Titre_Recette)
frame = Frame(20, 540, 800, 30, showBoundary=0)
frame.addFromList(flow_Ligne1, pdf)
# ===============
# ------- Colonne 1 -------
# ===============
flow_Col1 = []
# ------- Ligne 1 -------
Titre1_1 = Paragraph("Huiles - gr.", style=st_Titre)
flow_Col1.append(Titre1_1)
# ------- Ligne 2 -------
# # Nom HV
HV_Nom = []
HV_Nom = [[u[0]] for u in Liste_Full]
tb_HVNom = Table(HV_Nom, len(HV_Nom) * [45 * mm], len(HV_Nom) * [5 * mm])
# # Qt HV
HV_Qt = []
HV_Qt = [[u[2]] for u in Liste_Full]
tb_HVQt = Table(HV_Qt, len(HV_Qt) * [15 * mm], len(HV_Qt) * [5 * mm])
Ligne2_Col1 = Table([[tb_HVNom, tb_HVQt]], [140,50])
st_L2C1 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
Ligne2_Col1.setStyle(st_L2C1)
flow_Col1.append(Ligne2_Col1)
# ------- Ligne 3 -------
Titre1_2 = Paragraph("<br/>" + "Hydroxyde de sodium & H2O - gr.", style=st_Titre)
flow_Col1.append(Titre1_2)
# ------- Ligne 4 -------
# # SC TT Qt
TxT_SC_TT_Qt = []
TxT_SC_TT_Qt = [['Soude Caustique - NaOH']]
TxTSC_TT_Qt = Table(TxT_SC_TT_Qt)
SC_TT_Qt = []
SC_TT_Qt = [[Liste_Indices_Finaux[2]]]
SCTT_Qt = Table(SC_TT_Qt)
# # Eau TT Qt
TxT_H2O_TT_Qt = []
TxT_H2O_TT_Qt = [['Eau distillée']]
TxTH2O_TT_Qt = Table(TxT_H2O_TT_Qt)
H2O_TT_Qt = []
H2O_TT_Qt = [[Liste_Indices_Finaux[3]]]
H2OTT_Qt = Table(H2O_TT_Qt)
Ligne4_Col1 = Table([[TxTSC_TT_Qt, SCTT_Qt], [TxTH2O_TT_Qt, H2OTT_Qt]], [140,50])
#
st_L4C1 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
#
Ligne4_Col1.setStyle(st_L4C1)
flow_Col1.append(Ligne4_Col1)
# ------- Ligne 5 -------
Titre1_3 = Paragraph("<br/>" + "Réduction & Concentration", style=st_Titre)
flow_Col1.append(Titre1_3)
# ------- Ligne 6 -------
# # Réduction de soude caustique
TxT_Reduc_Soude = []
TxT_Reduc_Soude = [['Réduction soude caustique']]
TxTReducSoude = Table(TxT_Reduc_Soude)
Reduc_Soude_Qt = []
Reduc_Soude_Qt = [[Liste_Indices_Finaux[0]]]
ReducSoudeQt = Table(Reduc_Soude_Qt)
# # Concentration Lessive
TxT_Concentration_Lessive = []
TxT_Concentration_Lessive = [['Concentration Lessive']]
TxTConcentrationLessive = Table(TxT_Concentration_Lessive)
Concentration_Lessive_Qt = []
Concentration_Lessive_Qt = [[Liste_Indices_Finaux[1]]]
ConcentrationLessiveQt = Table(Concentration_Lessive_Qt)
Ligne6_Col1 = Table([[TxTReducSoude, ReducSoudeQt], [TxTConcentrationLessive, ConcentrationLessiveQt]], [140,50])
#
st_L6C1 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
#
Ligne6_Col1.setStyle(st_L6C1)
flow_Col1.append(Ligne6_Col1)
frame = Frame(20, 330, 190, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_Col1, pdf)
# ===============
# ------- Colonne 2 -------
# ===============
flow_Col2 = []
# ------- Ligne 1 -------
Titre2_1 = Paragraph("Poids - gr.", style=st_Titre)
flow_Col2.append(Titre2_1)
# ------- Ligne 2 -------
# # HV TT Qt
TxT_HV_TT_Qt = []
TxT_HV_TT_Qt = [['Huiles']]
TxTHVTTQt = Table(TxT_HV_TT_Qt)
HV_TT_Qt = []
HV_TT_Qt = [[Liste_Somme[0]]]
HVTTQt = Table(HV_TT_Qt)
# # Qt TT Recette
TxT_Rec_TT_Qt = []
TxT_Rec_TT_Qt = [['Recette']]
TxTTT_Qt = Table(TxT_Rec_TT_Qt, [133])
Rec_TT_Qt = []
Rec_TT_Qt = [[Qt_TT_Recette]]
RecTT_Qt = Table(Rec_TT_Qt, [33])
Ligne1_Col2 = Table([[TxTHVTTQt, HVTTQt], [TxTTT_Qt, RecTT_Qt]], [105,55])
#
st_L1C2 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
#
Ligne1_Col2.setStyle(st_L1C2)
flow_Col2.append(Ligne1_Col2)
# ------- Ligne 3 -------
st_Red = ParagraphStyle(
name='Normal',
fontName='Verdana-Bold',
fontSize=8,
textColor='red'
)
flow_Prix = []
Titre2_2 = Paragraph("<br/>" +"Coût de revient", style=st_Titre)
Titre2_2a = Paragraph("(*)", style=st_Red)
Titre2_final = Table([[Titre2_2, Titre2_2a]], [90, 80])
flow_Col2.append(Titre2_final)
# ------- Ligne 4 -------
# # HV Prix
TxT_HV_Prix = []
TxT_HV_Prix = [['Recette']]
TxTHVPrix = Table(TxT_HV_Prix)
HV_Prix = []
HV_Prix = [[prix]]
HVPrix = Table(HV_Prix)
Ligne2_Col2 = Table([[TxTHVPrix, HVPrix]], [105,55])
#
st_L2C2 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
#
Ligne2_Col2.setStyle(st_L2C2)
flow_Col2.append(Ligne2_Col2)
# ------- Ligne 5 -------
DateStart = Paragraph("<br/>" + "Date de création", style=st_Titre)
flow_Col2.append(DateStart)
Cure = Paragraph("<br/>" + "Temps de séquestration", style=st_Titre)
flow_Col2.append(Cure)
Ph = Paragraph("<br/>" + "Mesure Ph", style=st_Titre)
flow_Col2.append(Ph)
frame = Frame(226.67, 330, 160, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_Col2, pdf)
# ===============
# ------- Colonne 3 -------
# ===============
flow_Col3 = []
# ------- Ligne 1 -------
Titre3_1 = Paragraph("Propriétés du savon", style=st_Titre)
flow_Col3.append(Titre3_1)
# ------- Ligne 2 -------
# Indice Dureté
TxT_Durete = []
TxT_Durete = [['Dureté']]
TxTDurete = Table(TxT_Durete)
Durete_val = []
Durete_val = [[Liste_Indices_Finaux[6]]]
Dureteval = Table(Durete_val)
# Indice Détergent
TxT_Detergent = []
TxT_Detergent = [['Détergent']]
TxTDetergent = Table(TxT_Detergent)
Detergent_val = []
Detergent_val = [[Liste_Indices_Finaux[7]]]
Detergentval = Table(Detergent_val)
# Indice Hydratation
TxT_Hydratation = []
TxT_Hydratation = [['Hydratation']]
TxTHydratation = Table(TxT_Hydratation)
Hydratation_val = []
Hydratation_val = [[Liste_Indices_Finaux[8]]]
Hydratationval = Table(Hydratation_val)
# Indice Moussant
TxT_Moussant = []
TxT_Moussant = [['Moussant']]
TxTMoussant = Table(TxT_Moussant)
Moussant_val = []
Moussant_val = [[Liste_Indices_Finaux[9]]]
Moussantval = Table(Moussant_val)
# Indice QMousse
TxT_QMousse = []
TxT_QMousse = [['Qualité de la mousse']]
TxTQMousse = Table(TxT_QMousse)
QMousse_val = []
QMousse_val = [[Liste_Indices_Finaux[10]]]
QMousseval = Table(QMousse_val)
ts_Durete = TableStyle([
("BACKGROUND", (0, -5), (0, -5), colors.HexColor("#FFCCFF")),
])
ts_Detergent = TableStyle([
("BACKGROUND", (0, -4), (0, -4), colors.HexColor("#FFC000")),
])
ts_Hydratation = TableStyle([
("BACKGROUND", (0, -3), (0, -3), colors.HexColor("#D8E4BC")),
])
ts_Moussant = TableStyle([
("BACKGROUND", (0, -2), (0, -2), colors.HexColor("#92CDDC")),
])
ts_QMousse = TableStyle([
("BACKGROUND", (0, -1), (0, -1), colors.HexColor("#538DD5")),
])
st_L1C3 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
#
Ligne1_Col3 = Table([[TxTDurete, Dureteval], [TxTDetergent, Detergentval], [TxTHydratation, Hydratationval], [TxTMoussant, Moussantval], [TxTQMousse, QMousseval]], [145, 55])
Ligne1_Col3.setStyle(st_L1C3)
Ligne1_Col3.setStyle(ts_Durete)
Ligne1_Col3.setStyle(ts_Detergent)
Ligne1_Col3.setStyle(ts_Hydratation)
Ligne1_Col3.setStyle(ts_Moussant)
Ligne1_Col3.setStyle(ts_QMousse)
flow_Col3.append(Ligne1_Col3)
# ------- Ligne 3 -------
Titre3_2 = Paragraph("<br/>" + "Acides Gras Saturés", style=st_Titre)
flow_Col3.append(Titre3_2)
# ------- Ligne 4 -------
# Indice Acides Gras Saturés
#La
TxT_La = []
TxT_La = [['La Laurique C12:0']]
TxTLa = Table(TxT_La)
La_val = []
La_val = [[Liste_Indices_Finaux[11]]]
Laval = Table(La_val)
#M
TxT_M = []
TxT_M = [['M Myristique C14:0']]
TxTM = Table(TxT_M)
M_val = []
M_val = [[Liste_Indices_Finaux[12]]]
Mval = Table(M_val)
#P
TxT_P = []
TxT_P = [['P Palmistique C16:0']]
TxTP = Table(TxT_P)
P_val = []
P_val = [[Liste_Indices_Finaux[13]]]
Pval = Table(P_val)
#S
TxT_S = []
TxT_S = [['S Stéarique C18:0']]
TxTS = Table(TxT_S)
S_val = []
S_val = [[Liste_Indices_Finaux[14]]]
Sval = Table(S_val)
ts_AGS = TableStyle([
("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#FF66FF")),
])
Ligne2_Col3 = Table([[TxTLa, Laval], [TxTM, Mval], [TxTP, Pval], [TxTS, Sval]], [145, 55])
Ligne2_Col3.setStyle(st_L1C3)
Ligne2_Col3.setStyle(ts_AGS)
flow_Col3.append(Ligne2_Col3)
#
frame = Frame(403.34, 330, 200, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_Col3, pdf)
# ===============
# ------- Colonne 4 -------
# ===============
flow_Col4 = []
# ------- Ligne 1 -------
Titre4_1 = Paragraph("Acides Gras Insaturés", style=st_Titre)
flow_Col4.append(Titre4_1)
# ------- Ligne 2 -------
# Indice Acides Gras Insaturés
# C18
TxT_C18 = []
TxT_C18 = [['C18H34O3 Ricinoléique']]
TxTC18 = Table(TxT_C18)
C18_val = []
C18_val = [[Liste_Indices_Finaux[15]]]
C18val = Table(C18_val)
# O
TxT_O = []
TxT_O = [['O Oléique']]
TxTO = Table(TxT_O)
O_val = []
O_val = [[Liste_Indices_Finaux[16]]]
Oval = Table(O_val)
# L
TxT_L = []
TxT_L = [['L Linoléique']]
TxTL = Table(TxT_L)
L_val = []
L_val = [[Liste_Indices_Finaux[17]]]
Lval = Table(L_val)
# Ln
TxT_Ln = []
TxT_Ln = [['Ln Linolénique']]
TxTLn = Table(TxT_Ln)
Ln_val = []
Ln_val = [[Liste_Indices_Finaux[18]]]
Lnval = Table(Ln_val)
ts_AGI = TableStyle([
("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#FF3399")),
])
st_L2C4 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
Ligne2_Col4 = Table([[TxTC18, C18val], [TxTO, Oval], [TxTL, Lval], [TxTLn, Lnval]], [145, 55])
Ligne2_Col4.setStyle(st_L2C4)
Ligne2_Col4.setStyle(ts_AGI)
flow_Col4.append(Ligne2_Col4)
# ------- Ligne 3 -------
Titre4_2 = Paragraph("<br/>" + "Indices", style=st_Titre)
flow_Col4.append(Titre4_2)
# ------- Ligne 4 -------
# # Indice I.N.S
TxT_Indice_INS = []
TxT_Indice_INS = [['Indice I.N.S (dureté)']]
TxTIndiceINS = Table(TxT_Indice_INS)
Indice_INS_val = []
Indice_INS_val = [[Liste_Indices_Finaux[4]]]
IndiceINSval = Table(Indice_INS_val)
# # Indice IODE
TxT_Indice_IODE = []
TxT_Indice_IODE = [['Indice IODE (conservation)']]
TxTIndiceIODE = Table(TxT_Indice_IODE, [133])
IndiceIODE_val = []
IndiceIODE_val = [[Liste_Indices_Finaux[5]]]
IndiceIODEval = Table(IndiceIODE_val, [33])
Ligne4_Col4 = Table([[TxTIndiceINS, IndiceINSval], [TxTIndiceIODE, IndiceIODEval]], [145,55])
#
st_L4C4 = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 10),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
])
Indices = TableStyle([
("BACKGROUND", (0, 0), (0, -1), colors.yellow),
])
#
Ligne4_Col4.setStyle(st_L4C4)
Ligne4_Col4.setStyle(Indices)
flow_Col4.append(Ligne4_Col4)
frame = Frame(620.01, 330, 200, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_Col4, pdf)
# ==================
# ------- Ligne Ajouts --------
# ==================
flow_Ligne_Ajouts = []
# ------- Ligne Ajouts -------
styles = getSampleStyleSheet()
Titre5_1 = Paragraph("Ajouts sélectionnés", style=st_Titre_Ajouts)
Titre5_1.underlineWidth=50
flow_Ligne_Ajouts.append(Titre5_1)
# ------- Sous-ColonneX en 2 lignes -------
pos_x = [60, 250, 440, 630, 60, 250, 440, 630] # Position en x des 4 ColonneX Ligne 1 et des 4 autres ColonneX Ligne 2
Largeur_tb = [150, 150, 150, 150, 150, 150, 150, 150] # Largeur TableX
nb = len(Listes_Ajouts_Full) # Nb de type d'ajouts
# print("nb", nb)
L1 = [[290,20], [275,37], [255,55], [235,75], [220,90]] # Position et Hauteur Y frame 1 à 4 de la ligne 1 (selon le nb de sélection)
L2 = [[20], [37], [55], [75], [90]] # Hauteur Y frame 1 à 4 de la ligne 2 (selon le nb de sélection)
Step_Y = [[30], [50], [70], [90], [110]] # Position Y frame 1 à 4 de la Ligne 2 (selon le nb de sélection)
if nb <= 4: # Ligne 1 -------------- NbColonne < 4
# print("Ligne 1 -------------- NbColonne <= 4")
for i in range(0, nb):
# print("i", i)
Col = "Col" + str(i)
Col = []
if len(Listes_Ajouts_Full) != 0:
for z in range(0, len(Listes_Ajouts_Full[i])):
# print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
Col.append(Listes_Ajouts_Full[i][z])
# print("Col(", i, ")", Col)
List_Col = "List_Col" + str(i)
tb_Col = "tb_Col" + str(i)
tb = "tb" + str(i)
# print("Col", Col)
List_Col = [[z[0]] for z in Col]
tb_Col = Table(List_Col)
#
st_Ajouts = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 8),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
('LEFTPADDING', (0, 0), (-1, -1), 0),
])
tb = Table([[tb_Col]], [Largeur_tb[i]])
tb.setStyle(st_Ajouts)
#
flow_Col = "flow_Col" + str(i)
flow_Col = []
flow_Col.append(tb)
frame = "frame" + str(i)
frame = Frame(pos_x[i], L1[max_Ligne1][0], 150, L1[max_Ligne1][1], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
frame.addFromList(flow_Col, pdf)
if nb > 4: # Ligne 1 -------------- NbColonne >= 4
# print("Ligne 1 -------------- NbColonne >= 4")
for i in range(0, 4):
# print("i", i)
Col = "Col" + str(i)
Col = []
if len(Listes_Ajouts_Full) != 0:
for z in range(0, len(Listes_Ajouts_Full[i])):
# print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
Col.append(Listes_Ajouts_Full[i][z])
# print("Col(", i, ")", Col)
List_Col = "List_Col" + str(i)
tb_Col = "tb_Col" + str(i)
tb = "tb" + str(i)
# print("Col", Col)
List_Col = [[z[0]] for z in Col]
tb_Col = Table(List_Col)
#
st_Ajouts = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 8),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
('LEFTPADDING', (0, 0), (-1, -1), 0),
])
tb = Table([[tb_Col]], [Largeur_tb[i]])
tb.setStyle(st_Ajouts)
#
flow_Col = "flow_Col" + str(i)
flow_Col = []
flow_Col.append(tb)
frame = "frame" + str(i)
frame = Frame(pos_x[i], L1[max_Ligne1][0], 150, L1[max_Ligne1][1], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
frame.addFromList(flow_Col, pdf)
if nb > 4: # Ligne 2 -------------- NbColonne > 4
for i in range(4 , nb):
# print("Ligne 2 -------------- NbColonne > 4")
# print("i", i)
Col = "Col" + str(i)
Col = []
if len(Listes_Ajouts_Full) != 0:
for z in range(0, len(Listes_Ajouts_Full[i])):
# print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
Col.append(Listes_Ajouts_Full[i][z])
# print("Col(", i, ")", Col)
List_Col = "List_Col" + str(i)
tb_Col = "tb_Col" + str(i)
tb = "tb" + str(i)
# print("Col", Col)
List_Col = [[z[0]] for z in Col]
tb_Col = Table(List_Col)
#
st_Ajouts = TableStyle([
# ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
# ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
('FONTSIZE', (0, 0), (-1, -1), 8),
('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
('TOPPADDING', (0, 0), (-1, -1), 0),
('BOTTOMPADDING', (0, 0), (-1, -1), 0),
('LEFTPADDING', (0, 0), (-1, -1), 0),
])
tb = Table([[tb_Col]], [Largeur_tb[i]])
tb.setStyle(st_Ajouts)
#
flow_Col = "flow_Col" + str(i)
flow_Col = []
flow_Col.append(tb)
frame = "frame" + str(i)
# print("L1[max_Ligne1][0] ------------------ ", L1[max_Ligne1][0], " ", test[max_Ligne2][0], " ", (L1[max_Ligne1][0] - test[max_Ligne1][0]))
# print("L2[max_Ligne2][0] ------------------ ", L2[max_Ligne2][0])
frame = Frame(pos_x[i] , (L1[max_Ligne1][0] - Step_Y[max_Ligne2][0]), 150, L2[max_Ligne2][0], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
frame.addFromList(flow_Col, pdf)
frame = Frame(20, 125, 800, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_Ligne_Ajouts, pdf)
# =========================
# ------- Ligne HV prix manquant --------
# =========================
st_Price = ParagraphStyle(
name='Normal',
fontName='Verdana-Bold',
fontSize=8,
textColor='red'
)
flow_Prix = []
HV_wo_Prix = Paragraph("(*) Huiles dont les prix ne sont pas indiqués : " + Liste_HV_wo_Price, style=st_Price)
flow_Prix.append(HV_wo_Prix)
frame = Frame(20, 100, 723, 20, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_Prix, pdf)
# ========================
# ------- Ligne Rappel Sécurité --------
# ========================
# # Colonne 1
flow_PIC = []
Retour_Chariot='''<br/><br/>'''
P_0 = Paragraph(Retour_Chariot, style=st_Titre)
flow_PIC.append(P_0)
img_SC = Image("ICO\SC.jpg", 50, 71)
flow_PIC.append(img_SC)
frame = Frame(20, 20, 80, 100, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
frame.addFromList(flow_PIC, pdf)
# # Colonne 2
st_Secure = ParagraphStyle(
name='Normal',
fontName='Verdana-Bold',
fontSize=6,
textColor='red'
)
st_Paragraphe_Secure = ParagraphStyle(
name='Normal',
alignment=0,
leftIndent=24,
rightIndent=24,
fontName='Verdana-Bold',
fontSize=6,
textColor='black',
leading=8 # interligne
)
st_Link = ParagraphStyle(
name='Normal',
fontName='Verdana-Bold',
fontSize=6,
textColor='blue',
leading=8 # interligne
)
flow_Secure = []
# ------- Ligne 1 -------
Titre4_1 = Paragraph("Précautions de sécurité", style=st_Secure)
flow_Secure.append(Titre4_1)
P_1 = Paragraph("Dans un lieu très bien aéré, lors de la pesée et du mélange (émulsion) de l'eau et la soude caustique, il est impératif de porter des lunettes, des gants de protection néoprène floké coton épaisseur 0.72 (EN374-3 niveau K) puis un masque adéquat." + "<br/>" + "Toujours verser lentement la soude caustique dans leau tiède. Utiliser uniquement un fouet et un récipient en inox de préférence. ", style=st_Paragraphe_Secure)
flow_Secure.append(P_1)
text1='''<br/><a href=https://www.vdp.com/FR/Nieuws/date/desc/1/2269/0/en-374-2016-profond-changement-de-la-norme-relative-aux-gants-resistant-aux-produits-chimiques.html><u>EN 374, la norme relative aux gants résistant aux produits chimiques</u></a>'''
P_2 = Paragraph(text1, style=st_Link)
flow_Secure.append(P_2)
text2='''<a href=http://www.inrs.fr/publications/bdd/fichetox/fiche.html?refINRS=FICHETOX_20><u>Hydroxyde de sodium et solutions aqueuses</u></a>'''
P_3 = Paragraph(text2, style=st_Link)
flow_Secure.append(P_3)
text3='''<a href=https://www.protecthoms.com/normes-masque-hygiene><u>Protection contre les aérosols solides ou liquides toxiques</u></a>'''
P_4 = Paragraph(text3, style=st_Link)
flow_Secure.append(P_4)
frame = Frame(100, 20, 723, 80, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
frame.addFromList(flow_Secure, pdf)
pdf.save()
# ===================
# --- Création TxT ---
# ===================
# r ouverture en lecture (READ).
# w ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé. Si le fichier n'existe pas, il sera créé
# a ouverture en mode ajout à la fin du fichier (APPEND). Si le fichier n'existe pas, il sera créé
# b ouverture en mode binaire.
# t ouverture en mode texte.
# x crée un nouveau fichier et l'ouvre pour écriture
# ------- Nom Dossier & Fichier PDF Cible -------
Nom_File_txt = Nom_Rec.get() + ".txt"
# print("Nom_File_txt", Nom_File_txt)
# 1 -- Création du ficher cilbe
# os.path.join prend un répertoire et un nom de fichier et les concatène pour former un chemin d'accès complet.
with open(os.path.join(Dossier_Cible, Nom_File_txt), 'w', encoding='utf-8') as file_object:
pass
# Fermeture du fichier
file_object.close()
# 2 -- Ecriture Titre Recette
# L'instruction with garantie la fermeture du fichier en fin de bloc
# w -- Ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé.
with open(os.path.join(Dossier_Cible, Nom_File_txt), 'w', encoding='utf-8') as file_object:
# Ajout 1er. ligne
file_object.write(Nom_Rec.get() + '\n' + '\n')
file_object.close()
# 3 -- Ecriture Liste HV Qt Prix INCI SAP
# - Création d'un tableau type Tuples -
# exemple : [('Coco Vierge CHAOKOH', 120.0, 1.704, 'Sodium Cocoate'), ('Olive Filipo', 100.0, 0.62, 'Sodium Olivate'), ('Argan-yari', 16.8, 0.551, 'Sodium Arganate'), ('Babassu', 25.63, 0, 'Sodium Babassuate')]
a = []
b =[]
c = []
d = []
combs = []
for u in range(0, len(Liste_Full)):
a.append(Liste_Full[u][0])
b.append(str(Liste_Full[u][2]))
c.append(str(Liste_Full[u][24]))
d.append(Liste_Full[u][25])
# print(a, '\n', b, '\n', c)
for i in range(0, len(a)):
x = a[i]
y = b[i]
z = c[i]
w = d[i]
combs.append((x,y,z,w))
# print("combs", combs, type(combs))
# print("combs", type(combs))
# - Titre des colonnes -
columnNames = ("Nom Huile", "Quantité gr.", "Prix", "Nom INCI SAP")
# - Calcule de la plus longue chaîne de caractères pour chaque colonne du tableau. -
columnSizes = [0, 0, 0, 0]
for column in range(4):
maxSize = len(columnNames[column])
for line in combs:
maxSize = max(len(line[column]), maxSize)
columnSizes[column] = maxSize
# - Formats des lignes utilisés pour écrire dans le fichier -
# calcule : +------------+------------+-----------+---------------+
separatorRow = "+%s+%s+%s+%s+" % ("-" * (columnSizes[0] + 2),
"-" * (columnSizes[1] + 2),
"-" * (columnSizes[2] + 2),
"-" * (columnSizes[3] + 2))
# calcule : | %-10s | %-10s | %-9s | %13s |
lineFormat = "| %%-%ds | %%-%ds | %%-%ds | %%%ds |" % (columnSizes[0], columnSizes[1], columnSizes[2], columnSizes[3])
# - Ecriture dans le ficher avec les données formatées -
try:
# L'instruction with garantie la fermeture du fichier en fin de bloc
with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a', encoding='utf-8') as file_object:
print(separatorRow, file=file_object)
print(lineFormat % columnNames, file=file_object)
print(separatorRow, file=file_object)
for mot in combs:
# mot correspond à un tuple de la liste combs --> on peut donc s'en servir avec l'opérateur de formatage
print(lineFormat % mot, file=file_object)
print(separatorRow, file=file_object)
# print("File generated")
except IOError as exception:
print("Cannot write data to file " + str(exception), file=sys.stderr)
file_object.close()
# 4 -- Ecriture Liste Ajouts et une deuxième colonne
# - Conversion List in List en une simple List -
from collections import Iterable
def flatten(Listes_Ajouts_Full):
for item in Listes_Ajouts_Full:
if isinstance(item, Iterable) and not isinstance(item, str):
for x in flatten(item):
yield x
else:
yield item
result = list(flatten(Listes_Ajouts_Full))
# print("list", list, result) # exemple : ['Acide Stéarique', 'Acide Palmitique', 'Acide Oléique', 'Acide Myristique', 'Acide Laurique', 'Extrait CO2 de Romarin BIO', 'Vitanime E naturel', 'ARG - Rouge', 'Aloe vera', 'Lait', 'Lait de coco', 'Miel', 'Violette', 'Arbre à thè [Tea Tree]', 'Camomille Romaine', 'Geranium Rosat', 'Hydroxyéthyl Cellulose (HEC)', 'Cacao', 'Café', 'Cannelle', 'Carthame']
# - Ajout d'un deuxième paramètre -
DP = []
for i in range(0, len(result)):
DP.append(result[i])
DP.append("...")
# print("DP ", DP) # exemple : ['Acide Stéarique', '...', 'Acide Palmitique', '...', 'Acide Oléique', '...', 'Acide Myristique', '...', 'Acide Laurique', '...', 'Extrait CO2 de Romarin BIO', '...', 'Vitanime E naturel', '...', 'ARG - Rouge', '...', 'Aloe vera', '...', 'Lait', '...', 'Lait de coco', '...', 'Miel', '...', 'Violette', '...', 'Arbre à thè [Tea Tree]', '...', 'Camomille Romaine', '...', 'Geranium Rosat', '...', 'Hydroxyéthyl Cellulose (HEC)', '...', 'Cacao', '...', 'Café', '...', 'Cannelle', '...', 'Carthame', '...']
# - Construction simple List par paire -
a = []
b = []
combs = []
for u in range(0, len(DP), 2): # List a pour les nom des Ajouts --> ['Acide Stéarique', 'Acide Palmitique', 'Acide Oléique', 'Acide Myristique', 'Acide Laurique', 'Extrait CO2 de Romarin BIO', 'Vitanime E naturel', 'ARG - Rouge', 'Aloe vera', 'Lait', 'Lait de coco', 'Miel', 'Violette', 'Arbre à thè [Tea Tree]', 'Camomille Romaine', 'Geranium Rosat', 'Hydroxyéthyl Cellulose (HEC)', 'Cacao', 'Café', 'Cannelle', 'Carthame']
a.append(DP[u])
for u in range(1, len(DP), 2): # List b pour le deuxième paramètre --> ['...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...']
b.append(DP[u])
# print(a, '\n', b)
for i in range(0, len(a)):
x = a[i]
y = b[i]
combs.append((x,y))
# print("combs", combs, type(combs)) # [('Acide Stéarique', '...'), ('Acide Palmitique', '...'), ('Acide Oléique', '...'), ('Acide Myristique', '...'), ('Acide Laurique', '...'), ('Extrait CO2 de Romarin BIO', '...'), ('Vitanime E naturel', '...'), ('ARG - Rouge', '...'), ('Aloe vera', '...'), ('Lait', '...'), ('Lait de coco', '...'), ('Miel', '...'), ('Violette', '...'), ('Arbre à thè [Tea Tree]', '...'), ('Camomille Romaine', '...'), ('Geranium Rosat', '...'), ('Hydroxyéthyl Cellulose (HEC)', '...'), ('Cacao', '...'), ('Café', '...'), ('Cannelle', '...'), ('Carthame', '...')] <class 'list'>
# print("combs", type(combs)) # <class 'list'>
# - Conversion simple List en Tuple -
tup = tuple(combs)
# print("tuple(combs) ", tup) # (('Acide Stéarique', '...'), ('Acide Palmitique', '...'), ('Acide Oléique', '...'), ('Acide Myristique', '...'), ('Acide Laurique', '...'), ('Extrait CO2 de Romarin BIO', '...'), ('Vitanime E naturel', '...'), ('ARG - Rouge', '...'), ('Aloe vera', '...'), ('Lait', '...'), ('Lait de coco', '...'), ('Miel', '...'), ('Violette', '...'), ('Arbre à thè [Tea Tree]', '...'), ('Camomille Romaine', '...'), ('Geranium Rosat', '...'), ('Hydroxyéthyl Cellulose (HEC)', '...'), ('Cacao', '...'), ('Café', '...'), ('Cannelle', '...'), ('Carthame', '...'))
# - Titre des colonnes -
columnNames = ("Nom Ajouts", "Quantité gr.")
# - Calcule de la plus longue chaîne de caractères pour chaque colonne du tableau. -
columnSizes = [0,0]
for column in range(2):
maxSize = len(columnNames[column])
for line in tup:
maxSize = max(len(line[column]), maxSize)
columnSizes[column] = maxSize
# - Formats des lignes utilisés pour écrire dans le fichier -
# calcule : +------------+------------+-----------+---------------+
separatorRow = "+%s+%s+" % ("-" * (columnSizes[0] +2),
"-" * (columnSizes[1] + 2))
# calcule : | %-10s | %-10s | %-9s | %13s |
lineFormat = "| %%-%ds | %%-%ds |" % \
(columnSizes[0], columnSizes[1])
# - Ecriture dans le ficher avec les données formatées -
try:
# L'instruction with garantie la fermeture du fichier en fin de bloc
with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a', encoding='utf-8') as file_object:
print(separatorRow, file=file_object)
print(lineFormat % columnNames, file=file_object)
print(separatorRow, file=file_object)
for mot in tup:
# mot correspond à un tuple de la liste combs --> on peut donc s'en servir avec l'opérateur de formatage
print(lineFormat % mot, file=file_object)
print(separatorRow, file=file_object)
# print("File generated")
except IOError as exception:
print("Cannot write data to file " + str(exception), file=sys.stderr)
# a -- Ouverture en mode ajout à la fin du fichier (APPEND)
# with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a') as file_object:
# # Ajout texte en fin de fichier
# for u in range(0, len(Liste_Full)):
# file_object.write(str(Liste_Full[u][0]) + "\t" + "\t" + str(Liste_Full[u][2]) + '\n')
# file_object.close()
# Vidange des liste suivantes - cela permet générer à nouveau un PDF (avec ou sans les mêmes ajouts)
Elements[:] = []
Element_Ligne1[:] = []
Element_Ligne2[:] = []
Listes_Ajouts_Full[:] = []
Liste_Ajouts1[:] = []
Liste_Ajouts2[:] = []
Liste_Ajouts3[:] = []
Liste_Ajouts4[:] = []
Liste_Ajouts5[:] = []
Liste_Ajouts6[:] = []
Liste_Ajouts7[:] = []
Liste_Ajouts8[:] = [] |
Partager