Replace widget search to widget dict (performance)

This commit is contained in:
2020-08-26 08:34:03 +02:00
parent 0f22a2812b
commit 844f1c8b27
7 changed files with 17 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ from ui.aclmanager_ui import Ui_diag_aclmanager
class AclManager(QtWidgets.QDialog, Ui_diag_aclmanager):
"""ACL manager."""
def __init__(self, parent):
def __init__(self, parent=None):
super(AclManager, self).__init__(parent)
self.setupUi(self)
self.setFixedSize(self.size())

View File

@@ -29,6 +29,9 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
self.setWindowTitle("{0} - {1}".format(position, name))
self.gb_io.setTitle(self.gb_io.title().format(name))
self.__qwa = {}
"""Quick widget access."""
self.position = position
self.name = name
self.inputs = inputs.copy()
@@ -72,6 +75,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
name = val.objectName()
if name not in lst_names:
# Remove old io from layout
del self.__qwa[name]
layout.removeRow(layout.getWidgetPosition(val)[0])
counter = -1
@@ -147,6 +151,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
val.valueChanged.connect(self._change_sbx_dvalue)
val.setObjectName(name)
self.__qwa[name] = val
return val
@QtCore.pyqtSlot(int)
@@ -267,7 +272,8 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
:param io_name: Name of IO
:return: (actual value, last value) <class 'tuple'>
"""
child = self.findChild(self.search_class, io_name)
# child = self.findChild(self.search_class, io_name)
child = self.__qwa[io_name]
actual_value = child.value()
last_value = child.value() if child.property("last_value") is None else child.property("last_value")
if child.property("frm"):
@@ -285,7 +291,8 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
:param io_name: Name of IO
:param value: Process value as <class 'bool'> or <class 'bytes'>
"""
child = self.findChild(self.search_class, io_name)
# child = self.findChild(self.search_class, io_name)
child = self.__qwa[io_name]
if child.property("frm"):
value = struct.unpack(child.property("frm"), value)[0]
elif type(value) == bytearray:
@@ -300,7 +307,8 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
:param io_name: Name of IO
:param value: New value as bytes or bool for widget
"""
child = self.findChild(self.search_class, io_name)
# child = self.findChild(self.search_class, io_name)
child = self.__qwa[io_name]
if child.property("frm"):
value = struct.unpack(child.property("frm"), value)[0]
elif type(value) == bytearray:

View File

@@ -14,7 +14,7 @@ from ui.mqttmanager_ui import Ui_diag_mqtt
class MqttManager(QtWidgets.QDialog, Ui_diag_mqtt):
"""MQTT settings for option window."""
def __init__(self, parent):
def __init__(self, parent=None):
super(MqttManager, self).__init__(parent)
self.setupUi(self)
self.setFixedSize(self.size())

View File

@@ -52,7 +52,7 @@ class RevPiCommander(QtWidgets.QMainWindow, Ui_win_revpicommander):
# Load sub windows
self.diag_connections = RevPiPlcList(self)
self.diag_search = AvahiSearch(self)
self.diag_info = RevPiInfo(self, __version__)
self.diag_info = RevPiInfo(__version__, self)
self.diag_options = RevPiOption(self)
self.diag_program = RevPiProgram(self)
self.win_log = revpilogfile.RevPiLogfile(self)

View File

@@ -13,7 +13,7 @@ from ui.revpiinfo_ui import Ui_diag_revpiinfo
class RevPiInfo(QtWidgets.QDialog, Ui_diag_revpiinfo):
"""Version information window."""
def __init__(self, parent, version: str):
def __init__(self, version: str, parent=None):
super(RevPiInfo, self).__init__(parent)
self.setupUi(self)

View File

@@ -104,7 +104,7 @@ class DataThread(QtCore.QThread):
class RevPiLogfile(QtWidgets.QMainWindow, Ui_win_revpilogfile):
"""Log file viewer for daemon and plc program log."""
def __init__(self, parent):
def __init__(self, parent=None):
u"""Init RevPiLogfile-Class."""
super(RevPiLogfile, self).__init__(parent)
self.setupUi(self)

View File

@@ -16,7 +16,7 @@ from ui.revpioption_ui import Ui_diag_options
class RevPiOption(QtWidgets.QDialog, Ui_diag_options):
"""Set options of RevPiPyLoad."""
def __init__(self, parent):
def __init__(self, parent=None):
super(RevPiOption, self).__init__(parent)
self.setupUi(self)
self.setFixedSize(self.size())