Skip to content

Commit

Permalink
wip(gallery): Improve handling stills and albums
Browse files Browse the repository at this point in the history
Before now API support for galleries was incomplete. Most of the
return values were the wrong types, etc. (my bad)

I changed some things too. Getting and setting the name from the Gallery
object instead of as a property of the GalleryStillAlbum seemed obtuse.
So I took inspiration from the MarkerCollection object and added the
parent object into all the function calls for GalleryStillAlbum.

I did a similar thing with gallery stills to more easily get and set
their labels.

See TODO comments for more info.

These changes are untested. Further changes are likely required.
  • Loading branch information
in03 committed Mar 15, 2023
1 parent 580ae91 commit 10e7be6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 61 deletions.
40 changes: 9 additions & 31 deletions src/pydavinci/wrappers/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,8 @@ def __init__(self, obj: "PyRemoteGallery") -> None:
else:
raise TypeError(f"{type(obj)} is not a valid {self.__class__.__name__} type")

# TODO: make get/set_album_name properties of "GalleryStillAlbum" instead of "Gallery"
# Not sure how to go about this. Seems unnatural having to pass the album back to the
# parent object just to get and set the album name. --in03

def get_album_name(self, gallery_still_album: "GalleryStillAlbum") -> str:
"""
Gets name of ``GalleryStillAlbum``
Returns:
str: name
"""
return self._obj.GetAlbumName(gallery_still_album)

def set_album_name(self, gallery_still_album: "GalleryStillAlbum", name: str) -> bool:
"""
Changes ``GalleryStillAlbum`` name to ``name``
Args:
name (str): new ``GalleryStillAlbum`` name
Returns:
bool: ``True`` if successful, ``False`` otherwise
"""
return self._obj.SetAlbumName(gallery_still_album, name)

# TODO: Does "Album" adequately imply current album?
# Not sure if I should follow "active_timeline" convention here.
@property
def album(self) -> "GalleryStillAlbum":
"""
Expand All @@ -50,18 +27,18 @@ def album(self) -> "GalleryStillAlbum":
Returns:
GalleryStillAlbum: ``GalleryStillAlbum`` object
"""
return self._obj.GetCurrentStillAlbum()
@album.setter
def album(self, gallery_still_album: "GalleryStillAlbum") -> bool:
return GalleryStillAlbum(self._obj, self._obj.GetCurrentStillAlbum())

@album.setter
def album(self, gallery_still_album: str) -> bool:
"""
Changes current album to ``GalleryStillAlbum`` object.
Returns:
bool: ``True`` if successful, ``False`` otherwise
"""
return self._obj.SetCurrentStillAlbum(gallery_still_album)

@property
def albums(self) -> List["GalleryStillAlbum"]:
"""
Expand All @@ -70,4 +47,5 @@ def albums(self) -> List["GalleryStillAlbum"]:
Returns:
(List[GalleryStill]): List of ``GalleryStillAlbum`` objects
"""
return self._obj.GetGalleryStillAlbums()

return [GalleryStillAlbum(self._obj, x) for x in self._obj.GetGalleryStillAlbums()]
27 changes: 26 additions & 1 deletion src/pydavinci/wrappers/gallerystill.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@
from pydavinci.wrappers._resolve_stubs import PyRemoteGalleryStillAlbum # type: ignore


class GalleryStill:
def __init__(
self, parent_obj: "PyRemoteGalleryStillAlbum", obj: "PyRemoteGalleryStill"
) -> None:

if is_resolve_obj(obj):
self._obj: "PyRemoteGalleryStill" = obj
self.parent_obj: "PyRemoteGalleryStillAlbum" = parent_obj
else:
raise TypeError(f"{type(obj)} is not a valid {self.__class__.__name__} type")
raise TypeError(f"{type(obj)} is not a valid {self.__class__.__name__} type")

@property
def label(self) -> str:
"""
Gets the label of a ``GalleryStill`` object
Returns:
str: ``GalleryStill`` label
"""
return self.parent_obj.GetLabel(self._obj)

@label.setter
def label(self, label: str) -> bool:
"""
Sets the ``label`` of a ``GalleryStill`` object
Returns:
bool: ``True`` if successful, ``False`` otherwise
"""
return self.parent_obj.SetLabel(self._obj, label)
69 changes: 40 additions & 29 deletions src/pydavinci/wrappers/gallerystillalbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
from pydavinci.wrappers._resolve_stubs import PyRemoteGalleryStillAlbum # type: ignore


class GalleryStillAlbum:
def __init__(
self,
parent_obj: "PyRemoteGallery",
obj: "PyRemoteGalleryStillAlbum",
) -> None:

if is_resolve_obj(obj):
self._obj: "PyRemoteGalleryStillAlbum" = obj
self.parent_obj: "PyRemoteGallery" = parent_obj
else:
raise TypeError(f"{type(obj)} is not a valid {self.__class__.__name__} type")

Expand All @@ -21,30 +29,31 @@ def stills(self) -> List["GalleryStill"]:
Returns:
(List[GalleryStill]): List of ``GalleryStill`` objects
"""
return self._obj.GetStills()

def get_label(self, gallery_still: "GalleryStill") -> str:
"""
Gets the label of a ``GalleryStill`` object

Returns:
str: ``GalleryStill`` label
"""
return self._obj.GetLabel(gallery_still)

def set_label(self, gallery_still: "GalleryStill", label: str) -> bool:
"""
Sets the ``label`` of a ``GalleryStill`` object
return [GalleryStill(self._obj, x) for x in self._obj.GetStills()]

Returns:
bool: ``True`` if successful, ``False`` otherwise
"""
return self._obj.SetLabel(gallery_still, label)

def export_stills(self, gallery_stills: List["GalleryStill"], folder_path: str, file_prefix: str, format_: str) -> bool:
@property
def name(self) -> str:

# TODO: Is this really wrong to do?
# I feel like it makes more sense for the name to be a property of the album
# than to return an album object back to the gallery object.
# Also I haven't seen any other instances of importing the resolve obj at this level.
# So feeling very cheeky.

return self.parent_obj.GetAlbumName(self._obj)

@name.setter
def name(self, name: str) -> bool:

return self.parent_obj.SetAlbumName(self._obj, name)

def export_stills(
self, gallery_stills: List["GalleryStill"], folder_path: str, file_prefix: str, format_: str
) -> bool:
"""
Exports list of ``GalleryStill`` objects to directory with ``file_prefix`` using ``format_``
Supported ``format``:
```
"dpx"
Expand All @@ -66,25 +75,27 @@ def export_stills(self, gallery_stills: List["GalleryStill"], folder_path: str,
Returns:
bool: ``True`` if successful, ``False`` otherwise
"""

return self._obj.ExportStills(gallery_stills, folder_path, file_prefix, format_)


remote_gallery_stills = [x._obj for x in gallery_stills]
return self._obj.ExportStills(remote_gallery_stills, folder_path, file_prefix, format_)

def delete_stills(self, gallery_stills: List["GalleryStill"]) -> bool:
"""
Deletes specified list of ``GalleryStill`` objects '[galleryStill]'
Args:
gallery_stills (List["GalleryStill"]): List of GalleryStill objects
Returns:
bool: ``True`` if successful, ``False`` otherwise
"""

return self._obj.DeleteStills(gallery_stills)

remote_gallery_stills = [x._obj for x in gallery_stills]
return self._obj.DeleteStills(remote_gallery_stills)

# TODO: Add repr method
# Should ideally return name, but that's a method of the parent object.
# See gallery.py --in03
# See gallery.py

# def __repr__(self) -> str:
# return f"GalleryStillAlbum(name: {self.name})"
# return f"GalleryStillAlbum(name: {self.name})"

0 comments on commit 10e7be6

Please sign in to comment.