-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.py
5591 lines (3640 loc) · 179 KB
/
library.py
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 json
import os.path
from catalog_manage import *
from convert_manage import BddTypeDetection, ConvertBcmOuvrages, ConvertBcmComposants, ConvertCSV, ConvertMXDB, \
ConvertNevarisXml, ConvertNevarisExcel
from convert_manage import ConvertAllmetre, ConvertFavorite, ConvertExcel, ConvertExtern, ConvertKukat
from formatting_widget import Formatting
from hierarchy_qs import MyQstandardItem
from main_datas import *
from message import LoadingSplash
from models import ModelsTabDel
from tools import afficher_message as msg, get_bdd_paths
from tools import find_global_point, open_folder, open_file, copy_to_clipboard, settings_read
from tools import get_look_tableview, get_real_path_of_apn_file, settings_save
from tools import get_look_treeview, settings_get, move_window_tool, MyContextMenu
from translation_manage import *
from ui_library import Ui_Library
from ui_library_modify import Ui_LibraryModify
from ui_library_tab import Ui_LibraryTab
from ui_library_tab_manage import Ui_LibraryTabManage
from ui_library_synchro import Ui_LibrarySynchro
from browser import browser_file
tab_max_count = 11
class Library(QWidget):
choisir_attribut_signal = pyqtSignal(str, str)
def __init__(self, asc):
super().__init__()
# ---------------------------------------
# LOADING UI
# ---------------------------------------
self.ui = Ui_Library()
self.ui.setupUi(self)
self.tab_bar = LibraryTabBar()
self.ui.librairies_tabs.setTabBar(self.tab_bar)
library_setting = settings_read(library_setting_file)
self.ismaximized_on = library_setting.get("ismaximized_on", False)
if not self.ismaximized_on:
largeur = library_setting.get("width", 800)
hauteur = library_setting.get("height", 600)
self.resize(largeur, hauteur)
# -----------------------------------------------
# Parent
# -----------------------------------------------
self.asc = asc
self.asc.langue_change.connect(lambda main=self: self.ui.retranslateUi(main))
self.asc.langue_change.connect(self.tabs_reset_all)
self.allplan: AllplanDatas = self.asc.allplan
self.catalog: CatalogDatas = self.asc.catalog
# ---------------------------------------
# VARIABLES
# ---------------------------------------
self.change_made = False
self.current_qs = None
self.current_mode = "Ajout"
current_tab = library_setting.get("index_tab", 0)
if current_tab < 0:
current_tab = 0
self.current_tab_index = current_tab
# ---------------------------------------
# LOADING MANAGE TAB
# ---------------------------------------
self.widget_manage_tab = LibraryTabManage(self)
# -----------------------------------------------
# LOADING WIDGET DELETE
# -----------------------------------------------
self.widget_library_del = ModelsTabDel(self.ui.librairies_tabs)
self.widget_library_del.validation_supprimer.connect(self.widget_manage_tab.library_used_changed)
self.tab_bar.del_signal.connect(self.tab_delete_confirm_show)
# -----------------------------------------------
# LOADING SIGNALS
# -----------------------------------------------
self.ui.librairies_tabs.currentChanged.connect(self.tab_changed)
self.ui.librairies_tabs.tabBarDoubleClicked.connect(self.tab_double_clicked)
self.ui.librairies_tabs.customContextMenuRequested.connect(self.tab_menu_show)
self.tab_bar.move_signal.connect(self.tab_moved)
@staticmethod
def a___________________initialisation___________________():
pass
def tab_manager_creation(self):
title = self.tr("Gestion")
self.ui.librairies_tabs.addTab(self.widget_manage_tab,
get_icon(external_bdd_option_icon),
title)
self.ui.librairies_tabs.setTabToolTip(0, f"{title} (F6)")
def show_library(self, current_qs: MyQstandardItem, current_parent: QWidget, current_mode="Ajout") -> None:
self.current_mode = current_mode
self.current_qs = current_qs
if current_mode == "Ajout":
self.setWindowModality(Qt.WindowModal)
else:
self.setWindowModality(Qt.ApplicationModal)
if not self.widget_manage_tab.initialize_ok:
self.tab_manager_creation()
self.widget_manage_tab.library_initialize()
for index_widget in range(1, self.ui.librairies_tabs.count()):
widget_tab = self.ui.librairies_tabs.widget(index_widget)
if not isinstance(widget_tab, LibraryTab):
continue
widget_tab.current_mode = current_mode
if current_mode == "Ajout":
widget_tab.current_qs = current_qs
widget_tab.mode_manage()
move_window_tool(widget_parent=current_parent, widget_current=self)
if self.ismaximized_on:
self.showMaximized()
else:
self.show()
self.tab_changed(tab_index=self.current_tab_index)
def hierarchy_selection_changed(self, new_qs: QStandardItem):
for index_widget in range(1, self.ui.librairies_tabs.count()):
widget_tab = self.ui.librairies_tabs.widget(index_widget)
if not isinstance(widget_tab, LibraryTab):
continue
widget_tab.current_qs = new_qs
widget_tab.mode_manage()
@staticmethod
def a___________________tab_changed___________________():
pass
def tab_changed(self, tab_index: int) -> None:
self.current_tab_index = tab_index
tab_widget: LibraryTab = self.ui.librairies_tabs.widget(tab_index)
if not isinstance(tab_widget, LibraryTab):
return
tab_widget.ui.library_hierarchy.setFocus()
if tab_widget.library_model.rowCount() != 0:
return
if not self.isVisible():
return
tab_widget.loading_model()
@staticmethod
def a___________________tab_add___________________():
pass
def tab_add(self, title: str, bdd_path_file: str, bdd_type: str) -> None:
for tab_index in range(self.ui.librairies_tabs.count()):
if self.ui.librairies_tabs.tabText(tab_index) == title:
return
widget_library_tab = LibraryTab(self, bdd_type, bdd_path_file, title)
widget_library_tab.current_qs = self.current_qs
bdd_icon = get_icon(bdd_icons_dict.get(bdd_type, bdd_icons_dict[bdd_type_xml]))
tab_index = self.ui.librairies_tabs.addTab(widget_library_tab, bdd_icon, title)
if tab_index <= 6:
self.ui.librairies_tabs.setTabToolTip(tab_index, f"{title} (F{tab_index + 6})")
else:
self.ui.librairies_tabs.setTabToolTip(tab_index, title)
widget_library_tab.ajouter_signal.connect(self.catalog.hierarchie_coller_datas)
widget_library_tab.current_mode = self.current_mode
widget_library_tab.mode_manage()
@staticmethod
def a___________________tab_delete___________________():
pass
def tab_delete_confirm_show(self, tab_index: int) -> None:
if tab_index == -1 or tab_index == 0:
return
self.move_widget_under_tab(tab_index=tab_index,
widget_to_show=self.widget_library_del)
self.widget_library_del.del_ask_show(tab_index=tab_index)
@staticmethod
def a___________________tab_moved__________________():
pass
def tab_moved(self) -> None:
self.change_made = True
self.tab_redefine_shortcut()
def tab_redefine_shortcut(self):
tabs_count = self.ui.librairies_tabs.count()
for tab_index in range(1, tabs_count):
title = self.ui.librairies_tabs.tabText(tab_index)
if tab_index <= 6:
self.ui.librairies_tabs.setTabToolTip(tab_index, f"{title} (F{tab_index + 6})")
else:
self.ui.librairies_tabs.setTabToolTip(tab_index, title)
@staticmethod
def a___________________tab_renamed__________________():
pass
def tab_renamed(self, original_title: str, new_title: str) -> None:
tabs_count = self.ui.librairies_tabs.count()
for tab_index in range(tabs_count):
title = self.ui.librairies_tabs.tabText(tab_index)
if title == original_title:
self.ui.librairies_tabs.setTabText(tab_index, new_title)
if tab_index <= 6:
self.ui.librairies_tabs.setTabToolTip(tab_index, f"{title} (F{tab_index + 6})")
return
self.ui.librairies_tabs.setTabToolTip(tab_index, title)
return
@staticmethod
def a___________________tab_double_clicked__________________():
pass
def tab_double_clicked(self, tab_index: int) -> None:
if not isinstance(tab_index, int):
return
if tab_index == -1:
self.widget_manage_tab.library_add_clicked()
return
title = self.ui.librairies_tabs.tabText(tab_index)
self.widget_manage_tab.library_modify_tab(title=title)
@staticmethod
def a___________________tab_menu__________________():
pass
def tab_menu_show(self, point: QPoint):
tab_index = self.tab_bar.tabAt(point)
tab_count = self.ui.librairies_tabs.count()
title = self.ui.librairies_tabs.tabText(tab_index)
self.ui.librairies_tabs.setCurrentIndex(tab_index)
menu = MyContextMenu()
menu.add_title(title=self.windowTitle())
menu_empty = True
# ------------------------------
# Add
# ------------------------------
if tab_count < tab_max_count:
menu_empty = False
menu.add_action(qicon=get_icon(add_icon),
title=self.tr('Ajouter'),
action=self.widget_manage_tab.library_add_clicked)
# ------------------------------
# Modify
# ------------------------------
if tab_index > 0:
menu_empty = False
menu.add_action(qicon=get_icon(external_bdd_option_icon),
title=self.tr('Modifier'),
action=lambda: self.widget_manage_tab.library_modify_tab(title=title))
# ------------------------------
# Used
# ------------------------------
menu.add_action(qicon=get_icon(on_icon),
title=self.tr("Ne plus utiliser"),
action=lambda: self.widget_manage_tab.library_used_changed(tab_index=tab_index))
# ------------------------------
# tools
# ------------------------------
menu.addSeparator()
bdd_path = self.widget_manage_tab.find_bdd_path_file(title=title)
if bdd_path is not None:
bdd_folder_path: str = find_folder_path(bdd_path)
if bdd_folder_path != "":
if os.path.exists(bdd_folder_path):
menu.add_action(qicon=get_icon(open_icon),
title=self.tr("Ouvrir le dossier"),
action=lambda: self.tab_open_folder(bdd_folder_path))
menu.addSeparator()
if os.path.exists(bdd_path) and bdd_path.endswith(openable_file_extension):
menu.add_action(qicon=get_icon(open_text_editor_icon),
title=self.tr("Ouvrir le fichier"),
action=lambda: open_file(bdd_path))
if not menu_empty:
menu.exec_(self.tab_bar.mapToGlobal(point))
@staticmethod
def tab_open_folder(bdd_foler_path: str):
if QApplication.keyboardModifiers() == Qt.ControlModifier:
copy_to_clipboard(value=bdd_foler_path, show_msg=True)
open_folder(bdd_foler_path)
@staticmethod
def tab_open_file(bdd_path: str):
if QApplication.keyboardModifiers() == Qt.ControlModifier:
copy_to_clipboard(value=bdd_path, show_msg=True)
open_file(bdd_path)
@staticmethod
def a___________________reset___________________():
pass
def tabs_reset_all(self) -> None:
self.close()
if not self.widget_manage_tab.initialize_ok:
return
self.ui.librairies_tabs.blockSignals(True)
self.ui.librairies_tabs.clear()
self.widget_manage_tab.library_reset()
self.widget_manage_tab.initialize_ok = False
self.ui.librairies_tabs.blockSignals(False)
@staticmethod
def a___________________tab_tools___________________():
pass
def move_widget_under_tab(self, tab_index: int, widget_to_show: QWidget) -> None:
point: QPoint = self.ui.librairies_tabs.tabBar().tabRect(tab_index).bottomRight()
global_point: QPoint = self.ui.librairies_tabs.tabBar().mapToGlobal(point)
tab_width = self.ui.librairies_tabs.tabBar().tabRect(tab_index).width()
widget_width = widget_to_show.size().width()
position_max = self.size().width()
position_end = widget_width + point.x()
if position_end < position_max:
widget_to_show.move(global_point - QPoint(tab_width, 0))
else:
widget_to_show.move(global_point - QPoint(widget_width, 0))
@staticmethod
def a___________________signals___________________():
pass
def librairie_reception_valeur(self, number: str, value: str) -> None:
self.choisir_attribut_signal.emit(number, value)
def ne_pas_fermer_ui(self) -> None:
current_index = self.ui.librairies_tabs.currentIndex()
current_tab: LibraryTab = self.ui.librairies_tabs.widget(current_index)
if current_tab is None:
return
current_tab.close_ui = False
@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.widget_manage_tab.library_add_clicked()
return
if event.key() == Qt.Key_F2:
tab_index = self.ui.librairies_tabs.currentIndex()
if tab_index == 0:
self.widget_manage_tab.library_modify_clicked()
return
title = self.ui.librairies_tabs.tabText(tab_index)
self.widget_manage_tab.library_modify_tab(title=title)
return
if event.key() == Qt.Key_Escape:
self.close()
return
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.librairies_tabs.count()
if event.key() not in shortcuts:
return
index_tab = shortcuts.index(event.key())
if index_tab == -1 or index_tab >= tab_count:
return
self.ui.librairies_tabs.setCurrentIndex(index_tab)
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):
self.widget_manage_tab.library_save_action()
super().closeEvent(event)
@staticmethod
def a___________________end___________________():
pass
class LibraryTabManage(QWidget):
def __init__(self, widget_library: Library):
super().__init__()
# ---------------------------------------
# LOADING UI
# ---------------------------------------
self.ui = Ui_LibraryTabManage()
self.ui.setupUi(self)
# -----------------------------------------------
# Parent
# -----------------------------------------------
self.widget_library = widget_library
self.asc = self.widget_library.asc
self.asc.langue_change.connect(lambda main=self: self.ui.retranslateUi(main))
self.library_tabs = self.widget_library.ui.librairies_tabs
self.widget_library_modify = LibraryModify(self)
self.widget_library_modify.save_add.connect(self.library_add_action)
self.widget_library_modify.save_modifications.connect(self.library_modify_action)
# ---------------------------------------
# VARIABLES
# ---------------------------------------
self.initialize_ok = False
self.bdd_type_list = list(bdd_icons_dict)
# ---------------------------------------
# LOADING CATEGORIES
# ---------------------------------------
get_look_tableview(self.ui.category)
self.category_model = QStandardItemModel()
self.categories_initialize()
self.ui.category.setModel(self.category_model)
self.ui.category.horizontalHeader().setFixedHeight(24)
self.ui.category.setCurrentIndex(self.category_model.index(0, 0))
self.ui.category.selectionModel().currentRowChanged.connect(self.category_changed)
# ---------------------------------------
# LOADING LIBRARIES
# ---------------------------------------
get_look_tableview(self.ui.library)
self.library_model = QStandardItemModel()
self.library_model.setHorizontalHeaderLabels(["",
self.tr("Titre"),
self.tr("Chemin"),
self.tr("Type"),
self.tr("Actif")])
self.icon_col = 0
self.title_col = 1
self.bdd_path_col = 2
self.bdd_type_col = 3
self.used_col = 4
self.library_filter = QSortFilterProxyModel()
self.library_filter.setSourceModel(self.library_model)
self.library_filter.setFilterKeyColumn(self.bdd_type_col)
self.library_filter.setSortLocaleAware(True)
self.ui.library.setModel(self.library_filter)
self.ui.library.doubleClicked.connect(self.library_double_clicked)
self.ui.library.selectionModel().currentRowChanged.connect(self.library_selection_changed)
self.ui.library.customContextMenuRequested.connect(self.library_menu_show)
self.ui.library.horizontalHeader().sortIndicatorChanged.connect(self.library_scroll)
# ---------------------------------------
# CHARGEMENT boutons
# ---------------------------------------
self.ui.library_add.clicked.connect(self.library_add_clicked)
self.ui.library_del.clicked.connect(self.library_delete_clicked)
self.ui.library_modify.clicked.connect(self.library_modify_clicked)
self.ui.library_help.clicked.connect(self.library_help_show)
self.ui.library_help.customContextMenuRequested.connect(self.library_help_show)
self.ui.quit.clicked.connect(self.widget_library.close)
@staticmethod
def a___________________initialisation___________________():
pass
def categories_initialize(self):
self.category_model.setHorizontalHeaderLabels([self.tr("Type")])
self.category_model.appendRow([QStandardItem(get_icon(external_bdd_all_icon), self.tr("Toutes"))])
self.category_model.appendRow([QStandardItem(get_icon(catalog_icon), bdd_type_xml)])
a = self.tr("Favoris")
self.category_model.appendRow([QStandardItem(get_icon(attribute_model_show_icon), f"Allplan - {a}")])
self.category_model.appendRow([QStandardItem(get_icon(allplan_icon), bdd_type_kukat)])
self.category_model.appendRow([QStandardItem(get_icon(external_bdd_bcm_icon), bdd_type_bcm)])
self.category_model.appendRow([QStandardItem(get_icon(external_bdd_nevaris_icon), bdd_type_nevaris)])
self.category_model.appendRow([QStandardItem(get_icon(excel_icon), type_excel)])
self.category_model.appendRow([QStandardItem(get_icon(external_bdd_show_icon), self.tr("Autres"))])
def library_initialize(self):
if self.initialize_ok:
return
library_config = settings_read(library_config_file)
use_tabs = list()
for title, datas in library_config.items():
title: str
datas: dict
bdd_path_file = datas.get("path", "")
bdd_type = datas.get("type", "")
if self.library_tabs.count() < tab_max_count:
tab_index = datas.get("use", 0)
else:
tab_index = 0
if bdd_type == "Allplan - Smart-Catalog":
bdd_type = bdd_type_xml
if bdd_path_file == "" or bdd_type not in bdd_icons_dict:
continue
if not bdd_path_file.startswith("http") and not os.path.exists(bdd_path_file):
continue
if bdd_path_file.upper().endswith(".FIC"):
msg(titre=application_title,
message="Attention : Le format de fichier Fic de GIMI n'est plus pris en charge.\n"
"Vous pouvez désormais exporter votre bibliothèque GIMI au format XML.\n"
"Pour plus d'informations, veuillez contacter Euriciel au 02 47 27 86 29.")
continue
if tab_index != 0:
if tab_index is True:
use_tabs.append([len(use_tabs), title, bdd_path_file, bdd_type])
else:
use_tabs.append([tab_index, title, bdd_path_file, bdd_type])
self.library_add_action(title=title,
bdd_path_file=bdd_path_file,
bdd_type=bdd_type,
used_bool=tab_index != 0)
use_tabs.sort()
for tab_data in use_tabs:
_, title, bdd_path_file, bdd_type = tab_data
self.widget_library.tab_add(title=title,
bdd_path_file=bdd_path_file,
bdd_type=bdd_type)
library_setting = settings_read(library_setting_file)
order = library_setting.get("order", 0)
order_col = library_setting.get("order_col", 1)
header = self.library_header_manage()
if header is not None:
if isinstance(order, int) and isinstance(order_col, int):
self.ui.library.sortByColumn(order_col, order)
header.setSortIndicator(order_col, order)
self.initialize_ok = True
if self.library_model.rowCount() == 0:
return
catogery_index = library_setting.get("category", 0)
if isinstance(catogery_index, int):
self.ui.category.setCurrentIndex(self.category_model.index(catogery_index, 0))
else:
self.ui.category.setCurrentIndex(self.category_model.index(0, 0))
title = library_setting.get("title", "")
if isinstance(title, str) and title != "":
self.library_select_row(title)
else:
self.ui.library.selectionModel().setCurrentIndex(self.library_filter.index(0, 0),
QItemSelectionModel.Select |
QItemSelectionModel.Rows)
self.library_buttons_refresh()
def library_reset(self):
if not self.initialize_ok:
return
library_model_row_count = self.library_model.rowCount()
if library_model_row_count != 0:
# self.library_model.blockSignals(True)
self.library_model.clear()
self.library_model.setHorizontalHeaderLabels(["",
self.tr("Titre"),
self.tr("Chemin"),
self.tr("Type"),
self.tr("Actif")])
# self.library_model.blockSignals(False)
# category_model_row_count = self.category_model.rowCount()
#
# if category_model_row_count == 0:
# return
#
# # self.category_model.blockSignals(True)
# self.category_model.clear()
# self.categories_initialize()
# # self.category_model.blockSignals(False)
@staticmethod
def a___________________category___________________():
pass
def category_changed(self, qm_category_current: QModelIndex) -> bool:
if not qm_check(qm_category_current):
self.library_filter.setFilterRegExp("")
self.library_header_manage()
self.library_selection_changed(self.ui.library.currentIndex())
self.library_buttons_refresh()
print("library -- WidgetLibraryTabManage -- category_changed -- not qm_check(qm_current)")
return False
current_bdd_type = qm_category_current.data()
txt_favorite = self.tr("Favoris")
if current_bdd_type == self.tr("Toutes"):
self.library_filter.setFilterRegExp("")
elif current_bdd_type == f"Allplan - {txt_favorite}":
self.library_filter.setFilterRegExp(bdd_type_fav)
elif current_bdd_type == self.tr("Autres"):
regexp = "|".join(categories_extern)
self.library_filter.setFilterRegExp(regexp)
elif current_bdd_type == bdd_type_nevaris or current_bdd_type == bdd_type_nevaris_xlsx:
regexp = f"{bdd_type_nevaris}|{bdd_type_nevaris_xlsx}"
self.library_filter.setFilterRegExp(regexp)
elif current_bdd_type == type_bcm_c or current_bdd_type == bdd_type_bcm:
regexp = f"{type_bcm_c}|{bdd_type_bcm}"
self.library_filter.setFilterRegExp(regexp)
else:
self.library_filter.setFilterRegExp(current_bdd_type)
self.library_header_manage()
qm_current = self.ui.library.currentIndex()
if not qm_check(qm_current) and self.library_filter.rowCount() > 0:
qm_current = self.library_filter.index(0, self.title_col)
if qm_check(qm_current):
self.ui.library.setCurrentIndex(qm_current)
else:
self.library_selection_changed(qm_current)
self.library_scroll()
self.library_buttons_refresh()
return True
def catagory_choose(self, bdd_type: str) -> bool:
bdd_type = self.category_convert(category_name=bdd_type)
# -------------------------------
# Define new current category
# -------------------------------
qm_category_current_index = self.ui.category.currentIndex()
if not qm_check(qm_category_current_index):
print("library -- WidgetLibraryTabManage -- catagory_choose -- not qm_check(qm_category_current_index)")
return False
current_row = qm_category_current_index.row()
if current_row == 0:
return True
current_type = qm_category_current_index.data()
if current_type == bdd_type:
return True
search_category = self.category_model.findItems(bdd_type, Qt.MatchContains, 0)
if len(search_category) == 0:
print("library -- WidgetLibraryTabManage -- catagory_choose -- len(search_category) == 0")
return False
qs = search_category[0]
qm_category_index = qs.index()
if not qm_check(qm_category_index):
print("library -- WidgetLibraryTabManage -- catagory_choose -- not qm_check(qm_category_index)")
return False
self.ui.category.setCurrentIndex(qm_category_index)
return True
def category_convert(self, category_name: str) -> str:
if category_name in [bdd_type_xml, bdd_type_kukat, type_excel]:
return category_name
if category_name == bdd_type_fav:
txt_favorite = self.tr("Favoris")
return f"Allplan - {txt_favorite}"
if category_name in [bdd_type_bcm, type_bcm_c]:
return bdd_type_bcm
if category_name in [type_synermi, type_capmi, type_progemi, type_extern,
type_gimi, type_allmetre_e, type_allmetre_a]:
return self.tr("Autres")
return category_name
@staticmethod
def a___________________library_header___________________():
pass
def library_header_manage(self):
header = self.ui.library.horizontalHeader()
if header is None:
return None
if header.height() != 24:
header.setFixedHeight(24)
header.setSectionResizeMode(self.icon_col, QHeaderView.Fixed)
self.ui.library.setColumnWidth(self.icon_col, 35)
self.ui.library.setColumnHidden(self.bdd_type_col, True)
header.setSectionResizeMode(self.used_col, QHeaderView.Fixed)
self.ui.library.setColumnWidth(self.used_col, 50)
header.setSectionResizeMode(self.title_col, QHeaderView.ResizeToContents)
header.setSectionResizeMode(self.bdd_path_col, QHeaderView.Stretch)
return header
@staticmethod
def a___________________library_selection___________________():
pass
def library_select_row(self, title: str) -> bool:
selection_model = self.ui.library.selectionModel()
if selection_model is None:
print("library -- WidgetLibraryTabManage -- library_select -- selection_model is None")
return False
qm_filter_start = self.library_filter.index(0, self.title_col)
search_library = self.library_filter.match(qm_filter_start, Qt.DisplayRole, title, 1, Qt.MatchExactly)
if len(search_library) == 0:
print("library -- WidgetLibraryTabManage -- library_select_row -- len(search_library) == 0")
return False
qm_current = search_library[0]
if not qm_check(qm_current):
print("library -- WidgetLibraryTabManage -- library_select_row -- not qm_check(qm_library)")
return False
self.ui.library.setCurrentIndex(qm_current)
return True
def library_selection_changed(self, qm_current: QModelIndex):
used = self.find_qm(qm_current=qm_current, column=self.used_col, value=True)
if used is None:
self.ui.library_del.setEnabled(False)
return
self.library_used_manage(used=used)
def library_double_clicked(self, qm_current: QModelIndex):
if not qm_check(qm_current):
print("library -- WidgetLibraryTabManage -- library_double_clicked -- not qm_check(qm_current)")
return
current_col = qm_current.column()
if current_col == self.used_col:
return
self.library_used_clicked()
def library_scroll(self):
qm_filter_current = self.ui.library.currentIndex()
if not qm_check(qm_filter_current):
return
self.ui.library.scrollTo(qm_filter_current, QAbstractItemView.PositionAtCenter)
@staticmethod
def a___________________library_add___________________():
pass
def library_add_clicked(self):
current_index = self.ui.category.selectionModel().currentIndex()
if not qm_check(current_index):
print("library -- WidgetLibraryTabManage -- library_add_clicked -- not qm_check(current_index)")
return
current_bdd_type = current_index.data()
if current_bdd_type == bdd_type_bcm:
default_path = settings_get(file_name=library_setting_file, info_name="path_bcm")
elif current_bdd_type == bdd_type_xml:
default_path = settings_get(file_name=library_setting_file, info_name="path_cat")
elif current_bdd_type == bdd_type_fav:
default_path = settings_get(file_name=library_setting_file, info_name="path_favorites")
elif current_bdd_type == bdd_type_kukat:
default_path = settings_get(file_name=library_setting_file, info_name="path_kukat")