Skip to content

Commit

Permalink
DOC: Add missing docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjgraf committed Feb 2, 2021
1 parent 693741f commit c60e20c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion vimiv/gui/metadatawidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MetadataWidget(QLabel):
_mainwindow_width: width of the mainwindow.
_path: Absolute path of the current image to load metadata of.
_current_set: Holds a string of the currently selected keyset.
_handler: MetadataHandler for _path or None. Use the handler property to access.
_handler: MetadataHandler for _path or None. Accessed via handler property.
"""

STYLESHEET = """
Expand Down
50 changes: 43 additions & 7 deletions vimiv/imutils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@


class _InternalKeyHandler(dict):
"""Handler to load all internal keys of a single image.
Attributes:
_path: Apsolute path of the image to load the metadata of.
_reader: QImageReader or None of _path. Accessed via reder property.
"""

def __init__(self, path: str):
super().__init__(
{
Expand All @@ -39,27 +46,38 @@ def __init__(self, path: str):

@property
def reader(self) -> QImageReader:
"""Return QImageReader instance of _path."""
if self._reader is None:
self._reader = QImageReader(self._path)
return self._reader

def _get_filesize(self):
"""Get the file size."""
return files.get_size_file(self._path)

def _get_filetype(self):
"""Get the file type."""
return files.imghdr.what(self._path)

def _get_xdimension(self):
"""Get the x dimension in pixels."""
return self.reader.size().width()

def _get_ydimension(self):
"""Get the y dimension in pixels."""
return self.reader.size().height()

def __getitem__(self, key: str) -> Tuple[str, str, str]:
"""Intrypoint to extract the key of the image at _path.
Args:
key: internal key to fetch.
"""
key, func = super().get(key.lower())
return (key, key, func())

def get_keys(self) -> Iterable[str]:
"""Returns a sequence of all available metadata keys."""
return (key for key, _ in super().values())


Expand Down Expand Up @@ -94,6 +112,11 @@ def get_date_time(self) -> str:
self.raise_exception("Retrieving exif date-time")

def fetch_key(self, _base_key: str) -> Tuple[str, str, str]:
"""Fetch a single metadata key.
Args:
_base_key: metadata key to fetch.
"""
self.raise_exception("Getting formatted keys")

def get_keys(self) -> Iterable[str]:
Expand Down Expand Up @@ -269,6 +292,7 @@ def fetch_key(self, base_key: str) -> Tuple[str, str, str]:
return None

def get_keys(self) -> Iterable[str]:
"""Return a iteable of all available metadata keys."""
return (key for key in self._metadata if not is_hex(key.rpartition(".")[2]))

def copy_metadata(self, dest: str, reset_orientation: bool = True) -> None:
Expand Down Expand Up @@ -330,7 +354,13 @@ def _external_handler(self) -> ExternalKeyHandler:
return self._ext_handler

def fetch_keys(self, desired_keys: Sequence[str]) -> Dict[Any, Tuple[str, str]]:
"""Throws: UnsupportedMetadataOperation"""
"""Extracts a list of metadata keys.
Throws: UnsupportedMetadataOperation.
Args:
desired_keys: list of metadata keys to extract.
"""
metadata = dict()

for base_key in desired_keys:
Expand All @@ -344,6 +374,18 @@ def fetch_keys(self, desired_keys: Sequence[str]) -> Dict[Any, Tuple[str, str]]:

return metadata

def fetch_key(self, key: str) -> Tuple[str, str, str]:
"""Extracts a single metadata key.
Throws: UnsupportedMetadataOperation.
Args:
key: single metadata key to extract.
"""
if key.lower().startswith("vimiv"):
return self._internal_handler[key]
return self._external_handler.fetch_key(key)

def get_keys(self) -> Iterable[str]:
"""Retrieve the name of all metadata keys available.
Expand All @@ -353,12 +395,6 @@ def get_keys(self) -> Iterable[str]:
self._internal_handler.get_keys(), self._external_handler.get_keys()
)

def fetch_key(self, key: str) -> Tuple[str, str, str]:
"""Throws: UnsupportedMetadataOperation"""
if key.lower().startswith("vimiv"):
return self._internal_handler[key]
return self._external_handler.fetch_key(key)


class ExifOrientation:
"""Namespace for exif orientation tags.
Expand Down

0 comments on commit c60e20c

Please sign in to comment.