mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
breaking get_current_timeline into more functions
This commit is contained in:
parent
5fcb19bc67
commit
318237ded6
3 changed files with 59 additions and 33 deletions
|
|
@ -24,6 +24,8 @@ from .lib import (
|
||||||
get_project_manager,
|
get_project_manager,
|
||||||
get_current_project,
|
get_current_project,
|
||||||
get_current_timeline,
|
get_current_timeline,
|
||||||
|
get_any_timeline,
|
||||||
|
get_new_timeline,
|
||||||
create_bin,
|
create_bin,
|
||||||
get_media_pool_item,
|
get_media_pool_item,
|
||||||
create_media_pool_item,
|
create_media_pool_item,
|
||||||
|
|
@ -95,6 +97,8 @@ __all__ = [
|
||||||
"get_project_manager",
|
"get_project_manager",
|
||||||
"get_current_project",
|
"get_current_project",
|
||||||
"get_current_timeline",
|
"get_current_timeline",
|
||||||
|
"get_any_timeline",
|
||||||
|
"get_new_timeline",
|
||||||
"create_bin",
|
"create_bin",
|
||||||
"get_media_pool_item",
|
"get_media_pool_item",
|
||||||
"create_media_pool_item",
|
"create_media_pool_item",
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ log = Logger.get_logger(__name__)
|
||||||
self = sys.modules[__name__]
|
self = sys.modules[__name__]
|
||||||
self.project_manager = None
|
self.project_manager = None
|
||||||
self.media_storage = None
|
self.media_storage = None
|
||||||
|
self.current_project = None
|
||||||
|
|
||||||
# OpenPype sequential rename variables
|
# OpenPype sequential rename variables
|
||||||
self.rename_index = 0
|
self.rename_index = 0
|
||||||
|
|
@ -85,47 +86,60 @@ def get_media_storage():
|
||||||
|
|
||||||
|
|
||||||
def get_current_project():
|
def get_current_project():
|
||||||
# initialize project manager
|
"""Get current project object.
|
||||||
get_project_manager()
|
"""
|
||||||
|
if not self.current_project:
|
||||||
|
self.current_project = get_project_manager().GetCurrentProject()
|
||||||
|
|
||||||
return self.project_manager.GetCurrentProject()
|
return self.current_project
|
||||||
|
|
||||||
|
|
||||||
def get_current_timeline(new=False, get_any=False):
|
def get_current_timeline(new=False):
|
||||||
"""Get current timeline object.
|
"""Get current timeline object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
new (bool, optional): return only new timeline. Defaults to False.
|
new (bool)[optional]: [DEPRECATED] if True it will create
|
||||||
get_any (bool, optional): return any even new if no timeline available.
|
new timeline if none exists
|
||||||
Defaults to False.
|
|
||||||
|
Returns:
|
||||||
|
TODO: will need to reflect future `None`
|
||||||
|
object: resolve.Timeline
|
||||||
|
"""
|
||||||
|
project = get_current_project()
|
||||||
|
timeline = project.GetCurrentTimeline()
|
||||||
|
|
||||||
|
# return current timeline if any
|
||||||
|
if timeline:
|
||||||
|
return timeline
|
||||||
|
|
||||||
|
# TODO: [deprecated] and will be removed in future
|
||||||
|
if new:
|
||||||
|
return get_new_timeline()
|
||||||
|
|
||||||
|
|
||||||
|
def get_any_timeline():
|
||||||
|
"""Get any timeline object.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
object | None: resolve.Timeline
|
||||||
|
"""
|
||||||
|
project = get_current_project()
|
||||||
|
timeline_count = project.GetTimelineCount()
|
||||||
|
if timeline_count > 0:
|
||||||
|
return project.GetTimelineByIndex(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_timeline():
|
||||||
|
"""Get new timeline object.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
object: resolve.Timeline
|
object: resolve.Timeline
|
||||||
"""
|
"""
|
||||||
# get current project
|
|
||||||
project = get_current_project()
|
project = get_current_project()
|
||||||
|
media_pool = project.GetMediaPool()
|
||||||
timeline = project.GetCurrentTimeline()
|
new_timeline = media_pool.CreateEmptyTimeline(self.pype_timeline_name)
|
||||||
|
project.SetCurrentTimeline(new_timeline)
|
||||||
# return current timeline only if it is not new
|
return new_timeline
|
||||||
if timeline and not new:
|
|
||||||
return timeline
|
|
||||||
|
|
||||||
# if get_any is True then return any timeline
|
|
||||||
if get_any:
|
|
||||||
timeline_count = project.GetTimelineCount()
|
|
||||||
if timeline_count == 0:
|
|
||||||
# if there is no timeline then create a new one
|
|
||||||
new = True
|
|
||||||
else:
|
|
||||||
return project.GetTimelineByIndex(1)
|
|
||||||
|
|
||||||
# create new timeline if new is True
|
|
||||||
if new:
|
|
||||||
media_pool = project.GetMediaPool()
|
|
||||||
new_timeline = media_pool.CreateEmptyTimeline(self.pype_timeline_name)
|
|
||||||
project.SetCurrentTimeline(new_timeline)
|
|
||||||
return new_timeline
|
|
||||||
|
|
||||||
|
|
||||||
def create_bin(name: str, root: object = None) -> object:
|
def create_bin(name: str, root: object = None) -> object:
|
||||||
|
|
@ -337,8 +351,13 @@ def get_current_timeline_items(
|
||||||
track_type = track_type or "video"
|
track_type = track_type or "video"
|
||||||
selecting_color = selecting_color or "Chocolate"
|
selecting_color = selecting_color or "Chocolate"
|
||||||
project = get_current_project()
|
project = get_current_project()
|
||||||
# make sure some timeline will be active with `any` argument
|
|
||||||
timeline = get_current_timeline(get_any=True)
|
# get timeline anyhow
|
||||||
|
timeline = (
|
||||||
|
get_current_timeline() or
|
||||||
|
get_any_timeline() or
|
||||||
|
get_new_timeline()
|
||||||
|
)
|
||||||
selected_clips = []
|
selected_clips = []
|
||||||
|
|
||||||
# get all tracks count filtered by track type
|
# get all tracks count filtered by track type
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,10 @@ class ClipLoader:
|
||||||
self.active_timeline = options["timeline"]
|
self.active_timeline = options["timeline"]
|
||||||
else:
|
else:
|
||||||
# create new sequence
|
# create new sequence
|
||||||
self.active_timeline = lib.get_current_timeline(new=True)
|
self.active_timeline = (
|
||||||
|
lib.get_current_timeline() or
|
||||||
|
lib.get_new_timeline()
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.active_timeline = lib.get_current_timeline()
|
self.active_timeline = lib.get_current_timeline()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue