[Bf-blender-cvs] [fa7bd4c0695] master: Cleanup: move utility to create a frame path into a static method

Campbell Barton noreply at git.blender.org
Tue Feb 15 07:25:10 CET 2022


Commit: fa7bd4c06954a9d5e9345000ca1d3f929ce67de1
Author: Campbell Barton
Date:   Tue Feb 15 16:50:08 2022 +1100
Branches: master
https://developer.blender.org/rBfa7bd4c06954a9d5e9345000ca1d3f929ce67de1

Cleanup: move utility to create a frame path into a static method

Add PlayRenderedAnim._frame_path_with_number_char since mixing
this logic inline made the code harder to follow.

===================================================================

M	release/scripts/startup/bl_operators/screen_play_rendered_anim.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/screen_play_rendered_anim.py b/release/scripts/startup/bl_operators/screen_play_rendered_anim.py
index 1c7b014992a..7ad3cacb395 100644
--- a/release/scripts/startup/bl_operators/screen_play_rendered_anim.py
+++ b/release/scripts/startup/bl_operators/screen_play_rendered_anim.py
@@ -44,6 +44,23 @@ class PlayRenderedAnim(Operator):
     bl_label = "Play Rendered Animation"
     bl_options = {'REGISTER'}
 
+    @staticmethod
+    def _frame_path_with_number_char(rd, ch, **kwargs):
+        # Replace the number with `ch`.
+
+        # NOTE: make an api call for this would be nice, however this isn't needed in many places.
+        file_a = rd.frame_path(frame=0, **kwargs)
+
+        frame_tmp = 9
+        file_b = rd.frame_path(frame=frame_tmp, **kwargs)
+
+        while len(file_a) == len(file_b):
+            frame_tmp = (frame_tmp * 10) + 9
+            file_b = rd.frame_path(frame=frame_tmp, **kwargs)
+        file_b = rd.frame_path(frame=int(frame_tmp / 10), **kwargs)
+
+        return ("".join((c if file_b[i] == c else ch) for i, c in enumerate(file_a)))
+
     def execute(self, context):
         import os
         import subprocess
@@ -71,21 +88,7 @@ class PlayRenderedAnim(Operator):
             player_path = guess_player_path(preset)
 
         if is_movie is False and preset in {'FRAMECYCLER', 'RV', 'MPLAYER'}:
-            # replace the number with '#'
-            file_a = rd.frame_path(frame=0, view=view_suffix)
-
-            # TODO, make an api call for this
-            frame_tmp = 9
-            file_b = rd.frame_path(frame=frame_tmp, view=view_suffix)
-
-            while len(file_a) == len(file_b):
-                frame_tmp = (frame_tmp * 10) + 9
-                file_b = rd.frame_path(frame=frame_tmp, view=view_suffix)
-            file_b = rd.frame_path(frame=int(frame_tmp / 10), view=view_suffix)
-
-            file = ("".join((c if file_b[i] == c else "#")
-                            for i, c in enumerate(file_a)))
-            del file_a, file_b, frame_tmp
+            file = PlayRenderedAnim._frame_path_with_number_char(rd, "#", view=view_suffix)
             file = bpy.path.abspath(file)  # expand '//'
         else:
             path_valid = True



More information about the Bf-blender-cvs mailing list