diff --git a/vimiv/gui/metadatawidget.py b/vimiv/gui/metadatawidget.py index cd58cf01f..2ec0ae7d7 100644 --- a/vimiv/gui/metadatawidget.py +++ b/vimiv/gui/metadatawidget.py @@ -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 = """ diff --git a/vimiv/imutils/metadata.py b/vimiv/imutils/metadata.py index 70451c5bb..7f603160b 100644 --- a/vimiv/imutils/metadata.py +++ b/vimiv/imutils/metadata.py @@ -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__( { @@ -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()) @@ -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]: @@ -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: @@ -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: @@ -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. @@ -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.