mirror of
https://github.com/naruxde/revpicommander.git
synced 2025-11-08 16:43:53 +01:00
String fields (> 4 Bytes) can be switched to numbers
This commit is contained in:
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -4,4 +4,7 @@
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
|
||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -187,7 +187,7 @@ class DebugControl(QtWidgets.QWidget, Ui_wid_debugcontrol):
|
||||
win = self.dict_windows[position]
|
||||
for io in self.dict_ios[io_type][position]: # type: list
|
||||
# ['name', bitlength, byte_address, 'bmk', bitaddress, 'byteorder', signed]
|
||||
value_procimg = ba_values[io[2]:io[2] + io[1]]
|
||||
value_procimg = bytes(ba_values[io[2]:io[2] + io[1]])
|
||||
if io[4] >= 0:
|
||||
# Bit-IO
|
||||
value_procimg = bool(
|
||||
|
||||
@@ -118,7 +118,13 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
# Bytes or string
|
||||
val = QtWidgets.QLineEdit()
|
||||
val.setReadOnly(read_only)
|
||||
val.setProperty("big_endian", byteorder == "big")
|
||||
val.setProperty("byte_length", byte_length)
|
||||
val.setProperty("signed", signed)
|
||||
val.setProperty("struct_type", "text")
|
||||
|
||||
val.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||
val.customContextMenuRequested.connect(self.on_context_menu)
|
||||
|
||||
# Set alias to use the same function name on all widget types
|
||||
val.setValue = val.setText
|
||||
@@ -186,6 +192,14 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
sender = self.sender()
|
||||
men = QtWidgets.QMenu(sender)
|
||||
|
||||
if sender.property("byte_length") > 4:
|
||||
# Textbox needs format buttons
|
||||
act_as_text = QtWidgets.QAction(self.tr("as text"))
|
||||
men.addAction(act_as_text)
|
||||
act_as_number = QtWidgets.QAction(self.tr("as number"))
|
||||
men.addAction(act_as_number)
|
||||
men.addSeparator()
|
||||
|
||||
act_signed = QtWidgets.QAction(self.tr("signed"), men)
|
||||
act_signed.setCheckable(True)
|
||||
act_signed.setChecked(sender.property("signed") or False)
|
||||
@@ -215,10 +229,17 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
elif rc == act_byteorder:
|
||||
sender.setProperty("big_endian", act_byteorder.isChecked())
|
||||
|
||||
if sender.property("frm"):
|
||||
sender.setProperty("frm", "{0}{1}".format(
|
||||
">" if act_byteorder.isChecked() else "<",
|
||||
sender.property("struct_type").lower() if act_signed.isChecked() else sender.property("struct_type").upper()
|
||||
sender.property("struct_type").lower() if act_signed.isChecked()
|
||||
else sender.property("struct_type").upper()
|
||||
))
|
||||
elif sender.property("byte_length") > 4:
|
||||
if rc == act_as_text:
|
||||
sender.setProperty("struct_type", "text")
|
||||
elif rc == act_as_number:
|
||||
sender.setProperty("struct_type", "number")
|
||||
|
||||
self.set_value(sender.objectName(), actual_value)
|
||||
men.deleteLater()
|
||||
@@ -280,6 +301,23 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
return struct.pack(child.property("frm"), int(actual_value)), \
|
||||
struct.pack(child.property("frm"), int(last_value))
|
||||
elif type(actual_value) == str:
|
||||
if child.property("struct_type") == "number":
|
||||
try:
|
||||
actual_value = int(actual_value).to_bytes(
|
||||
child.property("byte_length"),
|
||||
byteorder="big" if child.property("big_endian") else "little",
|
||||
signed=child.property("signed") or False
|
||||
)
|
||||
last_value = int(last_value).to_bytes(
|
||||
child.property("byte_length"),
|
||||
byteorder="big" if child.property("big_endian") else "little",
|
||||
signed=child.property("signed") or False
|
||||
)
|
||||
return actual_value, last_value
|
||||
except Exception:
|
||||
pi.logger.error("Could not convert '{0}' to bytes".format(actual_value))
|
||||
pass
|
||||
|
||||
return actual_value.encode(), last_value.encode()
|
||||
else:
|
||||
return actual_value, last_value
|
||||
@@ -311,7 +349,14 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
child = self.__qwa[io_name]
|
||||
if child.property("frm"):
|
||||
value = struct.unpack(child.property("frm"), value)[0]
|
||||
elif type(value) == bytearray:
|
||||
elif type(value) == bytes:
|
||||
if child.property("struct_type") == "number":
|
||||
value = str(int.from_bytes(
|
||||
value,
|
||||
byteorder="big" if child.property("big_endian") else "little",
|
||||
signed=child.property("signed") or False
|
||||
))
|
||||
else:
|
||||
value = value.decode()
|
||||
|
||||
child.setProperty("last_value", value)
|
||||
|
||||
@@ -329,7 +329,7 @@ class RevPiFiles(QtWidgets.QMainWindow, Ui_win_files):
|
||||
)
|
||||
self.lbl_path_revpi.setToolTip(self.lbl_path_revpi.text())
|
||||
|
||||
if lst_revpi:
|
||||
if lst_revpi is not None:
|
||||
lst_revpi.sort()
|
||||
|
||||
for path_file in lst_revpi:
|
||||
|
||||
Reference in New Issue
Block a user