Exemple #1
0
    def __init__(self):
        self._project_name = None
        self._project = None
        self._history_manager = None
        self._quit = False

        self._constants = Constants()

        self._root_stack_widget = widget.StackWidget()
        widget_manager.get().set_root_widget(self._root_stack_widget)

        self._root_background = widget.BackgroundWidget()
        self._root_stack_widget.push_child(self._root_background)
        self._root_background.color.value = constants.Ui.PANEL_COLOR

        self._root_layout = widget.HStackedLayoutWidget()
        self._root_background.set_child(self._root_layout)

        self._file_menu_widget = self._build_file_menu_widget()

        # Holds all project-related widgets so we can easily clear the whole list
        self._project_widgets = None
        self._library = None
        self._timeline = None

        # Playback-related fields
        self._is_playing = False
        self._playback_updater = None

        # This will set up the appropriate "no project loaded" layout
        self._close_project()

        self._update_controls_enabled(False)
Exemple #2
0
    def _close_project(self):
        if self._history_manager is not None:
            self._history_manager.destroy()
            self._history_manager = None

        if self._project is not None:
            self._project.engine_unload()

        self._project_name = None
        self._project = None

        self._root_layout.clear_children()
        if self._project_widgets is not None:
            self._project_widgets.root_layout.destroy()
            self._project_widgets = None

        self._library = None
        self._timeline = None

        self._root_layout.add_child(self._file_menu_widget)
        self._root_layout.add_padding(0.0, weight=1.0)

        self._root_background.layout_widget((0.0, 0.0),
                                            widget_manager.get().display_size,
                                            widget.HorizontalPlacement.FILL,
                                            widget.VerticalPlacement.FILL)

        self._update_controls_enabled()
Exemple #3
0
    def run(self):
        fps = 60
        dt = 1.0 / float(fps)
        clock = pygame.time.Clock()

        while not self._editor.should_quit():
            clock.tick(fps)

            parameter.update(dt)
            timer.update(dt)

            # Process events
            widget_manager.get().begin_process_events()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self._editor.request_quit()
                else:
                    widget_manager.get().process_event(event)

            self._editor.update(dt)

            drawing.drawing_begin(self._display_size[0], self._display_size[1])
            widget_manager.get().draw()
            drawing.drawing_end()

            pygame.display.flip()
Exemple #4
0
    def _load_project(self, project_name):
        pm = project_manager.get()
        new_project = project.Project()

        try:
            new_project.load(
                pm.get_project_directory(project_name) /
                project.PROJECT_FILENAME)
        except:
            modal_dialog.show_simple_modal_dialog(
                self._root_stack_widget, "Failed to load project",
                "An error was encountered trying to load the project '{}'.".
                format(project_name), ["OK"], None)
            return False

        if self._history_manager is not None:
            self._history_manager.destroy()
            self._history_manager = None
        self._history_manager = history_manager.HistoryManager(
            self._update_controls_enabled)

        if self._project is not None:
            self._project.engine_unload()

        self._project_name = project_name
        self._project = new_project
        self._project.engine_load()

        self._root_layout.clear_children()
        if self._project_widgets is not None:
            self._project_widgets.root_layout.destroy()
            self._project_widgets = None

        self._root_layout.add_child(self._file_menu_widget)

        self._project_widgets = self._build_project_widgets()
        self._root_layout.add_child(self._project_widgets.root_layout,
                                    weight=1.0)

        self._root_background.layout_widget((0.0, 0.0),
                                            widget_manager.get().display_size,
                                            widget.HorizontalPlacement.FILL,
                                            widget.VerticalPlacement.FILL)

        self._update_controls_enabled()
        return True
Exemple #5
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)
Exemple #6
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