Ejemplo n.º 1
0
    def __init__(self, category, clip, is_selected, on_click_func,
                 on_double_click_func):
        super().__init__()
        self.category = category
        self.clip = clip
        self.on_click_func = on_click_func
        self.on_double_click_func = on_double_click_func
        self.enabled = True

        self.desired_width = inches(1.5)
        self.desired_height = inches(1.0)

        self.background = widget.RectangleWidget()
        self.background.desired_width = self.desired_width
        self.background.desired_height = self.desired_height
        self.background.color.value = constants.rgba255(*self.category.color)
        self.background.border_thickness.value = points(1.0)
        self.background.border_color.value = self.SELECTED_COLOR if is_selected else self.UNSELECTED_COLOR
        self.background.radius.value = points(4.0)
        self.add_child(self.background)

        self.name = widget.TextWidget()
        self.name.text = self.clip.name
        self.name.x.value = self.desired_width * 0.5
        self.name.y.value = self.desired_height * 0.5
        self.name.horizontal_alignment = drawing.HorizontalAlignment.CENTER
        self.name.vertical_alignment = drawing.VerticalAlignment.MIDDLE
        self.add_child(self.name)
Ejemplo n.º 2
0
 def draw_visible(self, parent_transform):
     transform = parent_transform * self.get_transform()
     with transform:
         drawing.draw_rectangle(0.0,
                                0.0,
                                self.width.value,
                                self.height.value,
                                constants.rgba255(*self.color255),
                                border_thickness=points(2.0),
                                border_color=self._border_color.value)
Ejemplo n.º 3
0
def _get_measure_color(category):
    return constants.rgba255(
        *category.color) if category is not None else (0.0, 0.0, 0.0, 0.0)
Ejemplo n.º 4
0
    def _layout_widgets(self, animate=True):
        self._categories_layout.clear_children()
        self._categories_layout.margin = (self._padding, 0.0, self._padding,
                                          0.0)  # Side padding

        self._clips_layout.clear_children()
        self._clips_layout.margin = (0.0, 0.0, self._padding, 0.0
                                     )  # Side padding

        # Remove old categories
        removed_categories = [
            x for x in self._category_widgets
            if x not in self._project.clip_categories
        ]
        for removed_category in removed_categories:
            self._category_widgets.pop(removed_category).destroy()
            self._add_clip_widgets.pop(removed_category).destroy()

        # Remove old clips
        removed_clips = [
            x for x in self._clip_widgets if x not in self._project.clips
        ]
        for removed_clip in removed_clips:
            self._clip_widgets.pop(removed_clip).destroy()

        # Backup current positions and colors for animation
        prev_layout_height = self._categories_layout.height.value
        prev_category_positions = dict(
            (c, (w.x.value, w.y.value))
            for c, w in self._category_widgets.items())
        prev_category_colors = dict(
            (c, w.color.value) for c, w in self._category_widgets.items())
        prev_add_category_position = (self._add_category_widget.x.value,
                                      self._add_category_widget.y.value)
        prev_clip_positions = dict(
            (c, (w.x.value, w.y.value)) for c, w in self._clip_widgets.items())
        prev_clip_colors = dict(
            (c, w.color.value) for c, w in self._clip_widgets.items())
        prev_add_clip_positions = dict(
            (c, (w.x.value, w.y.value))
            for c, w in self._add_clip_widgets.items())

        # Add new categories
        for category in self._project.clip_categories:
            if category not in self._category_widgets:
                self._category_widgets[category] = CategoryWidget(
                    category,
                    lambda category=category: self._edit_category(category))
            if category not in self._add_clip_widgets:
                self._add_clip_widgets[category] = AddWidget(
                    lambda category=category: self._add_clip(category))

            # Add new clips
            for clip_id in category.clip_ids:
                clip = self._project.get_clip_by_id(clip_id)
                if clip not in self._clip_widgets:
                    self._clip_widgets[clip] = ClipWidget(
                        category,
                        clip,
                        clip_id == self._selected_clip_id,
                        lambda clip_id=clip_id: self._select_clip(clip_id),
                        lambda clip=clip: self._edit_clip(clip))

        self._categories_layout.add_padding(self._padding)
        self._clips_layout.set_row_size(0, self._padding)
        self._clips_layout.set_column_size(0, self._padding)

        # Layout categories in order
        for y, category in enumerate(self._project.clip_categories):
            category_widget = self._category_widgets[category]
            category_widget.color.value = constants.rgba255(*category.color)
            category_widget.name.text = category.name
            self._categories_layout.add_child(category_widget)
            self._categories_layout.add_padding(self._padding)

            # Layout clips in order
            for x, clip_id in enumerate(category.clip_ids):
                clip = self._project.get_clip_by_id(clip_id)
                clip_widget = self._clip_widgets[clip]
                clip_widget.color.value = constants.rgba255(*category.color)
                clip_widget.name.text = clip.name
                self._clips_layout.add_child(y * 2 + 1, x * 2 + 1, clip_widget)
                self._clips_layout.set_column_size(x * 2 + 2, self._padding)

            self._clips_layout.add_child(y * 2 + 1,
                                         len(category.clip_ids) * 2 + 1,
                                         self._add_clip_widgets[category])
            self._clips_layout.set_column_size(
                len(category.clip_ids) * 2 + 2, self._padding)

            self._clips_layout.set_row_size(y * 2 + 2, self._padding)

        self._categories_layout.add_child(self._add_category_widget)
        self._categories_layout.add_padding(self._padding)

        # Do this so that the heights of the two layouts match
        self._clips_layout.set_row_size(
            len(self._project.clip_categories) * 2 + 1,
            self._add_category_widget.desired_height)
        self._clips_layout.set_row_size(
            len(self._project.clip_categories) * 2 + 2, self._padding)

        self._root_layout.layout_children()

        def animate_position(widget, old_position):
            new_x = widget.x.value
            new_y = widget.y.value
            widget.x.value = old_position[0]
            widget.x.transition().target(new_x).duration(0.125).ease_out()
            widget.y.value = old_position[1] + (
                self._categories_layout.height.value - prev_layout_height)
            widget.y.transition().target(new_y).duration(0.125).ease_out()

        def animate_color(widget, old_color):
            new_color = widget.color.value
            widget.color.value = old_color
            widget.color.transition().target(new_color).duration(
                0.125).ease_out()

        # Revert categories and clips to their original positions and colors and animate them
        for category, widget in self._category_widgets.items():
            old_position = prev_category_positions.get(category, None)
            if old_position is not None:
                animate_position(widget, old_position)
            old_color = prev_category_colors.get(category, None)
            if old_color is not None:
                animate_color(widget, old_color)
        animate_position(self._add_category_widget, prev_add_category_position)

        for clip, widget in self._clip_widgets.items():
            old_position = prev_clip_positions.get(clip, None)
            if old_position is not None:
                animate_position(widget, old_position)
            old_color = prev_clip_colors.get(clip, None)
            if old_color is not None:
                animate_color(widget, old_color)

        for category, widget in self._add_clip_widgets.items():
            old_position = prev_add_clip_positions.get(category, None)
            if old_position is not None:
                animate_position(widget, old_position)

        # Make sure selection color is up to date
        self._select_clip(self._selected_clip_id)