Commit d8113b38 authored by yatinmaan's avatar yatinmaan

WIP: Add "Add Effect" button to Clip Tab

parent f1cbcebb
Pipeline #96398 failed with stage
in 17 minutes and 7 seconds
......@@ -225,6 +225,16 @@ class EffectProperties(Gtk.Expander, Loggable):
_("Select a clip on the timeline to configure its associated effects"))
self._infobar.show_all()
# Add effect popover button
self.add_effect_button = Gtk.Button(_("Add Effect"))
self.effect_search_entry = Gtk.SearchEntry()
self.effect_search_entry.connect("search-changed", self._search_entry_cb)
self.effect_listbox = Gtk.ListBox()
self.effect_listbox.connect("row-activated", self.effect_row_activate_cb)
self.effect_listbox.set_filter_func(self._search_filter)
self.effect_popover = self._create_effects_popover(self.effect_listbox, self.effect_search_entry)
self.effect_popover.set_relative_to(self.add_effect_button)
# Prepare the main container widgets and lay out everything
self._expander_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self._vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
......@@ -238,6 +248,7 @@ class EffectProperties(Gtk.Expander, Loggable):
self._vbox.show_all()
self._expander_box.pack_start(self.no_effect_infobar, expand=False, fill=False, padding=0)
self._expander_box.pack_start(self._vbox, expand=False, fill=False, padding=0)
self._expander_box.pack_end(self.add_effect_button, False, False, PADDING)
self._expander_box.show_all()
self.add(self._expander_box)
self.hide()
......@@ -255,6 +266,12 @@ class EffectProperties(Gtk.Expander, Loggable):
self.remove_effect_action.set_enabled(False)
remove_effect_button.set_action_name("clipproperties-effects.remove-effect")
self.open_effect_popover_action = Gio.SimpleAction.new("open-effect-popover", None)
self.open_effect_popover_action.connect("activate", self.popover_action_cb)
self.app.add_action(self.open_effect_popover_action)
self.app.shortcuts.add("app.open-effect-popover", ["<Primary>e"],
_("Open the Effects Popover"))
# Connect all the widget signals
self.treeview_selection.connect("changed", self._treeviewSelectionChangedCb)
self.connect("drag-motion", self._drag_motion_cb)
......@@ -267,6 +284,52 @@ class EffectProperties(Gtk.Expander, Loggable):
self.app.project_manager.connect_after(
"new-project-loaded", self._newProjectLoadedCb)
self.connect('notify::expanded', self._expandedCb)
self.add_effect_button.connect("clicked", self.add_effect_button_cb)
def _create_effects_popover(self, listbox, search_entry):
popover = Gtk.Popover()
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
scroll_window = Gtk.ScrolledWindow()
scroll_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scroll_window.props.max_content_height = 350
scroll_window.props.propagate_natural_height = True
self.app.gui.editor.effectlist.add_effects_to_listbox(listbox, only_text=True)
scroll_window.add(listbox)
vbox.pack_start(search_entry, False, False, 0)
vbox.pack_end(scroll_window, True, True, 0)
vbox.show_all()
popover.add(vbox)
return popover
def add_effect_button_cb(self, button):
self.effect_search_entry.set_text("")
self.effect_popover.popup()
def popover_action_cb(self, _unused1, _unused2):
if self.clip:
self.app.gui.editor.switchContextTab(self.clip)
self.add_effect_button_cb(self.add_effect_button)
def effect_row_activate_cb(self, listbox, row):
self.app.gui.editor.effectlist.apply_selected_effect(listbox, row)
self.effect_popover.hide()
def _search_filter(self, row):
effect_box = row.get_child().get_child()
label = effect_box.get_children()[0]
label_text = label.get_text().lower()
search_key = self.effect_search_entry.get_text().lower()
return search_key in label_text
def _search_entry_cb(self, search_entry):
self.effect_listbox.invalidate_filter()
def _newProjectLoadedCb(self, unused_app, project):
if self._selection is not None:
......
......@@ -393,7 +393,7 @@ class EffectListWidget(Gtk.Box, Loggable):
# Used for showing search results and favourites
self.search_view = Gtk.ListBox(activate_on_single_click=False)
self.search_view.connect("row-activated", self._apply_selected_effect)
self.search_view.connect("row-activated", self.apply_selected_effect)
placeholder_text = Gtk.Label(_("No effects"))
placeholder_text.props.visible = True
......@@ -420,7 +420,7 @@ class EffectListWidget(Gtk.Box, Loggable):
def _load_available_effects_cb(self):
self._set_up_category_view()
self._add_effects_to_listbox(self.search_view)
self.add_effects_to_listbox(self.search_view)
def _set_up_category_view(self):
"""Adds expanders and effects to the category view."""
......@@ -434,11 +434,11 @@ class EffectListWidget(Gtk.Box, Loggable):
listbox = expander.get_child()
category_name = expander.get_label()
self._add_effects_to_listbox(listbox, category_name)
self.add_effects_to_listbox(listbox, category_name)
self.category_view.show_all()
def _add_effects_to_listbox(self, listbox, category=None):
def add_effects_to_listbox(self, listbox, category=None, only_text=False):
"""Adds effect rows to the given listbox."""
effects = self.app.effects.video_effects + self.app.effects.audio_effects
for effect in effects:
......@@ -450,7 +450,7 @@ class EffectListWidget(Gtk.Box, Loggable):
effect_info = self.app.effects.getInfo(name)
if not category or category in effect_info.categories:
widget = self._create_effect_widget(name)
widget = self._create_effect_widget(name, only_text)
listbox.add(widget)
def _create_category_widget(self, category):
......@@ -458,13 +458,13 @@ class EffectListWidget(Gtk.Box, Loggable):
expander = Gtk.Expander(label=category, margin=SPACING)
listbox = Gtk.ListBox(activate_on_single_click=False)
listbox.connect("row-activated", self._apply_selected_effect)
listbox.connect("row-activated", self.apply_selected_effect)
expander.add(listbox)
return expander
def _create_effect_widget(self, effect_name):
def _create_effect_widget(self, effect_name, only_text):
"""Creates list box row for the given effect."""
effect_info = self.app.effects.getInfo(effect_name)
......@@ -472,22 +472,25 @@ class EffectListWidget(Gtk.Box, Loggable):
effect_box.effect_name = effect_name
effect_box.set_tooltip_text(effect_info.description)
label = Gtk.Label(effect_info.human_name, xalign=0)
icon = Gtk.Image.new_from_pixbuf(effect_info.icon)
# Set up favourite button
fav_button = Gtk.Button()
fav_button.props.relief = Gtk.ReliefStyle.NONE
fav_button.props.halign = Gtk.Align.CENTER
fav_button.props.valign = Gtk.Align.CENTER
fav_button.set_tooltip_text(_("Add to Favourites"))
if not only_text:
# Show effect thumbnail
icon = Gtk.Image.new_from_pixbuf(effect_info.icon)
effect_box.pack_start(icon, False, True, SPACING / 2)
starred = effect_name in self.app.settings.favourite_effects
self._set_fav_button_state(fav_button, starred)
fav_button.connect("clicked", self._fav_button_cb, effect_box.effect_name)
# Set up favourite button
fav_button = Gtk.Button()
fav_button.props.relief = Gtk.ReliefStyle.NONE
fav_button.props.halign = Gtk.Align.CENTER
fav_button.props.valign = Gtk.Align.CENTER
fav_button.set_tooltip_text(_("Add to Favourites"))
starred = effect_name in self.app.settings.favourite_effects
self._set_fav_button_state(fav_button, starred)
fav_button.connect("clicked", self._fav_button_cb, effect_box.effect_name)
effect_box.pack_end(fav_button, False, True, SPACING / 2)
effect_box.pack_start(icon, False, True, SPACING / 2)
effect_box.pack_start(label, True, True, 0)
effect_box.pack_end(fav_button, False, True, SPACING / 2)
# Set up drag behavoir
eventbox = Gtk.EventBox(visible_window=False)
......@@ -523,7 +526,7 @@ class EffectListWidget(Gtk.Box, Loggable):
Gtk.drag_set_icon_surface(context, surface)
def _apply_selected_effect(self, unused_listbox, row):
def apply_selected_effect(self, unused_listbox, row):
"""Adds the selected effect to the single selected clip, if any."""
effect_box = row.get_child().get_child()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment