예제 #1
0
    def __init__(self, stack_widget, on_name_chosen_func):
        self._stack_widget = stack_widget
        self._on_name_chosen_func = on_name_chosen_func

        layout = widget.VStackedLayoutWidget()

        title = widget.TextWidget()
        title.text = "Save project as"
        title.size.value = points(20.0)
        title.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        title.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        layout.add_child(title)

        layout.add_padding(points(12.0))

        options_layout = widget.HStackedLayoutWidget()
        layout.add_child(options_layout)

        name_title = widget.TextWidget()
        options_layout.add_child(name_title, horizontal_placement = widget.HorizontalPlacement.RIGHT)
        name_title.text = "Name:"
        name_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        name_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        options_layout.add_padding(points(4.0))

        self._name = widget.InputWidget()
        options_layout.add_child(self._name)

        layout.add_padding(points(12.0))

        buttons_layout = widget.HStackedLayoutWidget()
        layout.add_child(buttons_layout)
        buttons_layout.add_padding(0.0, weight = 1.0)

        cancel_button = widget.TextButtonWidget()
        buttons_layout.add_child(cancel_button)
        cancel_button.text = "Cancel"
        cancel_button.action_func = self._cancel

        buttons_layout.add_padding(points(4.0))

        save_button = widget.TextButtonWidget()
        buttons_layout.add_child(save_button)
        save_button.text = "Save"
        save_button.action_func = self._save

        self._destroy_func = modal_dialog.show_modal_dialog(stack_widget, layout)
예제 #2
0
    def __init__(self, root_stack_widget, project, history_manager,
                 update_tracks_func):
        self._root_stack_widget = root_stack_widget
        self._project = project
        self._history_manager = history_manager
        self._update_tracks_func = update_tracks_func

        self._selected_clip_id = None

        self._padding = points(4.0)

        self._root_layout = widget.GridLayoutWidget()
        self._root_layout.set_row_weight(0, 1.0)
        self._root_layout.set_column_weight(0, 1.0)

        h_scrollbar = widget.HScrollbarWidget()
        self._root_layout.add_child(1, 0, h_scrollbar)

        v_scrollbar = widget.VScrollbarWidget()
        self._root_layout.add_child(0, 1, v_scrollbar)

        vertical_scroll_area = widget.ScrollAreaWidget()
        self._root_layout.add_child(0, 0, vertical_scroll_area)
        vertical_scroll_area.vertical_scrollbar = v_scrollbar

        vertical_scroll_area_layout = widget.HStackedLayoutWidget()
        vertical_scroll_area.set_child(vertical_scroll_area_layout)

        self._categories_layout = widget.VStackedLayoutWidget()
        vertical_scroll_area_layout.add_child(self._categories_layout)

        horizontal_scroll_area = widget.ScrollAreaWidget()
        vertical_scroll_area_layout.add_child(horizontal_scroll_area,
                                              weight=1.0)
        horizontal_scroll_area.horizontal_scrollbar = h_scrollbar

        self._clips_layout = widget.GridLayoutWidget()
        horizontal_scroll_area.set_child(self._clips_layout)

        self._category_widgets = {}  # Maps ClipCategory -> CategoryWidget
        self._add_category_widget = AddWidget(
            self._add_category)  # AddWidget at the end of categories
        self._clip_widgets = {}  # Maps Clip -> ClipWidget
        self._add_clip_widgets = {}  # Maps ClipCategory -> AddWidget

        self._layout_widgets(False)
예제 #3
0
    def _build_edit_menu_widget(self, project_widgets):
        background = widget.BackgroundWidget()
        background.color.value = constants.Ui.MENU_COLOR
        background.border_thickness.value = points(2.0)
        background.border_color.value = constants.darken_color(
            constants.Ui.MENU_COLOR, 0.5)

        layout = widget.VStackedLayoutWidget()
        background.set_child(layout)
        layout.margin = self._constants.MENU_PADDING

        project_widgets.play_pause_button = widget.IconButtonWidget()
        layout.add_child(project_widgets.play_pause_button)
        project_widgets.play_pause_button.icon_name = "play"
        project_widgets.play_pause_button.action_func = self._play_pause

        layout.add_padding(self._constants.MENU_PADDING)

        project_widgets.stop_button = widget.IconButtonWidget()
        layout.add_child(project_widgets.stop_button)
        project_widgets.stop_button.icon_name = "stop"
        project_widgets.stop_button.action_func = self._stop

        layout.add_padding(self._constants.MENU_PADDING)

        project_widgets.metronome_button = widget.IconButtonWidget()
        layout.add_child(project_widgets.metronome_button)
        project_widgets.metronome_button.icon_name = self._get_metronome_icon()
        project_widgets.metronome_button.action_func = self._toggle_metronome

        layout.add_padding(0.0, weight=1.0)

        project_widgets.undo_button = widget.IconButtonWidget()
        layout.add_child(project_widgets.undo_button)
        project_widgets.undo_button.icon_name = "undo"
        project_widgets.undo_button.action_func = self._undo

        layout.add_padding(self._constants.MENU_PADDING)

        project_widgets.redo_button = widget.IconButtonWidget()
        layout.add_child(project_widgets.redo_button)
        project_widgets.redo_button.icon_name = "redo"
        project_widgets.redo_button.action_func = self._redo

        return background
예제 #4
0
def show_simple_modal_dialog(stack_widget, title, text, buttons,
                             on_closed_func):
    layout = widget.VStackedLayoutWidget()

    title_widget = widget.TextWidget()
    layout.add_child(title_widget)
    title_widget.text = title
    title_widget.size.value = points(20.0)
    title_widget.horizontal_alignment = drawing.HorizontalAlignment.CENTER
    title_widget.vertical_alignment = drawing.VerticalAlignment.MIDDLE

    layout.add_padding(points(12.0))

    text_widget = widget.TextWidget()
    layout.add_child(text_widget)
    text_widget.text = text
    text_widget.horizontal_alignment = drawing.HorizontalAlignment.CENTER
    text_widget.vertical_alignment = drawing.VerticalAlignment.MIDDLE

    layout.add_padding(points(12.0))

    buttons_layout = widget.HStackedLayoutWidget()
    layout.add_child(buttons_layout)
    buttons_layout.add_padding(0.0, weight=1.0)

    class Context:
        def __init__(self):
            self.destroy_func = None

        def button_pressed(self, i):
            self.destroy_func()
            if on_closed_func is not None:
                on_closed_func(i)

    context = Context()
    for i, button_text in enumerate(buttons):
        button_widget = widget.TextButtonWidget()
        if i > 0:
            buttons_layout.add_padding(points(4.0))
        buttons_layout.add_child(button_widget)
        button_widget.text = button_text
        button_widget.action_func = lambda i=i: context.button_pressed(i)

    context.destroy_func = show_modal_dialog(stack_widget, layout)
예제 #5
0
    def _build_project_widgets(self):
        class ProjectWidgets:
            pass

        project_widgets = ProjectWidgets()

        project_widgets.root_layout = widget.HStackedLayoutWidget()

        timeline_library_layout = widget.VStackedLayoutWidget()
        project_widgets.root_layout.add_child(timeline_library_layout,
                                              weight=1.0)

        self._timeline = timeline.Timeline(
            self._root_stack_widget, self._project, self._history_manager,
            lambda: self._library.selected_clip_id,
            self._on_time_bar_sample_changed)
        timeline_library_layout.add_child(self._timeline.root_layout,
                                          weight=1.0)

        timeline_library_divider = widget.RectangleWidget()
        timeline_library_layout.add_child(timeline_library_divider)
        timeline_library_divider.desired_height = self._constants.DIVIDER_SIZE
        timeline_library_divider.color.value = constants.Ui.MENU_COLOR
        timeline_library_divider.border_thickness.value = points(2.0)
        timeline_library_divider.border_color.value = constants.darken_color(
            constants.Ui.MENU_COLOR, 0.5)
        timeline_library_divider.left_open = True
        timeline_library_divider.right_open = True

        self._library = library.Library(self._root_stack_widget, self._project,
                                        self._history_manager,
                                        lambda: self._timeline.update_tracks())
        timeline_library_layout.add_child(self._library.root_layout,
                                          weight=1.0)

        edit_menu_widget = self._build_edit_menu_widget(project_widgets)
        project_widgets.root_layout.add_child(edit_menu_widget)

        self._last_clicked_sample_index = None

        return project_widgets
예제 #6
0
    def __init__(self, stack_widget, on_project_selected_func):
        self._stack_widget = stack_widget
        self._on_project_selected_func = on_project_selected_func

        layout = widget.VStackedLayoutWidget()

        title = widget.TextWidget()
        title.text = "Load project"
        title.size.value = points(20.0)
        title.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        title.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        layout.add_child(title)

        layout.add_padding(points(12.0))

        # $TODO replace this with a list widget (which does not currently exist!)
        self._name = widget.InputWidget()
        layout.add_child(self._name)

        layout.add_padding(points(12.0))

        buttons_layout = widget.HStackedLayoutWidget()
        layout.add_child(buttons_layout)
        buttons_layout.add_padding(0.0, weight=1.0)

        cancel_button = widget.TextButtonWidget()
        buttons_layout.add_child(cancel_button)
        cancel_button.text = "Cancel"
        cancel_button.action_func = self._cancel

        buttons_layout.add_padding(points(4.0))

        load_button = widget.TextButtonWidget()
        buttons_layout.add_child(load_button)
        load_button.text = "Load"
        load_button.action_func = self._load

        self._destroy_func = modal_dialog.show_modal_dialog(
            stack_widget, layout)
예제 #7
0
    def __init__(self, display_size):
        self._display_size = display_size

        root_h = widget.HStackedLayoutWidget()
        root_v = widget.VStackedLayoutWidget()
        scroll_area = widget.ScrollAreaWidget()
        scrollbar_h = widget.HScrollbarWidget()
        scrollbar_v_layout = widget.VStackedLayoutWidget()
        scrollbar_v = widget.VScrollbarWidget()
        scroll_area.horizontal_scrollbar = scrollbar_h
        scroll_area.vertical_scrollbar = scrollbar_v

        root_h.add_child(root_v, weight=1.0)
        root_h.add_child(scrollbar_v_layout)
        scrollbar_v_layout.add_child(scrollbar_v, weight=1.0)
        scrollbar_v_layout.add_padding(scrollbar_h.desired_height)
        root_v.add_child(scroll_area, weight=1.0)
        root_v.add_child(scrollbar_h)

        root_inner_background = widget.BackgroundWidget()
        root_inner_background.color.value = (0.25, 0.25, 0.5, 1.0)
        scroll_area.set_child(root_inner_background)

        root = widget.HStackedLayoutWidget()
        root.desired_width = display_size[0] * 1.5
        root.desired_height = display_size[1] * 2.0
        root.margin = inches(0.25)
        root_inner_background.set_child(root)

        a = widget.RectangleWidget()
        a.color.value = (1.0, 0.0, 0.0, 1.0)
        a.border_thickness.value = points(4)
        a.border_color.value = (1, 1, 1, 1)
        a.radius.value = inches(0.25)

        a.radius.transition().target(
            inches(1.25)).delay(2.0).duration(1.0).ease_in_ease_out()

        b = widget.VStackedLayoutWidget()

        c1 = widget.TextButtonWidget()
        c1.text = "Button"

        def show_dialog():
            layout = widget.HStackedLayoutWidget()
            btn = widget.IconButtonWidget()
            btn.icon_name = "metronome"
            layout.add_child(btn)
            btn.action_func = modal_dialog.show_modal_dialog(
                self._stack_widget, layout)

        c1.action_func = show_dialog

        c2 = widget.IconButtonWidget()
        c2.icon_name = "metronome"
        c2.action_func = lambda: print("Button!")

        c3 = widget.DropdownWidget()
        c3.set_options([(1, "Test option"),
                        (2, "A very long option that's cut off"),
                        (3, "Something else")])

        c4 = widget.SpinnerWidget()

        c5 = widget.InputWidget()

        d = widget.RectangleWidget()
        d.color.value = (0.0, 0.0, 1.0, 1.0)

        root.add_child(a, weight=1.0)
        root.add_padding(inches(0.25))
        root.add_child(b, weight=2.0)
        b.add_child(c1,
                    weight=0.0,
                    horizontal_placement=widget.HorizontalPlacement.CENTER,
                    vertical_placement=widget.VerticalPlacement.MIDDLE)
        b.add_child(c2,
                    weight=0.0,
                    horizontal_placement=widget.HorizontalPlacement.CENTER,
                    vertical_placement=widget.VerticalPlacement.MIDDLE)
        b.add_child(c3,
                    weight=0.0,
                    horizontal_placement=widget.HorizontalPlacement.CENTER,
                    vertical_placement=widget.VerticalPlacement.MIDDLE)
        b.add_padding(points(20.0))
        b.add_child(c4,
                    weight=0.0,
                    horizontal_placement=widget.HorizontalPlacement.CENTER,
                    vertical_placement=widget.VerticalPlacement.MIDDLE)
        b.add_padding(inches(0.25))
        b.add_child(c5,
                    weight=0.0,
                    horizontal_placement=widget.HorizontalPlacement.CENTER,
                    vertical_placement=widget.VerticalPlacement.MIDDLE)
        b.add_padding(inches(0.25))
        b.add_child(d, weight=2.0)

        root_h.layout_widget((0.0, 0.0), display_size,
                             widget.HorizontalPlacement.FILL,
                             widget.VerticalPlacement.FILL)

        self._stack_widget = widget.StackWidget()
        self._stack_widget.push_child(root_h)
        widget_manager.get().set_root_widget(self._stack_widget)
예제 #8
0
    def __init__(self, stack_widget):
        self._stack_widget = stack_widget

        layout = widget.VStackedLayoutWidget()

        title = widget.TextWidget()
        title.text = "Settings"
        title.size.value = points(20.0)
        title.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        title.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        layout.add_child(title)

        layout.add_padding(points(12.0))

        options_layout = widget.GridLayoutWidget()
        layout.add_child(options_layout)

        options_layout.set_column_size(1, points(4.0))

        input_device_title = widget.TextWidget()
        options_layout.add_child(
            0,
            0,
            input_device_title,
            horizontal_placement=widget.HorizontalPlacement.RIGHT)
        input_device_title.text = "Input device:"
        input_device_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        input_device_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        input_device_count = engine.get_input_device_count()
        self._input_device = widget.DropdownWidget()
        options_layout.add_child(0, 2, self._input_device)
        self._input_device.set_options([(i, engine.get_input_device_name(i))
                                        for i in range(input_device_count)])
        self._input_device.selected_option_index = settings.get(
        ).input_device_index

        options_layout.set_row_size(1, points(12.0))

        output_device_title = widget.TextWidget()
        options_layout.add_child(
            2,
            0,
            output_device_title,
            horizontal_placement=widget.HorizontalPlacement.RIGHT)
        output_device_title.text = "Output device:"
        output_device_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        output_device_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        output_device_count = engine.get_output_device_count()
        self._output_device = widget.DropdownWidget()
        options_layout.add_child(2, 2, self._output_device)
        self._output_device.set_options([(i, engine.get_output_device_name(i))
                                         for i in range(output_device_count)])
        self._output_device.selected_option_index = settings.get(
        ).output_device_index

        layout.add_padding(points(12.0))

        buttons_layout = widget.HStackedLayoutWidget()
        layout.add_child(buttons_layout)
        buttons_layout.add_padding(0.0, weight=1.0)

        cancel_button = widget.TextButtonWidget()
        buttons_layout.add_child(cancel_button)
        cancel_button.text = "Cancel"
        cancel_button.action_func = self._cancel

        buttons_layout.add_padding(points(4.0))

        ok_button = widget.TextButtonWidget()
        buttons_layout.add_child(ok_button)
        ok_button.text = "OK"
        ok_button.action_func = self._accept

        self._destroy_func = modal_dialog.show_modal_dialog(
            stack_widget, layout)
예제 #9
0
    def __init__(self, stack_widget, on_project_created_func):
        self._stack_widget = stack_widget
        self._on_project_created_func = on_project_created_func

        layout = widget.VStackedLayoutWidget()

        title = widget.TextWidget()
        title.text = "New project"
        title.size.value = points(20.0)
        title.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        title.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        layout.add_child(title)

        layout.add_padding(points(12.0))

        options_layout = widget.GridLayoutWidget()
        layout.add_child(options_layout)

        options_layout.set_column_size(1, points(4.0))

        name_title = widget.TextWidget()
        options_layout.add_child(0, 0, name_title, horizontal_placement = widget.HorizontalPlacement.RIGHT)
        name_title.text = "Name:"
        name_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        name_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        self._name = widget.InputWidget()
        options_layout.add_child(0, 2, self._name)

        options_layout.set_row_size(1, points(12.0))

        sample_rate_title = widget.TextWidget()
        options_layout.add_child(2, 0, sample_rate_title, horizontal_placement = widget.HorizontalPlacement.RIGHT)
        sample_rate_title.text = "Sample rate:"
        sample_rate_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        sample_rate_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        self._sample_rate = widget.DropdownWidget()
        self._sample_rate.set_options(_SAMPLE_RATES)
        self._sample_rate.selected_option_index = 0
        options_layout.add_child(2, 2, self._sample_rate)

        options_layout.set_row_size(3, points(12.0))

        beats_per_minute_title = widget.TextWidget()
        options_layout.add_child(4, 0, beats_per_minute_title, horizontal_placement = widget.HorizontalPlacement.RIGHT)
        beats_per_minute_title.text = "Beats per minute:"
        beats_per_minute_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        beats_per_minute_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        self._beats_per_minute = widget.SpinnerWidget()
        self._beats_per_minute.min_value = 40.0
        self._beats_per_minute.max_value = 160.0
        self._beats_per_minute.value = 60.0
        self._beats_per_minute.decimals = 1
        options_layout.add_child(4, 2, self._beats_per_minute)

        options_layout.set_row_size(5, points(12.0))

        beats_per_measure_title = widget.TextWidget()
        options_layout.add_child(6, 0, beats_per_measure_title, horizontal_placement = widget.HorizontalPlacement.RIGHT)
        beats_per_measure_title.text = "Beats per measure:"
        beats_per_measure_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        beats_per_measure_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        self._beats_per_measure = widget.SpinnerWidget()
        self._beats_per_measure.min_value = 2.0
        self._beats_per_measure.max_value = 8.0
        self._beats_per_measure.value = 4.0
        self._beats_per_measure.decimals = 0
        options_layout.add_child(6, 2, self._beats_per_measure)

        layout.add_padding(points(12.0))

        buttons_layout = widget.HStackedLayoutWidget()
        layout.add_child(buttons_layout)
        buttons_layout.add_padding(0.0, weight = 1.0)

        cancel_button = widget.TextButtonWidget()
        buttons_layout.add_child(cancel_button)
        cancel_button.text = "Cancel"
        cancel_button.action_func = self._cancel

        buttons_layout.add_padding(points(4.0))

        create_button = widget.TextButtonWidget()
        buttons_layout.add_child(create_button)
        create_button.text = "Create"
        create_button.action_func = self._create

        self._destroy_func = modal_dialog.show_modal_dialog(stack_widget, layout)
예제 #10
0
    def __init__(self, stack_widget, category, on_accept_func, on_delete_func):
        self._stack_widget = stack_widget
        self._on_accept_func = on_accept_func
        self._on_delete_func = on_delete_func

        layout = widget.VStackedLayoutWidget()

        title = widget.TextWidget()
        if category is None:
            title.text = "Create category"
        else:
            title.text = "Edit category"
        title.size.value = points(20.0)
        title.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        title.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        layout.add_child(title)

        layout.add_padding(points(12.0))

        options_layout = widget.GridLayoutWidget()
        layout.add_child(options_layout)

        options_layout.set_column_size(1, points(4.0))

        name_title = widget.TextWidget()
        options_layout.add_child(
            0,
            0,
            name_title,
            horizontal_placement=widget.HorizontalPlacement.RIGHT)
        name_title.text = "Name:"
        name_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        name_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        name_gain_layout = widget.HStackedLayoutWidget()
        options_layout.add_child(0, 2, name_gain_layout)

        self._name = widget.InputWidget()
        name_gain_layout.add_child(self._name)
        if category is not None:
            self._name.text = category.name

        name_gain_layout.add_padding(points(4.0))

        self._gain_spinner = widget.SpinnerWidget()
        name_gain_layout.add_child(self._gain_spinner)
        self._gain_spinner.min_value = 0.0
        self._gain_spinner.max_value = 1.0
        self._gain_spinner.value = 1.0 if category is None else category.gain
        self._gain_spinner.decimals = 2

        options_layout.set_row_size(1, points(12.0))

        color_title = widget.TextWidget()
        options_layout.add_child(
            2,
            0,
            color_title,
            horizontal_placement=widget.HorizontalPlacement.RIGHT)
        color_title.text = "Color:"
        color_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        color_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        selected_color = category.color if category is not None else project.CATEGORY_COLORS[
            0]
        self._color_picker = ColorPickerWidget(4, project.CATEGORY_COLORS,
                                               selected_color)
        options_layout.add_child(2, 2, self._color_picker)

        layout.add_padding(points(12.0))

        buttons_layout = widget.HStackedLayoutWidget()
        layout.add_child(buttons_layout)

        if category is not None:
            delete_button = widget.IconButtonWidget()
            buttons_layout.add_child(delete_button)
            delete_button.icon_name = "delete"
            delete_button.action_func = self._delete

        buttons_layout.add_padding(points(4.0), weight=1.0)

        accept_button = widget.IconButtonWidget()
        buttons_layout.add_child(accept_button)
        accept_button.color = constants.Ui.ACCEPT_BUTTON_COLOR
        accept_button.icon_name = "accept"
        accept_button.action_func = self._accept

        buttons_layout.add_padding(points(4.0))

        reject_button = widget.IconButtonWidget()
        buttons_layout.add_child(reject_button)
        reject_button.color = constants.Ui.REJECT_BUTTON_COLOR
        reject_button.icon_name = "reject"
        reject_button.action_func = self._reject

        self._destroy_func = modal_dialog.show_modal_dialog(
            stack_widget, layout)
예제 #11
0
    def __init__(self, stack_widget, project, clip, on_accept_func,
                 on_delete_func):
        self._stack_widget = stack_widget
        self._project = project
        self._clip = clip
        self._on_accept_func = on_accept_func
        self._on_delete_func = on_delete_func

        layout = widget.VStackedLayoutWidget()

        title = widget.TextWidget()
        if clip is None:
            title.text = "Record clip"
        else:
            title.text = "Edit clip"
        title.size.value = points(20.0)
        title.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        title.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        layout.add_child(title)

        layout.add_padding(points(12.0))

        name_gain_layout = widget.HStackedLayoutWidget()
        layout.add_child(
            name_gain_layout,
            horizontal_placement=widget.HorizontalPlacement.CENTER)

        name_title = widget.TextWidget()
        name_gain_layout.add_child(
            name_title, horizontal_placement=widget.HorizontalPlacement.RIGHT)
        name_title.text = "Name:"
        name_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        name_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        name_gain_layout.add_padding(points(4.0))

        self._name = widget.InputWidget()
        name_gain_layout.add_child(self._name)
        if clip is not None:
            self._name.text = clip.name

        name_gain_layout.add_padding(points(4.0))

        self._gain_spinner = widget.SpinnerWidget()
        name_gain_layout.add_child(self._gain_spinner)
        self._gain_spinner.min_value = 0.0
        self._gain_spinner.max_value = 1.0
        self._gain_spinner.value = 1.0 if clip is None else clip.gain
        self._gain_spinner.decimals = 2

        layout.add_padding(points(12.0))

        self._time_bar = time_bar.TimeBarWidget()
        layout.add_child(
            self._time_bar,
            horizontal_placement=widget.HorizontalPlacement.CENTER)
        self._time_bar.desired_width = inches(
            8.0) - _get_waveform_border_thickness() * 2.0
        self._time_bar.desired_height = points(20.0)
        self._time_bar.on_sample_changed_func = self._on_time_bar_sample_changed

        layout.add_padding(points(4.0))

        self._waveform_viewer = WaveformWidget()
        layout.add_child(self._waveform_viewer)
        self._waveform_viewer.desired_width = inches(8.0)
        self._waveform_viewer.desired_height = inches(2.0)
        if clip is None:
            self._waveform_viewer.set_waveform_samples([0.0])
            self._waveform_viewer.sample_count = 0
            self._waveform_viewer.enabled = False
        else:
            self._waveform_viewer.set_waveform_samples(
                engine.get_clip_samples(clip.engine_clip,
                                        _MAX_WAVEFORM_SAMPLES))
            self._waveform_viewer.sample_count = clip.sample_count
            self._waveform_viewer.start_sample_index = clip.start_sample_index
            self._waveform_viewer.end_sample_index = clip.end_sample_index

        layout.add_padding(points(12.0))

        measures_layout = widget.HStackedLayoutWidget()
        layout.add_child(measures_layout)

        self._intro_checkbox = widget.CheckboxWidget()
        measures_layout.add_child(
            self._intro_checkbox,
            vertical_placement=widget.VerticalPlacement.MIDDLE)
        self._intro_checkbox.set_checked(
            True if self._clip is None else self._clip.has_intro, False)
        self._intro_checkbox.action_func = self._update_measures_text

        measures_layout.add_padding(points(4.0))

        intro_text = widget.TextWidget()
        measures_layout.add_child(
            intro_text,
            horizontal_placement=widget.HorizontalPlacement.LEFT,
            vertical_placement=widget.VerticalPlacement.MIDDLE)
        intro_text.text = "Intro measure"
        intro_text.horizontal_alignment = drawing.HorizontalAlignment.LEFT
        intro_text.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        self._measures_text = widget.TextWidget()
        measures_layout.add_child(
            self._measures_text,
            weight=1.0,
            vertical_placement=widget.VerticalPlacement.MIDDLE)
        self._measures_text.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        self._measures_text.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        outro_text = widget.TextWidget()
        measures_layout.add_child(
            outro_text,
            horizontal_placement=widget.HorizontalPlacement.RIGHT,
            vertical_placement=widget.VerticalPlacement.MIDDLE)
        outro_text.text = "Outro measure"
        outro_text.horizontal_alignment = drawing.HorizontalAlignment.RIGHT
        outro_text.vertical_alignment = drawing.VerticalAlignment.MIDDLE

        measures_layout.add_padding(points(4.0))

        self._outro_checkbox = widget.CheckboxWidget()
        measures_layout.add_child(
            self._outro_checkbox,
            vertical_placement=widget.VerticalPlacement.MIDDLE)
        self._outro_checkbox.set_checked(
            True if self._clip is None else self._clip.has_outro, False)
        self._outro_checkbox.action_func = self._update_measures_text

        layout.add_padding(points(12.0))

        buttons_layout = widget.HStackedLayoutWidget()
        layout.add_child(buttons_layout)

        self._record_button = widget.IconButtonWidget()
        buttons_layout.add_child(self._record_button)
        self._record_button.color = (0.75, 0.0, 0.0, 1.0)
        self._record_button.icon_name = "record"
        self._record_button.action_func = self._record

        buttons_layout.add_padding(points(4.0))

        self._play_pause_button = widget.IconButtonWidget()
        buttons_layout.add_child(self._play_pause_button)
        self._play_pause_button.icon_name = "play"
        self._play_pause_button.action_func = self._play_pause
        self._play_pause_button.set_enabled(clip is not None, False)

        buttons_layout.add_padding(points(4.0))

        self._stop_button = widget.IconButtonWidget()
        buttons_layout.add_child(self._stop_button)
        self._stop_button.icon_name = "stop"
        self._stop_button.action_func = self._stop
        self._stop_button.set_enabled(clip is not None, False)

        buttons_layout.add_padding(points(4.0))

        self._metronome_button = widget.IconButtonWidget()
        buttons_layout.add_child(self._metronome_button)
        self._metronome_button.icon_name = self._get_metronome_icon()
        self._metronome_button.action_func = self._toggle_metronome

        if clip is not None:
            buttons_layout.add_padding(points(4.0))

            self._delete_button = widget.IconButtonWidget()
            buttons_layout.add_child(self._delete_button)
            self._delete_button.icon_name = "delete"
            self._delete_button.action_func = self._delete

        buttons_layout.add_padding(points(4.0), weight=1.0)

        self._accept_button = widget.IconButtonWidget()
        buttons_layout.add_child(self._accept_button)
        self._accept_button.color = constants.Ui.ACCEPT_BUTTON_COLOR
        self._accept_button.icon_name = "accept"
        self._accept_button.action_func = self._accept

        buttons_layout.add_padding(points(4.0))

        self._reject_button = widget.IconButtonWidget()
        buttons_layout.add_child(self._reject_button)
        self._reject_button.color = constants.Ui.REJECT_BUTTON_COLOR
        self._reject_button.icon_name = "reject"
        self._reject_button.action_func = self._reject

        self._engine_clip = None
        self._is_recording = False
        self._recording_updater = None
        self._is_playing = False
        self._playback_updater = None
        self._last_clicked_sample_index = None

        self._update_time_bar()
        self._update_measures_text()

        self._destroy_func = modal_dialog.show_modal_dialog(
            stack_widget, layout)
예제 #12
0
def show_modal_dialog(stack_widget, layout_widget):
    global _active_modal_count
    global _background_widget

    widget_manager.get().release_focused_widget(None)

    # Only create the background for the first modal, otherwise things would darken multiple times
    create_background = _background_widget is None
    _active_modal_count += 1

    if _background_widget is None:
        _background_widget = widget.RectangleWidget()
        _background_widget.width.value, _background_widget.height.value = widget_manager.get(
        ).display_size
        _background_widget.color.value = (0.0, 0.0, 0.0, 0.0)

    dialog_background = widget.BackgroundWidget()
    dialog_background.color.value = constants.Ui.DIALOG_COLOR
    dialog_background.border_thickness.value = points(4.0)
    dialog_background.border_color.value = constants.darken_color(
        constants.Ui.DIALOG_COLOR, 0.5)
    dialog_background.radius.value = inches(0.125)

    outer_layout = widget.HStackedLayoutWidget()
    outer_layout.margin = inches(0.25)

    outer_layout_b = widget.VStackedLayoutWidget()

    dialog_background.set_child(outer_layout)
    outer_layout.add_child(outer_layout_b)
    outer_layout_b.add_child(layout_widget)

    dialog_background.layout_widget((0.0, 0.0),
                                    widget_manager.get().display_size,
                                    widget.HorizontalPlacement.CENTER,
                                    widget.VerticalPlacement.MIDDLE)

    ui_blocker = widget.AbsoluteLayoutWidget()

    dialog_height = dialog_background.height.value
    dialog_end_y = dialog_background.y.value
    dialog_start_y = dialog_end_y - (widget_manager.get().display_size[1] +
                                     dialog_height) * 0.5
    if SNAP_TO_PIXELS:
        dialog_start_y = float(round(dialog_start_y))

    if create_background:
        stack_widget.push_child(_background_widget)
    stack_widget.push_child(dialog_background)
    stack_widget.push_child(ui_blocker)

    transition_time = 0.25
    _background_widget.color.transition().target(
        (0.0, 0.0, 0.0, 0.5)).duration(transition_time).ease_out()
    dialog_background.y.value = dialog_start_y
    dialog_background.y.transition().target(dialog_end_y).duration(
        transition_time).ease_out()

    def clear_ui_blocker():
        stack_widget.remove_child(ui_blocker)
        # Don't destroy the UI blocker yet - it will be reused

    transition_timer = timer.Timer(clear_ui_blocker, transition_time)

    def destroy_dialog():
        global _active_modal_count
        assert not transition_timer.is_running()

        stack_widget.push_child(ui_blocker)

        # If this is the last active modal, fade the background out
        if _active_modal_count == 1:
            _background_widget.color.transition().target(
                (0.0, 0.0, 0.0, 0.0)).duration(transition_time).ease_in()
        dialog_background.y.transition().target(dialog_start_y).duration(
            transition_time).ease_in()

        _active_modal_count -= 1
        assert _active_modal_count >= 0

        def clear_widgets():
            global _background_widget

            # Remove the background if no new modal has been created since we started the transition
            if _active_modal_count == 0:
                stack_widget.remove_child(_background_widget)
                _background_widget.destroy()
                _background_widget = None

            stack_widget.remove_child(dialog_background)
            stack_widget.remove_child(ui_blocker)
            dialog_background.destroy()
            ui_blocker.destroy()

        timer.Timer(clear_widgets, transition_time)

    return destroy_dialog
예제 #13
0
    def __init__(self, root_stack_widget, project, history_manager,
                 get_selected_clip_id_func, on_time_bar_sample_changed_func):
        self._root_stack_widget = root_stack_widget
        self._project = project
        self._history_manager = history_manager
        self._get_selected_clip_id_func = get_selected_clip_id_func

        self._padding = _get_measure_padding()

        self._root_layout = widget.GridLayoutWidget()
        self._root_layout.set_row_weight(1, 1.0)
        self._root_layout.set_column_weight(0, 1.0)

        time_bar_layout = widget.HStackedLayoutWidget()
        self._root_layout.add_child(0, 0, time_bar_layout)

        # The measure layout has a total extra size of padding, therefore pad by padding/2 on each side
        # Inset on left by (padding : track : padding : padding/2)
        # Inset on right by (padding/2)
        left_padding = _get_track_width() + self._padding * 2.5
        right_padding = self._padding * 0.5

        time_bar_layout.margin = (left_padding, points(4.0), right_padding,
                                  points(4.0))

        self._time_bar = time_bar.TimeBarWidget()
        time_bar_layout.add_child(self._time_bar, weight=1.0)
        self._time_bar.desired_height = points(20.0)
        self._time_bar.max_sample = 1.0
        self._time_bar.end_sample = 1.0
        self._time_bar.on_sample_changed_func = on_time_bar_sample_changed_func

        h_scrollbar = widget.HScrollbarWidget()
        self._root_layout.add_child(2, 0, h_scrollbar)

        v_scrollbar = widget.VScrollbarWidget()
        self._root_layout.add_child(1, 1, v_scrollbar)

        vertical_scroll_area = widget.ScrollAreaWidget()
        self._root_layout.add_child(1, 0, vertical_scroll_area)
        vertical_scroll_area.vertical_scrollbar = v_scrollbar

        vertical_scroll_area_layout = widget.HStackedLayoutWidget()
        vertical_scroll_area.set_child(vertical_scroll_area_layout)

        self._tracks_layout = widget.VStackedLayoutWidget()
        vertical_scroll_area_layout.add_child(self._tracks_layout)

        horizontal_scroll_area = widget.ScrollAreaWidget()
        vertical_scroll_area_layout.add_child(horizontal_scroll_area,
                                              weight=1.0)
        horizontal_scroll_area.horizontal_scrollbar = h_scrollbar

        self._measures_layout = widget.AbsoluteLayoutWidget(
        )  # Can't use a grid because measure can span, unfortunately
        horizontal_scroll_area.set_child(self._measures_layout)

        self._track_widgets = {}  # Maps Track -> TrackWidget
        self._add_track_widget = AddTrackWidget(
            self._add_track)  # AddTrackWidget at the end of tracks
        self._measure_widgets = {}  # Maps (Track, index) -> MeasureWidget

        # Update the time bar when we scroll
        self._time_bar.width.add_change_listener(
            lambda x: self._update_time_bar())
        self._measures_layout.x.add_change_listener(
            lambda x: self._update_time_bar())

        self._layout_widgets(False)