Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bpy/utils/__init__.py
| Show First 20 Lines • Show All 444 Lines • ▼ Show 20 Lines | def preset_paths(subdir): | ||||
| for path in _addon_utils.paths(): | for path in _addon_utils.paths(): | ||||
| directory = _os.path.join(path, "presets", subdir) | directory = _os.path.join(path, "presets", subdir) | ||||
| if _os.path.isdir(directory): | if _os.path.isdir(directory): | ||||
| dirs.append(directory) | dirs.append(directory) | ||||
| return dirs | return dirs | ||||
| def smpte_from_seconds(time, fps=None): | def smpte_from_seconds(time, fps=None, fps_base=None): | ||||
| """ | """ | ||||
| Returns an SMPTE formatted string from the *time*: | Returns an SMPTE formatted string from the *time*: | ||||
| ``HH:MM:SS:FF``. | ``HH:MM:SS:FF``. | ||||
| If the *fps* is not given the current scene is used. | If *fps* and *fps_base* are not given the current scene is used. | ||||
| :arg time: time in seconds. | :arg time: time in seconds. | ||||
| :type time: int, float or ``datetime.timedelta``. | :type time: int, float or ``datetime.timedelta``. | ||||
| :return: the frame string. | :return: the frame string. | ||||
| :rtype: string | :rtype: string | ||||
| """ | """ | ||||
| return smpte_from_frame(time_to_frame(time, fps=fps), fps) | return smpte_from_frame( | ||||
| time_to_frame(time, fps=fps, fps_base=fps_base), | |||||
| fps=fps, | |||||
| fps_base=fps_base | |||||
| ) | |||||
| def smpte_from_frame(frame, fps=None, fps_base=None): | def smpte_from_frame(frame, fps=None, fps_base=None): | ||||
| """ | """ | ||||
| Returns an SMPTE formatted string from the *frame*: | Returns an SMPTE formatted string from the *frame*: | ||||
| ``HH:MM:SS:FF``. | ``HH:MM:SS:FF``. | ||||
| If *fps* and *fps_base* are not given the current scene is used. | If *fps* and *fps_base* are not given the current scene is used. | ||||
| :arg frame: frame number. | :arg frame: frame number. | ||||
| :type frame: int or float. | :type frame: int or float. | ||||
| :return: the frame string. | :return: the frame string. | ||||
| :rtype: string | :rtype: string | ||||
| """ | """ | ||||
| if fps is None: | if fps is None: | ||||
| fps = _bpy.context.scene.render.fps | fps = _bpy.context.scene.render.fps | ||||
| if fps_base is None: | if fps_base is None: | ||||
| fps_base = _bpy.context.scene.render.fps_base | fps_base = _bpy.context.scene.render.fps_base | ||||
| fps = fps / fps_base | |||||
| sign = "-" if frame < 0 else "" | sign = "-" if frame < 0 else "" | ||||
| frame = abs(frame * fps_base) | frame = abs(frame) | ||||
| return ( | return ( | ||||
| "%s%02d:%02d:%02d:%02d" % ( | "%s%02d:%02d:%02d:%02d" % ( | ||||
| sign, | sign, | ||||
| int(frame / (3600 * fps)), # HH | int(frame / (3600 * fps)), # HH | ||||
| int((frame / (60 * fps)) % 60), # MM | int((frame / (60 * fps)) % 60), # MM | ||||
| int((frame / fps) % 60), # SS | int((frame / fps) % 60), # SS | ||||
| int(frame % fps), # FF | int(frame % fps), # FF | ||||
| Show All 13 Lines | def time_from_frame(frame, fps=None, fps_base=None): | ||||
| """ | """ | ||||
| if fps is None: | if fps is None: | ||||
| fps = _bpy.context.scene.render.fps | fps = _bpy.context.scene.render.fps | ||||
| if fps_base is None: | if fps_base is None: | ||||
| fps_base = _bpy.context.scene.render.fps_base | fps_base = _bpy.context.scene.render.fps_base | ||||
| fps = fps / fps_base | |||||
| from datetime import timedelta | from datetime import timedelta | ||||
| return timedelta(0, (frame * fps_base) / fps) | return timedelta(0, frame / fps) | ||||
| def time_to_frame(time, fps=None, fps_base=None): | def time_to_frame(time, fps=None, fps_base=None): | ||||
| """ | """ | ||||
| Returns a float frame number from a time given in seconds or | Returns a float frame number from a time given in seconds or | ||||
| as a datetime.timedelta object. | as a datetime.timedelta object. | ||||
| If *fps* and *fps_base* are not given the current scene is used. | If *fps* and *fps_base* are not given the current scene is used. | ||||
| :arg time: time in seconds. | :arg time: time in seconds. | ||||
| :type time: number or a ``datetime.timedelta`` object | :type time: number or a ``datetime.timedelta`` object | ||||
| :return: the frame. | :return: the frame. | ||||
| :rtype: float | :rtype: float | ||||
| """ | """ | ||||
| if fps is None: | if fps is None: | ||||
| fps = _bpy.context.scene.render.fps | fps = _bpy.context.scene.render.fps | ||||
| if fps_base is None: | if fps_base is None: | ||||
| fps_base = _bpy.context.scene.render.fps_base | fps_base = _bpy.context.scene.render.fps_base | ||||
| fps = fps / fps_base | |||||
| from datetime import timedelta | from datetime import timedelta | ||||
| if isinstance(time, timedelta): | if isinstance(time, timedelta): | ||||
| time = time.total_seconds() | time = time.total_seconds() | ||||
| return (time / fps_base) * fps | return time * fps | ||||
| def preset_find(name, preset_path, display_name=False, ext=".py"): | def preset_find(name, preset_path, display_name=False, ext=".py"): | ||||
| if not name: | if not name: | ||||
| return None | return None | ||||
| for directory in preset_paths(preset_path): | for directory in preset_paths(preset_path): | ||||
| ▲ Show 20 Lines • Show All 428 Lines • Show Last 20 Lines | |||||