-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.py
121 lines (75 loc) · 3.32 KB
/
history.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
#!/usr/bin/python3
# -*- coding: utf-8 -*
from PyQt5.Qt import *
from history_manage import ActionInfo, index_action
from tools import changer_selection_apparence, taille_police_menu, menu_ht_ligne
class WidgetHistory(QListWidget):
"""Script pour le widget type_surfaces"""
undo_selection_signal = pyqtSignal(list)
redo_selection_signal = pyqtSignal(list)
def __init__(self, parent_actuel, mode_current: str):
super().__init__(parent=parent_actuel)
self.setGeometry(100, 100, 300, 300)
self.setWindowFlags(Qt.Popup)
self.history = list()
self.mode_current = mode_current
self.selected_events = list()
self.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.setAlternatingRowColors(True)
self.setSelectionMode(QAbstractItemView.MultiSelection)
self.setIconSize(QSize(20, 20))
self.setGridSize(QSize(self.gridSize().width(), menu_ht_ligne))
self.setMouseTracking(True)
self.itemEntered.connect(self.item_hovered)
self.itemPressed.connect(self.item_selected)
changer_selection_apparence(self)
self.installEventFilter(self)
def chargement(self, dict_actions: dict):
self.clear()
liste = list()
for event, datas in reversed(dict_actions.items()):
datas: ActionInfo
data: dict = datas.data
nom_action = data.get("nom_action", "")
qlistwidgetitem = QListWidgetItem(nom_action)
qlistwidgetitem.setData(index_action, event)
font = qlistwidgetitem.font()
font.setPointSize(taille_police_menu)
qlistwidgetitem.setFont(font)
if "icone" in data:
icone: QIcon = data["icone"]
qlistwidgetitem.setIcon(icone)
if "tooltips" in data:
tooltips = data["tooltips"]
qlistwidgetitem.setToolTip(tooltips)
self.addItem(qlistwidgetitem)
self.history = liste
def item_hovered(self, item: QListWidgetItem):
index_actuel = self.indexFromItem(item).row()
for index_item in range(self.count()):
item = self.item(index_item)
item.setSelected(index_item <= index_actuel)
def item_selected(self):
self.selected_events = list()
for index_item in range(self.count()):
item = self.item(index_item)
self.selected_events.append(item.data(index_action))
if not item.isSelected():
break
if self.mode_current == "undo":
self.undo_selection_signal.emit(self.selected_events)
elif self.mode_current == "redo":
self.redo_selection_signal.emit(self.selected_events)
self.close()
@staticmethod
def a___________________event______():
pass
def eventFilter(self, obj: QWidget, event: QEvent):
if obj == self.verticalScrollBar() or obj == self.horizontalScrollBar():
return super().eventFilter(obj, event)
if event.type() == QEvent.MouseButtonRelease:
self.hide()
return super().eventFilter(obj, event)
@staticmethod
def a___________________end______():
pass