Repository navigation
Expand file tree
/
Copy pathEcuZoneCheckBox.py
More file actions
155 lines (128 loc) · 5.12 KB
/
Copy pathEcuZoneCheckBox.py
File metadata and controls
155 lines (128 loc) · 5.12 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
"""
EcuZoneCheckBox.py
Copyright (C) 2024 - 2025 Marc Postema (mpostema09 -at- gmail.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Or, point your browser to http://www.gnu.org/copyleft/gpl.html
"""
from PySide6.QtCore import Qt, Slot
from PySide6.QtWidgets import QCheckBox
class EcuZoneCheckBox(QCheckBox):
"""
"""
initialValue = 0
newValue = 0
style = ""
zoneObject = {}
itemReadOnly = False
def __init__(self, parent, zoneObject: dict, readOnly: bool):
super(EcuZoneCheckBox, self).__init__(parent)
self.itemReadOnly = readOnly
self.zoneObject = zoneObject
# Notify changes, to change color if changed
self.checkStateChanged.connect(self.stateChange)
# Save current style-sheet
self.style = self.styleSheet()
@Slot()
def stateChange(self, state):
if state != self.newValue:
self.newValue = state
if self.newValue == self.initialValue or self.initialValue == 0:
self.setStyleSheet(self.style)
else:
self.setStyleSheet("background-color: rgb(42, 130, 218)")
def getDescriptionName(self):
return self.zoneObject["name"]
def getCorrespondingByte(self):
return self.zoneObject["byte"]
def getCorrespondingByteSize(self):
return 1
def setCheckState(self, val):
self.initialValue = val;
super().setCheckState(val)
def isCheckBoxChanged(self, virginWrite: bool):
return self.isEnabled() and not(self.itemReadOnly) and self.initialValue != 0 and self.initialValue != self.checkState()
def getValuesAsCSV(self):
value = "Disabled"
if self.isEnabled():
if self.checkState() == Qt.Checked:
value = "01"
else:
value = "00"
return value
def clearZoneValue(self):
self.initialValue = 0
self.setCheckState(Qt.Unchecked)
def getZoneAndHex(self, virginWrite: bool):
value = "None"
if "mask" in self.zoneObject:
print("EcuZoneCheckBox.getZoneAndHex(..) has mask?")
else:
if self.isCheckBoxChanged(virginWrite):
if self.checkState() == Qt.Checked:
value = "01"
else:
value = "00"
return value
def update(self, byte: str):
mask = int(self.zoneObject["mask"], 2)
if "available_logic" in self.zoneObject and "active_high" == self.zoneObject["available_logic"]:
if self.isChecked():
value = (int(byte, 16) | mask)
byte = "%0.2X" % value
else:
value = (int(byte, 16) & ~mask)
byte = "%0.2X" % value
else:
if self.isChecked():
value = (int(byte, 16) & ~mask)
byte = "%0.2X" % value
else:
value = (int(byte, 16) | mask)
byte = "%0.2X" % value
return byte
def changeZoneOption(self, data: str, valueType: str):
if "mask" in self.zoneObject:
byteData = []
for i in range(0, len(data), 2):
byteData.append(data[i:i + 2])
# Is this option used for this Zone (NAC/RCC JSON Files)
if "zoneLength" in self.zoneObject:
zoneLength = self.zoneObject["zoneLength"]
if isinstance(zoneLength, list):
if len(byteData) not in zoneLength:
return 2
else:
if zoneLength != len(byteData):
return 2
byteNr = self.zoneObject["byte"]
mask = int(self.zoneObject["mask"], 2)
# Integrity wrong, size does not match
if byteNr < 0 or byteNr >= len(byteData):
return 1
byte = int(byteData[byteNr], 16) & mask
if "available_logic" in self.zoneObject and "active_high" == self.zoneObject["available_logic"]:
if byte > 0:
self.setCheckState(Qt.Checked)
else:
self.setCheckState(Qt.Unchecked)
else:
if byte > 0:
self.setCheckState(Qt.Unchecked)
else:
self.setCheckState(Qt.Checked)
else:
if data == "01":
self.setCheckState(Qt.Checked)
elif data == "00":
self.setCheckState(Qt.Unchecked)
return 0