Пример #1
0
class SubdivEditor(QWidget):

    def __init__(self):
        super().__init__()
        self._ui_model = None
        self._updater = None

        self._subdiv_count = QSpinBox()
        self._subdiv_count.setMinimum(2)
        self._subdiv_count.setMaximum(32)
        self._subdiv_line_style = LineStyle()
        self._subdiv_warp = NumberSlider(3, 0.001, 0.999)
        self._subdiv_apply = QPushButton('Subdivide (Insert)')

        self._subdiv_line_style.select_line_style(1)

        sl = QGridLayout()
        sl.setContentsMargins(0, 0, 0, 0)
        sl.setSpacing(2)
        sl.setColumnStretch(0, 0)
        sl.setColumnStretch(1, 1)
        sl.addWidget(QLabel('Parts:'), 0, 0)
        sl.addWidget(self._subdiv_count, 0, 1)
        sl.addWidget(QLabel('Style:'), 1, 0)
        sl.addWidget(self._subdiv_line_style, 1, 1)
        sl.addWidget(QLabel('Warp:'), 2, 0)
        sl.addWidget(self._subdiv_warp, 2, 1)

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(2)
        v.addWidget(HeaderLine('Create subdivision'), 0, Qt.AlignTop)
        v.addLayout(sl, 0)
        v.addWidget(self._subdiv_apply, 0)
        self.setLayout(v)

    def set_ui_model(self, ui_model):
        self._ui_model = ui_model
        self._updater = ui_model.get_updater()
        self._updater.register_updater(self._perform_updates)

        QObject.connect(
                self._subdiv_count, SIGNAL('valueChanged(int)'), self._change_count)

        QObject.connect(
                self._subdiv_line_style,
                SIGNAL('currentIndexChanged(int)'),
                self._change_line_style)

        QObject.connect(
                self._subdiv_warp, SIGNAL('numberChanged(float)'), self._change_warp)

        QObject.connect(self._subdiv_apply, SIGNAL('clicked()'), self._apply_subdivision)

        self._update_all()

    def unregister_updaters(self):
        self._updater.unregister_updater(self._perform_updates)

    def _perform_updates(self, signals):
        update_signals = set([
            'signal_grid_pattern_selection',
            'signal_grid_pattern_line_selection',
            'signal_grid_pattern_modified',
            'signal_grid_pattern_subdiv'])
        if not signals.isdisjoint(update_signals):
            self._update_all()

    def _get_selected_line_ts(self):
        grid_manager = self._ui_model.get_grid_manager()
        gp_id = grid_manager.get_selected_grid_pattern_id()
        if gp_id == None:
            return None

        # Get line selection info
        gp = grid_manager.get_grid_pattern(gp_id)
        gp_lines = gp.get_lines()
        lines_dict = dict(gp_lines)
        selected_line_ts = gp.get_selected_line()

        return selected_line_ts if selected_line_ts in lines_dict else None

    def _update_all(self):
        selected_line_ts = self._get_selected_line_ts()
        self.setEnabled(selected_line_ts != None)

        grid_manager = self._ui_model.get_grid_manager()

        old_block = self._subdiv_count.blockSignals(True)
        self._subdiv_count.setValue(grid_manager.get_grid_pattern_subdiv_part_count())
        self._subdiv_count.blockSignals(old_block)

        self._subdiv_line_style.select_line_style(
                grid_manager.get_grid_pattern_subdiv_line_style())
        self._subdiv_warp.set_number(grid_manager.get_grid_pattern_subdiv_warp())

    def _change_count(self, new_count):
        grid_manager = self._ui_model.get_grid_manager()
        grid_manager.set_grid_pattern_subdiv_part_count(new_count)
        self._updater.signal_update(set(['signal_grid_pattern_subdiv']))

    def _change_line_style(self, dummy):
        new_style = self._subdiv_line_style.get_current_line_style()
        grid_manager = self._ui_model.get_grid_manager()
        grid_manager.set_grid_pattern_subdiv_line_style(new_style)
        self._updater.signal_update(set(['signal_grid_pattern_subdiv']))

    def _change_warp(self, new_warp):
        grid_manager = self._ui_model.get_grid_manager()
        grid_manager.set_grid_pattern_subdiv_warp(new_warp)
        self._updater.signal_update(set(['signal_grid_pattern_subdiv']))

    def _apply_subdivision(self):
        selected_line_ts = self._get_selected_line_ts()
        assert selected_line_ts != None

        grid_manager = self._ui_model.get_grid_manager()
        gp_id = grid_manager.get_selected_grid_pattern_id()
        gp = grid_manager.get_grid_pattern(gp_id)

        part_count = grid_manager.get_grid_pattern_subdiv_part_count()
        warp_value = grid_manager.get_grid_pattern_subdiv_warp()
        line_style = grid_manager.get_grid_pattern_subdiv_line_style()

        gp.subdivide_interval(selected_line_ts, part_count, warp_value, line_style)
        self._updater.signal_update(set(['signal_grid_pattern_modified']))
Пример #2
0
class TimeEnvelope(QWidget):

    def __init__(self):
        super().__init__()
        self._ui_model = None
        self._au_id = None
        self._updater = None

        header = HeaderLine(self._get_title())

        self._enabled_toggle = QCheckBox('Enabled')
        if self._allow_loop():
            self._loop_toggle = QCheckBox('Loop')
        if self._allow_release_toggle():
            self._release_toggle = QCheckBox('Release')
        self._scale_amount = NumberSlider(2, -4, 4, title='Scale amount:')
        self._scale_center = NumberSlider(0, -3600, 3600, title='Scale center:')

        h = QHBoxLayout()
        h.addWidget(self._enabled_toggle)
        if self._allow_loop():
            h.addWidget(self._loop_toggle)
        if self._allow_release_toggle():
            h.addWidget(self._release_toggle)
        h.addWidget(self._scale_amount)
        h.addWidget(self._scale_center)

        self._envelope = self._make_envelope_widget()

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(0)
        v.addWidget(header)
        v.addLayout(h)
        v.addWidget(self._envelope)
        self.setLayout(v)

    def set_au_id(self, au_id):
        self._au_id = au_id

    def set_ui_model(self, ui_model):
        self._ui_model = ui_model
        self._updater = ui_model.get_updater()
        self._updater.register_updater(self._perform_updates)
        self._update_envelope()

        QObject.connect(
                self._enabled_toggle,
                SIGNAL('stateChanged(int)'),
                self._enabled_changed)
        if self._allow_loop():
            QObject.connect(
                    self._loop_toggle,
                    SIGNAL('stateChanged(int)'),
                    self._loop_enabled_changed)
        if self._allow_release_toggle():
            QObject.connect(
                    self._release_toggle,
                    SIGNAL('stateChanged(int)'),
                    self._release_changed)
        QObject.connect(
                self._scale_amount,
                SIGNAL('numberChanged(float)'),
                self._scale_amount_changed)
        QObject.connect(
                self._scale_center,
                SIGNAL('numberChanged(float)'),
                self._scale_center_changed)
        QObject.connect(
                self._envelope,
                SIGNAL('envelopeChanged()'),
                self._envelope_changed)

    def unregister_updaters(self):
        self._updater.unregister_updater(self._perform_updates)

    def _perform_updates(self, signals):
        update_signals = set(['signal_au', self._get_update_signal_type()])
        if not signals.isdisjoint(update_signals):
            self._update_envelope()

    def _update_envelope(self):
        old_block = self._enabled_toggle.blockSignals(True)
        self._enabled_toggle.setCheckState(
                Qt.Checked if self._get_enabled() else Qt.Unchecked)
        self._enabled_toggle.blockSignals(old_block)

        self._envelope.setEnabled(self._get_enabled())
        self._scale_amount.setEnabled(self._get_enabled())
        self._scale_center.setEnabled(self._get_enabled())

        if self._allow_loop():
            old_block = self._loop_toggle.blockSignals(True)
            self._loop_toggle.setEnabled(self._get_enabled())
            self._loop_toggle.setCheckState(
                    Qt.Checked if self._get_loop_enabled() else Qt.Unchecked)
            self._loop_toggle.blockSignals(old_block)

        if self._allow_release_toggle():
            old_block = self._release_toggle.blockSignals(True)
            self._release_toggle.setEnabled(self._get_enabled())
            self._release_toggle.setCheckState(
                    Qt.Checked if self._get_release_enabled() else Qt.Unchecked)
            self._release_toggle.blockSignals(old_block)

        self._scale_amount.set_number(self._get_scale_amount())
        self._scale_center.set_number(self._get_scale_center())

        envelope = self._get_envelope_data()
        self._envelope.set_nodes(envelope['nodes'])
        if self._allow_loop():
            self._envelope.set_loop_markers(envelope['marks'])
            self._envelope.set_loop_enabled(self._get_loop_enabled())

    def _enabled_changed(self, state):
        new_enabled = (state == Qt.Checked)
        self._set_enabled(new_enabled)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _loop_enabled_changed(self, state):
        new_enabled = (state == Qt.Checked)
        self._set_loop_enabled(new_enabled)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _release_changed(self, state):
        new_enabled = (state == Qt.Checked)
        self._set_release_enabled(new_enabled)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _scale_amount_changed(self, num):
        self._set_scale_amount(num)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _scale_center_changed(self, num):
        self._set_scale_center(num)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _envelope_changed(self):
        new_nodes, new_loop = self._envelope.get_clear_changed()

        envelope = self._get_envelope_data()
        if new_nodes:
            envelope['nodes'] = new_nodes
        if new_loop:
            envelope['marks'] = new_loop

        if new_nodes or new_loop:
            self._set_enabled(True)

        self._set_envelope_data(envelope)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    # Protected callbacks

    def _get_title(self):
        raise NotImplementedError

    def _allow_loop(self):
        raise NotImplementedError

    def _allow_release_toggle(self):
        return False

    def _make_envelope_widget(self):
        raise NotImplementedError

    def _get_update_signal_type(self):
        raise NotImplementedError

    def _get_enabled(self):
        raise NotImplementedError

    def _set_enabled(self, enabled):
        raise NotImplementedError

    def _get_loop_enabled(self):
        raise NotImplementedError

    def _set_loop_enabled(self, enabled):
        raise NotImplementedError

    def _get_release_enabled(self):
        raise NotImplementedError

    def _set_release_enabled(self, enabled):
        raise NotImplementedError

    def _get_scale_amount(self):
        raise NotImplementedError

    def _set_scale_amount(self, value):
        raise NotImplementedError

    def _get_scale_center(self):
        raise NotImplementedError

    def _set_scale_center(self, value):
        raise NotImplementedError

    def _get_envelope_data(self):
        raise NotImplementedError

    def _set_envelope_data(self, envelope):
        raise NotImplementedError
Пример #3
0
class SubdivEditor(QWidget, Updater):
    def __init__(self):
        super().__init__()
        self._subdiv_count = QSpinBox()
        self._subdiv_count.setMinimum(2)
        self._subdiv_count.setMaximum(32)
        self._subdiv_line_style = LineStyle()
        self._subdiv_warp = NumberSlider(3, 0.001, 0.999)
        self._subdiv_apply = QPushButton('Subdivide (Insert)')

        self._subdiv_line_style.select_line_style(1)

        self._controls_layout = QGridLayout()
        self._controls_layout.setContentsMargins(0, 0, 0, 0)
        self._controls_layout.setSpacing(2)
        self._controls_layout.setColumnStretch(0, 0)
        self._controls_layout.setColumnStretch(1, 1)
        self._controls_layout.addWidget(QLabel('Parts:'), 0, 0)
        self._controls_layout.addWidget(self._subdiv_count, 0, 1)
        self._controls_layout.addWidget(QLabel('Style:'), 1, 0)
        self._controls_layout.addWidget(self._subdiv_line_style, 1, 1)
        self._controls_layout.addWidget(QLabel('Warp:'), 2, 0)
        self._controls_layout.addWidget(self._subdiv_warp, 2, 1)

        self._header = HeaderLine('Create subdivision')

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(2)
        v.addWidget(self._header, 0, Qt.AlignTop)
        v.addLayout(self._controls_layout, 0)
        v.addWidget(self._subdiv_apply, 0)
        self.setLayout(v)

    def _on_setup(self):
        self.register_action('signal_grid_pattern_selection', self._update_all)
        self.register_action('signal_grid_pattern_line_selection',
                             self._update_all)
        self.register_action('signal_grid_pattern_modified', self._update_all)
        self.register_action('signal_grid_pattern_subdiv', self._update_all)
        self.register_action('signal_style_changed', self._update_style)

        self._update_config()

        self._subdiv_count.valueChanged.connect(self._change_count)
        self._subdiv_line_style.currentIndexChanged.connect(
            self._change_line_style)
        self._subdiv_warp.numberChanged.connect(self._change_warp)
        self._subdiv_apply.clicked.connect(self._apply_subdivision)

        self._update_all()

    def _update_style(self):
        self._header.update_style(self._ui_model.get_style_manager())
        self._update_config()
        self.update()

    def _update_config(self):
        style_mgr = self._ui_model.get_style_manager()
        config = DEFAULT_CONFIG.copy()
        custom_config = get_config_with_custom_style(style_mgr)
        config.update(custom_config)

        spacing = style_mgr.get_scaled_size_param('small_padding')
        self._controls_layout.setSpacing(spacing)
        self.layout().setSpacing(spacing)

        self._subdiv_line_style.set_config(config, style_mgr)

    def _get_selected_line_ts(self):
        grid_mgr = self._ui_model.get_grid_manager()
        gp_id = grid_mgr.get_selected_grid_pattern_id()
        if gp_id == None:
            return None

        # Get line selection info
        gp = grid_mgr.get_grid_pattern(gp_id)
        gp_lines = gp.get_lines()
        lines_dict = dict(gp_lines)
        selected_line_ts = gp.get_selected_line()

        return selected_line_ts if selected_line_ts in lines_dict else None

    def _update_all(self):
        selected_line_ts = self._get_selected_line_ts()
        self.setEnabled(selected_line_ts != None)

        grid_mgr = self._ui_model.get_grid_manager()

        old_block = self._subdiv_count.blockSignals(True)
        self._subdiv_count.setValue(
            grid_mgr.get_grid_pattern_subdiv_part_count())
        self._subdiv_count.blockSignals(old_block)

        self._subdiv_line_style.select_line_style(
            grid_mgr.get_grid_pattern_subdiv_line_style())
        self._subdiv_warp.set_number(grid_mgr.get_grid_pattern_subdiv_warp())

    def _change_count(self, new_count):
        grid_mgr = self._ui_model.get_grid_manager()
        grid_mgr.set_grid_pattern_subdiv_part_count(new_count)
        self._updater.signal_update('signal_grid_pattern_subdiv')

    def _change_line_style(self, dummy):
        new_style = self._subdiv_line_style.get_current_line_style()
        grid_mgr = self._ui_model.get_grid_manager()
        grid_mgr.set_grid_pattern_subdiv_line_style(new_style)
        self._updater.signal_update('signal_grid_pattern_subdiv')

    def _change_warp(self, new_warp):
        grid_mgr = self._ui_model.get_grid_manager()
        grid_mgr.set_grid_pattern_subdiv_warp(new_warp)
        self._updater.signal_update('signal_grid_pattern_subdiv')

    def _apply_subdivision(self):
        selected_line_ts = self._get_selected_line_ts()
        assert selected_line_ts != None

        grid_mgr = self._ui_model.get_grid_manager()
        gp_id = grid_mgr.get_selected_grid_pattern_id()
        gp = grid_mgr.get_grid_pattern(gp_id)

        part_count = grid_mgr.get_grid_pattern_subdiv_part_count()
        warp_value = grid_mgr.get_grid_pattern_subdiv_warp()
        line_style = grid_mgr.get_grid_pattern_subdiv_line_style()

        gp.subdivide_interval(selected_line_ts, part_count, warp_value,
                              line_style)
        self._updater.signal_update('signal_grid_pattern_modified')
Пример #4
0
class TimeEnvelope(QWidget):
    def __init__(self):
        super().__init__()
        self._ui_model = None
        self._au_id = None
        self._updater = None

        header = HeaderLine(self._get_title())

        self._enabled_toggle = QCheckBox('Enabled')
        if self._allow_loop():
            self._loop_toggle = QCheckBox('Loop')
        if self._allow_release_toggle():
            self._release_toggle = QCheckBox('Release')
        self._scale_amount = NumberSlider(2, -4, 4, title='Scale amount:')
        self._scale_center = NumberSlider(0,
                                          -3600,
                                          3600,
                                          title='Scale center:')

        h = QHBoxLayout()
        h.addWidget(self._enabled_toggle)
        if self._allow_loop():
            h.addWidget(self._loop_toggle)
        if self._allow_release_toggle():
            h.addWidget(self._release_toggle)
        h.addWidget(self._scale_amount)
        h.addWidget(self._scale_center)

        self._envelope = self._make_envelope_widget()

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(0)
        v.addWidget(header)
        v.addLayout(h)
        v.addWidget(self._envelope)
        self.setLayout(v)

    def set_au_id(self, au_id):
        self._au_id = au_id

    def set_ui_model(self, ui_model):
        self._ui_model = ui_model
        self._updater = ui_model.get_updater()
        self._updater.register_updater(self._perform_updates)
        self._update_envelope()

        QObject.connect(self._enabled_toggle, SIGNAL('stateChanged(int)'),
                        self._enabled_changed)
        if self._allow_loop():
            QObject.connect(self._loop_toggle, SIGNAL('stateChanged(int)'),
                            self._loop_enabled_changed)
        if self._allow_release_toggle():
            QObject.connect(self._release_toggle, SIGNAL('stateChanged(int)'),
                            self._release_changed)
        QObject.connect(self._scale_amount, SIGNAL('numberChanged(float)'),
                        self._scale_amount_changed)
        QObject.connect(self._scale_center, SIGNAL('numberChanged(float)'),
                        self._scale_center_changed)
        QObject.connect(self._envelope, SIGNAL('envelopeChanged()'),
                        self._envelope_changed)

    def unregister_updaters(self):
        self._updater.unregister_updater(self._perform_updates)

    def _perform_updates(self, signals):
        update_signals = set(['signal_au', self._get_update_signal_type()])
        if not signals.isdisjoint(update_signals):
            self._update_envelope()

    def _update_envelope(self):
        old_block = self._enabled_toggle.blockSignals(True)
        self._enabled_toggle.setCheckState(
            Qt.Checked if self._get_enabled() else Qt.Unchecked)
        self._enabled_toggle.blockSignals(old_block)

        self._envelope.setEnabled(self._get_enabled())
        self._scale_amount.setEnabled(self._get_enabled())
        self._scale_center.setEnabled(self._get_enabled())

        if self._allow_loop():
            old_block = self._loop_toggle.blockSignals(True)
            self._loop_toggle.setEnabled(self._get_enabled())
            self._loop_toggle.setCheckState(
                Qt.Checked if self._get_loop_enabled() else Qt.Unchecked)
            self._loop_toggle.blockSignals(old_block)

        if self._allow_release_toggle():
            old_block = self._release_toggle.blockSignals(True)
            self._release_toggle.setEnabled(self._get_enabled())
            self._release_toggle.setCheckState(
                Qt.Checked if self._get_release_enabled() else Qt.Unchecked)
            self._release_toggle.blockSignals(old_block)

        self._scale_amount.set_number(self._get_scale_amount())
        self._scale_center.set_number(self._get_scale_center())

        envelope = self._get_envelope_data()
        self._envelope.set_nodes(envelope['nodes'])
        if self._allow_loop():
            self._envelope.set_loop_markers(envelope['marks'])
            self._envelope.set_loop_enabled(self._get_loop_enabled())

    def _enabled_changed(self, state):
        new_enabled = (state == Qt.Checked)
        self._set_enabled(new_enabled)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _loop_enabled_changed(self, state):
        new_enabled = (state == Qt.Checked)
        self._set_loop_enabled(new_enabled)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _release_changed(self, state):
        new_enabled = (state == Qt.Checked)
        self._set_release_enabled(new_enabled)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _scale_amount_changed(self, num):
        self._set_scale_amount(num)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _scale_center_changed(self, num):
        self._set_scale_center(num)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    def _envelope_changed(self):
        new_nodes, new_loop = self._envelope.get_clear_changed()

        envelope = self._get_envelope_data()
        if new_nodes:
            envelope['nodes'] = new_nodes
        if new_loop:
            envelope['marks'] = new_loop

        if new_nodes or new_loop:
            self._set_enabled(True)

        self._set_envelope_data(envelope)
        self._updater.signal_update(set([self._get_update_signal_type()]))

    # Protected callbacks

    def _get_title(self):
        raise NotImplementedError

    def _allow_loop(self):
        raise NotImplementedError

    def _allow_release_toggle(self):
        return False

    def _make_envelope_widget(self):
        raise NotImplementedError

    def _get_update_signal_type(self):
        raise NotImplementedError

    def _get_enabled(self):
        raise NotImplementedError

    def _set_enabled(self, enabled):
        raise NotImplementedError

    def _get_loop_enabled(self):
        raise NotImplementedError

    def _set_loop_enabled(self, enabled):
        raise NotImplementedError

    def _get_release_enabled(self):
        raise NotImplementedError

    def _set_release_enabled(self, enabled):
        raise NotImplementedError

    def _get_scale_amount(self):
        raise NotImplementedError

    def _set_scale_amount(self, value):
        raise NotImplementedError

    def _get_scale_center(self):
        raise NotImplementedError

    def _set_scale_center(self, value):
        raise NotImplementedError

    def _get_envelope_data(self):
        raise NotImplementedError

    def _set_envelope_data(self, envelope):
        raise NotImplementedError
Пример #5
0
class SubdivEditor(QWidget):
    def __init__(self):
        super().__init__()
        self._ui_model = None
        self._updater = None

        self._subdiv_count = QSpinBox()
        self._subdiv_count.setMinimum(2)
        self._subdiv_count.setMaximum(32)
        self._subdiv_line_style = LineStyle()
        self._subdiv_warp = NumberSlider(3, 0.001, 0.999)
        self._subdiv_apply = QPushButton('Subdivide (Insert)')

        self._subdiv_line_style.select_line_style(1)

        sl = QGridLayout()
        sl.setContentsMargins(0, 0, 0, 0)
        sl.setSpacing(2)
        sl.setColumnStretch(0, 0)
        sl.setColumnStretch(1, 1)
        sl.addWidget(QLabel('Parts:'), 0, 0)
        sl.addWidget(self._subdiv_count, 0, 1)
        sl.addWidget(QLabel('Style:'), 1, 0)
        sl.addWidget(self._subdiv_line_style, 1, 1)
        sl.addWidget(QLabel('Warp:'), 2, 0)
        sl.addWidget(self._subdiv_warp, 2, 1)

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(2)
        v.addWidget(HeaderLine('Create subdivision'), 0, Qt.AlignTop)
        v.addLayout(sl, 0)
        v.addWidget(self._subdiv_apply, 0)
        self.setLayout(v)

    def set_ui_model(self, ui_model):
        self._ui_model = ui_model
        self._updater = ui_model.get_updater()
        self._updater.register_updater(self._perform_updates)

        QObject.connect(self._subdiv_count, SIGNAL('valueChanged(int)'),
                        self._change_count)

        QObject.connect(self._subdiv_line_style,
                        SIGNAL('currentIndexChanged(int)'),
                        self._change_line_style)

        QObject.connect(self._subdiv_warp, SIGNAL('numberChanged(float)'),
                        self._change_warp)

        QObject.connect(self._subdiv_apply, SIGNAL('clicked()'),
                        self._apply_subdivision)

        self._update_all()

    def unregister_updaters(self):
        self._updater.unregister_updater(self._perform_updates)

    def _perform_updates(self, signals):
        update_signals = set([
            'signal_grid_pattern_selection',
            'signal_grid_pattern_line_selection',
            'signal_grid_pattern_modified', 'signal_grid_pattern_subdiv'
        ])
        if not signals.isdisjoint(update_signals):
            self._update_all()

    def _get_selected_line_ts(self):
        grid_manager = self._ui_model.get_grid_manager()
        gp_id = grid_manager.get_selected_grid_pattern_id()
        if gp_id == None:
            return None

        # Get line selection info
        gp = grid_manager.get_grid_pattern(gp_id)
        gp_lines = gp.get_lines()
        lines_dict = dict(gp_lines)
        selected_line_ts = gp.get_selected_line()

        return selected_line_ts if selected_line_ts in lines_dict else None

    def _update_all(self):
        selected_line_ts = self._get_selected_line_ts()
        self.setEnabled(selected_line_ts != None)

        grid_manager = self._ui_model.get_grid_manager()

        old_block = self._subdiv_count.blockSignals(True)
        self._subdiv_count.setValue(
            grid_manager.get_grid_pattern_subdiv_part_count())
        self._subdiv_count.blockSignals(old_block)

        self._subdiv_line_style.select_line_style(
            grid_manager.get_grid_pattern_subdiv_line_style())
        self._subdiv_warp.set_number(
            grid_manager.get_grid_pattern_subdiv_warp())

    def _change_count(self, new_count):
        grid_manager = self._ui_model.get_grid_manager()
        grid_manager.set_grid_pattern_subdiv_part_count(new_count)
        self._updater.signal_update(set(['signal_grid_pattern_subdiv']))

    def _change_line_style(self, dummy):
        new_style = self._subdiv_line_style.get_current_line_style()
        grid_manager = self._ui_model.get_grid_manager()
        grid_manager.set_grid_pattern_subdiv_line_style(new_style)
        self._updater.signal_update(set(['signal_grid_pattern_subdiv']))

    def _change_warp(self, new_warp):
        grid_manager = self._ui_model.get_grid_manager()
        grid_manager.set_grid_pattern_subdiv_warp(new_warp)
        self._updater.signal_update(set(['signal_grid_pattern_subdiv']))

    def _apply_subdivision(self):
        selected_line_ts = self._get_selected_line_ts()
        assert selected_line_ts != None

        grid_manager = self._ui_model.get_grid_manager()
        gp_id = grid_manager.get_selected_grid_pattern_id()
        gp = grid_manager.get_grid_pattern(gp_id)

        part_count = grid_manager.get_grid_pattern_subdiv_part_count()
        warp_value = grid_manager.get_grid_pattern_subdiv_warp()
        line_style = grid_manager.get_grid_pattern_subdiv_line_style()

        gp.subdivide_interval(selected_line_ts, part_count, warp_value,
                              line_style)
        self._updater.signal_update(set(['signal_grid_pattern_modified']))
Пример #6
0
class SubdivEditor(QWidget, Updater):

    def __init__(self):
        super().__init__()
        self._subdiv_count = QSpinBox()
        self._subdiv_count.setMinimum(2)
        self._subdiv_count.setMaximum(32)
        self._subdiv_line_style = LineStyle()
        self._subdiv_warp = NumberSlider(3, 0.001, 0.999)
        self._subdiv_apply = QPushButton('Subdivide (Insert)')

        self._subdiv_line_style.select_line_style(1)

        self._controls_layout = QGridLayout()
        self._controls_layout.setContentsMargins(0, 0, 0, 0)
        self._controls_layout.setSpacing(2)
        self._controls_layout.setColumnStretch(0, 0)
        self._controls_layout.setColumnStretch(1, 1)
        self._controls_layout.addWidget(QLabel('Parts:'), 0, 0)
        self._controls_layout.addWidget(self._subdiv_count, 0, 1)
        self._controls_layout.addWidget(QLabel('Style:'), 1, 0)
        self._controls_layout.addWidget(self._subdiv_line_style, 1, 1)
        self._controls_layout.addWidget(QLabel('Warp:'), 2, 0)
        self._controls_layout.addWidget(self._subdiv_warp, 2, 1)

        self._header = HeaderLine('Create subdivision')

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(2)
        v.addWidget(self._header, 0, Qt.AlignTop)
        v.addLayout(self._controls_layout, 0)
        v.addWidget(self._subdiv_apply, 0)
        self.setLayout(v)

    def _on_setup(self):
        self.register_action('signal_grid_pattern_selection', self._update_all)
        self.register_action('signal_grid_pattern_line_selection', self._update_all)
        self.register_action('signal_grid_pattern_modified', self._update_all)
        self.register_action('signal_grid_pattern_subdiv', self._update_all)
        self.register_action('signal_style_changed', self._update_style)

        self._update_config()

        self._subdiv_count.valueChanged.connect(self._change_count)
        self._subdiv_line_style.currentIndexChanged.connect(self._change_line_style)
        self._subdiv_warp.numberChanged.connect(self._change_warp)
        self._subdiv_apply.clicked.connect(self._apply_subdivision)

        self._update_all()

    def _update_style(self):
        self._header.update_style(self._ui_model.get_style_manager())
        self._update_config()
        self.update()

    def _update_config(self):
        style_mgr = self._ui_model.get_style_manager()
        config = DEFAULT_CONFIG.copy()
        custom_config = get_config_with_custom_style(style_mgr)
        config.update(custom_config)

        spacing = style_mgr.get_scaled_size_param('small_padding')
        self._controls_layout.setSpacing(spacing)
        self.layout().setSpacing(spacing)

        self._subdiv_line_style.set_config(config, style_mgr)

    def _get_selected_line_ts(self):
        grid_mgr = self._ui_model.get_grid_manager()
        gp_id = grid_mgr.get_selected_grid_pattern_id()
        if gp_id == None:
            return None

        # Get line selection info
        gp = grid_mgr.get_grid_pattern(gp_id)
        gp_lines = gp.get_lines()
        lines_dict = dict(gp_lines)
        selected_line_ts = gp.get_selected_line()

        return selected_line_ts if selected_line_ts in lines_dict else None

    def _update_all(self):
        selected_line_ts = self._get_selected_line_ts()
        self.setEnabled(selected_line_ts != None)

        grid_mgr = self._ui_model.get_grid_manager()

        old_block = self._subdiv_count.blockSignals(True)
        self._subdiv_count.setValue(grid_mgr.get_grid_pattern_subdiv_part_count())
        self._subdiv_count.blockSignals(old_block)

        self._subdiv_line_style.select_line_style(
                grid_mgr.get_grid_pattern_subdiv_line_style())
        self._subdiv_warp.set_number(grid_mgr.get_grid_pattern_subdiv_warp())

    def _change_count(self, new_count):
        grid_mgr = self._ui_model.get_grid_manager()
        grid_mgr.set_grid_pattern_subdiv_part_count(new_count)
        self._updater.signal_update('signal_grid_pattern_subdiv')

    def _change_line_style(self, dummy):
        new_style = self._subdiv_line_style.get_current_line_style()
        grid_mgr = self._ui_model.get_grid_manager()
        grid_mgr.set_grid_pattern_subdiv_line_style(new_style)
        self._updater.signal_update('signal_grid_pattern_subdiv')

    def _change_warp(self, new_warp):
        grid_mgr = self._ui_model.get_grid_manager()
        grid_mgr.set_grid_pattern_subdiv_warp(new_warp)
        self._updater.signal_update('signal_grid_pattern_subdiv')

    def _apply_subdivision(self):
        selected_line_ts = self._get_selected_line_ts()
        assert selected_line_ts != None

        grid_mgr = self._ui_model.get_grid_manager()
        gp_id = grid_mgr.get_selected_grid_pattern_id()
        gp = grid_mgr.get_grid_pattern(gp_id)

        part_count = grid_mgr.get_grid_pattern_subdiv_part_count()
        warp_value = grid_mgr.get_grid_pattern_subdiv_warp()
        line_style = grid_mgr.get_grid_pattern_subdiv_line_style()

        gp.subdivide_interval(selected_line_ts, part_count, warp_value, line_style)
        self._updater.signal_update('signal_grid_pattern_modified')