Пример #1
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
    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 _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)