-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
activelist.py
105 lines (84 loc) · 3.26 KB
/
activelist.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
from base_ui import WidgetUI,CommunicationHandler
import PyQt6.QtWidgets
from PyQt6.QtCore import QAbstractTableModel,Qt,QModelIndex
class ActiveClassModel(QAbstractTableModel):
def __init__(self):
super(ActiveClassModel, self).__init__()
self.items = []
self.header = ["Name", "Class","Instance","Class ID","Handler ID"]
def data(self, index, role):
if role == Qt.ItemDataRole.DisplayRole:
idx = index.row()
d = self.items[idx]
if(index.column() == 0):
return d["name"]
elif(index.column() == 1):
return d["cls"]
elif(index.column() == 2):
return d["unique"]
elif(index.column() == 3):
return "0x{:X}".format(int(d["id"]))
elif(index.column() == 4):
return d["cmdaddr"]
else:
return None
def headerData(self,section,orientation,role):
if role == Qt.ItemDataRole.DisplayRole:
if orientation == Qt.Orientation.Horizontal:
return self.header[section]
def getHeader(self):
return self.header
def rowCount(self, index):
return len(self.items)
def columnCount(self, index):
return len(self.header)
def clearItems(self):
self.beginResetModel()
self.items.clear()
self.endResetModel()
def count(self):
return len(self.items)
def addItem(self,item):
cnt = len(self.items)
self.beginInsertRows(QModelIndex(),cnt,cnt)
self.items.append(item)
self.endInsertRows()
def setItems(self,items):
self.beginResetModel()
self.items = items
self.endResetModel()
class ActiveClassDialog(PyQt6.QtWidgets.QDialog):
def __init__(self, parent = None):
PyQt6.QtWidgets.QDialog.__init__(self, parent)
self.active_class_ui = ActiveClassUI(parent)
self.layout = PyQt6.QtWidgets.QVBoxLayout()
self.layout.setContentsMargins(0,0,0,0)
self.layout.addWidget(self.active_class_ui)
self.setLayout(self.layout)
self.setWindowTitle("Active modules")
class ActiveClassUI(WidgetUI, CommunicationHandler):
def __init__(self, parent = None):
WidgetUI.__init__(self, parent, 'activelist.ui')
CommunicationHandler.__init__(self)
self.parent = parent
self.pushButton_refresh.clicked.connect(self.read)
self.items = ActiveClassModel()
self.tableView.setModel(self.items)
header = self.tableView.horizontalHeader()
header.setSectionResizeMode(0,PyQt6.QtWidgets.QHeaderView.ResizeMode.Stretch) # Stretch first section
def showEvent(self, a0):
self.tableView.resizeColumnsToContents()
self.read()
def read(self):
self.get_value_async("sys","lsactive",self.updateCb)
def updateCb(self,string):
self.parent.show()
items = []
for line in string.split("\n"):
e = line.split(":")
if(len(e) < 4):
continue
item = {"name":e[0],"cls":e[1], "unique":e[2], "id":e[3],"cmdaddr":e[4]}
items.append(item)
self.items.setItems(items)
self.tableView.resizeColumnsToContents()