-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtools.py
More file actions
4321 lines (2979 loc) · 132 KB
/
tools.py
File metadata and controls
4321 lines (2979 loc) · 132 KB
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
#!/usr/bin/python3
# -*- coding: utf-8 -*
import glob
import io
import json
import os.path
import platform
import shutil
import subprocess
import urllib.request
import webbrowser
from collections import OrderedDict, Counter
from datetime import datetime
from io import BytesIO
from typing import Union
import clr
import openpyxl
import requests
from ftfy import fix_text
from lxml import etree
from send2trash import send2trash
from main_datas import *
from translation_manage import get_favorites_allplan_dict
from ui_message import Ui_Message
try:
# noinspection PyUnresolvedReferences
clr.AddReference("System.Windows.Forms")
# noinspection PyUnresolvedReferences
from System.Windows.Forms import OpenFileDialog, SaveFileDialog, FileDialogCustomPlace, DialogResult
load_ok = True
except Exception as error2:
print(f"browser -- get_common_dialog_path -- {error2}")
load_ok = False
invalid_chars = ("<", ">", ":", '"', "/", "\\", "|", "?", "*")
invalides_mots = ("CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
"COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9")
menu_ht_ligne = 24
menu_ht_widget = 20
taille_police = 10
taille_police_menu = 10
def a___________________validateurs_______________():
pass
class ValidatorModel(QValidator):
def __init__(self, model, column_index=0):
QValidator.__init__(self)
self.model: QStandardItemModel = model
self.column_index = column_index
def validate(self, p_str: str, p_int: int):
# Si ce que l'utilisateur a tapé est exactement un élément de la liste, alors c'est 100 % acceptable
recherche = self.model.findItems(p_str, Qt.MatchExactly, self.column_index)
if len(recherche) == 1:
return QValidator.Acceptable, p_str, p_int
# Si c'est le début d'au moins 1 élément de la liste, c'est Intermediate (probablement
# acceptable + tard, mais pas encore certain)
try:
recherche = self.model.findItems(p_str, Qt.MatchContains, self.column_index)
if len(recherche) > 0:
return QValidator.Intermediate, p_str, p_int
except IndexError:
return QValidator.Invalid, p_str, -1
except AttributeError:
return QValidator.Invalid, p_str, -1
# Si c'est ni acceptable, ni intermediate, c'est invalide...
return QValidator.Invalid, p_str, -1
def fixup(self, p_str):
pass
class ValidatorInt(QValidator):
def __init__(self, min_val=None, max_val=None):
super().__init__()
self.liste = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"]
if isinstance(min_val, int):
self.min_val = min_val
else:
self.min_val = None
if isinstance(max_val, int):
self.max_val = max_val
else:
self.max_val = None
def validate(self, p_str, p_int):
if p_int == 0:
return QValidator.Acceptable, p_str, p_int
# Si ce que l'utilisateur a tapé est exactement un élément de la liste, alors c'est 100 % acceptable
try:
if p_str[p_int - 1] in self.liste:
if self.min_val is None and self.max_val is None:
return QValidator.Acceptable, p_str, p_int
value_int = int(p_str)
if self.min_val is not None:
if value_int < self.min_val:
return QValidator.Invalid, p_str, -1
if self.max_val is not None:
if value_int > self.max_val:
return QValidator.Invalid, p_str, -1
return QValidator.Acceptable, p_str, p_int
except IndexError:
print("IndexError")
return QValidator.Invalid, p_str, -1
except AttributeError:
print("AttributeError")
return QValidator.Invalid, p_str, -1
except ValueError:
print("ValueError")
return QValidator.Invalid, p_str, -1
# Si c'est ni acceptable, ni intermediate, c'est invalide...
return QValidator.Invalid, p_str, -1
def fixup(self, p_str):
pass
class ValidatorDouble(QValidator):
def __init__(self, min_val=None, max_val=None):
super().__init__()
self.liste = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "-"]
if isinstance(min_val, int):
self.min_val = min_val
else:
self.min_val = None
if isinstance(max_val, int):
self.max_val = max_val
else:
self.max_val = None
def validate(self, p_str: str, p_int: int):
if p_int == 0:
return QValidator.Acceptable, p_str, p_int
# Si ce que l'utilisateur a tapé est exactement un élément de la liste, alors c'est 100 % acceptable
try:
if p_str[p_int - 1] in self.liste:
# Vérification qu'une seule virgule exite
if p_str.count(",") + p_str.count(".") > 1:
return QValidator.Invalid, p_str, -1
if self.min_val is None and self.max_val is None:
return QValidator.Acceptable, p_str, p_int
p_str_format = p_str.replace(",", ".")
value_int = float(p_str_format)
if self.min_val is not None:
if value_int < self.min_val:
return QValidator.Invalid, p_str, -1
if self.max_val is not None:
if value_int > self.max_val:
return QValidator.Invalid, p_str, -1
return QValidator.Acceptable, p_str, p_int
except IndexError:
return QValidator.Invalid, p_str, -1
except AttributeError:
return QValidator.Invalid, p_str, -1
except ValueError:
return QValidator.Invalid, p_str, -1
# Si c'est ni acceptable, ni intermediate, c'est invalide...
return QValidator.Invalid, p_str, -1
def fixup(self, p_str):
pass
class ValidatorDate(QValidator):
def __init__(self):
super().__init__()
self.liste = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/"]
def validate(self, p_str: str, p_int: int):
if p_int == 0:
return QValidator.Acceptable, p_str, p_int
# Si ce que l'utilisateur a tapé est exactement un élément de la liste, alors c'est 100 % acceptable
try:
if p_str[p_int - 1] in self.liste:
return QValidator.Acceptable, p_str, p_int
except IndexError:
return QValidator.Invalid, p_str, -1
except AttributeError:
return QValidator.Invalid, p_str, -1
# Si c'est ni acceptable, ni intermediate, c'est invalide...
return QValidator.Invalid, p_str, -1
def fixup(self, p_str):
pass
def a___________________menu_______________():
pass
class MyContextMenu(QMenu):
help_request = pyqtSignal(str)
def __init__(self, title="", qicon=None, tooltips_visible=True, tooltips="", short_link=""):
super().__init__()
self.menu_ht_line = 24
self.tooltips_visible = tooltips_visible
current_font = self.font()
current_font.setPointSize(taille_police_menu)
self.setFont(current_font)
changer_apparence_selection(widget=self)
if isinstance(title, str) and title != "":
self.setTitle(title)
if isinstance(qicon, QIcon):
self.setIcon(qicon)
if isinstance(tooltips, bool):
self.setToolTipsVisible(tooltips_visible)
else:
self.setToolTipsVisible(True)
if isinstance(tooltips, str) and tooltips != "":
self.setToolTip(tooltips)
if isinstance(short_link, str) and short_link != "":
self.setWhatsThis(short_link)
def add_title(self, title: str, short_link="") -> QAction:
action_widget = QWidgetAction(self)
action_widget.setEnabled(False)
action_widget.setIconVisibleInMenu(False)
if not title.startswith("<b>"):
title = f"<b> --- {title} --- "
else:
title = f" --- {title} --- "
label = QLabel(title)
font_w = label.font()
font_w.setPointSize(taille_police_menu)
label.setFont(font_w)
label.setAlignment(Qt.AlignCenter)
label.setFixedHeight(self.menu_ht_line)
label.setMinimumWidth(300)
label.setStyleSheet("background: #BAD0E7; color: #4D4D4D; border: 1px solid #C4C4C4")
action_widget.setDefaultWidget(label)
if isinstance(short_link, str) and short_link != "":
action_widget.setWhatsThis(short_link)
self.addAction(action_widget)
return action_widget
def add_action(self, qicon=None, title="", action=None, tooltips="", objectname="", short_link="") -> QAction:
if isinstance(qicon, QIcon):
if action is not None:
new_action = self.addAction(qicon, title, action)
else:
new_action = self.addAction(qicon, title)
else:
if action is not None:
new_action = self.addAction(title, action)
else:
new_action = self.addAction(title)
if isinstance(tooltips, str) and tooltips != "":
new_action.setToolTip(tooltips)
elif self.tooltips_visible:
new_action.setToolTip(title)
if isinstance(objectname, str) and objectname != "":
new_action.setObjectName(objectname)
if isinstance(short_link, str) and short_link != "":
new_action.setWhatsThis(short_link)
return new_action
def keyPressEvent(self, event: QKeyEvent):
super().keyPressEvent(event)
if event.key() != Qt.Key_F1:
return
position_cursor = QCursor().pos()
try:
local_pos = self.mapFromGlobal(position_cursor)
action = self.actionAt(local_pos)
except Exception as error:
print(f"tools -- MyContextMenu -- keyPressEvent -- error : {error}")
return
if not isinstance(action, QAction):
print(f"tools -- MyContextMenu -- keyPressEvent -- not isinstance(widget, QPushButton)")
return
short_link = action.whatsThis()
if short_link == "":
short_link = self.whatsThis()
if self.whatsThis() == "":
return
self.help_request.emit(short_link)
@staticmethod
def a___________________end______():
pass
def a___________________message_______________():
pass
class WidgetMessage(QDialog):
def __init__(self):
super().__init__()
# Chargement de l'interface
self.ui = Ui_Message()
self.ui.setupUi(self)
self.setWindowModality(Qt.ApplicationModal)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.ui.bt_oui.clicked.connect(self.bouton_oui_clicked)
self.ui.bt_non.clicked.connect(self.bouton_non_clicked)
self.ui.bt_save.clicked.connect(self.bouton_save_clicked)
self.ui.bt_annuler.clicked.connect(self.bouton_annuler_clicked)
self.deplier_actif = False
self.avec_checkbox = False
self.save = False
self.reponse = None
self.check = False
self.ht_defaut = 104
self.ht_chk = 123
self.ht_details_chk = 126
self.ht_details = 225
self.resize(QSize(300, self.ht_defaut))
self.ui.bt_deplier.clicked.connect(self.gestion_deplier)
self.ui.copy.clicked.connect(self.message_copy)
self.ui.save.clicked.connect(self.message_save)
def show_message(self, title: str, message: str, infos="",
type_bouton=None, defaut_bouton=None,
bt_oui=str(), bt_non=str(), bt_annuler=True,
icone_question=False, icone_avertissement=False, icone_critique=False, icone_valide=False,
icone_sauvegarde=False, icone_lock=False, icone_ouvrir=False,
details=None, txt_save=str(), afficher_details=False):
"""
Permet d'afficher un message
:param title: Titre de la fenêtre
:param message: Message à afficher
:param infos: Checkbox pour ne plus afficher -> nom de l'élément dans la base de registre
:param type_bouton: Défini le type de bouton :
QMessageBox.Ok | QMessageBox.No | QMessageBox.Cancel | QMessageBox.Save)
:param defaut_bouton: Défini le bouton par défaut à selectionner
:param bt_oui: Texte du bouton oui -> QMessageBox.Ok
:param bt_non: Texte du bouton non -> QMessageBox.No
:param bt_annuler: (obsolète)
:param icone_question: Permet d'afficher l'icône de question
:param icone_avertissement: Permet d'afficher l'icône de l'avertissement
:param icone_critique: Permet d'afficher l'icône d'une erreur critique
:param icone_valide: Permet d'afficher l'icône pour la validation (OK)
:param icone_sauvegarde: Permet d'affciher l'icône de sauvegarde
:param icone_lock: Permet d'affciher l'icône de sauvegarde
:param icone_ouvrir: Permet d'afficher l'icône ouvrir
:param details: Permet d'afficher plus de détails
:param txt_save: Permet d'afficher et de modifier le texte -> QMessageBox.Save
:param afficher_details: Bool permettant d'afficher ou masquer les détails (défaut false)
:return: None
"""
# Gestion du titre
self.setWindowTitle(title)
# Gestion du message
self.ui.message.setText(message)
# Gestion icône
self.gestion_icone(icone_question,
icone_avertissement,
icone_critique,
icone_valide,
icone_sauvegarde,
icone_lock,
icone_ouvrir)
# Gestion boutons
self.gestions_boutons(type_bouton, defaut_bouton, bt_oui, bt_non, bt_annuler, txt_save)
# Gestion checkbox
self.gestion_checkbox(infos)
# Géstion détails
self.gestion_details(details, not afficher_details)
self.exec()
def gestion_icone(self, icone_question: bool, icone_avertissement: bool, icone_critique: bool, icone_valide,
icone_sauvegarde: bool, icone_lock: bool, icone_ouvrir: bool):
"""
Permet de gérer les icônes
:param icone_question: Permet d'afficher l'icône de question
:param icone_avertissement: Permet d'afficher l'icône de l'avertissement
:param icone_critique: Permet d'afficher l'icône d'une erreur critique
:param icone_valide: Permet d'afficher l'icône pour la validation (OK)
:param icone_sauvegarde: Permet d'affciher l'icône de sauvegarde
:param icone_lock: Permet d'affciher l'icône cadenas
:param icone_ouvrir: Permet d'afficher l'icône Ouvrir
:return: None
"""
image = information_icon
if icone_question:
image = help_icon
elif icone_avertissement:
image = warning_icon
elif icone_critique:
image = error_icon
elif icone_valide:
image = valid_icon
elif icone_sauvegarde:
image = save_icon
elif icone_lock:
image = lock_icon
elif icone_ouvrir:
image = open_icon
self.ui.icon.setIcon(get_icon(image))
def gestions_boutons(self, type_bouton=None, defaut_bouton=None,
bt_oui=str(), bt_non=str(), bt_annuler=True, txt_save=str()):
"""
Permet de gérer les textes et l'affichage des boutons
:param type_bouton: Défini le type de bouton
:param defaut_bouton: Défini le bouton par défaut à selectionner
:param bt_oui: Texte du bouton oui -> QMessageBox.Ok
:param bt_non: Texte du bouton non -> QMessageBox.No
:param bt_annuler: Permet de cacher le bouton annuler -> QMessageBox.Cancel
:param txt_save: Permet de changer le nom save -> QMessageBox.Save
:return: None
"""
if type_bouton is not None:
# Bouton seul (4)
if type_bouton == QMessageBox.No:
self.ui.bt_oui.setVisible(False)
self.ui.bt_annuler.setVisible(False)
self.ui.bt_save.setVisible(False)
elif type_bouton == QMessageBox.Save:
self.ui.bt_oui.setVisible(False)
self.ui.bt_non.setVisible(False)
self.ui.bt_annuler.setVisible(False)
elif type_bouton == QMessageBox.Cancel:
self.ui.bt_oui.setVisible(False)
self.ui.bt_non.setVisible(False)
self.ui.bt_save.setVisible(False)
# Bouton OK (3)
elif type_bouton == QMessageBox.Ok | QMessageBox.No:
self.ui.bt_annuler.setVisible(False)
self.ui.bt_save.setVisible(False)
elif type_bouton == QMessageBox.Ok | QMessageBox.Save:
self.ui.bt_annuler.setVisible(False)
self.ui.bt_non.setVisible(False)
elif type_bouton == QMessageBox.Ok | QMessageBox.Cancel:
self.ui.bt_non.setVisible(False)
self.ui.bt_save.setVisible(False)
# Bouton non (2)
elif type_bouton == QMessageBox.No | QMessageBox.Save:
self.ui.bt_oui.setVisible(False)
self.ui.bt_annuler.setVisible(False)
elif type_bouton == QMessageBox.No | QMessageBox.Cancel:
self.ui.bt_oui.setVisible(False)
self.ui.bt_save.setVisible(False)
# Bouton save (1)
elif type_bouton == QMessageBox.Save | QMessageBox.Cancel:
self.ui.bt_oui.setVisible(False)
self.ui.bt_non.setVisible(False)
# Bouton triple
elif type_bouton == QMessageBox.Ok | QMessageBox.Save | QMessageBox.Cancel:
self.ui.bt_non.setVisible(False)
elif type_bouton == QMessageBox.Ok | QMessageBox.No | QMessageBox.Save:
self.ui.bt_annuler.setVisible(False)
elif type_bouton == QMessageBox.Ok | QMessageBox.No | QMessageBox.Cancel:
self.ui.bt_save.setVisible(False)
elif type_bouton == QMessageBox.Ok | QMessageBox.Save | QMessageBox.Cancel:
self.ui.bt_non.setVisible(False)
elif type_bouton == QMessageBox.No | QMessageBox.Save | QMessageBox.Cancel:
self.ui.bt_oui.setVisible(False)
elif type_bouton == QMessageBox.Ok | QMessageBox.No | QMessageBox.Save | QMessageBox.Cancel:
pass
else:
self.ui.bt_non.setVisible(False)
self.ui.bt_annuler.setVisible(False)
self.ui.bt_oui.setText("OK")
else:
if (bt_oui == "" or bt_oui == "Ok") and bt_non == "" and txt_save == "":
self.ui.bt_non.setVisible(False)
self.ui.bt_annuler.setVisible(False)
self.ui.bt_oui.setText("OK")
self.ui.bt_oui.setFocus()
if defaut_bouton is not None:
if defaut_bouton == QMessageBox.No:
self.ui.bt_non.setFocus()
elif defaut_bouton == QMessageBox.Save:
self.ui.bt_save.setFocus()
elif defaut_bouton == QMessageBox.Cancel:
self.ui.bt_annuler.setFocus()
if bt_oui != "":
self.ui.bt_oui.setText(f" {bt_oui} ")
if bt_non != "":
self.ui.bt_non.setText(f" {bt_non} ")
if txt_save != "":
self.ui.bt_save.setVisible(True)
self.ui.bt_save.setText(f" {txt_save} ")
else:
self.ui.bt_save.setVisible(False)
if not bt_annuler:
pass
self.sizeHint()
def gestion_checkbox(self, infos: str):
"""
Permet de gérer l'affichage de la checkbox
:param infos: Checkbox pour ne plus afficher -> nom de l'élément dans la base de registre
:return: None
"""
if infos == "":
self.ui.infos_widget.setVisible(False)
return
self.avec_checkbox = True
def gestion_details(self, details, afficher_details):
"""
Permet de gérer l'affichage du détail
:param details: Permet d'afficher plus de détails
:param afficher_details: Permet d'afficher plus de détails
:return:
"""
texte = ""
if isinstance(details, list):
nb_caractere = 3
try:
nb_items = str(len(details))
nb_caractere = len(nb_items)
except ValueError:
pass
for index_item in range(len(details)):
try:
index_str = str(index_item)
index_str = index_str.zfill(nb_caractere)
except ValueError:
index_str = f"{index_item}"
texte += f"{index_str} ==> {details[index_item]}\n"
elif isinstance(details, dict):
for key in details.keys():
texte += f"{key} ==> {details[key]}\n"
else:
texte = details
self.deplier_actif = afficher_details
if details is None or details == "":
self.ui.bt_deplier.setVisible(False)
self.ui.details_widget.setVisible(False)
self.ui.details.clear()
self.deplier_actif = False
return
self.ui.bt_deplier.setVisible(True)
self.ui.details.setText(f"{texte}")
self.gestion_deplier()
def gestion_deplier(self):
"""
Permet de gérer l'affichage de l'icône pour déplier et replier les détails
:return: None
"""
self.deplier_actif = not self.deplier_actif
self.setMaximumHeight(16777215)
self.ui.details_widget.setVisible(self.deplier_actif)
if self.deplier_actif:
self.ui.bt_deplier.setIcon(get_icon(detail_hide_icon))
height = self.ui.message_widget.height()
if height < 40:
height = 40
self.ui.message_widget.setMaximumHeight(height)
return
self.ui.bt_deplier.setIcon(get_icon(detail_show_icon))
self.ui.message_widget.setMaximumHeight(16777215)
self.adjustSize()
self.resize(self.width(), 0)
self.setMaximumHeight(self.height())
def bouton_oui_clicked(self):
"""
Permet de mettre en mémoire la réponse de l'utilisateur = OK
:return: None
"""
self.save = True
self.reponse = QMessageBox.Ok
self.check = self.ui.checkbox.isChecked()
# print(f"bouton_ok_clicked -- checkbox == {self.ui.checkbox.isChecked()}")
self.close()
def bouton_non_clicked(self):
"""
Permet de mettre en mémoire la réponse de l'utilisateur = No
:return:None
"""
self.save = True
self.reponse = QMessageBox.No
self.check = self.ui.checkbox.isChecked()
# print(f"bouton_no_clicked -- checkbox == {self.ui.checkbox.isChecked()}")
self.close()
def message_copy(self):
text = self.ui.details.toPlainText()
if not isinstance(text, str):
return
QApplication.clipboard().setText(text)
def message_save(self):
shortcuts_list = [asc_export_path]
a = QCoreApplication.translate("tools", "Fichier")
file_path = browser_file(parent=self,
title=application_title,
datas_filters={f"{a} TXT": [".txt"]},
registry=[app_setting_file, "path_export"],
shortcuts_list=shortcuts_list,
current_path=asc_export_path,
default_path="",
use_setting_first=True,
use_save=True)
if file_path == "":
return
text = self.ui.details.toPlainText()
if not isinstance(text, str):
return
try:
with open(file_path, "w", encoding="UTF-8") as file:
file.write(text)
except Exception as error:
print(f"message -- WidgetMessage -- message_save -- error : {error}")
def bouton_annuler_clicked(self):
"""
Permet de mettre en mémoire la réponse de l'utilisateur = Cancel
:return: None
"""
self.save = True
self.reponse = QMessageBox.Cancel
self.check = self.ui.checkbox.isChecked()
# print(f"bouton_cancel_clicked -- checkbox == {self.ui.checkbox.isChecked()}")
self.close()
def bouton_save_clicked(self):
"""
Permet de mettre en mémoire la réponse de l'utilisateur = Save
:return: None
"""
self.save = True
self.reponse = QMessageBox.Save
self.check = self.ui.checkbox.isChecked()
# print(f"bouton_cancel_clicked -- checkbox == {self.ui.checkbox.isChecked()}")
self.close()
@staticmethod
def a___________________event______():
pass
def closeEvent(self, event: QCloseEvent):
if not self.save:
self.reponse = QMessageBox.Cancel
self.check = False
super().closeEvent(event)
@staticmethod
def a___________________end______():
pass
def a___________________browser_______________():
pass
def browser_file(parent: QObject, title: str, datas_filters: dict, registry: list, shortcuts_list: list,
current_path="", default_path="",
file_name="", use_setting_first=True, use_save=False) -> str:
"""
:param parent: Objet parent
:param title: Title of dialog
:param datas_filters: {"Images" : [".png", ".jpg"], "Pdf" : [".pdf"]}
:param registry: [file_setting_name, setting_name]
:param shortcuts_list: shortcut paths list
:param current_path: current_path
:param default_path: default_path
:param file_name: file_name
:param use_setting_first: True = searh in the registry + current + default // False = current + registry + default
:param use_save: bool : False = for select file // True = For save file
:return: Path of select file or empty text
"""
if not isinstance(title, str) or not isinstance(current_path, str) or not isinstance(default_path, str):
print(f"browser -- browser_file -- not isinstance(title, str)")
return ""
if not isinstance(datas_filters, dict) or not isinstance(registry, list) or not isinstance(shortcuts_list, list):
print(f"browser -- browser_file -- not isinstance(title, str)")
return ""
if not isinstance(file_name, str) or not isinstance(use_setting_first, bool) or not isinstance(use_save, bool):
print(f"browser -- browser_file -- not isinstance(file_name, str)")
return ""
current_folder = find_folder_path(current_path)
default_folder = find_folder_path(default_path)
if len(registry) != 2:
settings_folder = default_folder
else:
settings_folder = settings_get(file_name=registry[0], info_name=registry[1])
if settings_folder is None:
settings_folder = default_folder
target_folder = ""
if not use_setting_first:
if current_folder != "" and current_folder != "\\" and os.path.exists(current_folder):
target_folder = f"{current_folder}{file_name}"
else:
if settings_folder != "" and settings_folder != "\\" and os.path.exists(settings_folder):
target_folder = f"{settings_folder}{file_name}"
else:
if default_folder != "" and default_folder != "\\" and os.path.exists(default_folder):
target_folder = f"{default_folder}{file_name}"
else:
if settings_folder != "" and settings_folder != "\\" and os.path.exists(settings_folder):
target_folder = f"{settings_folder}{file_name}"
else:
if current_folder != "" and current_folder != "\\" and os.path.exists(current_folder):
target_folder = f"{current_folder}{file_name}"
else:
if default_folder != "" and default_folder != "\\" and os.path.exists(default_folder):
target_folder = f"{default_folder}{file_name}"
if load_ok == "":
file_path = browser_file_classic(parent=parent,
title=title,
datas_filters=datas_filters,
target_folder=target_folder,
use_save=use_save)
else:
file_path = browser_file_new(title=title,
datas_filters=datas_filters,
shortcuts_list=shortcuts_list,
target_folder=target_folder,
use_save=use_save)
if file_name == file_path:
return ""
if file_path == "":
return ""
folder_current = find_folder_path(file_path)
if folder_current != "" and folder_current != "\\":
if len(registry) == 2:
settings_save_value(file_name=registry[0], key_name=registry[1], value=folder_current)
file_path: str = file_path.replace("/", "\\")
return file_path
# if accepter_tous:
# return chemin_fichier
#
# if use_save:
#
# if len(liste_extensions) == 0:
# return chemin_fichier
#
# extension_actuelle = liste_extensions[0]
#
# if chemin_fichier.endswith(extension_actuelle):
# return chemin_fichier
#
# chemin_fichier += extension_actuelle
# return chemin_fichier
#
# for extension in liste_extensions:
#
# extension: str
# fichier_upper = chemin_fichier.upper()
#
# if fichier_upper.endswith(extension.upper()):
# return chemin_fichier
#
# afficher_message(titre=parent.tr("Erreur extension de fichier"),
# message=parent.tr("L'extension du fichier est non valide !"),
# icone_avertissement=True)
#
# return ""
def browser_file_classic(parent: QObject, title: str, datas_filters: dict, target_folder: str, use_save=False) -> str:
extensions_list = list()
filters_list = list()
for filter_title, extensions in datas_filters.items():
for extension in extensions: