Skip to content

Commit

Permalink
fixes in notification cleanup after node controller deletion
Browse files Browse the repository at this point in the history
Found a way of doing it via the destroyed signal (#186)
  • Loading branch information
denisri committed Jun 8, 2021
1 parent 9946465 commit dfe6a70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from populse_mia.user_interface.pipeline_manager.process_mia import ProcessMIA
from populse_mia.software_properties import Config
from . import type_editors
import sip

if sys.version_info[0] >= 3:
unicode = str
Expand Down Expand Up @@ -753,7 +754,6 @@ def release_process(self):
# only implemented in CapsulNodeController
pass


# FIXME temporary: another implementation of NodeController using Capsul
# AttributedProcessWidget widget
class CapsulNodeController(QWidget):
Expand Down Expand Up @@ -788,12 +788,6 @@ def __init__(self, project, scan_list, pipeline_manager_tab,
hlayout.addWidget(label_node_name)
hlayout.addWidget(self.line_edit_node_name)
v_box_final.addLayout(hlayout)
# this cannot be done in __del__ since the C++ part will be already
# destroyed by then
# However this signal seems never to be emitted, and I don't understand
# why. So release_process() has to be callesd manually from the
# pipeline manager. Sigh.
self.destroyed.connect(self.release_process)

def display_parameters(self, node_name, process, pipeline):
"""Display the parameters of the selected node.
Expand Down Expand Up @@ -854,14 +848,27 @@ def display_parameters(self, node_name, process, pipeline):
self.layout().addWidget(self.process_widget)
self.process.on_trait_change(self.parameters_changed)

# this cannot be done in __del__ since the C++ part will be already
# destroyed by then
# However this signal seems never to be emitted, and I don't understand
# why. So release_process() has to be callesd manually from the
# pipeline manager. Sigh.
self.destroyed.connect(partial(self.static_release, process,
self.parameters_changed))

@staticmethod
def static_release(process, param_changed):
process.on_trait_change(param_changed, remove=True)

def release_process(self):
"""
remove notification from process
"""
if hasattr(self, 'process'):
self.process.on_trait_change(self.parameters_changed, remove=True)
try:
self.value_changed.disconnect()
if not sip.isdeleted(self):
self.value_changed.disconnect()
except TypeError:
pass # it was not connected: OK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,12 +1067,6 @@ def displayNodeParameters(self, node_name, process):
else:
Node_Controller = NodeController

# this should be done automatically upon destruction of the former
# node controller, however it is not. The destroyed signal never fires.
# Moreover the destructor is called later, at an unexpected time, when
# the C++ object is already destroyed (and thus cannot be disconnected)
if self.nodeController:
self.nodeController.release_process()
self.nodeController = Node_Controller(
self.project, self.scan_list, self, self.main_window)
self.nodeController.visibles_tags = \
Expand Down

0 comments on commit dfe6a70

Please sign in to comment.