Commit 988cafaf authored by yatinmaan's avatar yatinmaan

effects: Add Favourites feature

parent ba93cb4f
Pipeline #92114 passed with stage
in 18 minutes and 38 seconds
<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="star" class="svg-inline--fa fa-star fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="white" d="M528.1 171.5L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6zM388.6 312.3l23.7 138.4L288 385.4l-124.3 65.3 23.7-138.4-100.6-98 139-20.2 62.2-126 62.2 126 139 20.2-100.6 98z"></path></svg>
<!--Derived work based on
Font Awesome Free 5.1.0 by @fontawesome - https://fontawesome.com
License - https://fontawesome.com/license (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
-->
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="star" class="svg-inline--fa fa-star fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="white" d="M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"></path></svg>
<!--Derived work based on
Font Awesome Free 5.1.0 by @fontawesome - https://fontawesome.com
License - https://fontawesome.com/license (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
-->
......@@ -12,7 +12,14 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
<object class="GtkToggleButton" id="favourites_toggle">
<property name="label" translatable="yes">Favourites</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
<signal name="toggled" handler="_favourites_toggle_cb" swapped="no"/>
</object>
</child>
</object>
<packing>
......
......@@ -158,6 +158,10 @@ HIDDEN_EFFECTS = [
"gdkpixbufoverlay"]
GlobalSettings.addConfigSection('effect-library')
GlobalSettings.addConfigOption('favourite_effects',
section='effect-library',
key='favourite-effects',
default=[])
ICON_WIDTH = 80
ICON_HEIGHT = 45
......@@ -368,6 +372,10 @@ class EffectListWidget(Gtk.Box, Loggable):
self._drag_icon = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(get_pixmap_dir(), "effects", "defaultthumbnail.svg"),
ICON_WIDTH, ICON_HEIGHT)
self._star_icon_regular = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(get_pixmap_dir(), "star-regular.svg"), 15, 15)
self._star_icon_solid = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(get_pixmap_dir(), "star-solid.svg"), 15, 15)
self.set_orientation(Gtk.Orientation.VERTICAL)
builder = Gtk.Builder()
......@@ -376,15 +384,19 @@ class EffectListWidget(Gtk.Box, Loggable):
toolbar = builder.get_object("effectslibrary_toolbar")
toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR)
self.searchEntry = builder.get_object("search_entry")
self.fav_view_toggle = builder.get_object("favourites_toggle")
self.fav_view_toggle.set_image(Gtk.Image.new_from_pixbuf(self._star_icon_solid))
self.main_view = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.category_view = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.search_view = Gtk.ListBox(activate_on_single_click=False)
self.search_view.connect("row-activated", self._apply_selected_effect)
self.search_view.set_filter_func(self._search_filter)
# Used for showing search results and favourites
self.all_effects_view = Gtk.ListBox(activate_on_single_click=False)
self.all_effects_view.connect("row-activated", self._apply_selected_effect)
self.main_view.pack_start(self.category_view, True, True, 0)
self.main_view.pack_start(self.search_view, True, True, 0)
self.main_view.pack_start(self.all_effects_view, True, True, 0)
scrollwin = Gtk.ScrolledWindow()
scrollwin.props.hscrollbar_policy = Gtk.PolicyType.NEVER
......@@ -400,11 +412,11 @@ class EffectListWidget(Gtk.Box, Loggable):
scrollwin.show_all()
toolbar.show_all()
self.search_view.hide()
self.all_effects_view.hide()
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.all_effects_view)
def _set_up_category_view(self):
# Add category expanders
......@@ -454,8 +466,22 @@ class EffectListWidget(Gtk.Box, Loggable):
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"))
fav_button.connect("clicked", self._fav_button_cb, effect_box.effect_name)
if effect_name in self.app.settings.favourite_effects:
self._set_fav_button_state(fav_button, True)
else:
self._set_fav_button_state(fav_button, False)
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)
......@@ -510,6 +536,61 @@ class EffectListWidget(Gtk.Box, Loggable):
toplevel=True):
clip.ui.add_effect(effect_info)
def _set_fav_button_state(self, button, is_active):
button.active = is_active
if button.active:
button.props.image = Gtk.Image.new_from_pixbuf(self._star_icon_solid)
else:
button.props.image = Gtk.Image.new_from_pixbuf(self._star_icon_regular)
def _fav_button_cb(self, clicked_button, effect):
# Toggle the state of clicked button
self._set_fav_button_state(clicked_button, not clicked_button.active)
# Get the listbox for the clicked button
current_listbox = clicked_button.get_parent().get_parent().get_parent().get_parent()
# Get all listboxes which contain the effect
effect_info = self.app.effects.getInfo(effect)
all_effect_listboxes = [category_expander.get_child()
for category_expander in self.category_view.get_children()
if category_expander.get_label() in effect_info.categories]
all_effect_listboxes.append(self.all_effects_view)
# Find and sync state in other listboxes
for listbox in all_effect_listboxes:
if listbox != current_listbox:
for row in listbox.get_children():
effect_box = row.get_child().get_child()
if effect == effect_box.effect_name:
fav_button = effect_box.get_children()[2]
# Sync the state with the clicked button
self._set_fav_button_state(fav_button, clicked_button.active)
# Update the favourites list
if clicked_button.active:
self.app.settings.favourite_effects.append(effect)
else:
self.app.settings.favourite_effects = \
[fav for fav in self.app.settings.favourite_effects if fav != effect]
self.all_effects_view.invalidate_filter()
def _favourites_filter(self, row):
effect_box = row.get_child().get_child()
effect_name = effect_box.effect_name
return effect_name in self.app.settings.favourite_effects
def _favourites_toggle_cb(self, toggle):
if toggle.get_active():
self.all_effects_view.set_filter_func(self._favourites_filter)
self.all_effects_view.invalidate_filter()
if not self.all_effects_view.props.visible:
self._switch_to_view(self.all_effects_view)
else:
self._switch_to_view(self.category_view)
def _search_filter(self, row):
effect_box = row.get_child().get_child()
label = effect_box.get_children()[1]
......@@ -521,16 +602,26 @@ class EffectListWidget(Gtk.Box, Loggable):
def _search_entry_changed_cb(self, search_entry):
if search_entry.get_text():
self.search_view.invalidate_filter()
self.search_view.show_all()
self.category_view.hide()
self.all_effects_view.set_filter_func(self._search_filter)
self.all_effects_view.invalidate_filter()
if not self.all_effects_view.props.visible:
self._switch_to_view(self.all_effects_view)
else:
self.category_view.show()
self.search_view.hide()
if self.fav_view_toggle.props.active:
self.all_effects_view.set_filter_func(self._favourites_filter)
self.all_effects_view.invalidate_filter()
else:
self._switch_to_view(self.category_view)
def _search_entry_icon_clicked_cb(self, entry, unused, unused1):
entry.set_text("")
def _switch_to_view(self, view):
for v in self.main_view.get_children():
v.hide()
view.show_all()
PROPS_TO_IGNORE = ['name', 'qos', 'silent', 'message', 'parent']
......
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