示例#1
0
class TonePitchSpin(QWidget, ProcessorUpdater):
    def __init__(self, index):
        super().__init__()
        self._index = index

        self._spin = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._spin.setMinimum(0.000001)
        self._spin.setMaximum(1024.0)
        self._spin.setValue(1)

        h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        h.addWidget(QLabel('Pitch factor:'))
        h.addWidget(self._spin)
        self.setLayout(h)

    def _on_setup(self):
        self.register_action('signal_au', self._update_value)
        self.register_action(self._get_update_signal_type(),
                             self._update_value)
        self._update_value()
        self._spin.valueChanged.connect(self._value_changed)

        self.register_action('signal_style_changed', self._update_style)
        self._update_style()

    def _update_style(self):
        style_mgr = self._ui_model.get_style_manager()
        self._spin.update_style(style_mgr)
        self.layout().setSpacing(
            style_mgr.get_scaled_size_param('small_padding'))

    def _get_update_signal_type(self):
        return ''.join(('signal_proc_add_tone_', self._au_id, self._proc_id))

    def _update_value(self):
        add_params = utils.get_proc_params(self._ui_model, self._au_id,
                                           self._proc_id)

        if self._index >= add_params.get_tone_count():
            # We have been removed
            return

        old_block = self._spin.blockSignals(True)
        new_pitch = add_params.get_tone_pitch(self._index)
        if new_pitch != self._spin.value():
            self._spin.setValue(new_pitch)
        self._spin.blockSignals(old_block)

    def _value_changed(self, pitch):
        add_params = utils.get_proc_params(self._ui_model, self._au_id,
                                           self._proc_id)
        add_params.set_tone_pitch(self._index, pitch)
        self._updater.signal_update(self._get_update_signal_type())
示例#2
0
文件: addproc.py 项目: kagu/kunquat
class TonePitchSpin(QWidget, ProcessorUpdater):

    def __init__(self, index):
        super().__init__()
        self._index = index

        self._spin = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._spin.setMinimum(0.000001)
        self._spin.setMaximum(1024.0)
        self._spin.setValue(1)

        h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        h.addWidget(QLabel('Pitch factor:'))
        h.addWidget(self._spin)
        self.setLayout(h)

    def _on_setup(self):
        self.register_action('signal_au', self._update_value)
        self.register_action(self._get_update_signal_type(), self._update_value)
        self._update_value()
        self._spin.valueChanged.connect(self._value_changed)

        self.register_action('signal_style_changed', self._update_style)
        self._update_style()

    def _update_style(self):
        style_mgr = self._ui_model.get_style_manager()
        self._spin.update_style(style_mgr)
        self.layout().setSpacing(style_mgr.get_scaled_size_param('small_padding'))

    def _get_update_signal_type(self):
        return ''.join(('signal_proc_add_tone_', self._au_id, self._proc_id))

    def _update_value(self):
        add_params = utils.get_proc_params(self._ui_model, self._au_id, self._proc_id)

        if self._index >= add_params.get_tone_count():
            # We have been removed
            return

        old_block = self._spin.blockSignals(True)
        new_pitch = add_params.get_tone_pitch(self._index)
        if new_pitch != self._spin.value():
            self._spin.setValue(new_pitch)
        self._spin.blockSignals(old_block)

    def _value_changed(self, pitch):
        add_params = utils.get_proc_params(self._ui_model, self._au_id, self._proc_id)
        add_params.set_tone_pitch(self._index, pitch)
        self._updater.signal_update(self._get_update_signal_type())
示例#3
0
文件: toolbar.py 项目: Jasu/kunquat
class LengthEditor(QWidget, Updater):

    def __init__(self):
        super().__init__()
        self._is_latest_committed = True

        self._spinbox = VarPrecSpinBox(step_decimals=0, max_decimals=5)
        self._spinbox.setMinimum(0)
        self._spinbox.setMaximum(1024)

        h = QHBoxLayout()
        h.setContentsMargins(5, 0, 5, 0)
        h.setSpacing(5)
        h.addWidget(QLabel('Pattern length'))
        h.addWidget(self._spinbox)
        self.setLayout(h)

    def _on_setup(self):
        self.register_action('signal_module', self._update_value)
        self.register_action('signal_pattern_length', self._update_value)
        self.register_action('signal_selection', self._update_value)
        self.register_action('signal_order_list', self._update_value)
        self.register_action('signal_sheet_undo', self._update_value)
        self.register_action('signal_sheet_redo', self._update_value)

        self._update_value()

        self._spinbox.valueChanged.connect(self._change_length)
        self._spinbox.editingFinished.connect(self._change_length_final)

    def _get_pattern(self):
        module = self._ui_model.get_module()
        album = module.get_album()
        if not album.get_existence():
            return None

        selection = self._ui_model.get_selection()
        location = selection.get_location()
        song = album.get_song_by_track(location.get_track())
        pinst = song.get_pattern_instance(location.get_system())
        pattern = pinst.get_pattern()
        return pattern

    def _update_value(self):
        pattern = self._get_pattern()
        if not pattern:
            self.setEnabled(False)
            old_block = self._spinbox.blockSignals(True)
            self._spinbox.setValue(0)
            self._spinbox.blockSignals(old_block)
            return

        length = pattern.get_length()
        length_val = float(length)

        self.setEnabled(True)
        old_block = self._spinbox.blockSignals(True)
        if length_val != self._spinbox.value():
            self._spinbox.setValue(length_val)
        self._spinbox.blockSignals(old_block)

    def _change_value(self, new_value, is_final):
        pattern = self._get_pattern()
        if not pattern:
            return

        sheet_mgr = self._ui_model.get_sheet_manager()

        length = tstamp.Tstamp(new_value)
        if length == pattern.get_length():
            if is_final and not self._is_latest_committed:
                sheet_mgr.set_pattern_length(pattern, length, is_final)
                self._is_latest_committed = True
            return

        sheet_mgr.set_pattern_length(pattern, length, is_final)
        self._updater.signal_update('signal_pattern_length')

    def _change_length(self, new_value):
        self._is_latest_committed = False
        self._change_value(new_value, is_final=False)

    def _change_length_final(self):
        new_value = self._spinbox.value()
        self._change_value(new_value, is_final=True)
示例#4
0
文件: toolbar.py 项目: kagu/kunquat
class LengthEditor(QWidget, Updater):

    def __init__(self):
        super().__init__()
        self._is_latest_committed = True

        self._spinbox = VarPrecSpinBox(step_decimals=0, max_decimals=5)
        self._spinbox.setMinimum(0)
        self._spinbox.setMaximum(1024)

        h = QHBoxLayout()
        h.setContentsMargins(5, 0, 5, 0)
        h.setSpacing(5)
        h.addWidget(QLabel('Pattern length:'))
        h.addWidget(self._spinbox)
        self.setLayout(h)

    def _on_setup(self):
        self.register_action('signal_module', self._update_value)
        self.register_action('signal_pattern_length', self._update_value)
        self.register_action('signal_selection', self._update_value)
        self.register_action('signal_order_list', self._update_value)
        self.register_action('signal_sheet_undo', self._update_value)
        self.register_action('signal_sheet_redo', self._update_value)

        self.register_action('signal_style_changed', self._update_style)
        self._update_style()

        self._update_value()

        self._spinbox.valueChanged.connect(self._change_length)
        self._spinbox.editingFinished.connect(self._change_length_final)

    def _update_style(self):
        style_mgr = self._ui_model.get_style_manager()
        self._spinbox.update_style(style_mgr)
        margin_x = style_mgr.get_scaled_size_param('medium_padding')
        self.layout().setContentsMargins(margin_x, 0, margin_x, 0)
        self.layout().setSpacing(style_mgr.get_scaled_size_param('medium_padding'))

    def _get_pattern(self):
        module = self._ui_model.get_module()
        album = module.get_album()
        if not album.get_existence():
            return None

        selection = self._ui_model.get_selection()
        location = selection.get_location()
        song = album.get_song_by_track(location.get_track())
        pinst = song.get_pattern_instance(location.get_system())
        pattern = pinst.get_pattern()
        return pattern

    def _update_value(self):
        pattern = self._get_pattern()
        if not pattern:
            self.setEnabled(False)
            old_block = self._spinbox.blockSignals(True)
            self._spinbox.setValue(0)
            self._spinbox.blockSignals(old_block)
            return

        length = pattern.get_length()
        length_val = float(length)

        self.setEnabled(True)
        old_block = self._spinbox.blockSignals(True)
        if length_val != self._spinbox.value():
            self._spinbox.setValue(length_val)
        self._spinbox.blockSignals(old_block)

    def _change_value(self, new_value, is_final):
        pattern = self._get_pattern()
        if not pattern:
            return

        sheet_mgr = self._ui_model.get_sheet_manager()

        length = tstamp.Tstamp(new_value)
        if length == pattern.get_length():
            if is_final and not self._is_latest_committed:
                sheet_mgr.set_pattern_length(pattern, length, is_final)
                self._is_latest_committed = True
            return

        sheet_mgr.set_pattern_length(pattern, length, is_final)
        self._updater.signal_update('signal_pattern_length')

    def _change_length(self, new_value):
        self._is_latest_committed = False
        self._change_value(new_value, is_final=False)

    def _change_length_final(self):
        new_value = self._spinbox.value()
        self._change_value(new_value, is_final=True)
示例#5
0
class GeneralEditor(QWidget, Updater):
    def __init__(self):
        super().__init__()
        self._name = QLineEdit()

        self._length = VarPrecSpinBox(step_decimals=0, max_decimals=5)
        self._length.setMinimum(1)
        self._length.setMaximum(32)

        self._spacing_style = LineStyle(is_major_enabled=True)
        self._spacing_value = VarPrecSpinBox(step_decimals=1, max_decimals=2)
        self._spacing_value.setMinimum(0.01)
        self._spacing_value.setMaximum(1.0)

        self._offset = VarPrecSpinBox(step_decimals=1, max_decimals=5)
        self._offset.setMinimum(0)
        self._offset.setMaximum(32)

        nl = QHBoxLayout()
        nl.setContentsMargins(0, 0, 0, 0)
        nl.setSpacing(2)
        nl.addWidget(QLabel('Name:'), 0)
        nl.addWidget(self._name, 1)

        ll = QHBoxLayout()
        ll.setContentsMargins(0, 0, 0, 0)
        ll.setSpacing(2)
        ll.addWidget(QLabel('Grid length:'), 0)
        ll.addWidget(self._length, 1)

        sl = QHBoxLayout()
        sl.setContentsMargins(0, 0, 0, 0)
        sl.setSpacing(2)
        sl.addWidget(QLabel('Show lines'), 0)
        sl.addWidget(self._spacing_style, 3)
        sl.addWidget(QLabel('when spacing is ≥:'), 0)
        sl.addWidget(self._spacing_value, 1)

        ol = QHBoxLayout()
        ol.setContentsMargins(0, 0, 0, 0)
        ol.setSpacing(2)
        ol.addWidget(QLabel('Grid offset:'), 0)
        ol.addWidget(self._offset, 1)

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(2)
        v.addLayout(nl)
        v.addLayout(ll)
        v.addLayout(sl)
        v.addLayout(ol)
        self.setLayout(v)

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

        self._update_config()

        self._name.textEdited.connect(self._change_name)
        self._length.valueChanged.connect(self._change_length)
        self._spacing_style.currentIndexChanged.connect(
            self._select_spacing_style)
        self._spacing_value.valueChanged.connect(self._change_spacing)

        self._offset.valueChanged.connect(self._change_offset)

        self._update_all()

    def _update_style(self):
        self._update_config()
        style_mgr = self._ui_model.get_style_manager()
        for vps in (self._length, self._spacing_value, self._offset):
            vps.update_style(style_mgr)
        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)

        layout = self.layout()
        spacing = style_mgr.get_scaled_size_param('small_padding')
        for i in range(layout.count()):
            sub_layout = layout.itemAt(i).layout()
            if sub_layout:
                sub_layout.setSpacing(spacing)

        self._spacing_style.set_config(config, style_mgr)

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

        gp = grid_mgr.get_grid_pattern(gp_id)
        return gp

    def _update_all(self):
        gp = self._get_selected_grid_pattern()
        self.setEnabled(gp != None)
        if gp == None:
            return

        gp_name = gp.get_name()
        if gp_name != str(self._name.text()):
            old_block = self._name.blockSignals(True)
            self._name.setText(gp_name)
            self._name.blockSignals(old_block)

        gp_length = gp.get_length()
        gp_length_f = float(gp_length)

        if gp_length_f != self._length.value():
            old_block = self._length.blockSignals(True)
            self._length.setValue(gp_length_f)
            self._length.blockSignals(old_block)

        spacing_value = gp.get_line_style_spacing(
            self._spacing_style.get_current_line_style())

        if spacing_value != self._spacing_value.value():
            old_block = self._spacing_value.blockSignals(True)
            self._spacing_value.setValue(spacing_value)
            self._spacing_value.blockSignals(old_block)

        gp_offset = gp.get_offset()
        gp_offset_f = float(gp_offset)

        if gp_offset_f != self._offset.value():
            old_block = self._offset.blockSignals(True)
            self._offset.setValue(gp_offset_f)
            self._offset.blockSignals(old_block)

    def _change_name(self, text):
        text = str(text)

        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        gp.set_name(text)
        self._updater.signal_update('signal_grid_pattern_modified',
                                    'signal_grid_pattern_list')

    def _change_length(self, new_length):
        new_length_ts = tstamp.Tstamp(new_length)

        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        gp.set_length(new_length_ts)
        self._updater.signal_update('signal_grid_pattern_modified')

    def _select_spacing_style(self, new_style):
        self._spacing_style.select_line_style(new_style)
        self._update_all()

    def _change_spacing(self, new_spacing):
        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        line_style = self._spacing_style.get_current_line_style()
        gp.set_line_style_spacing(line_style, new_spacing)
        self._updater.signal_update('signal_grid_pattern_modified')

    def _change_offset(self, new_offset):
        new_offset_ts = tstamp.Tstamp(new_offset)

        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        gp.set_offset(new_offset_ts)
        self._updater.signal_update('signal_grid_pattern_modified')
示例#6
0
class InitStateEditor(QWidget, ProcessorUpdater):
    def __init__(self):
        super().__init__()

        self._init_val = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._init_val.setMinimum(-99999)
        self._init_val.setMaximum(99999)

        self._osc_speed = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._osc_speed.setMinimum(0)
        self._osc_speed.setMaximum(1000)

        self._osc_depth = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._osc_depth.setMinimum(0)
        self._osc_depth.setMaximum(99999)

        h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        h.setSpacing(10)
        h.addWidget(QLabel('Initial value:'), 0)
        h.addWidget(self._init_val, 1)
        h.addWidget(QLabel('Initial oscillation speed:'), 0)
        h.addWidget(self._osc_speed, 1)
        h.addWidget(QLabel('Initial oscillation depth:'), 0)
        h.addWidget(self._osc_depth, 1)

        self.setLayout(h)

    def _on_setup(self):
        self.register_action(self._get_update_signal_type(),
                             self._update_state)

        self._init_val.valueChanged.connect(self._set_init_value)
        self._osc_speed.valueChanged.connect(self._set_osc_speed)
        self._osc_depth.valueChanged.connect(self._set_osc_depth)

        self._update_state()

    def _get_update_signal_type(self):
        return 'signal_stream_init_state_{}'.format(self._proc_id)

    def _get_stream_params(self):
        module = self._ui_model.get_module()
        au = module.get_audio_unit(self._au_id)
        proc = au.get_processor(self._proc_id)
        stream_params = proc.get_type_params()
        return stream_params

    def _update_state(self):
        stream_params = self._get_stream_params()

        init_value = stream_params.get_init_value()
        if init_value != self._init_val.value():
            old_block = self._init_val.blockSignals(True)
            self._init_val.setValue(init_value)
            self._init_val.blockSignals(old_block)

        osc_speed = stream_params.get_init_osc_speed()
        if osc_speed != self._osc_speed.value():
            old_block = self._osc_speed.blockSignals(True)
            self._osc_speed.setValue(osc_speed)
            self._osc_speed.blockSignals(old_block)

        osc_depth = stream_params.get_init_osc_depth()
        if osc_depth != self._osc_depth.value():
            old_block = self._osc_depth.blockSignals(True)
            self._osc_depth.setValue(osc_depth)
            self._osc_depth.blockSignals(old_block)

    def _set_init_value(self, value):
        stream_params = self._get_stream_params()
        stream_params.set_init_value(value)
        self._updater.signal_update(self._get_update_signal_type())

    def _set_osc_speed(self, value):
        stream_params = self._get_stream_params()
        stream_params.set_init_osc_speed(value)
        self._updater.signal_update(self._get_update_signal_type())

    def _set_osc_depth(self, value):
        stream_params = self._get_stream_params()
        stream_params.set_init_osc_depth(value)
        self._updater.signal_update(self._get_update_signal_type())
示例#7
0
class InitStateEditor(QWidget, ProcessorUpdater):

    def __init__(self):
        super().__init__()

        self._init_val = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._init_val.setMinimum(-99999)
        self._init_val.setMaximum(99999)

        self._osc_speed = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._osc_speed.setMinimum(0)
        self._osc_speed.setMaximum(1000)

        self._osc_depth = VarPrecSpinBox(step_decimals=0, max_decimals=6)
        self._osc_depth.setMinimum(0)
        self._osc_depth.setMaximum(99999)

        h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        h.setSpacing(10)
        h.addWidget(QLabel('Initial value:'), 0)
        h.addWidget(self._init_val, 1)
        h.addWidget(QLabel('Initial oscillation speed:'), 0)
        h.addWidget(self._osc_speed, 1)
        h.addWidget(QLabel('Initial oscillation depth:'), 0)
        h.addWidget(self._osc_depth, 1)

        self.setLayout(h)

    def _on_setup(self):
        self.register_action(self._get_update_signal_type(), self._update_state)
        self.register_action('signal_style_changed', self._update_style)

        self._init_val.valueChanged.connect(self._set_init_value)
        self._osc_speed.valueChanged.connect(self._set_osc_speed)
        self._osc_depth.valueChanged.connect(self._set_osc_depth)

        self._update_style()
        self._update_state()

    def _get_update_signal_type(self):
        return 'signal_stream_init_state_{}'.format(self._proc_id)

    def _get_stream_params(self):
        module = self._ui_model.get_module()
        au = module.get_audio_unit(self._au_id)
        proc = au.get_processor(self._proc_id)
        stream_params = proc.get_type_params()
        return stream_params

    def _update_style(self):
        style_mgr = self._ui_model.get_style_manager()
        for vps in (self._init_val, self._osc_speed, self._osc_depth):
            vps.update_style(style_mgr)
        self.layout().setSpacing(style_mgr.get_scaled_size_param('large_padding'))

    def _update_state(self):
        stream_params = self._get_stream_params()

        init_value = stream_params.get_init_value()
        if init_value != self._init_val.value():
            old_block = self._init_val.blockSignals(True)
            self._init_val.setValue(init_value)
            self._init_val.blockSignals(old_block)

        osc_speed = stream_params.get_init_osc_speed()
        if osc_speed != self._osc_speed.value():
            old_block = self._osc_speed.blockSignals(True)
            self._osc_speed.setValue(osc_speed)
            self._osc_speed.blockSignals(old_block)

        osc_depth = stream_params.get_init_osc_depth()
        if osc_depth != self._osc_depth.value():
            old_block = self._osc_depth.blockSignals(True)
            self._osc_depth.setValue(osc_depth)
            self._osc_depth.blockSignals(old_block)

    def _set_init_value(self, value):
        stream_params = self._get_stream_params()
        stream_params.set_init_value(value)
        self._updater.signal_update(self._get_update_signal_type())

    def _set_osc_speed(self, value):
        stream_params = self._get_stream_params()
        stream_params.set_init_osc_speed(value)
        self._updater.signal_update(self._get_update_signal_type())

    def _set_osc_depth(self, value):
        stream_params = self._get_stream_params()
        stream_params.set_init_osc_depth(value)
        self._updater.signal_update(self._get_update_signal_type())
示例#8
0
class GeneralEditor(QWidget, Updater):

    def __init__(self):
        super().__init__()
        self._name = QLineEdit()

        self._length = VarPrecSpinBox(step_decimals=0, max_decimals=5)
        self._length.setMinimum(1)
        self._length.setMaximum(32)

        self._spacing_style = LineStyle(is_major_enabled=True)
        self._spacing_value = VarPrecSpinBox(step_decimals=1, max_decimals=2)
        self._spacing_value.setMinimum(0.01)
        self._spacing_value.setMaximum(1.0)

        self._offset = VarPrecSpinBox(step_decimals=1, max_decimals=5)
        self._offset.setMinimum(0)
        self._offset.setMaximum(32)

        nl = QHBoxLayout()
        nl.setContentsMargins(0, 0, 0, 0)
        nl.setSpacing(2)
        nl.addWidget(QLabel('Name:'), 0)
        nl.addWidget(self._name, 1)

        ll = QHBoxLayout()
        ll.setContentsMargins(0, 0, 0, 0)
        ll.setSpacing(2)
        ll.addWidget(QLabel('Grid length:'), 0)
        ll.addWidget(self._length, 1)

        sl = QHBoxLayout()
        sl.setContentsMargins(0, 0, 0, 0)
        sl.setSpacing(2)
        sl.addWidget(QLabel('Show lines'), 0)
        sl.addWidget(self._spacing_style, 3)
        sl.addWidget(QLabel('when spacing is ≥:'), 0)
        sl.addWidget(self._spacing_value, 1)

        ol = QHBoxLayout()
        ol.setContentsMargins(0, 0, 0, 0)
        ol.setSpacing(2)
        ol.addWidget(QLabel('Grid offset:'), 0)
        ol.addWidget(self._offset, 1)

        v = QVBoxLayout()
        v.setContentsMargins(0, 0, 0, 0)
        v.setSpacing(2)
        v.addLayout(nl)
        v.addLayout(ll)
        v.addLayout(sl)
        v.addLayout(ol)
        self.setLayout(v)

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

        self._update_config()

        self._name.textEdited.connect(self._change_name)
        self._length.valueChanged.connect(self._change_length)
        self._spacing_style.currentIndexChanged.connect(self._select_spacing_style)
        self._spacing_value.valueChanged.connect(self._change_spacing)

        self._offset.valueChanged.connect(self._change_offset)

        self._update_all()

    def _update_style(self):
        self._update_config()
        style_mgr = self._ui_model.get_style_manager()
        for vps in (self._length, self._spacing_value, self._offset):
            vps.update_style(style_mgr)
        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)

        layout = self.layout()
        spacing = style_mgr.get_scaled_size_param('small_padding')
        for i in range(layout.count()):
            sub_layout = layout.itemAt(i).layout()
            if sub_layout:
                sub_layout.setSpacing(spacing)

        self._spacing_style.set_config(config, style_mgr)

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

        gp = grid_mgr.get_grid_pattern(gp_id)
        return gp

    def _update_all(self):
        gp = self._get_selected_grid_pattern()
        self.setEnabled(gp != None)
        if gp == None:
            return

        gp_name = gp.get_name()
        if gp_name != str(self._name.text()):
            old_block = self._name.blockSignals(True)
            self._name.setText(gp_name)
            self._name.blockSignals(old_block)

        gp_length = gp.get_length()
        gp_length_f = float(gp_length)

        if gp_length_f != self._length.value():
            old_block = self._length.blockSignals(True)
            self._length.setValue(gp_length_f)
            self._length.blockSignals(old_block)

        spacing_value = gp.get_line_style_spacing(
                self._spacing_style.get_current_line_style())

        if spacing_value != self._spacing_value.value():
            old_block = self._spacing_value.blockSignals(True)
            self._spacing_value.setValue(spacing_value)
            self._spacing_value.blockSignals(old_block)

        gp_offset = gp.get_offset()
        gp_offset_f = float(gp_offset)

        if gp_offset_f != self._offset.value():
            old_block = self._offset.blockSignals(True)
            self._offset.setValue(gp_offset_f)
            self._offset.blockSignals(old_block)

    def _change_name(self, text):
        text = str(text)

        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        gp.set_name(text)
        self._updater.signal_update(
            'signal_grid_pattern_modified', 'signal_grid_pattern_list')

    def _change_length(self, new_length):
        new_length_ts = tstamp.Tstamp(new_length)

        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        gp.set_length(new_length_ts)
        self._updater.signal_update('signal_grid_pattern_modified')

    def _select_spacing_style(self, new_style):
        self._spacing_style.select_line_style(new_style)
        self._update_all()

    def _change_spacing(self, new_spacing):
        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        line_style = self._spacing_style.get_current_line_style()
        gp.set_line_style_spacing(line_style, new_spacing)
        self._updater.signal_update('signal_grid_pattern_modified')

    def _change_offset(self, new_offset):
        new_offset_ts = tstamp.Tstamp(new_offset)

        gp = self._get_selected_grid_pattern()
        if gp == None:
            return

        gp.set_offset(new_offset_ts)
        self._updater.signal_update('signal_grid_pattern_modified')