Skip to content

Commit 74eb933

Browse files
Merge pull request #1189 from nstelter-slac/make_weak_ref
MNT: make sure we pass a weak ref of the current object to widget_destroyed
2 parents 72161ad + 3889650 commit 74eb933

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

examples/camviewer/camviewer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# import epics
22
# from qtpy import uic
33
import functools
4+
import weakref
45
from qtpy.QtCore import Slot, Signal, QPointF, QRectF
56
from qtpy.QtGui import QPen
67
from qtpy.QtWidgets import QSizePolicy
@@ -141,7 +142,7 @@ def __init__(self, parent=None, args=None):
141142
self.ui.setROIButton.clicked.connect(self.setROI)
142143
self.ui.resetROIButton.clicked.connect(self.resetROI)
143144

144-
self.destroyed.connect(functools.partial(widget_destroyed, self.channels))
145+
self.destroyed.connect(functools.partial(widget_destroyed, self.channels, weakref.ref(self)))
145146

146147
@Slot()
147148
def zoomIn(self):

pydm/widgets/baseplot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import json
33
import warnings
4+
import weakref
45
from abc import abstractmethod
56
from qtpy.QtGui import QColor, QBrush, QMouseEvent
67
from qtpy.QtCore import Signal, Slot, Property, QTimer, Qt, QEvent, QObject, QRect
@@ -126,7 +127,7 @@ def __init__(
126127
self.bar_graph_item = None
127128

128129
if hasattr(self, "channels"):
129-
self.destroyed.connect(functools.partial(widget_destroyed, self.channels))
130+
self.destroyed.connect(functools.partial(widget_destroyed, self.channels, weakref.ref(self)))
130131

131132
@property
132133
def color_string(self) -> str:

pydm/widgets/logdisplay.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
logger = logging.getLogger(__name__)
2323

2424

25-
def logger_destroyed(log, obj):
25+
def logger_destroyed(log):
2626
"""
2727
Callback invoked when the Widget is destroyed.
2828
This method is used to ensure that the log handlers are cleared.
@@ -31,9 +31,6 @@ def logger_destroyed(log, obj):
3131
----------
3232
log : Logger
3333
The logger object being used by the PyDMLogDisplay widget.
34-
obj : QWidget
35-
The widget which is being destroyed. All childs of this widget are
36-
already destroyed and must not be accessed.
3734
"""
3835
if log:
3936
for handler in log.handlers:

0 commit comments

Comments
 (0)