def _reassign_settings(self, checked):
        if not checked:
            return

        forms = {}
        components = ("planning_assignment", "planning_collision_avoidance")
        hbox = QtGui.QHBoxLayout()
        for component in components:
            form = SettingsTableWidget(self._controller.arguments, component,
                                       include_parent=True)
            forms[component] = form

            vbox = QtGui.QVBoxLayout()
            vbox.addWidget(form)

            group = QtGui.QGroupBox(form.get_title())
            group.setLayout(vbox)

            hbox.addWidget(group)

        dialog = QtGui.QDialog(self._controller.central_widget)
        dialog.setWindowTitle("Change assignment settings")

        dialogButtons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
        dialogButtons.accepted.connect(dialog.accept)
        dialogButtons.rejected.connect(dialog.reject)

        dialogLayout = QtGui.QVBoxLayout()
        dialogLayout.addLayout(hbox)
        dialogLayout.addWidget(dialogButtons)

        dialog.setLayout(dialogLayout)

        # Show the dialog and handle the input.
        result = dialog.exec_()
        if result != QtGui.QDialog.Accepted:
            return

        # Update the settings from the dialog forms.
        for component, form in forms.iteritems():
            settings = self._controller.arguments.get_settings(component)
            try:
                values, disallowed = form.get_all_values()
                form.check_disallowed(disallowed)
            except ValueError as e:
                QtGui.QMessageBox.critical(self._controller.central_widget,
                                           "Invalid value", e.message)
                return

            for key, value in values.iteritems():
                try:
                    settings.set(key, value)
                except ValueError as e:
                    QtGui.QMessageBox.critical(self._controller.central_widget,
                                               "Settings error", e.message)
                    return
예제 #2
0
    def _reassign_settings(self, checked):
        if not checked:
            return

        forms = {}
        components = ("planning_assignment", "planning_collision_avoidance")
        hbox = QtGui.QHBoxLayout()
        for component in components:
            form = SettingsTableWidget(self._controller.arguments,
                                       component,
                                       include_parent=True)
            forms[component] = form

            vbox = QtGui.QVBoxLayout()
            vbox.addWidget(form)

            group = QtGui.QGroupBox(form.get_title())
            group.setLayout(vbox)

            hbox.addWidget(group)

        dialog = QtGui.QDialog(self._controller.central_widget)
        dialog.setWindowTitle("Change assignment settings")

        dialogButtons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                               | QtGui.QDialogButtonBox.Cancel)
        dialogButtons.accepted.connect(dialog.accept)
        dialogButtons.rejected.connect(dialog.reject)

        dialogLayout = QtGui.QVBoxLayout()
        dialogLayout.addLayout(hbox)
        dialogLayout.addWidget(dialogButtons)

        dialog.setLayout(dialogLayout)

        # Show the dialog and handle the input.
        result = dialog.exec_()
        if result != QtGui.QDialog.Accepted:
            return

        # Update the settings from the dialog forms.
        for component, form in forms.iteritems():
            settings = self._controller.arguments.get_settings(component)
            try:
                values, disallowed = form.get_all_values()
                form.check_disallowed(disallowed)
            except ValueError as e:
                QtGui.QMessageBox.critical(self._controller.central_widget,
                                           "Invalid value", e.message)
                return

            for key, value in values.iteritems():
                try:
                    settings.set(key, value)
                except ValueError as e:
                    QtGui.QMessageBox.critical(self._controller.central_widget,
                                               "Settings error", e.message)
                    return
예제 #3
0
    def _get_form(self, component):
        """
        Create a settings widget for a reconstructor.
        If the reconstructor class has a settings name `component` with
        the format "reconstruction_*", then a `SettingsTableWidget` is returned.
        Otherwise, an empty `QWidget` is returned.
        """

        try:
            self._arguments.get_settings(component)
        except KeyError:
            return QtGui.QWidget()
        else:
            return SettingsTableWidget(self._arguments, component)
예제 #4
0
    def _fill_forms(self):
        # Create the settings table widgets.
        self._forms = {}

        components = (
            "planning", "planning_runner",
            "planning_algorithm", "planning_problem",
            "planning_assignment", "planning_collision_avoidance"
        )
        prefix = self._controller.arguments.get_settings("planning").name
        pattern = r'^{}: ([a-z])'.format(re.escape(prefix))

        self._settings_container = QtGui.QScrollArea()
        self._settings_container.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        settings_layout = QtGui.QVBoxLayout()
        width = self._listWidget.sizeHint().width()

        for component in components:
            form = SettingsTableWidget(self._controller.arguments, component,
                                       include_parent=False)

            title = form.get_title()
            short_title = re.sub(pattern, lambda m: m.group(1).upper(),
                                 form.get_settings().name)
            settings_group = QtGui.QGroupBox(short_title)
            settings_group.setToolTip(title)
            settings_group.setCheckable(True)
            settings_group.toggled.connect(partial(self._toggle_settings, settings_group, form))
            settings_group.setStyleSheet("""
                QGroupBox::indicator { width: 0; height: 0 }
                QGroupBox::title {
                    padding: 0 3px;
                    border: 1px outset #aaaaaa;
                    background: #f0f0f0;
                }
            """)

            form.setFixedWidth(width)
            form_layout = QtGui.QHBoxLayout()
            form_layout.addWidget(form)
            form_layout.addStretch(1)

            settings_group.setLayout(form_layout)
            settings_layout.addWidget(settings_group)

            self._forms[component] = form

        settings_widget = QtGui.QWidget()
        settings_widget.setLayout(settings_layout)

        self._settings_container.setWidgetResizable(True)
        self._settings_container.setWidget(settings_widget)
예제 #5
0
    def show(self):
        """
        Show the reconstruction view.
        """

        self._add_menu_bar()

        # Create the image.
        figure = plt.figure(frameon=False)
        self._axes = figure.add_axes([0, 0, 1, 1])
        self._axes.axis("off")
        self._canvas = FigureCanvas(figure)

        # Create the tabs (and corresponding widgets).
        top_tabs, bottom_tabs = self._create_tabs()

        # Create the panels. These are tabs containing the forms for each input
        # source (dataset, dump and stream). Additionally, there are stacked
        # widgets for the reconstructor-specific and model-specific settings.
        self._panels = QtGui.QTabWidget()
        self._panels.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                   QtGui.QSizePolicy.Minimum)

        self._source_forms = []

        arguments = self._controller.arguments
        self._stacked_reconstructor = Stacked_Settings_Form(
            arguments, "reconstructor_class")
        self._stacked_model = Stacked_Settings_Form(arguments, "model_class")

        for source in self._sources:
            form = SettingsTableWidget(arguments, source["component"])

            # Handle changes to the reconstructor and model class combo box
            # selection widgets to show its settings in the respective stacked
            # widget.
            self._stacked_reconstructor.register_form(form)
            self._stacked_model.register_form(form)

            # Register the source settings widget.
            self._panels.addTab(form, source["title"])
            self._source_forms.append(form)

        # Create the toggle button (using the stopped state as default).
        self._toggle_button = QtGui.QPushButton(
            QtGui.QIcon("assets/start.png"), "Start")
        self._toggle_button.clicked.connect(self._toggle)

        # Create the snapshot button.
        self._snapshot_button = QtGui.QPushButton(
            QtGui.QIcon("assets/snapshot.png"), "Snapshot")
        self._snapshot_button.clicked.connect(self._snapshot)

        # Create the layout and add the widgets.
        vbox_left_buttons = QtGui.QHBoxLayout()
        vbox_left_buttons.addWidget(self._toggle_button)
        vbox_left_buttons.addWidget(self._snapshot_button)

        vbox_left = QtGui.QVBoxLayout()
        vbox_left.addWidget(self._panels)
        vbox_left.addWidget(self._stacked_reconstructor)
        vbox_left.addWidget(self._stacked_model)
        vbox_left.addLayout(vbox_left_buttons)

        vbox_right = QtGui.QVBoxLayout()
        vbox_right.addWidget(top_tabs, 2)
        vbox_right.addWidget(bottom_tabs, 1)

        hbox = QtGui.QHBoxLayout(self._controller.central_widget)
        hbox.addLayout(vbox_left)
        hbox.addLayout(vbox_right)

        # Update the stacked widgets when switching tabs in the panel, and
        # ensure the first stacked widget is loaded.
        self._panels.currentChanged.connect(self._update_form)
        self._update_form(0)