Commit 154b2beb authored by yatinmaan's avatar yatinmaan

effects: Add Effect Popover and Shortcut

parent 4dd0a0b9
Pipeline #99169 failed with stage
in 13 minutes and 54 seconds
......@@ -28,6 +28,7 @@ from gi.repository import Gtk
from gi.repository import Pango
from pitivi.configure import get_ui_dir
from pitivi.effects import EffectsPopover
from pitivi.effects import EffectsPropertiesManager
from pitivi.effects import HIDDEN_EFFECTS
from pitivi.undo.timeline import CommitTimelineFinalizingAction
......@@ -225,6 +226,12 @@ 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.effect_popover = EffectsPopover(app)
self.add_effect_button = Gtk.MenuButton(_("Add Effect"))
self.add_effect_button.set_popover(self.effect_popover)
self.add_effect_button.props.halign = Gtk.Align.CENTER
# 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 +245,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()
......@@ -267,6 +275,12 @@ 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("toggled", self.add_effect_button_cb)
def add_effect_button_cb(self, button):
# MenuButton interacts directly with the popover, bypassing our subclassed method
if button.props.active:
self.effect_popover.search_entry.set_text("")
def _newProjectLoadedCb(self, unused_app, project):
if self._selection is not None:
......
......@@ -50,6 +50,7 @@ from pitivi.configure import get_ui_dir
from pitivi.settings import GlobalSettings
from pitivi.utils.loggable import Loggable
from pitivi.utils.ui import EFFECT_TARGET_ENTRY
from pitivi.utils.ui import PADDING
from pitivi.utils.ui import SPACING
from pitivi.utils.widgets import FractionWidget
from pitivi.utils.widgets import GstElementSettingsWidget
......@@ -393,7 +394,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 +421,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 +435,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 +451,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 +459,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 +473,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 +527,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()
......@@ -632,6 +636,60 @@ class EffectListWidget(Gtk.Box, Loggable):
child_view.hide()
class EffectsPopover(Gtk.Popover, Loggable):
"""Popover for adding effects."""
def __init__(self, app):
Gtk.Popover.__init__(self)
Loggable.__init__(self)
self.app = app
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, margin=PADDING)
self.search_entry = Gtk.SearchEntry()
self.search_entry.connect("search-changed", self._search_entry_cb)
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.listbox = Gtk.ListBox()
self.listbox.connect("row-activated", self._effect_row_activate_cb)
self.listbox.set_filter_func(self._search_filter)
placeholder_text = Gtk.Label(_("No effects"))
placeholder_text.props.visible = True
self.listbox.set_placeholder(placeholder_text)
self.app.gui.editor.effectlist.add_effects_to_listbox(self.listbox, only_text=True)
scroll_window.add(self.listbox)
vbox.pack_start(self.search_entry, False, False, 0)
vbox.pack_end(scroll_window, True, True, 0)
vbox.show_all()
self.add(vbox)
def _effect_row_activate_cb(self, listbox, row):
self.app.gui.editor.effectlist.apply_selected_effect(listbox, row)
self.hide()
def _search_entry_cb(self, search_entry):
self.listbox.invalidate_filter()
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.search_entry.get_text().lower()
return search_key in label_text
def popup(self):
self.search_entry.set_text("")
Gtk.Popover.popup(self)
PROPS_TO_IGNORE = ['name', 'qos', 'silent', 'message', 'parent']
......
......@@ -31,6 +31,7 @@ from pitivi.autoaligner import AutoAligner
from pitivi.configure import get_ui_dir
from pitivi.configure import in_devel
from pitivi.dialogs.prefs import PreferencesDialog
from pitivi.effects import EffectsPopover
from pitivi.settings import GlobalSettings
from pitivi.timeline.elements import Clip
from pitivi.timeline.elements import TransitionClip
......@@ -1557,6 +1558,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
left_size_group.add_widget(zoom_box)
self.timeline = Timeline(self.app, left_size_group)
self.effects_popover = EffectsPopover(self.app)
# Vertical Scrollbar. It will be displayed only when needed.
self.vscrollbar = Gtk.Scrollbar(orientation=Gtk.Orientation.VERTICAL,
......@@ -1666,6 +1668,12 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
self.app.shortcuts.add("timeline.add-layer", ["<Primary>n"],
_("Add layer"))
self.add_effect_action = Gio.SimpleAction.new("add-effect", None)
self.add_effect_action.connect("activate", self.__add_effect_cb)
group.add_action(self.add_effect_action)
self.app.shortcuts.add("timeline.add-effect", ["<Primary>e"],
_("Add an effect to the selected clip"))
if in_devel():
self.gapless_action = Gio.SimpleAction.new("toggle-gapless-mode", None)
self.gapless_action.connect("activate", self._gaplessmode_toggled_cb)
......@@ -1890,6 +1898,12 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
priority = len(self.ges_timeline.get_layers())
self.timeline.create_layer(priority)
def __add_effect_cb(self, unused_action, unused_parameter):
clip = self.timeline.selection.getSingleClip()
if clip:
self.effects_popover.set_relative_to(clip.ui)
self.effects_popover.popup()
def _alignSelectedCb(self, unused_action, unused_parameter):
if not self.ges_timeline:
return
......
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