Source code for

# PM - Notes, Oct 25, 2022
# this module has issues.
# find_gallery_item() returns XGalleryItem which in may have properties such as Graphic (XGraphic).
# the issues is as soon as the XGalleryItem is returned from find_gallery_item() it has already lost its properties.
# see my post:
# Checking the reference count inside of find_gallery_item() show there is only 1 ref could. Which means 0 references
# because sys.getrefcount() add 1 reference to the object that is being checked.
# find_gallery_graphic() has been added which duplicates the code of find_gallery_item() due to these issues.
# find_gallery_graphic() does successfully return XGraphic object, However I am not sure if this graphic can be used
# as it is. I tried inserting the XGraphic into a Draw XShape and putting it on the document, however it appears to
# always be the same graphic even though the criteria is change for find_gallery_graphic()
from __future__ import annotations
from typing import TYPE_CHECKING, Any, List, cast
from pathlib import Path
from typing import overload
import uno
from import XGalleryItem
from import XGalleryTheme
from import XGalleryThemeProvider
from import XGraphic

from ooodev.utils import file_io as mFileIo
from ooodev.loader import lo as mLo
from ooodev.utils import props as mProps
from ooodev.utils import info as mInfo
from ooodev.exceptions import ex as mEx
from ooodev.utils.kind.search_match_kind import SearchMatchKind as SearchMatchKind
from ooodev.utils.kind.gallery_kind import GalleryKind as GalleryKind
from ooodev.utils.kind.gallery_search_by_kind import SearchByKind as SearchByKind

from import _Events
from import LoNamedEvent

from import GalleryItemTypeEnum as GalleryItemTypeEnum
from import GalleryItemType as GalleryItemType

from ooodev.meta.static_meta import StaticProperty, classproperty

    from import EventObject
    from import XPropertySetInfo

[docs]class GalleryObj: """ Represents Most properties of ``XGalleryItem``. An instance of this class is returned from :py:meth:`` in place of ``XGalleryItem`` instance. This is due to a `bug <>`_ in ``LO 7.4``. """ # special case for this class. Matching most of GalleryItem properties so # using Camel case
[docs] def __init__(self, itm: XGalleryItem) -> None: self._graphic = mProps.Props.get(itm, "Graphic", None) self._drawing = mProps.Props.get(itm, "Drawing", None) url = cast(str, mProps.Props.get(itm, "URL", "")) self._url = Gallery.get_absolute_url(url) self._gallery_item_type = mProps.Props.get(itm, "GalleryItemType", 0) self._title = mProps.Props.get(itm, "Title", "") self._implementation_id = getattr(itm, "ImplementationId", None) self._implementation_name = getattr(itm, "ImplementationName", "") self._property_set_info = getattr(itm, "PropertySetInfo", None) self._property_to_default = getattr(itm, "PropertyToDefault", None) self._thumbnail = mProps.Props.get(itm, "Thumbnail", None)
@property def Graphic(self) -> XGraphic: return self._graphic @property def Drawing(self) -> Any: return self._drawing @property def URL(self) -> str: return self._url @property def GalleryItemType(self) -> int: return self._gallery_item_type @property def Title(self) -> str: return self._title @property def ImplementationId(self) -> uno.ByteSequence: return self._implementation_id # type: ignore @property def ImplementationName(self) -> str: return self._implementation_name @property def PropertySetInfo(self) -> XPropertySetInfo: return self._property_set_info # type: ignore @property def PropertyToDefault(self) -> Any: return self._property_to_default @property def Thumbnail(self) -> Any: return self._thumbnail
class _GalleryManager: """Manages clearing and resetting for Gallery static class""" @staticmethod def on_disposed(source: Any, event: EventObject) -> None: # Clean up static properties that may have been dynamically created. # print("Gallery Static Property Cleanup") data_attrs = ("_gallery_dir",) for attr in data_attrs: if hasattr(Gallery, attr): delattr(Gallery, attr) _Events().on(LoNamedEvent.BRIDGE_DISPOSED, _GalleryManager.on_disposed) __all__ = ("Gallery",)