def connect(cls, controller_widget, control_name, control_instance): """ Connect a 'File' controller trait and a 'FileControlWidget' controller widget control. Parameters ---------- cls: FileControlWidget (mandatory) a StrControlWidget control controller_widget: ControllerWidget (mandatory) a controller widget that contains the controller we want to update control_name: str (mandatory) the name of the controller widget control we want to synchronize with the controller control_instance: QWidget (mandatory) the instance of the controller widget control we want to synchronize with the controller """ # Check if the control is connected if not control_instance.connected: # Update one element of the controller. # Hook: function that will be called to update a specific # controller trait when a 'userModification' qt signal is emited widget_hook = partial(cls.update_controller, weak_proxy(controller_widget), control_name, weak_proxy(control_instance), False) # When a qt 'userModification' signal is emited, update the # 'control_name' controller trait value control_instance.path.userModification.connect(widget_hook) widget_hook2 = partial(cls.update_controller, weak_proxy(controller_widget), control_name, weak_proxy(control_instance), True) control_instance.path.editingFinished.connect(widget_hook2) # Update the control. # Hook: function that will be called to update the control value # when the 'control_name' controller trait is modified. controller_hook = SomaPartial(cls.update_controller_widget, weak_proxy(controller_widget), control_name, weak_proxy(control_instance)) # When the 'control_name' controller trait value is modified, # update the corresponding control controller_widget.controller.on_trait_change(controller_hook, name=control_name, dispatch='ui') # Store the trait - control connection we just build control_instance._controller_connections = (widget_hook, widget_hook2, controller_hook) logger.debug("Add 'File' connection: {0}.".format( control_instance._controller_connections)) # Update the control connection status control_instance.connected = True
def connect(cls, controller_widget, control_name, control_instance): """ Connect an 'Enum' controller trait and an 'EnumControlWidget' controller widget control. Parameters ---------- cls: EnumControlWidget (mandatory) an EnumControlWidget control controller_widget: ControllerWidget (mandatory) a controller widget that contains the controller we want to update control_name: str (mandatory) the name of the controller widget control we want to synchronize with the controller control_instance: QComboBox (mandatory) the instance of the controller widget control we want to synchronize with the controller """ # Update one element of the controller widget. # Hook: function that will be called to update the specific widget # when a trait event is detected. controller_hook = SomaPartial(cls.update_controller_widget, weak_proxy(controller_widget), control_name, weak_proxy(control_instance)) # When the 'control_name' controller trait value is modified, update # the corresponding control controller_widget.controller.on_trait_change(controller_hook, name=control_name, dispatch='ui') # Store the trait - control connection we just build control_instance._controller_connections = (controller_hook, ) logger.debug("Add 'Compound' connection: {0} / {1}".format( control_name, control_instance))
def __setstate__(self, state): """ Restore the callbacks that have been removed by __getstate__. """ state['_callbacks'] = dict((i, SomaPartial(self._value_callback, *i)) for i in state['_callbacks']) super(Node, self).__setstate__(state) for callback_key, value_callback in six.iteritems(self._callbacks): self.set_callback_on_plug(callback_key[0], value_callback)
def connect(self, source_plug_name, dest_node, dest_plug_name): """ Connect linked plugs of two nodes Parameters ---------- source_plug_name: str (mandatory) the source plug name dest_node: Node (mandatory) the destination node dest_plug_name: str (mandatory) the destination plug name """ # add a callback to spread the source plug value value_callback = SomaPartial(self.__class__._value_callback, weak_proxy(self), source_plug_name, weak_proxy(dest_node), dest_plug_name) self._callbacks[(source_plug_name, dest_node, dest_plug_name)] = value_callback self.set_callback_on_plug(source_plug_name, value_callback)
def connect(cls, controller_widget, control_name, control_instance): """ Connect a 'List' controller trait and a 'DictControlWidget' controller widget control. Parameters ---------- cls: StrControlWidget (mandatory) a StrControlWidget control controller_widget: ControllerWidget (mandatory) a controller widget that contains the controller we want to update control_name: str (mandatory) the name of the controller widget control we want to synchronize with the controller control_instance: QFrame (mandatory) the instance of the controller widget control we want to synchronize with the controller """ # Check if the control is connected if not control_instance.connected: # Update the dict item when one of his associated controller trait # changed. # Hook: function that will be called to update the controller # associated with a dict widget when a dict widget inner controller # trait is modified. dict_controller_hook = SomaPartial( cls.update_controller, weak_proxy(controller_widget), control_name, weak_proxy(control_instance)) # Go through all dict widget inner controller user traits for trait_name in control_instance.controller.user_traits(): # And add the callback on each user trait control_instance.controller.on_trait_change( dict_controller_hook, trait_name) logger.debug("Item '{0}' of a 'DictControlWidget', add " "a callback on inner controller trait " "'{0}'.".format(control_name, trait_name)) # Update the dict controller widget. # Hook: function that will be called to update the specific widget # when a trait event is detected on the dict controller. controller_hook = SomaPartial( cls.update_controller_widget, weak_proxy(controller_widget), control_name, weak_proxy(control_instance)) # When the 'control_name' controller trait value is modified, # update the corresponding control controller_widget.controller.on_trait_change( controller_hook, control_name, dispatch='ui') # Update the dict connection status control_instance._controller_connections = ( dict_controller_hook, controller_hook) logger.debug("Add 'Dict' connection: {0}.".format( control_instance._controller_connections)) # Connect also all dict items inner_controls = control_instance.controller_widget._controls for (inner_control_name, inner_control_groups) in six.iteritems(inner_controls): for group, inner_control \ in six.iteritems(inner_control_groups): # Unpack the control item inner_control_instance = inner_control[2] inner_control_class = inner_control[1] # Call the inner control connect method inner_control_class.connect( control_instance.controller_widget, inner_control_name, inner_control_instance) # Update the dict control connection status control_instance.connected = True
def connect(cls, controller_widget, control_name, control_instance): """ Connect a 'List' controller trait and an 'OffscreenListControlWidget' controller widget control. Parameters ---------- cls: StrControlWidget (mandatory) a StrControlWidget control controller_widget: ControllerWidget (mandatory) a controller widget that contains the controller we want to update control_name: str (mandatory) the name of the controller widget control we want to synchronize with the controller control_instance: QFrame (mandatory) the instance of the controller widget control we want to synchronize with the controller """ # Check if the control is connected if not control_instance.connected: # Update the list item when one of his associated controller trait # changed. # Hook: function that will be called to update the controller # associated with a list widget when a list widget inner controller # trait is modified. list_controller_hook = SomaPartial(cls.update_controller, weak_proxy(controller_widget), control_name, weak_proxy(control_instance)) # Go through all list widget inner controller user traits for trait_name in control_instance.controller.user_traits(): # And add the callback on each user trait control_instance.controller.on_trait_change( list_controller_hook, trait_name, dispatch='ui') logger.debug("Item '{0}' of a 'ListControlWidget', add " "a callback on inner controller trait " "'{0}'.".format(control_name, trait_name)) # Update the list controller widget. # Hook: function that will be called to update the specific widget # when a trait event is detected on the list controller. controller_hook = SomaPartial(cls.update_controller_widget, weak_proxy(controller_widget), control_name, weak_proxy(control_instance)) # When the 'control_name' controller trait value is modified, # update the corresponding control controller_widget.controller.on_trait_change(controller_hook, control_name, dispatch='ui') # Update the list connection status control_instance._controller_connections = (list_controller_hook, controller_hook) logger.debug("Add 'List' connection: {0}.".format( control_instance._controller_connections)) # Update the list control connection status control_instance.connected = True