Skip to content

Commit 50b35b5

Browse files
committed
MNT: parent args passed into Qt provided class __init__ should be
positional args not use keyword arguments For context: - Positional args: Func(1, 2) - Keyword args: Func(a=1, b=2) pyqt5 works still if we use the keyword argument 'parent' for super calls to qt class __init__ calls, but pyside6 throws an error (it generally seems a bit more strict about things). You can inspect an __init__ call (ex: 'print(inspect.signature(QLabel.__init__))') to see if/what keyword arguments are accepted by it. The __init__ calls changed in this patch don't accept a 'parent' keyword arg, just a positional arg for it.
1 parent 0806a50 commit 50b35b5

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

pydm/widgets/datetime.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ def __init__(self, parent=None, init_channel=None):
5050
self._block_past_date = True
5151
self._relative = True
5252
self._time_base = TimeBase.Milliseconds
53-
54-
QtWidgets.QDateTimeEdit.__init__(self, parent=parent)
53+
# We can't do 'parent=parent' here since its only a positional argument, since the python qt
54+
# docs can sometimes be sparse you can use python's inspect module to see function's arg details,
55+
# like 'print(inspect.signature(QLabel.__init__)'
56+
QtWidgets.QDateTimeEdit.__init__(self, parent)
5557
PyDMWritableWidget.__init__(self, init_channel=init_channel)
5658
self.setDisplayFormat("yyyy/MM/dd hh:mm:ss.zzz")
5759
self.setDateTime(QtCore.QDateTime.currentDateTime())
@@ -121,9 +123,9 @@ def value_changed(self, new_val):
121123

122124
val = QtCore.QDateTime.currentDateTime()
123125
if self._relative:
124-
val = val.addMSecs(new_val)
126+
val = val.addMSecs(int(new_val))
125127
else:
126-
val.setMSecsSinceEpoch(new_val)
128+
val.setMSecsSinceEpoch(int(new_val))
127129
self.setDateTime(val)
128130

129131

@@ -150,7 +152,10 @@ class PyDMDateTimeLabel(QtWidgets.QLabel, PyDMWidget):
150152
"""
151153

152154
def __init__(self, parent=None, init_channel=None):
153-
QtWidgets.QLabel.__init__(self, parent=parent)
155+
# We can't do 'parent=parent' here since its only a positional argument, since the python qt
156+
# docs can sometimes be sparse you can use python's inspect module to see function's arg details,
157+
# like 'print(inspect.signature(QLabel.__init__)'
158+
QtWidgets.QLabel.__init__(self, parent)
154159
PyDMWidget.__init__(self, init_channel=init_channel)
155160

156161
self._block_past_date = True
@@ -201,7 +206,7 @@ def value_changed(self, new_val):
201206

202207
val = QtCore.QDateTime.currentDateTime()
203208
if self._relative:
204-
val = val.addMSecs(new_val)
209+
val = val.addMSecs(int(new_val))
205210
else:
206-
val.setMSecsSinceEpoch(new_val)
211+
val.setMSecsSinceEpoch(int(new_val))
207212
self.setText(val.toString(self.textFormat))

pydm/widgets/logdisplay.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ class GuiHandler(QObject, logging.Handler):
6969
message = Signal(str)
7070

7171
def __init__(self, level=logging.NOTSET, parent=None):
72-
logging.Handler.__init__(self, level=level)
73-
QObject.__init__(self, parent=parent)
72+
# We can't do 'arg=arg' here since they are only positionals argument, since the python qt
73+
# docs can sometimes be sparse you can use python's inspect module to see function's arg details,
74+
# like 'print(inspect.signature(QLabel.__init__)'
75+
logging.Handler.__init__(self, level)
76+
QObject.__init__(self, parent)
7477

7578
def emit(self, record):
7679
"""Emit formatted log messages when received but only if level is set."""

pydm/widgets/tab_bar.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class PyDMTabBar(QTabBar, PyDMWidget):
1212
"""PyDMTabBar is used internally by PyDMTabWidget, and shouldn't be directly used on its own."""
1313

1414
def __init__(self, parent=None):
15-
super(PyDMTabBar, self).__init__(parent=parent)
15+
# We can't do 'parent=parent' here since its only a positional argument, since the python qt
16+
# docs can sometimes be sparse you can use python's inspect module to see function's arg details,
17+
# like 'print(inspect.signature(QLabel.__init__)'
18+
super(PyDMTabBar, self).__init__(parent)
1619
self.tab_channels = {}
1720
self.tab_connection_status = {}
1821
self.tab_alarm_severity = {}

0 commit comments

Comments
 (0)