[pitivi] undo: Fix cyclic import



commit 67311317e7344f9e0b3508e18b1061f4c72b8e87
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue May 3 08:57:55 2022 +0200

    undo: Fix cyclic import
    
    ```
    Cyclic import (pitivi.undo.markers -> pitivi.undo.undo) (cyclic-import)
    ```

 pitivi/undo/markers.py  | 66 ++++++++++++++++++++++++++++++++++++++++++++++---
 pitivi/undo/project.py  |  2 +-
 pitivi/undo/timeline.py |  2 +-
 pitivi/undo/undo.py     | 59 -------------------------------------------
 4 files changed, 65 insertions(+), 64 deletions(-)
---
diff --git a/pitivi/undo/markers.py b/pitivi/undo/markers.py
index be45f52b6..52128d36e 100644
--- a/pitivi/undo/markers.py
+++ b/pitivi/undo/markers.py
@@ -15,13 +15,73 @@
 # You should have received a copy of the GNU Lesser General Public
 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
 """Undo/redo logic for markers."""
+from typing import Dict
+
+from gi.repository import GES
+from gi.repository import GObject
 from gi.repository import Gst
 
-from pitivi.undo.undo import MetaContainerObserver
 from pitivi.undo.undo import UndoableAutomaticObjectAction
 from pitivi.utils.loggable import Loggable
 
 
+class MetaChangedAction(UndoableAutomaticObjectAction):
+
+    def __init__(self, meta_container, item, current_value, new_value):
+        UndoableAutomaticObjectAction.__init__(self, meta_container)
+        self.item = item
+        self.old_value = current_value
+        self.new_value = new_value
+
+    def __repr__(self):
+        return "<MetaChangedAction %s.%s: %s -> %s>" % (self.auto_object, self.item, self.old_value, 
self.new_value)
+
+    def do(self):
+        self.auto_object.set_meta(self.item, self.new_value)
+
+    def undo(self):
+        self.auto_object.set_meta(self.item, self.old_value)
+
+
+class MetaContainerObserver(GObject.Object):
+    """Monitor for MetaContainer changes.
+
+    Attributes:
+        meta_container (GES.MetaContainer): The object to be monitored.
+        action_log (UndoableActionLog): The action log where to report actions.
+    """
+
+    def __init__(self, meta_container: GES.MetaContainer, action_log):
+        self.meta_container: GES.MetaContainer = meta_container
+        self.action_log = action_log
+
+        self.metas = {}
+
+        self.marker_list_observers = {}
+
+        def set_meta(unused_meta_container, item, value):
+            self.__update_meta(item, value)
+        meta_container.foreach(set_meta)
+
+        meta_container.connect("notify-meta", self._notify_meta_cb)
+
+    def _notify_meta_cb(self, meta_container, item, value):
+        current_value = self.metas.get(item)
+        action = MetaChangedAction(meta_container, item, current_value, value)
+        self.__update_meta(item, value)
+        self.action_log.push(action)
+
+    def release(self):
+        self.meta_container.disconnect_by_func(self._notify_meta_cb)
+        self.meta_container = None
+
+    def __update_meta(self, item, value):
+        self.metas[item] = value
+        if isinstance(self.metas[item], GES.MarkerList):
+            observer = MarkerListObserver(self.metas[item], self.action_log)
+            self.marker_list_observers[self.metas[item]] = observer
+
+
 class MarkerListObserver(Loggable):
     """Monitors a MarkerList and reports UndoableActions.
 
@@ -32,12 +92,12 @@ class MarkerListObserver(Loggable):
         action_log (UndoableActionLog): The action log where to report actions.
     """
 
-    def __init__(self, ges_marker_list, action_log):
+    def __init__(self, ges_marker_list: GES.MarkerList, action_log):
         Loggable.__init__(self)
 
         self.action_log = action_log
 
-        self.marker_observers = {}
+        self.marker_observers: Dict[GES.Marker, MetaContainerObserver] = {}
 
         ges_marker_list.connect("marker-added", self._marker_added_cb)
         ges_marker_list.connect("marker-removed", self._marker_removed_cb)
diff --git a/pitivi/undo/project.py b/pitivi/undo/project.py
index beba2240c..ce2f052a2 100644
--- a/pitivi/undo/project.py
+++ b/pitivi/undo/project.py
@@ -19,9 +19,9 @@ from gi.repository import GES
 from gi.repository import GObject
 from gi.repository import Gst
 
+from pitivi.undo.markers import MetaContainerObserver
 from pitivi.undo.timeline import TimelineObserver
 from pitivi.undo.undo import Action
-from pitivi.undo.undo import MetaContainerObserver
 from pitivi.undo.undo import UndoableAction
 
 
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index fdade6d29..5dad27290 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -19,9 +19,9 @@ from gi.repository import GObject
 from gi.repository import Gst
 
 from pitivi.effects import PROPS_TO_IGNORE
+from pitivi.undo.markers import MetaContainerObserver
 from pitivi.undo.undo import FinalizingAction
 from pitivi.undo.undo import GObjectObserver
-from pitivi.undo.undo import MetaContainerObserver
 from pitivi.undo.undo import UndoableAction
 from pitivi.undo.undo import UndoableAutomaticObjectAction
 from pitivi.utils.loggable import Loggable
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 000ef1bdd..edc61f222 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -17,7 +17,6 @@
 """Undo/redo."""
 import contextlib
 
-from gi.repository import GES
 from gi.repository import GObject
 
 from pitivi.utils.loggable import Loggable
@@ -430,64 +429,6 @@ class UndoableActionLog(GObject.Object, Loggable):
         return False
 
 
-class MetaChangedAction(UndoableAutomaticObjectAction):
-
-    def __init__(self, meta_container, item, current_value, new_value):
-        UndoableAutomaticObjectAction.__init__(self, meta_container)
-        self.item = item
-        self.old_value = current_value
-        self.new_value = new_value
-
-    def __repr__(self):
-        return "<MetaChangedAction %s.%s: %s -> %s>" % (self.auto_object, self.item, self.old_value, 
self.new_value)
-
-    def do(self):
-        self.auto_object.set_meta(self.item, self.new_value)
-
-    def undo(self):
-        self.auto_object.set_meta(self.item, self.old_value)
-
-
-class MetaContainerObserver(GObject.Object):
-    """Monitor for MetaContainer changes.
-
-    Attributes:
-        meta_container (GES.MetaContainer): The object to be monitored.
-        action_log (UndoableActionLog): The action log where to report actions.
-    """
-
-    def __init__(self, meta_container, action_log):
-        self.meta_container = meta_container
-        self.action_log = action_log
-
-        self.metas = {}
-
-        self.marker_list_observers = {}
-
-        def set_meta(unused_meta_container, item, value):
-            self.__update_meta(item, value)
-        meta_container.foreach(set_meta)
-
-        meta_container.connect("notify-meta", self._notify_meta_cb)
-
-    def _notify_meta_cb(self, meta_container, item, value):
-        current_value = self.metas.get(item)
-        action = MetaChangedAction(meta_container, item, current_value, value)
-        self.__update_meta(item, value)
-        self.action_log.push(action)
-
-    def release(self):
-        self.meta_container.disconnect_by_func(self._notify_meta_cb)
-        self.meta_container = None
-
-    def __update_meta(self, item, value):
-        self.metas[item] = value
-        if isinstance(self.metas[item], GES.MarkerList):
-            from pitivi.undo.markers import MarkerListObserver
-            observer = MarkerListObserver(self.metas[item], self.action_log)
-            self.marker_list_observers[self.metas[item]] = observer
-
-
 class PropertyChangedAction(UndoableAutomaticObjectAction):
 
     def __init__(self, gobject, field_name, old_value, new_value):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]