-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathformula_favorite.py
More file actions
2084 lines (1356 loc) · 67.1 KB
/
formula_favorite.py
File metadata and controls
2084 lines (1356 loc) · 67.1 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 os
from PyQt5.Qt import *
from allplan_manage import AllplanDatas, col_favoris_formule_titre, col_favoris_formule_famille, AllplanPaths
from allplan_manage import col_favoris_formule_formule
from catalog_manage import CatalogDatas
from formatting_widget import Formatting
from main_datas import attribute_model_show_icon, icons_path, paste_icon
from main_datas import delete_icon, valid_icon, error_icon, windows_close_hover_icon, get_icon
from main_datas import formula_fav_setting_file, app_setting_file, formula_fav_config_file, add_icon, options_icon
from models import ModelsTabDel
from tools import afficher_message as msg
from tools import qm_check, find_new_title, move_window_tool, recherche_image, application_title, MyContextMenu
from tools import settings_save, get_look_tableview, settings_read, browser_file
from ui_formula_favorite import Ui_FormulaFavorite
from ui_formula_favorite_modify import Ui_FormulaFavoriteModify
from ui_formula_favorite_tab import Ui_FormulaFavoriteTab
class FormulaFavorite(QWidget):
def __init__(self, asc):
super().__init__()
# -----------------------------------------------
# Parent
# -----------------------------------------------
self.asc = asc
self.asc.langue_change.connect(lambda main=self: self.ui.retranslateUi(main))
# -----------------------------------------------
# Interface
# -----------------------------------------------
self.ui = Ui_FormulaFavorite()
self.ui.setupUi(self)
self.ui.onglet.setTabBar(FormulaFavoriteTabBar())
# -----------------------------------------------
# Settings
# -----------------------------------------------
formula_fav = settings_read(formula_fav_setting_file)
self.ismaximized_on = formula_fav.get("ismaximized_on", False)
if not isinstance(self.ismaximized_on, bool):
self.ismaximized_on = False
width = formula_fav.get("width", 800)
if not isinstance(width, int):
width = 800
height = formula_fav.get("height", 600)
if not isinstance(height, int):
width = 800
self.resize(width, height)
# -----------------------------------------------
self.formulas_fav_model = QStandardItemModel()
self.tabs_list = list()
# -----------------------------------------------
# Allplan datas
# -----------------------------------------------
self.allplan: AllplanDatas = self.asc.allplan
# -----------------------------------------------
# Widget modifier un onglet
# -----------------------------------------------
self.widget_tab_modify = FormulaFavoriteModify(self.ui.onglet, self.allplan)
self.widget_tab_modify.appliquer_modifications.connect(self.onglet_renommer_action)
self.asc.langue_change.connect(
lambda main=self.widget_tab_modify: self.widget_tab_modify.ui.retranslateUi(main))
# -----------------------------------------------
# Widget supprimer un onglet
# -----------------------------------------------
self.widget_tab_del = ModelsTabDel(self.ui.onglet)
self.widget_tab_del.validation_supprimer.connect(self.onglet_suppression_action)
# -----------------------------------------------
# Signaux onglet
# -----------------------------------------------
self.ui.onglet.tabBarClicked.connect(self.onglet_clic)
self.ui.onglet.tabBarDoubleClicked.connect(self.onglet_double_clic)
tab_bar: FormulaFavoriteTabBar = self.ui.onglet.tabBar()
tab_bar.del_signal.connect(self.onglet_suppression)
tab_bar.move_signal.connect(self.onglet_deplacement)
# -----------------------------------------------
# Autres boutons
# -----------------------------------------------
self.ui.bt_enregistrer.clicked.connect(self.enregistrer)
self.ui.bt_quitter.clicked.connect(self.close)
self.change_made = False
self.ui.onglet.customContextMenuRequested.connect(self.onglet_afficher_menu)
@staticmethod
def a___________________chargement______():
pass
def formula_fav_personnaliser(self, parent_actuel: QWidget, nom_onglet="", formula_name=""):
self.onglets_chargement()
self.change_made = False
if nom_onglet == "" or nom_onglet not in self.tabs_list:
self.formula_fav_show(parent_actuel=parent_actuel)
return
index_onglet = self.tabs_list.index(nom_onglet)
self.ui.onglet.setCurrentIndex(index_onglet)
current_widget: FormulaFavoriteTab = self.ui.onglet.widget(index_onglet)
if not isinstance(current_widget, FormulaFavoriteTab):
self.formula_fav_show(parent_actuel=parent_actuel)
return
current_widget.gestion_header()
if formula_name != "":
current_widget.formula_select(formula_name=formula_name)
current_widget.ui.titre.setFocus()
self.formula_fav_show(parent_actuel=parent_actuel)
def formula_fav_show(self, parent_actuel):
move_window_tool(widget_parent=parent_actuel, widget_current=self)
if self.ismaximized_on:
self.showMaximized()
else:
self.show()
@staticmethod
def a___________________onglet_chargement_______________():
pass
def onglets_chargement(self):
print("WidgetFormulaFavorite -- onglets_chargement -- dbu")
self.formulas_fav_model.clear()
self.ui.onglet.blockSignals(True)
self.ui.onglet.clear()
self.tabs_list.clear()
self.onglet_ajouter_button_add()
self.ui.onglet.blockSignals(False)
dict_elements = settings_read(formula_fav_config_file)
if len(dict_elements) == 0:
dict_elements = self.formula_initialization()
for nom_onglet, family_datas in dict_elements.items():
nom_onglet = find_new_title(base_title=nom_onglet, titles_list=self.tabs_list)
family_datas: dict
icone_onglet = family_datas.get("icon", "")
icone_onglet = recherche_image(image_name=icone_onglet, image_default="attribute_model_show.svg")
formulas_dict: dict = family_datas.get("formulas", dict())
self.onglet_ajouter_action(nom_onglet, icone_onglet, formulas_dict=formulas_dict)
formula_fav = settings_read(formula_fav_setting_file)
tab_index = formula_fav.get("tab_index", 0)
if not isinstance(tab_index, int):
self.ui.onglet.setCurrentIndex(0)
elif tab_index < 0:
self.ui.onglet.setCurrentIndex(0)
else:
self.ui.onglet.setCurrentIndex(tab_index)
formula_name = formula_fav.get("formula_name", "")
if not isinstance(formula_name, str):
return
if formula_name == "":
return
widget = self.ui.onglet.widget(tab_index)
if not isinstance(widget, FormulaFavoriteTab):
self.change_made = False
return
widget.formula_select(formula_name=formula_name)
self.change_made = False
def formula_initialization(self) -> dict:
nom_onglet = self.onglet_recherche_titre()
formula_name = self.formulas_recherche_titre(nom_onglet="")
formula_txt = "@99@"
formulas_dict = {formula_name: formula_txt}
datas = {nom_onglet: {"icon": attribute_model_show_icon,
"formulas": formulas_dict}}
settings_save(formula_fav_config_file, datas)
return datas
@staticmethod
def a___________________model_gestion______():
pass
def favoris_fav_model_add(self, nom_onglet: str, formula_name="", formula="", save=False) -> str:
if formula_name == "":
formula_name = self.formulas_recherche_titre(nom_onglet=nom_onglet)
self.formulas_fav_model.appendRow([QStandardItem(formula_name),
QStandardItem(formula),
QStandardItem(nom_onglet)])
self.formulas_fav_model.sort(col_favoris_formule_titre)
if not save:
return formula_name
self.enregistrer_config()
return formula_name
def favoris_fav_model_del_family(self, nom_onglet: str) -> bool:
recherche = self.favoris_model_find_familly(nom_onglet=nom_onglet, reverse=True)
if len(recherche) == 0:
return False
for qs_titre in recherche:
if not isinstance(qs_titre, QStandardItem):
print("WidgetFormulaFavorite -- onglet_renommer_model -- not isinstance(qs_titre, QStandardItem)")
continue
row_actuel = qs_titre.row()
self.formulas_fav_model.takeRow(row_actuel)
return True
def favoris_model_rename_familly(self, ancien_titre: str, nouveau_titre: str) -> bool:
recherche = self.favoris_model_find_familly(nom_onglet=ancien_titre)
if len(recherche) == 0:
return False
for qs_titre in recherche:
if not isinstance(qs_titre, QStandardItem):
print("WidgetFormulaFavorite -- onglet_renommer_model -- not isinstance(qs_titre, QStandardItem)")
continue
qs_titre.setText(nouveau_titre)
return True
def favoris_model_find_familly(self, nom_onglet: str, reverse=False) -> list:
recherche = self.formulas_fav_model.findItems(nom_onglet, Qt.MatchExactly, col_favoris_formule_famille)
if len(recherche) == 0:
print(f"WidgetFormulaFavorite -- favoris_model_find_familly -- le titre {nom_onglet} n'a pas été trouvé !")
return list()
recherche.sort(reverse=reverse)
return recherche
@staticmethod
def a___________________onglet_menu______():
pass
def onglet_afficher_menu(self, point: QPoint):
index_onglet = self.ui.onglet.tabBar().tabAt(point)
if index_onglet == -1:
menu = MyContextMenu(tooltips_visible=False)
menu.add_title(title=self.windowTitle())
menu.add_action(qicon=get_icon(add_icon),
title=self.tr('Nouveau'),
action=self.onglet_ajouter)
menu.exec_(self.ui.onglet.mapToGlobal(point))
return
widget_onglet = self.ui.onglet.widget(index_onglet)
if self.ui.onglet.currentIndex() != index_onglet:
self.ui.onglet.setCurrentIndex(index_onglet)
if not isinstance(widget_onglet, FormulaFavoriteTab):
print("WidgetFormulaFavorite -- onglet_afficher_menu -- "
"not isinstance(widget_onglet, WidgetFormulaFavoriteTab)")
return
menu = MyContextMenu(tooltips_visible=False)
menu.add_title(title=self.windowTitle())
menu.add_action(qicon=get_icon(add_icon),
title=self.tr('Nouveau'),
action=self.onglet_ajouter)
menu.add_action(qicon=get_icon(options_icon),
title=self.tr('Éditer'),
action=lambda: self.onglet_renommer_afficher(index_onglet=index_onglet,
widget_onglet=widget_onglet))
menu.add_action(qicon=get_icon(delete_icon),
title=self.tr('Supprimer'),
action=lambda: self.onglet_suppression_action(current_index=index_onglet))
menu.exec_(self.ui.onglet.mapToGlobal(point))
@staticmethod
def a___________________onglet_ajouter_______________():
pass
def onglet_ajouter_button_add(self):
self.ui.onglet.addTab(QWidget(), get_icon(add_icon), "")
def onglet_ajouter(self):
icone_onglet = ":/Images/attribute_model_show.svg"
formulas_dict = dict()
index_insertion = - 1
nom_onglet = self.onglet_ajouter_action(title="",
icone_onglet=icone_onglet,
formulas_dict=formulas_dict,
tab_index=index_insertion)
self.onglet_ajouter_afficher_menu(nom_onglet=nom_onglet,
icone_onglet=icone_onglet,
index_insertion=index_insertion)
def onglet_ajouter_afficher_menu(self, nom_onglet: str, icone_onglet: str, index_insertion: int):
# Définition de l'index d'insertion dans la liste
if index_insertion == -1:
index_insertion = self.ui.onglet.count() - 1
self.onglet_placement_widget(index_insertion, self.widget_tab_modify)
self.widget_tab_modify.formulas_fav_personnaliser(nom_onglet=nom_onglet,
icone_onglet=icone_onglet,
liste_onglets=self.tabs_list)
def onglet_ajouter_action(self, title="", icone_onglet="", formulas_dict=None, tab_index=-1) -> str:
if title == "":
title = self.onglet_recherche_titre()
if icone_onglet == "":
icone_onglet = attribute_model_show_icon
else:
icone_onglet = recherche_image(image_name=icone_onglet, image_default=attribute_model_show_icon)
# Définition de l'index d'insertion dans la liste
if tab_index == -1:
tab_index = len(self.tabs_list)
if formulas_dict is None:
formulas_dict = dict()
if len(formulas_dict) == 0:
self.favoris_fav_model_add(nom_onglet=title)
else:
formula_titles_list = self.formulas_lister_titre()
for formula_name, formula in formulas_dict.items():
formula_name = find_new_title(base_title=formula_name, titles_list=formula_titles_list)
self.favoris_fav_model_add(nom_onglet=title,
formula_name=formula_name,
formula=formula)
formula_titles_list.append(formula_name)
# Mise à jour de la liste des onglets
self.tabs_list.insert(tab_index, title)
# Création d'un nouvel onglet
tab = FormulaFavoriteTab(asc=self.asc,
widget_onglet=self,
nom_onglet=title,
icone_onglet=icone_onglet)
self.onglet_update_combo()
self.asc.langue_change.connect(lambda main=tab: tab.ui.retranslateUi(main))
tab.famille_change.connect(self.formula_changement_famille)
# Ajout de l'onglet
self.ui.onglet.insertTab(tab_index, tab, get_icon(icone_onglet), title)
if tab_index <= 6:
self.ui.onglet.setTabToolTip(tab_index, f"{title} (F{tab_index + 6})")
else:
self.ui.onglet.setTabToolTip(tab_index, title)
# Définition du nouvel onglet comme l'onglet utilisé
self.ui.onglet.setCurrentIndex(tab_index)
self.change_made = True
return title
def onglet_recherche_titre(self) -> str:
titre_base = self.tr("Favoris")
return find_new_title(base_title=titre_base, titles_list=self.tabs_list)
@staticmethod
def a___________________onglet_supprimer_______________():
pass
def onglet_suppression(self, current_index: int):
""" Gestion de la suppression d'un onglet
:param current_index: information envoyée par le programme informant l'index de l'onglet qui sera supprimé
:return: None
"""
if self.ui.onglet.count() <= 1:
return
# Définition du titre de l'onglet
nom_onglet = self.ui.onglet.tabText(current_index)
if nom_onglet not in self.tabs_list:
print("WidgetFormulaFavorite -- suppression_onglet -- titre_onglet not in self.liste_onglets")
return
self.onglet_placement_widget(current_index, self.widget_tab_del)
self.widget_tab_del.del_ask_show(tab_index=current_index)
def onglet_suppression_action(self, current_index):
nom_onglet = self.ui.onglet.tabText(current_index)
if not self.favoris_fav_model_del_family(nom_onglet=nom_onglet):
return
# Mise à jour de la liste des onglets
self.tabs_list.remove(nom_onglet)
# Suppression de la onglet
self.ui.onglet.blockSignals(True)
self.ui.onglet.removeTab(current_index)
self.ui.onglet.blockSignals(False)
if current_index == self.ui.onglet.count() - 1:
self.ui.onglet.setCurrentIndex(self.ui.onglet.count() - 2)
self.onglet_update_combo()
self.tab_redefine_shortcut()
self.change_made = True
@staticmethod
def a___________________onglet_renommer_______________():
pass
def onglet_placement_widget(self, current_index: int, widget):
point: QPoint = self.ui.onglet.tabBar().tabRect(current_index).bottomRight()
global_point: QPoint = self.ui.onglet.tabBar().mapToGlobal(point)
largeur_onglet = self.ui.onglet.tabBar().tabRect(current_index).width()
largeur_widget = widget.size().width()
position_max = self.size().width()
position_fin = largeur_widget + point.x()
if position_fin < position_max:
widget.move(global_point - QPoint(largeur_onglet, 0))
else:
widget.move(global_point - QPoint(largeur_widget, 0))
def onglet_renommer_action(self, ancien_titre: str, title: str, nouvelle_icone: str):
tab_index = self.ui.onglet.currentIndex()
ancien_index = self.tabs_list.index(ancien_titre)
widget_tab = self.ui.onglet.currentWidget()
if not isinstance(widget_tab, FormulaFavoriteTab):
print("WidgetFormulaFavorite -- onglet_renommer_action -- "
"not isinstance(widget, WidgetFormulaFavoriteTab)")
return
if ancien_titre != title:
formula_name = widget_tab.current_formula_find()
if not self.favoris_model_rename_familly(ancien_titre, title):
return
self.tabs_list[ancien_index] = title
self.ui.onglet.setTabText(tab_index, title)
if tab_index <= 6:
self.ui.onglet.setTabToolTip(tab_index, f"{title} (F{tab_index + 6})")
else:
self.ui.onglet.setTabToolTip(tab_index, title)
widget_tab.nom_onglet = title
widget_tab.onglet_renamed(title, formula_name)
self.onglet_update_combo(ancien_titre, title)
self.change_made = True
icone_actuelle = widget_tab.icone_onglet
if icone_actuelle != nouvelle_icone:
widget_tab.icone_onglet = nouvelle_icone
self.ui.onglet.setTabIcon(tab_index, get_icon(nouvelle_icone))
self.change_made = True
def onglet_renommer_afficher(self, index_onglet: int, widget_onglet):
if not isinstance(widget_onglet, FormulaFavoriteTab):
return
if self.ui.onglet.currentIndex() != index_onglet:
self.ui.onglet.setCurrentIndex(index_onglet)
self.onglet_placement_widget(index_onglet, self.widget_tab_modify)
self.widget_tab_modify.formulas_fav_personnaliser(nom_onglet=widget_onglet.nom_onglet,
icone_onglet=widget_onglet.icone_onglet,
liste_onglets=self.tabs_list)
@staticmethod
def a___________________onglet_gestion_combo_familles_______________():
pass
def onglet_update_combo(self, ancien_titre="", nouveau_titre=""):
for index_tab in range(self.ui.onglet.count()):
widget_tab = self.ui.onglet.widget(index_tab)
if not isinstance(widget_tab, FormulaFavoriteTab):
continue
widget_tab.combo_families_load(ancien_titre, nouveau_titre)
@staticmethod
def a___________________onglet_deplacement_______________():
pass
def onglet_deplacement(self, _, index_arrivee: int):
# Définition du titre de l'onglet
titre_onglet = self.ui.onglet.tabText(index_arrivee)
# Vérification que le titre de l'onglet est bien dans le datas des onglets
if titre_onglet not in self.tabs_list:
return
self.tabs_list.remove(titre_onglet)
self.tabs_list.insert(index_arrivee, titre_onglet)
self.onglet_update_combo()
self.tab_redefine_shortcut()
self.change_made = True
def tab_redefine_shortcut(self):
tabs_count = self.ui.onglet.count()
for tab_index in range(1, tabs_count):
title = self.ui.onglet.tabText(tab_index)
if tab_index <= 6:
self.ui.onglet.setTabToolTip(tab_index, f"{title} (F{tab_index + 6})")
else:
self.ui.onglet.setTabToolTip(tab_index, title)
@staticmethod
def a___________________onglet_clic_______________():
pass
def onglet_clic(self, current_index: int):
last_tab = self.ui.onglet.count() - 1
if current_index == last_tab:
self.onglet_ajouter()
return
widget: FormulaFavoriteTab = self.ui.onglet.widget(current_index)
if not isinstance(widget, FormulaFavoriteTab):
return
widget.gestion_header()
def onglet_double_clic(self, index_onglet: int):
"""Gestion du double clic sur le ui.onglet
:param index_onglet: information envoyée par le programme informant l'index du double clic -> -1 si aucun onglet
:return: None
"""
# Vérification si aucun onglet n'a été double cliqué
if index_onglet == -1:
self.onglet_ajouter()
return
widget = self.ui.onglet.currentWidget()
if not isinstance(widget, FormulaFavoriteTab):
return
self.onglet_renommer_afficher(index_onglet=index_onglet, widget_onglet=widget)
@staticmethod
def a___________________formulas_______________():
pass
def formulas_lister_titre(self, upper=True) -> list:
nb_items = self.formulas_fav_model.rowCount()
formula_titles_list = list()
for index_item in range(nb_items):
qs_formula_title = self.formulas_fav_model.item(index_item, col_favoris_formule_titre)
if not isinstance(qs_formula_title, QStandardItem):
continue
formula_titre = qs_formula_title.text()
if not isinstance(formula_titre, str):
continue
if upper:
formula_titre = formula_titre.upper()
formula_titles_list.append(formula_titre)
return formula_titles_list
def formulas_recherche_titre(self, nom_onglet: str) -> str:
formula_titles_list = self.formulas_lister_titre()
if nom_onglet != "":
titre_base = nom_onglet
else:
titre_base = self.tr("Formule")
titre_base = f"{titre_base} 01"
if len(formula_titles_list) == 0:
return titre_base
return find_new_title(base_title=titre_base, titles_list=formula_titles_list)
@staticmethod
def formulas_recup_datas(widget_tab):
formulas_dict = dict()
if not isinstance(widget_tab, FormulaFavoriteTab):
return formulas_dict
nb_item = widget_tab.filtre_famille.rowCount()
for index_row in range(nb_item):
qm_titre = widget_tab.filtre_famille.index(index_row, col_favoris_formule_titre)
if not qm_check(qm_titre):
continue
qm_formule = widget_tab.filtre_famille.index(index_row, col_favoris_formule_formule)
if not qm_check(qm_titre):
continue
formula_titre = qm_titre.data()
formula_actuel = qm_formule.data()
formulas_dict[formula_titre] = formula_actuel
return formulas_dict
def formula_changement_famille(self, index_tab: int, formula_name: str):
self.ui.onglet.setCurrentIndex(index_tab)
widget_tab = self.ui.onglet.widget(index_tab)
if not isinstance(widget_tab, FormulaFavoriteTab):
return
widget_tab.recherche_formule_titre(formula_name=formula_name)
@staticmethod
def a___________________sauvegarde_fichier_config_______________():
pass
def enregistrer_recherche_modifs(self) -> bool:
if self.change_made:
return True
for index_tab in range(self.ui.onglet.count()):
widget: FormulaFavoriteTab = self.ui.onglet.widget(index_tab)
if not isinstance(widget, FormulaFavoriteTab):
continue
widget.ui.titre.setFocus()
if widget.modification_en_cours:
return True
return False
def enregistrer(self):
self.enregistrer_setting(saved=True)
self.enregistrer_config()
self.change_made = False
self.close()
def enregistrer_setting(self, saved: bool):
datas_config = settings_read(file_name=formula_fav_setting_file)
if saved:
tab_index = self.ui.onglet.currentIndex()
datas_config["tab_index"] = tab_index
datas_config["formula_name"] = ""
widget_tab = self.ui.onglet.widget(tab_index)
if isinstance(widget_tab, FormulaFavoriteTab):
qm = widget_tab.ui.liste_formule.currentIndex()
if qm_check(qm):
formula_name = qm.data()
if isinstance(formula_name, str):
datas_config["formula_name"] = qm.data()
if self.isMaximized():
screennumber = QApplication.desktop().screenNumber(self)
screen = QApplication.desktop().screenGeometry(screennumber)
if isinstance(screen, QRect):
datas_config["height"] = screen.height()
datas_config["width"] = screen.width()
datas_config["ismaximized_on"] = True
settings_save(file_name=formula_fav_setting_file, config_datas=datas_config)
return
datas_config["height"] = self.size().height()
datas_config["width"] = self.size().width()
datas_config["ismaximized_on"] = False
settings_save(file_name=formula_fav_setting_file, config_datas=datas_config)
def enregistrer_config(self):
datas_elements = dict()
for index_tab in range(self.ui.onglet.count()):
widget: FormulaFavoriteTab = self.ui.onglet.widget(index_tab)
if not isinstance(widget, FormulaFavoriteTab):
continue
nom_onglet = widget.nom_onglet
icone_onglet = self.icone_supprimer_path(widget.icone_onglet)
formulas_dict = self.formulas_recup_datas(widget_tab=widget)
datas_elements[nom_onglet] = {"icon": icone_onglet, "formulas": formulas_dict}
widget.modification_en_cours = False
settings_save(formula_fav_config_file, datas_elements)
@staticmethod
def a___________________icone_gestion_______________():
pass
@staticmethod
def icone_supprimer_path(icone_onglet: str) -> str:
if icone_onglet.startswith(":/Images/"):
icone_onglet = icone_onglet.replace(":/Images/", "")
return icone_onglet
if icone_onglet.startswith(icons_path):
icone_onglet = icone_onglet.replace(icons_path, "")
return icone_onglet
return icone_onglet
@staticmethod
def a___________________event______():
pass
def keyPressEvent(self, event: QKeyEvent):
super().keyPressEvent(event)
if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_N:
self.onglet_ajouter()
return
if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_S:
self.enregistrer()
return
if event.key() == Qt.Key_F2:
current_index = self.ui.onglet.currentIndex()
if current_index == 0 or current_index == 1:
return
self.onglet_double_clic(self.ui.onglet.currentIndex())
return
if event.key() == Qt.Key_Escape:
self.close()
shortcuts = [Qt.Key_F6, Qt.Key_F7, Qt.Key_F8, Qt.Key_F9, Qt.Key_F10, Qt.Key_F11, Qt.Key_F12]
tab_count = self.ui.onglet.count()
if event.key() not in shortcuts:
return
tab_index = shortcuts.index(event.key())
if tab_index == -1 or tab_index >= tab_count - 1:
return
self.ui.onglet.setCurrentIndex(tab_index)
def changeEvent(self, event: QEvent):
if event.type() == QEvent.WindowStateChange:
if self.isMaximized():
self.ismaximized_on = True
else:
self.ismaximized_on = False
move_window_tool(widget_parent=self, widget_current=self)
super().changeEvent(event)
def closeEvent(self, event: QCloseEvent):
saved = True
if self.enregistrer_recherche_modifs():
if msg(titre=self.windowTitle(),
message=self.tr("Voulez-vous enregistrer les modifications?"),
type_bouton=QMessageBox.Ok | QMessageBox.No,
defaut_bouton=QMessageBox.Ok,
icone_sauvegarde=True) == QMessageBox.Ok:
self.enregistrer_config()
else:
saved = False
self.enregistrer_setting(saved=saved)
super().closeEvent(event)
@staticmethod
def a___________________end______():
pass
class FormulaFavoriteTab(QWidget):
famille_change = pyqtSignal(int, str)
def __init__(self, asc, widget_onglet: FormulaFavorite, nom_onglet: str, icone_onglet: str):
super().__init__()
# Création de l'interface
self.ui = Ui_FormulaFavoriteTab()
self.ui.setupUi(self)
self.asc = asc
self.allplan: AllplanDatas = self.asc.allplan
self.catalogue: CatalogDatas = self.asc.catalog
self.widget_onglet = widget_onglet
self.widget_options = Formatting()
self.widget_options.save_modif_formatage.connect(self.options_retour_datas)
self.ui.format_bt.clicked.connect(self.options_afficher)
# self.asc.langue_change.connect(lambda main=self: self.ui.retranslateUi(main))
# self.ui.valeur_attr.chargement(self.allplan)
# Définition des variables
self.nom_onglet = nom_onglet
self.icone_onglet = icone_onglet
self.formulas_fav_model = self.widget_onglet.formulas_fav_model
# -----------------------------------------------
# model
# -----------------------------------------------
self.filtre_famille = QSortFilterProxyModel()
self.filtre_famille.setSourceModel(self.formulas_fav_model)
self.filtre_famille.setFilterKeyColumn(col_favoris_formule_famille)
self.filtre_famille.setSortLocaleAware(True)
self.filtre_famille.setFilterRegExp(nom_onglet)
self.ui.liste_formule.setModel(self.filtre_famille)
self.gestion_header()
get_look_tableview(self.ui.liste_formule)
self.ui.liste_formule.selectionModel().selectionChanged.connect(self.changement_selection)
self.ui.liste_formule.setCurrentIndex(self.filtre_famille.index(0, col_favoris_formule_titre))