diff --git a/pdm.lock b/pdm.lock index 5c62a23..ac2656c 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default"] strategy = ["cross_platform"] lock_version = "4.4" -content_hash = "sha256:14fa7067ab34f838f77cef73035579eaf59f3bc59e618544a7337634c104005e" +content_hash = "sha256:6862214b26a0af56c999897fb0f628a8f02bfc55039f4aae96fcca08c384f076" [[package]] name = "bracex" @@ -76,16 +76,6 @@ files = [ {file = "ImageHash-4.3.1.tar.gz", hash = "sha256:7038d1b7f9e0585beb3dd8c0a956f02b95a346c0b5f24a9e8cc03ebadaf0aa70"}, ] -[[package]] -name = "imagesize" -version = "1.4.1" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -summary = "Getting image size from png/jpeg/jpeg2000/gif file" -files = [ - {file = "imagesize-1.4.1-py2.py3-none-any.whl", hash = "sha256:0d8d18d08f840c19d0ee7ca1fd82490fdc3729b7ac93f49870406ddde8ef8d8b"}, - {file = "imagesize-1.4.1.tar.gz", hash = "sha256:69150444affb9cb0d5cc5a92b3676f0b2fb7cd9ae39e947a5e11a36b4497cd4a"}, -] - [[package]] name = "markdown-it-py" version = "3.0.0" @@ -111,28 +101,22 @@ files = [ [[package]] name = "numpy" -version = "1.26.1" -requires_python = "<3.13,>=3.9" +version = "1.26.2" +requires_python = ">=3.9" summary = "Fundamental package for array computing in Python" files = [ - {file = "numpy-1.26.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:82e871307a6331b5f09efda3c22e03c095d957f04bf6bc1804f30048d0e5e7af"}, - {file = "numpy-1.26.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cdd9ec98f0063d93baeb01aad472a1a0840dee302842a2746a7a8e92968f9575"}, - {file = "numpy-1.26.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d78f269e0c4fd365fc2992c00353e4530d274ba68f15e968d8bc3c69ce5f5244"}, - {file = "numpy-1.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8ab9163ca8aeb7fd32fe93866490654d2f7dda4e61bc6297bf72ce07fdc02f67"}, - {file = "numpy-1.26.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:78ca54b2f9daffa5f323f34cdf21e1d9779a54073f0018a3094ab907938331a2"}, - {file = "numpy-1.26.1-cp310-cp310-win32.whl", hash = "sha256:d1cfc92db6af1fd37a7bb58e55c8383b4aa1ba23d012bdbba26b4bcca45ac297"}, - {file = "numpy-1.26.1-cp310-cp310-win_amd64.whl", hash = "sha256:d2984cb6caaf05294b8466966627e80bf6c7afd273279077679cb010acb0e5ab"}, - {file = "numpy-1.26.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cd7837b2b734ca72959a1caf3309457a318c934abef7a43a14bb984e574bbb9a"}, - {file = "numpy-1.26.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1c59c046c31a43310ad0199d6299e59f57a289e22f0f36951ced1c9eac3665b9"}, - {file = "numpy-1.26.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d58e8c51a7cf43090d124d5073bc29ab2755822181fcad978b12e144e5e5a4b3"}, - {file = "numpy-1.26.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6081aed64714a18c72b168a9276095ef9155dd7888b9e74b5987808f0dd0a974"}, - {file = "numpy-1.26.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:97e5d6a9f0702c2863aaabf19f0d1b6c2628fbe476438ce0b5ce06e83085064c"}, - {file = "numpy-1.26.1-cp311-cp311-win32.whl", hash = "sha256:b9d45d1dbb9de84894cc50efece5b09939752a2d75aab3a8b0cef6f3a35ecd6b"}, - {file = "numpy-1.26.1-cp311-cp311-win_amd64.whl", hash = "sha256:3649d566e2fc067597125428db15d60eb42a4e0897fc48d28cb75dc2e0454e53"}, - {file = "numpy-1.26.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:06934e1a22c54636a059215d6da99e23286424f316fddd979f5071093b648668"}, - {file = "numpy-1.26.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:76ff661a867d9272cd2a99eed002470f46dbe0943a5ffd140f49be84f68ffc42"}, - {file = "numpy-1.26.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:6965888d65d2848e8768824ca8288db0a81263c1efccec881cb35a0d805fcd2f"}, - {file = "numpy-1.26.1.tar.gz", hash = "sha256:c8c6c72d4a9f831f328efb1312642a1cafafaa88981d9ab76368d50d07d93cbe"}, + {file = "numpy-1.26.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b96e7b9c624ef3ae2ae0e04fa9b460f6b9f17ad8b4bec6d7756510f1f6c0c841"}, + {file = "numpy-1.26.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aa18428111fb9a591d7a9cc1b48150097ba6a7e8299fb56bdf574df650e7d1f1"}, + {file = "numpy-1.26.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:06fa1ed84aa60ea6ef9f91ba57b5ed963c3729534e6e54055fc151fad0423f0a"}, + {file = "numpy-1.26.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:96ca5482c3dbdd051bcd1fce8034603d6ebfc125a7bd59f55b40d8f5d246832b"}, + {file = "numpy-1.26.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:854ab91a2906ef29dc3925a064fcd365c7b4da743f84b123002f6139bcb3f8a7"}, + {file = "numpy-1.26.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f43740ab089277d403aa07567be138fc2a89d4d9892d113b76153e0e412409f8"}, + {file = "numpy-1.26.2-cp311-cp311-win32.whl", hash = "sha256:a2bbc29fcb1771cd7b7425f98b05307776a6baf43035d3b80c4b0f29e9545186"}, + {file = "numpy-1.26.2-cp311-cp311-win_amd64.whl", hash = "sha256:2b3fca8a5b00184828d12b073af4d0fc5fdd94b1632c2477526f6bd7842d700d"}, + {file = "numpy-1.26.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:1cc3d5029a30fb5f06704ad6b23b35e11309491c999838c31f124fee32107c79"}, + {file = "numpy-1.26.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:94cc3c222bb9fb5a12e334d0479b97bb2df446fbe622b470928f5284ffca3f8d"}, + {file = "numpy-1.26.2-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:fe6b44fb8fcdf7eda4ef4461b97b3f63c466b27ab151bec2366db8b197387841"}, + {file = "numpy-1.26.2.tar.gz", hash = "sha256:f65738447676ab5777f11e6bbbdb8ce11b785e105f690bc45966574816b6d3ea"}, ] [[package]] @@ -159,6 +143,16 @@ files = [ {file = "opencv_python-4.8.1.78-cp37-abi3-win_amd64.whl", hash = "sha256:b983197f97cfa6fcb74e1da1802c7497a6f94ed561aba6980f1f33123f904956"}, ] +[[package]] +name = "packaging" +version = "23.2" +requires_python = ">=3.7" +summary = "Core utilities for Python packages" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + [[package]] name = "pathvalidate" version = "3.2.0" @@ -175,15 +169,6 @@ version = "10.1.0" requires_python = ">=3.8" summary = "Python Imaging Library (Fork)" files = [ - {file = "Pillow-10.1.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:1ab05f3db77e98f93964697c8efc49c7954b08dd61cff526b7f2531a22410106"}, - {file = "Pillow-10.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:6932a7652464746fcb484f7fc3618e6503d2066d853f68a4bd97193a3996e273"}, - {file = "Pillow-10.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5f63b5a68daedc54c7c3464508d8c12075e56dcfbd42f8c1bf40169061ae666"}, - {file = "Pillow-10.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c0949b55eb607898e28eaccb525ab104b2d86542a85c74baf3a6dc24002edec2"}, - {file = "Pillow-10.1.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:ae88931f93214777c7a3aa0a8f92a683f83ecde27f65a45f95f22d289a69e593"}, - {file = "Pillow-10.1.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:b0eb01ca85b2361b09480784a7931fc648ed8b7836f01fb9241141b968feb1db"}, - {file = "Pillow-10.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d27b5997bdd2eb9fb199982bb7eb6164db0426904020dc38c10203187ae2ff2f"}, - {file = "Pillow-10.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:7df5608bc38bd37ef585ae9c38c9cd46d7c81498f086915b0f97255ea60c2818"}, - {file = "Pillow-10.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:41f67248d92a5e0a2076d3517d8d4b1e41a97e2df10eb8f93106c89107f38b57"}, {file = "Pillow-10.1.0-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:1fb29c07478e6c06a46b867e43b0bcdb241b44cc52be9bc25ce5944eed4648e7"}, {file = "Pillow-10.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2cdc65a46e74514ce742c2013cd4a2d12e8553e3a2563c64879f7c7e4d28bce7"}, {file = "Pillow-10.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:50d08cd0a2ecd2a8657bd3d82c71efd5a58edb04d9308185d66c3a5a5bed9610"}, @@ -212,6 +197,9 @@ summary = "Blazingly fast DataFrame library" files = [ {file = "polars-0.19.13-cp38-abi3-macosx_10_12_x86_64.whl", hash = "sha256:583cbd01911936cdfa5bf2310944f4737f6c8fefdc1823f8efd559e6f4ea8df7"}, {file = "polars-0.19.13-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:f08605a4d1a6cf595c8a1617d33e4d096957a82835e43aa714cf7626aa9cfb4b"}, + {file = "polars-0.19.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fb8a39ca0e4ff953004e4fa34dbb76a9d19546cc20106fc87c51f6154fc09840"}, + {file = "polars-0.19.13-cp38-abi3-manylinux_2_24_aarch64.whl", hash = "sha256:2342a090de16ffafe7cd37f66d77216a8c7bcc2fdd6471afbe349d97612c730d"}, + {file = "polars-0.19.13-cp38-abi3-manylinux_2_24_x86_64.whl", hash = "sha256:79449978d68301211e104bc135e57967d3d505f59d438aa0d04c4f2503f84ef2"}, {file = "polars-0.19.13-cp38-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:141c131a53601fbde506c0ec8609feab1e1075b4aa027421d7c9d4e4774e54ee"}, {file = "polars-0.19.13-cp38-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:b34b19b3734bfc6b33fbb9aa0a53f13138d765ca2ebf5e59442d0c38dac55db0"}, {file = "polars-0.19.13-cp38-abi3-win_amd64.whl", hash = "sha256:605ba001415f140ba157d1c121658e5f500e3cb0f69a5cc96790c2fd408d1065"}, @@ -227,13 +215,6 @@ dependencies = [ "numpy>=1.16.6", ] files = [ - {file = "pyarrow-13.0.0-cp310-cp310-macosx_10_14_x86_64.whl", hash = "sha256:1afcc2c33f31f6fb25c92d50a86b7a9f076d38acbcb6f9e74349636109550148"}, - {file = "pyarrow-13.0.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:70fa38cdc66b2fc1349a082987f2b499d51d072faaa6b600f71931150de2e0e3"}, - {file = "pyarrow-13.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cd57b13a6466822498238877892a9b287b0a58c2e81e4bdb0b596dbb151cbb73"}, - {file = "pyarrow-13.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f8ce69f7bf01de2e2764e14df45b8404fc6f1a5ed9871e8e08a12169f87b7a26"}, - {file = "pyarrow-13.0.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:588f0d2da6cf1b1680974d63be09a6530fd1bd825dc87f76e162404779a157dc"}, - {file = "pyarrow-13.0.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:6241afd72b628787b4abea39e238e3ff9f34165273fad306c7acf780dd850956"}, - {file = "pyarrow-13.0.0-cp310-cp310-win_amd64.whl", hash = "sha256:fda7857e35993673fcda603c07d43889fca60a5b254052a462653f8656c64f44"}, {file = "pyarrow-13.0.0-cp311-cp311-macosx_10_14_x86_64.whl", hash = "sha256:aac0ae0146a9bfa5e12d87dda89d9ef7c57a96210b899459fc2f785303dcbb67"}, {file = "pyarrow-13.0.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d7759994217c86c161c6a8060509cfdf782b952163569606bb373828afdd82e8"}, {file = "pyarrow-13.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:868a073fd0ff6468ae7d869b5fc1f54de5c4255b37f44fb890385eb68b68f95d"}, diff --git a/pyproject.toml b/pyproject.toml index 1b8ecd8..cb425bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,3 +71,11 @@ target-version = "py311" [tool.isort] profile = "black" + +[tool.pylint] +disable = [ + "C0114", # missing-module-docstring + "C0115", # missing-class-docstring + "C0116", # missing-function-docstring +] +max-line-length = 120 diff --git a/src/imdataset_creator/configs/keyworded.py b/src/imdataset_creator/configs/keyworded.py index 48360ec..de31ddd 100644 --- a/src/imdataset_creator/configs/keyworded.py +++ b/src/imdataset_creator/configs/keyworded.py @@ -39,7 +39,5 @@ def _obj_to_comment(obj) -> str: return "" def __repr__(self) -> str: - attrlist: list[str] = [ - f"{key}={val!r}" for key, val in vars(self).items() if all(k not in key for k in ("__",)) - ] + attrlist = [f"{key}={val!r}" for key, val in vars(self).items() if all(k not in key for k in ("__",))] return f"{self.__class__.__name__}({', '.join(attrlist)})" diff --git a/src/imdataset_creator/datarules/base_rules.py b/src/imdataset_creator/datarules/base_rules.py index ae15afe..65b82c0 100644 --- a/src/imdataset_creator/datarules/base_rules.py +++ b/src/imdataset_creator/datarules/base_rules.py @@ -176,7 +176,7 @@ class Input(Keyworded): @classmethod def from_cfg(cls, cfg: InputData): - return cls(Path(cfg["folder"]).expanduser(), cfg["expressions"]) + return cls(Path(cfg.get("folder", ".")).expanduser(), cfg["expressions"]) def run(self) -> PathGenerator: """ @@ -300,7 +300,7 @@ def combine_expr_conds(exprs: Iterable[Expr]) -> Expr: Parameters ---------- - exprs : list[Expr] + exprs : Iterable[Expr] A list of `Expr` objects to be combined. Returns diff --git a/src/imdataset_creator/datarules/dataset_builder.py b/src/imdataset_creator/datarules/dataset_builder.py index 18236b9..a49df56 100644 --- a/src/imdataset_creator/datarules/dataset_builder.py +++ b/src/imdataset_creator/datarules/dataset_builder.py @@ -2,7 +2,7 @@ import os import textwrap import warnings -from collections.abc import Collection, Generator, Iterable +from collections.abc import Collection, Container, Generator, Iterable, Mapping from datetime import datetime from io import BytesIO from pathlib import Path @@ -80,7 +80,7 @@ def combine_matchers( yield combination -def blacklist_schema(schema: ProducerSchema, blacklist: Collection) -> ProducerSchema: +def blacklist_schema(schema: ProducerSchema, blacklist: Container[str]) -> ProducerSchema: return [out for dct in schema if (out := {k: v for k, v in dct.items() if k not in blacklist})] @@ -129,7 +129,7 @@ def add_producers(self, *producers: Producer): for producer in producers: self.add_producer(producer) - def fill_from_config(self, cfg: dict[str, dict], no_warn=False): + def fill_from_config(self, cfg: Mapping[str, dict], no_warn=False): if not len(self.unready_rules): return @@ -277,7 +277,7 @@ def get_unfinished(self) -> LazyFrame: def get_unfinished_existing(self) -> LazyFrame: return self.get_unfinished().filter(pl.col("path").apply(os.path.exists)) - def filter(self, lst) -> DataFrame: # noqa: A003 + def filter(self, lst: Collection[str]) -> DataFrame: # noqa: A003 if len(self.unready_rules): warnings.warn( f"{len(self.unready_rules)} filters are not initialized and will not be populated", diff --git a/src/imdataset_creator/datarules/image_rules.py b/src/imdataset_creator/datarules/image_rules.py index 88b8379..cf6773b 100644 --- a/src/imdataset_creator/datarules/image_rules.py +++ b/src/imdataset_creator/datarules/image_rules.py @@ -29,9 +29,18 @@ def whash_db4(img) -> imagehash.ImageHash: return imagehash.whash(img, mode="db4") -def get_hwc(pth): +def _get_hwc(pth): img = Image.open(pth) - return {"width": img.width, "height": img.height, "channels": len(img.getbands())} + return img.height, img.width, len(img.getbands()) + + +def get_hwc(pth): + h, w, c = _get_hwc(pth) + return { + "height": h, + "width": w, + "channels": c, + } class ImShapeProducer(Producer): diff --git a/src/imdataset_creator/gui/__main__.py b/src/imdataset_creator/gui/__main__.py index fa4d1d8..577f3d3 100644 --- a/src/imdataset_creator/gui/__main__.py +++ b/src/imdataset_creator/gui/__main__.py @@ -1,5 +1,3 @@ -# this is one of those words that look weird when you hear it a lot - import logging import os import sys diff --git a/src/imdataset_creator/gui/config_inputs.py b/src/imdataset_creator/gui/config_inputs.py index e6ca7fd..3e78dd4 100644 --- a/src/imdataset_creator/gui/config_inputs.py +++ b/src/imdataset_creator/gui/config_inputs.py @@ -3,6 +3,7 @@ import contextlib import functools from copy import deepcopy as objcopy +from typing import Generic, Iterable, TypeVar from PySide6.QtCore import QRect, Qt, Signal, Slot from PySide6.QtGui import QAction, QMouseEvent @@ -403,7 +404,7 @@ def get_cfg(self) -> list[ItemConfig]: for item in self.items ] - def add_from_cfg(self, lst: list[ItemConfig]): + def add_from_cfg(self, lst: Iterable[ItemConfig]): for new_item in lst: item: ProceduralConfigItem = ProceduralConfigItem(self.registered_items[new_item["name"]], self) item.from_cfg(new_item["data"]) @@ -446,11 +447,14 @@ def get_settings(self): return ProceduralFlowListSettings(*self.items, parent=self.parent) -class ItemDeclaration: +T = TypeVar("T", bound=Keyworded, covariant=True) + + +class ItemDeclaration(Generic[T]): def __init__( self, title: str, - bound_item: type[Keyworded], + bound_item: type[T], desc: str | None = None, settings: ItemSettings | None = None, duplicable=True, @@ -468,4 +472,4 @@ def create_settings_widget(self, parent=None): def get(self, box: SettingsBox | None = None): if box is None: return self.bound_item() - return self.bound_item.from_cfg(box) + return self.bound_item.from_cfg(box.get_cfg()) diff --git a/src/imdataset_creator/gui/input_view.py b/src/imdataset_creator/gui/input_view.py index 1403340..a902440 100644 --- a/src/imdataset_creator/gui/input_view.py +++ b/src/imdataset_creator/gui/input_view.py @@ -19,7 +19,7 @@ ".tif", ) -InputView_ = ItemDeclaration( +InputView_ = ItemDeclaration[Input]( "Input", Input, settings=ItemSettings( diff --git a/src/imdataset_creator/gui/output_view.py b/src/imdataset_creator/gui/output_view.py index 2256a8b..cd7d2e0 100644 --- a/src/imdataset_creator/gui/output_view.py +++ b/src/imdataset_creator/gui/output_view.py @@ -3,6 +3,7 @@ from PySide6.QtCore import Qt from ..datarules import Output +from ..datarules.base_rules import Filter from ..image_filters import destroyers, resizer from .config_inputs import ItemDeclaration, ProceduralConfigList, ProceduralFlowListInput from .settings_inputs import ( @@ -47,7 +48,10 @@ def div_100(val): return val / 100 -ResizeFilterView_ = ItemDeclaration( +FilterDeclaration = ItemDeclaration[Filter] + + +ResizeFilterView_ = FilterDeclaration( "Resize", resizer.Resize, settings=ItemSettings( @@ -65,7 +69,7 @@ def div_100(val): ), ) -CropFilterView_ = ItemDeclaration( +CropFilterView_ = FilterDeclaration( "Crop", resizer.Crop, desc="Crop the image to the specified size. If the item is 0, it will not be considered", @@ -80,7 +84,7 @@ def div_100(val): ) -BlurFilterView_ = ItemDeclaration( +BlurFilterView_ = FilterDeclaration( "Blur", destroyers.Blur, settings=ItemSettings( @@ -92,7 +96,7 @@ def div_100(val): ), ) -NoiseFilterView_ = ItemDeclaration( +NoiseFilterView_ = FilterDeclaration( "Noise", destroyers.Noise, settings=ItemSettings( @@ -110,7 +114,7 @@ def div_100(val): ) -CompressionFilterView_ = ItemDeclaration( +CompressionFilterView_ = FilterDeclaration( "Compression", destroyers.Compression, settings=ItemSettings( @@ -126,7 +130,7 @@ def div_100(val): ), ) -RandomFlipFilterView_ = ItemDeclaration( +RandomFlipFilterView_ = FilterDeclaration( "Random Flip", bound_item=resizer.RandomFlip, settings=ItemSettings( @@ -147,7 +151,7 @@ def div_100(val): ), ) -RandomRotateFilterView_ = ItemDeclaration( +RandomRotateFilterView_ = FilterDeclaration( "Random Rotate", bound_item=resizer.RandomRotate, settings=ItemSettings( diff --git a/src/imdataset_creator/gui/settings_inputs.py b/src/imdataset_creator/gui/settings_inputs.py index 48790bd..6c9330d 100644 --- a/src/imdataset_creator/gui/settings_inputs.py +++ b/src/imdataset_creator/gui/settings_inputs.py @@ -4,9 +4,9 @@ from collections.abc import Callable from enum import Enum from pathlib import Path -from typing import Any +from typing import Any, Literal -from PySide6.QtCore import QDate, QDateTime, QRect, QSize, Qt, QTime, Signal, Slot +from PySide6.QtCore import QDate, QDateTime, QObject, QRect, QSize, Qt, QTime, Signal, Slot from PySide6.QtGui import QAction, QFont, QIcon, QMouseEvent from PySide6.QtWidgets import ( QCheckBox, @@ -85,7 +85,8 @@ def __init__( self.from_config_mod = from_config_mod self.to_config_mod = to_config_mod self.item: SettingsItem = item - for widget in self.create_widgets(): + self.widgets = self.create_widgets() + for widget in self.widgets: self.addWidget(widget) @abstractmethod @@ -523,10 +524,17 @@ def get_settings(self): return DateTimeInputSettings(self.format, self.default, self.calendar_popup) -class DirectoryInputSettings(SettingsItem): - def __init__(self, default: str = ""): +class FileInputSettings(SettingsItem): + def __init__(self, default: str = "", mode: Literal["directory", "file"] = "directory"): super().__init__() self.default = default + self.filemode = { + "directory": QFileDialog.FileMode.Directory, + "file": QFileDialog.FileMode.ExistingFile, + }.get( + mode, + QFileDialog.FileMode.Directory, + ) def create(self): self.text_widget: QLineEdit = QLineEdit() @@ -537,9 +545,9 @@ def create(self): self.folder_select.setIcon(QIcon.fromTheme("folder-open")) self.folder_select.clicked.connect(self.select_folder) self.filedialog = QFileDialog() - self.filedialog.setFileMode(QFileDialog.FileMode.Directory) - self.filedialog.setOption(QFileDialog.Option.ShowDirsOnly, True) - self.filedialog.setOption(QFileDialog.Option.DontResolveSymlinks, True) + self.filedialog.setFileMode(self.filemode) + if self.filemode is QFileDialog.FileMode.Directory: + self.filedialog.setOption(QFileDialog.Option.ShowDirsOnly, True) return [self.text_widget, self.folder_select] @@ -576,7 +584,12 @@ def __init__(self, default: str = ""): self.default = default def get_settings(self): - return DirectoryInputSettings(self.default) + return FileInputSettings(self.default, mode="directory") + + +class FileInput(DirectoryInput): + def get_settings(self): + return FileInputSettings(self.default, mode="file") ItemSettings = dict[str | tuple[str, ...], BaseInput] diff --git a/src/imdataset_creator/image_filters/destroyers.py b/src/imdataset_creator/image_filters/destroyers.py index da6e36f..0b74980 100644 --- a/src/imdataset_creator/image_filters/destroyers.py +++ b/src/imdataset_creator/image_filters/destroyers.py @@ -45,7 +45,6 @@ def run( ) -> np.ndarray: algorithms = self.algorithms or [BlurAlgorithm.AVERAGE] algorithm: BlurAlgorithm = choice(algorithms) - start, stop = self.blur_range ri = randint(start, stop) ksize: int