[pitivi] utils: Merge set/unset_children_state_recurse functions
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] utils: Merge set/unset_children_state_recurse functions
- Date: Fri, 25 Feb 2022 07:12:27 +0000 (UTC)
commit cf0203149de73f86a2867426330e0b9ac1168ad3
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Sun Jan 23 21:03:23 2022 +0100
utils: Merge set/unset_children_state_recurse functions
pitivi/timeline/elements.py | 11 +++++++----
pitivi/timeline/timeline.py | 10 +++-------
pitivi/utils/timeline.py | 8 ++------
pitivi/utils/ui.py | 26 ++++++++++----------------
4 files changed, 22 insertions(+), 33 deletions(-)
---
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 78343f9fe..42dab1960 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -53,8 +53,7 @@ from pitivi.utils.timeline import Selected
from pitivi.utils.timeline import UNSELECT
from pitivi.utils.timeline import Zoomable
from pitivi.utils.ui import EFFECT_TARGET_ENTRY
-from pitivi.utils.ui import set_children_state_recurse
-from pitivi.utils.ui import unset_children_state_recurse
+from pitivi.utils.ui import set_state_flags_recurse
KEYFRAME_LINE_HEIGHT = 2
KEYFRAME_LINE_ALPHA = 0.5
@@ -1413,18 +1412,22 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
handle.hide()
def _event_cb(self, element, event):
+ prelight = None
if (event.type == Gdk.EventType.ENTER_NOTIFY and
event.mode == Gdk.CrossingMode.NORMAL and
not self.timeline.scrubbing):
- set_children_state_recurse(self, Gtk.StateFlags.PRELIGHT, ignored_classes=(Marker,))
+ prelight = True
for handle in self.handles:
handle.enlarge()
elif (event.type == Gdk.EventType.LEAVE_NOTIFY and
event.mode == Gdk.CrossingMode.NORMAL):
- unset_children_state_recurse(self, Gtk.StateFlags.PRELIGHT)
+ prelight = False
for handle in self.handles:
handle.shrink()
+ if prelight is not None:
+ set_state_flags_recurse(self, Gtk.StateFlags.PRELIGHT, are_set=prelight,
ignored_classes=(Marker,))
+
return False
def _start_changed_cb(self, clip, pspec):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 111977038..f43709d86 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -61,12 +61,11 @@ from pitivi.utils.ui import PLAYHEAD_COLOR
from pitivi.utils.ui import PLAYHEAD_WIDTH
from pitivi.utils.ui import SEPARATOR_HEIGHT
from pitivi.utils.ui import set_cairo_color
-from pitivi.utils.ui import set_children_state_recurse
+from pitivi.utils.ui import set_state_flags_recurse
from pitivi.utils.ui import SNAPBAR_COLOR
from pitivi.utils.ui import SNAPBAR_WIDTH
from pitivi.utils.ui import SPACING
from pitivi.utils.ui import TOUCH_INPUT_SOURCES
-from pitivi.utils.ui import unset_children_state_recurse
from pitivi.utils.ui import URI_TARGET_ENTRY
from pitivi.utils.widgets import ZoomBox
@@ -1351,12 +1350,9 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
return None
- def _set_separators_prelight(self, light):
+ def _set_separators_prelight(self, prelight):
for sep in self.__on_separators:
- if light:
- set_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
- else:
- unset_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
+ set_state_flags_recurse(sep, Gtk.StateFlags.PRELIGHT, are_set=prelight)
def __drag_update(self, x, y):
"""Updates a clip or asset drag operation.
diff --git a/pitivi/utils/timeline.py b/pitivi/utils/timeline.py
index 36486d1c8..64eb8cd9d 100644
--- a/pitivi/utils/timeline.py
+++ b/pitivi/utils/timeline.py
@@ -123,12 +123,8 @@ class Selection(GObject.Object, Loggable):
for obj, selected in self.__get_selection_changes(old_selection):
obj.selected.selected = selected
if obj.ui:
- if selected:
- from pitivi.utils.ui import set_children_state_recurse
- set_children_state_recurse(obj.ui, Gtk.StateFlags.SELECTED)
- else:
- from pitivi.utils.ui import unset_children_state_recurse
- unset_children_state_recurse(obj.ui, Gtk.StateFlags.SELECTED)
+ from pitivi.utils.ui import set_state_flags_recurse
+ set_state_flags_recurse(obj.ui, Gtk.StateFlags.SELECTED, are_set=selected)
for element in obj.get_children(False):
if isinstance(obj, (GES.BaseEffect, GES.TextOverlay)):
continue
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index 776e00542..7ccb5e80e 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -869,25 +869,19 @@ def alter_style_class(style_class, target_widget, css_style):
css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
-def set_children_state_recurse(widget, state, ignored_classes=()):
+def set_state_flags_recurse(widget, state_flags, are_set, ignored_classes=()):
"""Sets the provided state on all children of the given widget."""
- widget.set_state_flags(state, False)
- for child in widget.get_children():
- if isinstance(child, ignored_classes):
- continue
-
- child.set_state_flags(state, False)
- if isinstance(child, Gtk.Container):
- set_children_state_recurse(child, state, ignored_classes)
+ if isinstance(widget, ignored_classes):
+ return
+ if are_set:
+ widget.set_state_flags(state_flags, clear=False)
+ else:
+ widget.unset_state_flags(state_flags)
-def unset_children_state_recurse(widget, state):
- """Unsets the provided state on all children of the given widget."""
- widget.unset_state_flags(state)
- for child in widget.get_children():
- child.unset_state_flags(state)
- if isinstance(child, Gtk.Container):
- unset_children_state_recurse(child, state)
+ if isinstance(widget, Gtk.Container):
+ for child in widget.get_children():
+ set_state_flags_recurse(child, state_flags, are_set, ignored_classes)
def disable_scroll_event_cb(widget, unused_event):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]