How to use the phylib.utils.connect function in phylib

To help you get started, we’ve selected a few phylib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cortex-lab / phy / phy / apps / base.py View on Github external
        @connect(sender=v)
        def on_select_channel(sender, channel_id=None, key=None, button=None):
            # Update the Selection object with the channel id clicked in the waveform view.
            self.selection.channel_id = channel_id
            emit('selected_channel_changed', v)
github cortex-lab / phy / phy / gui / widgets.py View on Github external
var data = %s;

            var options = {
              valueNames: %s,
              columns: %s,
              sort: %s,
            };

            var table = new Table('table', options, data);

        
        ''' % (data_json, value_names_json, columns_json, sort_json)
        self.build(lambda html: emit('ready', self))

        connect(event='select', sender=self, func=lambda *args: self.update(), last=True)
        connect(event='ready', sender=self, func=lambda *args: self._set_ready())
github cortex-lab / phy / phy / gui / widgets.py View on Github external
''' % (data_json, value_names_json, columns_json, sort_json)
        self.build(lambda html: emit('ready', self))

        connect(event='select', sender=self, func=lambda *args: self.update(), last=True)
        connect(event='ready', sender=self, func=lambda *args: self._set_ready())
github cortex-lab / phy / phy / cluster / views / base.py View on Github external
# Freeze and unfreeze the view when selecting clusters.
        self.actions.add(
            self.toggle_auto_update, checkable=True, checked=self.auto_update, show_shortcut=False)
        self.actions.add(self.screenshot, show_shortcut=False)
        self.actions.add(self.close, show_shortcut=False)
        self.actions.separator()

        # Color scheme actions.
        self.actions.add(self.next_color_scheme)
        self.actions.add(self.previous_color_scheme)
        self.actions.separator()

        emit('view_actions_created', self)

        on_select = partial(self.on_select_threaded, gui=gui)
        connect(on_select, event='select')

        # Save the view state in the GUI state.
        @connect(sender=gui)
        def on_close_view(sender, view):
            if view != self:
                return
            logger.debug("Close view %s.", self.name)
            self._closed = True
            gui.remove_menu(self.name)
            unconnect(on_select)
            gui.state.update_view_state(self, self.state)
            self.canvas.close()
            gc.collect(0)

        @connect(sender=gui)
        def on_close(sender):
github cortex-lab / phy / phy / cluster / supervisor.py View on Github external
def _eval(self, task):
        """Evaluate a task and call a callback function."""
        sender, name, args, kwargs = task
        logger.log(5, "Calling %s.%s(%s)", sender.__class__.__name__, name, args, kwargs)
        f = getattr(sender, name)
        callback = partial(self._callback, task)
        argspec = inspect.getfullargspec(f)
        argspec = argspec.args + argspec.kwonlyargs
        if 'callback' in argspec:
            f(*args, **kwargs, callback=callback)
        else:
            # HACK: use on_cluster event instead of callback.
            def _cluster_callback(tsender, up):
                self._callback(task, up)
            connect(_cluster_callback, event='cluster', sender=self.supervisor)
            f(*args, **kwargs)
            unconnect(_cluster_callback)
github cortex-lab / phy / phy / apps / base.py View on Github external
        @connect(sender=gui)  # noqa
        def on_close(sender):

            # Gather all GUI state attributes from views that are local and thus need
            # to be saved in the data directory.
            for view in gui.views:
                local_keys = getattr(view, 'local_state_attrs', [])
                local_keys = ['%s.%s' % (view.name, key) for key in local_keys]
                gui.state.add_local_keys(local_keys)

            # Update the controller params in the GUI state.
            for param in self._state_params:
                gui.state[param] = getattr(self, param, None)

            # Save the memcache.
            gui.state['GUI_VERSION'] = self.gui_version
            self.context.save_memcache()
github cortex-lab / phy / phy / apps / base.py View on Github external
                @connect
                def on_cluster(supervisor, up):
                    if isinstance(supervisor, Supervisor):
                        # After a clustering action, get the cluster ids as shown
                        # in the cluster view, and update the color selector accordingly.
                        @supervisor.cluster_view.get_ids
                        def _update(cluster_ids):
                            if cluster_ids is not None:
                                view.set_cluster_ids(cluster_ids)
github cortex-lab / phy / phy / apps / base.py View on Github external
        @connect
        def on_color_scheme_changed(sender, name):
            """Update the cluster colors when the color scheme is updated."""
            if sender == view:
                view.update_color(self.supervisor.selected_clusters)

        @connect(sender=self.supervisor)
        def on_cluster(sender, up):
            """Update the view after a clustering action."""
            if up.added:
                view.set_spike_clusters(self.supervisor.clustering.spike_clusters)
                if view.auto_update:
                    resort(is_async=False, up=up)

        connect(view.on_select)

        @connect
        def on_add_view(sender, view_):
            """Populate the view when it is added to the GUI."""
            if view_ == view:
                # Plot the view when adding it to the existing GUI.
                resort()

        @connect(sender=self.supervisor.cluster_view)
        def on_ready(sender):
            """Populate the view at startup, as soon as the cluster view has been loaded."""
            resort()

        @connect
        def on_close_view(sender, view_):
            """Unconnect all events when closing the view."""
github cortex-lab / phy / phy / apps / base.py View on Github external
        @connect
        def on_view_ready(view):
            if isinstance(view, ManualClusteringView):
                # Add auto update button.
                view.dock.add_button(
                    name='auto_update', icon='f021', checkable=True, checked=view.auto_update,
                    event='toggle_auto_update', callback=view.toggle_auto_update)

            # Update base views cluster ids after clustering actions.
            if isinstance(view, BaseGlobalView):
                @connect
                def on_cluster(supervisor, up):
                    if isinstance(supervisor, Supervisor):
                        # After a clustering action, get the cluster ids as shown
                        # in the cluster view, and update the color selector accordingly.
                        @supervisor.cluster_view.get_ids
                        def _update(cluster_ids):
github cortex-lab / phy / phy / cluster / supervisor.py View on Github external
# Create the cluster view.
        self.cluster_view = ClusterView(
            gui, data=self.cluster_info, columns=self.columns, sort=sort)
        # Update the action flow and similarity view when selection changes.
        connect(self._clusters_selected, event='select', sender=self.cluster_view)

        # Create the similarity view.
        self.similarity_view = SimilarityView(
            gui, columns=self.columns + ['similarity'], sort=('similarity', 'desc'))
        connect(
            self._get_similar_clusters, event='request_similar_clusters',
            sender=self.similarity_view)
        connect(self._similar_selected, event='select', sender=self.similarity_view)

        # Change the state after every clustering action, according to the action flow.
        connect(self._after_action, event='cluster', sender=self)