Beispiel #1
0
    def build_context_menu(self, builder):
        if self.model.context.is_online_master():
            x_datasets = extract_linked_datasets(self.x_schema["param"])
            y_datasets = extract_linked_datasets(self.y_schema["param"])
            for d, axis in chain(zip(x_datasets, repeat("x")),
                                 zip(y_datasets, repeat("y"))):
                action = builder.append_action(
                    "Set '{}' from crosshair".format(d))
                action.triggered.connect(lambda *a, axis=axis, d=d: (
                    self._set_dataset_from_crosshair(d, axis)))
            if len(x_datasets) == 1 and len(y_datasets) == 1:
                action = builder.append_action("Set both from crosshair")

                def set_both():
                    self._set_dataset_from_crosshair(x_datasets[0], "x")
                    self._set_dataset_from_crosshair(y_datasets[0], "y")

                action.triggered.connect(set_both)
        builder.ensure_separator()

        self.channel_menu_group = QtWidgets.QActionGroup(self)
        for name in self.data_names:
            action = builder.append_action(name)
            action.setCheckable(True)
            action.setActionGroup(self.channel_menu_group)
            action.setChecked(name == self.plot.active_channel_name)
            action.triggered.connect(
                lambda *a, name=name: self.plot.activate_channel(name))
        builder.ensure_separator()

        super().build_context_menu(builder)
Beispiel #2
0
    def _install_context_menu(self, data_names):
        entries = []

        x_datasets = extract_linked_datasets(self.x_schema["param"])
        y_datasets = extract_linked_datasets(self.y_schema["param"])
        for d, axis in chain(zip(x_datasets, repeat("x")),
                             zip(y_datasets, repeat("y"))):
            action = QtWidgets.QAction("Set '{}' from crosshair".format(d),
                                       self)
            action.triggered.connect(
                lambda *a, d=d: self._set_dataset_from_crosshair(d, axis))
            entries.append(action)
        if len(x_datasets) == 1 and len(y_datasets) == 1:
            action = QtWidgets.QAction("Set both from crosshair".format(d),
                                       self)

            def set_both():
                self._set_dataset_from_crosshair(x_datasets[0], "x")
                self._set_dataset_from_crosshair(y_datasets[0], "y")

            action.triggered.connect(set_both)
            entries.append(action)

        def append_separator():
            separator = QtWidgets.QAction("", self)
            separator.setSeparator(True)
            entries.append(separator)

        if entries:
            append_separator()

        self.channel_menu_group = QtWidgets.QActionGroup(self)
        first_action = None
        for name in data_names:
            action = QtWidgets.QAction(name, self)
            if not first_action:
                first_action = action
            action.setCheckable(True)
            action.setActionGroup(self.channel_menu_group)
            action.triggered.connect(
                lambda *a, name=name: self.plot.activate_channel(name))
            entries.append(action)
        if first_action:
            first_action.setChecked(True)
        append_separator()

        self.plotItem.getContextMenus = lambda ev: entries