diff --git a/tagstudio/src/core/library/alchemy/enums.py b/tagstudio/src/core/library/alchemy/enums.py index 7c70f92e6..08cf09dcb 100644 --- a/tagstudio/src/core/library/alchemy/enums.py +++ b/tagstudio/src/core/library/alchemy/enums.py @@ -3,6 +3,7 @@ from pathlib import Path +# TODO: REMOVE class TagColor(enum.IntEnum): DEFAULT = 1 BLACK = 2 @@ -42,12 +43,19 @@ class TagColor(enum.IntEnum): COOL_GRAY = 36 OLIVE = 37 - @staticmethod - def get_color_from_str(color_name: str) -> "TagColor": - for color in TagColor: - if color.name == color_name.upper().replace(" ", "_"): - return color - return TagColor.DEFAULT +#class TSStandardColors(enum.IntEnum): +# RED=1, +# YELLOW=2, +# CYAN=3, +# BLUE=4 +# #etc.. + +# @staticmethod +# def get_color_from_str(color_name: str) -> "TagColor": +# for color in TagColor: +# if color.name == color_name.upper().replace(" ", "_"): +# return color +# return TagColor.DEFAULT class SearchMode(enum.IntEnum): diff --git a/tagstudio/src/core/library/alchemy/library.py b/tagstudio/src/core/library/alchemy/library.py index 16d5f9c3c..fec38a6fd 100644 --- a/tagstudio/src/core/library/alchemy/library.py +++ b/tagstudio/src/core/library/alchemy/library.py @@ -52,7 +52,7 @@ _FieldID, ) from .joins import TagField, TagSubtag -from .models import Entry, Folder, Preferences, Tag, TagAlias, ValueType +from .models import Entry, Folder, Preferences, Tag, TagAlias, ValueType, Color, ColorNamespace logger = structlog.get_logger(__name__) @@ -91,6 +91,16 @@ def get_default_tags() -> tuple[Tag, ...]: return archive_tag, favorite_tag +def get_default_colors(namespace: ColorNamespace) -> list[Color]: + colors: list[Color] = [ + #TODO: make this the full tagstudio standard color set + Color(slug='red', hex_value="#e22c3c", name="RED", namespace_id=namespace.id), + Color(slug='yellow', hex_value="#ffd63d", name="YELLOW", namespace_id=namespace.id), + ] + + return colors + + @dataclass(frozen=True) class SearchResult: """Wrapper for search results. @@ -256,6 +266,7 @@ def open_sqlite_library( if add_default_data: tags = get_default_tags() + try: session.add_all(tags) session.commit() @@ -263,6 +274,27 @@ def open_sqlite_library( # default tags may exist already session.rollback() + #the default namespace shouldnt exist yet but we will check anyway + ts_std_namespace_name = "tagstudio_std" #TODO: move this elsewhere maybe + statement = select(ColorNamespace).where(ColorNamespace.name == ts_std_namespace_name) + ts_std_namespace = session.scalar(statement) + + if ts_std_namespace is None: + ts_std_namespace = ColorNamespace(name=ts_std_namespace_name) + session.add(ts_std_namespace) + session.commit() + + try: + colors = get_default_colors(ts_std_namespace) + session.add_all( + colors + ) + session.commit() + except IntegrityError: + #colors already exist + session.rollback() + + # dont check db version when creating new library if not is_new: db_version = session.scalar( diff --git a/tagstudio/src/core/library/alchemy/models.py b/tagstudio/src/core/library/alchemy/models.py index 8da0c4708..195710568 100644 --- a/tagstudio/src/core/library/alchemy/models.py +++ b/tagstudio/src/core/library/alchemy/models.py @@ -1,6 +1,6 @@ from pathlib import Path -from sqlalchemy import JSON, ForeignKey, Integer, event +from sqlalchemy import JSON, ForeignKey, Integer, event, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column, relationship from ...constants import TAG_ARCHIVED, TAG_FAVORITE @@ -211,6 +211,21 @@ def remove_tag(self, tag: Tag, field: TagBoxField | None = None) -> None: for tag_box_field in self.tag_box_fields: tag_box_field.tags.remove(tag) +#TODO: maybe make this a general namespace to be used for colors, tags, etc? +class ColorNamespace(Base): + __tablename__ = "color_namespaces" + id: Mapped[int] = mapped_column(primary_key=True) + name: Mapped[str] = mapped_column() + colors: Mapped[list["Color"]] = relationship() + +class Color(Base): + __tablename__ = "colors" + + slug: Mapped[str] = mapped_column(primary_key=True) + namespace_id: Mapped[int] = mapped_column(ForeignKey("color_namespaces.id"), primary_key = True) + + hex_value: Mapped[str] = mapped_column() + name: Mapped[str] = mapped_column() class ValueType(Base): """Define Field Types in the Library. diff --git a/tagstudio/src/core/palette.py b/tagstudio/src/core/palette.py index 422b35f7c..23855bb16 100644 --- a/tagstudio/src/core/palette.py +++ b/tagstudio/src/core/palette.py @@ -27,346 +27,348 @@ class UiColor(IntEnum): GREEN = 4 PURPLE = 5 +# keeping tag_colors and ui_colors around for future reference during migration to new Color model +# but they should be deleted eventually -TAG_COLORS: dict[TagColor, dict[ColorType, Any]] = { - TagColor.DEFAULT: { - ColorType.PRIMARY: "#1e1e1e", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#333333", - ColorType.LIGHT_ACCENT: "#FFFFFF", - ColorType.DARK_ACCENT: "#222222", - }, - TagColor.BLACK: { - ColorType.PRIMARY: "#111018", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#18171e", - ColorType.LIGHT_ACCENT: "#b7b6be", - ColorType.DARK_ACCENT: "#03020a", - }, - TagColor.DARK_GRAY: { - ColorType.PRIMARY: "#24232a", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#2a2930", - ColorType.LIGHT_ACCENT: "#bdbcc4", - ColorType.DARK_ACCENT: "#07060e", - }, - TagColor.GRAY: { - ColorType.PRIMARY: "#53525a", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#5b5a62", - ColorType.LIGHT_ACCENT: "#cbcad2", - ColorType.DARK_ACCENT: "#191820", - }, - TagColor.LIGHT_GRAY: { - ColorType.PRIMARY: "#aaa9b0", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#b6b4bc", - ColorType.LIGHT_ACCENT: "#cbcad2", - ColorType.DARK_ACCENT: "#191820", - }, - TagColor.WHITE: { - ColorType.PRIMARY: "#f2f1f8", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#fefeff", - ColorType.LIGHT_ACCENT: "#ffffff", - ColorType.DARK_ACCENT: "#302f36", - }, - TagColor.LIGHT_PINK: { - ColorType.PRIMARY: "#ff99c4", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#ffaad0", - ColorType.LIGHT_ACCENT: "#ffcbe7", - ColorType.DARK_ACCENT: "#6c2e3b", - }, - TagColor.PINK: { - ColorType.PRIMARY: "#ff99c4", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#ffaad0", - ColorType.LIGHT_ACCENT: "#ffcbe7", - ColorType.DARK_ACCENT: "#6c2e3b", - }, - TagColor.MAGENTA: { - ColorType.PRIMARY: "#f6466f", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#f7587f", - ColorType.LIGHT_ACCENT: "#fba4bf", - ColorType.DARK_ACCENT: "#61152f", - }, - TagColor.RED: { - ColorType.PRIMARY: "#e22c3c", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#b21f2d", - # ColorType.BORDER: '#e54252', - ColorType.LIGHT_ACCENT: "#f39caa", - ColorType.DARK_ACCENT: "#440d12", - }, - TagColor.RED_ORANGE: { - ColorType.PRIMARY: "#e83726", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#ea4b3b", - ColorType.LIGHT_ACCENT: "#f5a59d", - ColorType.DARK_ACCENT: "#61120b", - }, - TagColor.SALMON: { - ColorType.PRIMARY: "#f65848", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#f76c5f", - ColorType.LIGHT_ACCENT: "#fcadaa", - ColorType.DARK_ACCENT: "#6f1b16", - }, - TagColor.ORANGE: { - ColorType.PRIMARY: "#ed6022", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#ef7038", - ColorType.LIGHT_ACCENT: "#f7b79b", - ColorType.DARK_ACCENT: "#551e0a", - }, - TagColor.YELLOW_ORANGE: { - ColorType.PRIMARY: "#fa9a2c", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#fba94b", - ColorType.LIGHT_ACCENT: "#fdd7ab", - ColorType.DARK_ACCENT: "#66330d", - }, - TagColor.YELLOW: { - ColorType.PRIMARY: "#ffd63d", - ColorType.TEXT: ColorType.DARK_ACCENT, - # ColorType.BORDER: '#ffe071', - ColorType.BORDER: "#e8af31", - ColorType.LIGHT_ACCENT: "#fff3c4", - ColorType.DARK_ACCENT: "#754312", - }, - TagColor.MINT: { - ColorType.PRIMARY: "#4aed90", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#79f2b1", - ColorType.LIGHT_ACCENT: "#c8fbe9", - ColorType.DARK_ACCENT: "#164f3e", - }, - TagColor.LIME: { - ColorType.PRIMARY: "#92e649", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#b2ed72", - ColorType.LIGHT_ACCENT: "#e9f9b7", - ColorType.DARK_ACCENT: "#405516", - }, - TagColor.LIGHT_GREEN: { - ColorType.PRIMARY: "#85ec76", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#a3f198", - ColorType.LIGHT_ACCENT: "#e7fbe4", - ColorType.DARK_ACCENT: "#2b5524", - }, - TagColor.GREEN: { - ColorType.PRIMARY: "#28bb48", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#43c568", - ColorType.LIGHT_ACCENT: "#93e2c8", - ColorType.DARK_ACCENT: "#0d3828", - }, - TagColor.TEAL: { - ColorType.PRIMARY: "#1ad9b2", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#4de3c7", - ColorType.LIGHT_ACCENT: "#a0f3e8", - ColorType.DARK_ACCENT: "#08424b", - }, - TagColor.CYAN: { - ColorType.PRIMARY: "#49e4d5", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#76ebdf", - ColorType.LIGHT_ACCENT: "#bff5f0", - ColorType.DARK_ACCENT: "#0f4246", - }, - TagColor.LIGHT_BLUE: { - ColorType.PRIMARY: "#55bbf6", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#70c6f7", - ColorType.LIGHT_ACCENT: "#bbe4fb", - ColorType.DARK_ACCENT: "#122541", - }, - TagColor.BLUE: { - ColorType.PRIMARY: "#3b87f0", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#4e95f2", - ColorType.LIGHT_ACCENT: "#aedbfa", - ColorType.DARK_ACCENT: "#122948", - }, - TagColor.BLUE_VIOLET: { - ColorType.PRIMARY: "#5948f2", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#6258f3", - ColorType.LIGHT_ACCENT: "#9cb8fb", - ColorType.DARK_ACCENT: "#1b1649", - }, - TagColor.VIOLET: { - ColorType.PRIMARY: "#874ff5", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#9360f6", - ColorType.LIGHT_ACCENT: "#c9b0fa", - ColorType.DARK_ACCENT: "#3a1860", - }, - TagColor.PURPLE: { - ColorType.PRIMARY: "#bb4ff0", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#c364f2", - ColorType.LIGHT_ACCENT: "#dda7f7", - ColorType.DARK_ACCENT: "#531862", - }, - TagColor.PEACH: { - ColorType.PRIMARY: "#f1c69c", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#f4d4b4", - ColorType.LIGHT_ACCENT: "#fbeee1", - ColorType.DARK_ACCENT: "#613f2f", - }, - TagColor.BROWN: { - ColorType.PRIMARY: "#823216", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#8a3e22", - ColorType.LIGHT_ACCENT: "#cd9d83", - ColorType.DARK_ACCENT: "#3a1804", - }, - TagColor.LAVENDER: { - ColorType.PRIMARY: "#ad8eef", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#b99ef2", - ColorType.LIGHT_ACCENT: "#d5c7fa", - ColorType.DARK_ACCENT: "#492b65", - }, - TagColor.BLONDE: { - ColorType.PRIMARY: "#efc664", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#f3d387", - ColorType.LIGHT_ACCENT: "#faebc6", - ColorType.DARK_ACCENT: "#6d461e", - }, - TagColor.AUBURN: { - ColorType.PRIMARY: "#a13220", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#aa402f", - ColorType.LIGHT_ACCENT: "#d98a7f", - ColorType.DARK_ACCENT: "#3d100a", - }, - TagColor.LIGHT_BROWN: { - ColorType.PRIMARY: "#be5b2d", - ColorType.TEXT: ColorType.DARK_ACCENT, - ColorType.BORDER: "#c4693d", - ColorType.LIGHT_ACCENT: "#e5b38c", - ColorType.DARK_ACCENT: "#4c290e", - }, - TagColor.DARK_BROWN: { - ColorType.PRIMARY: "#4c2315", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#542a1c", - ColorType.LIGHT_ACCENT: "#b78171", - ColorType.DARK_ACCENT: "#211006", - }, - TagColor.COOL_GRAY: { - ColorType.PRIMARY: "#515768", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#5b6174", - ColorType.LIGHT_ACCENT: "#9ea1c3", - ColorType.DARK_ACCENT: "#181a37", - }, - TagColor.WARM_GRAY: { - ColorType.PRIMARY: "#625550", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#6c5e57", - ColorType.LIGHT_ACCENT: "#c0a392", - ColorType.DARK_ACCENT: "#371d18", - }, - TagColor.OLIVE: { - ColorType.PRIMARY: "#4c652e", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#586f36", - ColorType.LIGHT_ACCENT: "#b4c17a", - ColorType.DARK_ACCENT: "#23300e", - }, - TagColor.BERRY: { - ColorType.PRIMARY: "#9f2aa7", - ColorType.TEXT: ColorType.LIGHT_ACCENT, - ColorType.BORDER: "#aa43b4", - ColorType.LIGHT_ACCENT: "#cc8fdc", - ColorType.DARK_ACCENT: "#41114a", - }, -} +#TAG_COLORS: dict[TagColor, dict[ColorType, Any]] = { +# TagColor.DEFAULT: { +# ColorType.PRIMARY: "#1e1e1e", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#333333", +# ColorType.LIGHT_ACCENT: "#FFFFFF", +# ColorType.DARK_ACCENT: "#222222", +# }, +# TagColor.BLACK: { +# ColorType.PRIMARY: "#111018", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#18171e", +# ColorType.LIGHT_ACCENT: "#b7b6be", +# ColorType.DARK_ACCENT: "#03020a", +# }, +# TagColor.DARK_GRAY: { +# ColorType.PRIMARY: "#24232a", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#2a2930", +# ColorType.LIGHT_ACCENT: "#bdbcc4", +# ColorType.DARK_ACCENT: "#07060e", +# }, +# TagColor.GRAY: { +# ColorType.PRIMARY: "#53525a", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#5b5a62", +# ColorType.LIGHT_ACCENT: "#cbcad2", +# ColorType.DARK_ACCENT: "#191820", +# }, +# TagColor.LIGHT_GRAY: { +# ColorType.PRIMARY: "#aaa9b0", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#b6b4bc", +# ColorType.LIGHT_ACCENT: "#cbcad2", +# ColorType.DARK_ACCENT: "#191820", +# }, +# TagColor.WHITE: { +# ColorType.PRIMARY: "#f2f1f8", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#fefeff", +# ColorType.LIGHT_ACCENT: "#ffffff", +# ColorType.DARK_ACCENT: "#302f36", +# }, +# TagColor.LIGHT_PINK: { +# ColorType.PRIMARY: "#ff99c4", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#ffaad0", +# ColorType.LIGHT_ACCENT: "#ffcbe7", +# ColorType.DARK_ACCENT: "#6c2e3b", +# }, +# TagColor.PINK: { +# ColorType.PRIMARY: "#ff99c4", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#ffaad0", +# ColorType.LIGHT_ACCENT: "#ffcbe7", +# ColorType.DARK_ACCENT: "#6c2e3b", +# }, +# TagColor.MAGENTA: { +# ColorType.PRIMARY: "#f6466f", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#f7587f", +# ColorType.LIGHT_ACCENT: "#fba4bf", +# ColorType.DARK_ACCENT: "#61152f", +# }, +# TagColor.RED: { +# ColorType.PRIMARY: "#e22c3c", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#b21f2d", +# # ColorType.BORDER: '#e54252', +# ColorType.LIGHT_ACCENT: "#f39caa", +# ColorType.DARK_ACCENT: "#440d12", +# }, +# TagColor.RED_ORANGE: { +# ColorType.PRIMARY: "#e83726", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#ea4b3b", +# ColorType.LIGHT_ACCENT: "#f5a59d", +# ColorType.DARK_ACCENT: "#61120b", +# }, +# TagColor.SALMON: { +# ColorType.PRIMARY: "#f65848", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#f76c5f", +# ColorType.LIGHT_ACCENT: "#fcadaa", +# ColorType.DARK_ACCENT: "#6f1b16", +# }, +# TagColor.ORANGE: { +# ColorType.PRIMARY: "#ed6022", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#ef7038", +# ColorType.LIGHT_ACCENT: "#f7b79b", +# ColorType.DARK_ACCENT: "#551e0a", +# }, +# TagColor.YELLOW_ORANGE: { +# ColorType.PRIMARY: "#fa9a2c", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#fba94b", +# ColorType.LIGHT_ACCENT: "#fdd7ab", +# ColorType.DARK_ACCENT: "#66330d", +# }, +# TagColor.YELLOW: { +# ColorType.PRIMARY: "#ffd63d", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# # ColorType.BORDER: '#ffe071', +# ColorType.BORDER: "#e8af31", +# ColorType.LIGHT_ACCENT: "#fff3c4", +# ColorType.DARK_ACCENT: "#754312", +# }, +# TagColor.MINT: { +# ColorType.PRIMARY: "#4aed90", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#79f2b1", +# ColorType.LIGHT_ACCENT: "#c8fbe9", +# ColorType.DARK_ACCENT: "#164f3e", +# }, +# TagColor.LIME: { +# ColorType.PRIMARY: "#92e649", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#b2ed72", +# ColorType.LIGHT_ACCENT: "#e9f9b7", +# ColorType.DARK_ACCENT: "#405516", +# }, +# TagColor.LIGHT_GREEN: { +# ColorType.PRIMARY: "#85ec76", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#a3f198", +# ColorType.LIGHT_ACCENT: "#e7fbe4", +# ColorType.DARK_ACCENT: "#2b5524", +# }, +# TagColor.GREEN: { +# ColorType.PRIMARY: "#28bb48", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#43c568", +# ColorType.LIGHT_ACCENT: "#93e2c8", +# ColorType.DARK_ACCENT: "#0d3828", +# }, +# TagColor.TEAL: { +# ColorType.PRIMARY: "#1ad9b2", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#4de3c7", +# ColorType.LIGHT_ACCENT: "#a0f3e8", +# ColorType.DARK_ACCENT: "#08424b", +# }, +# TagColor.CYAN: { +# ColorType.PRIMARY: "#49e4d5", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#76ebdf", +# ColorType.LIGHT_ACCENT: "#bff5f0", +# ColorType.DARK_ACCENT: "#0f4246", +# }, +# TagColor.LIGHT_BLUE: { +# ColorType.PRIMARY: "#55bbf6", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#70c6f7", +# ColorType.LIGHT_ACCENT: "#bbe4fb", +# ColorType.DARK_ACCENT: "#122541", +# }, +# TagColor.BLUE: { +# ColorType.PRIMARY: "#3b87f0", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#4e95f2", +# ColorType.LIGHT_ACCENT: "#aedbfa", +# ColorType.DARK_ACCENT: "#122948", +# }, +# TagColor.BLUE_VIOLET: { +# ColorType.PRIMARY: "#5948f2", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#6258f3", +# ColorType.LIGHT_ACCENT: "#9cb8fb", +# ColorType.DARK_ACCENT: "#1b1649", +# }, +# TagColor.VIOLET: { +# ColorType.PRIMARY: "#874ff5", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#9360f6", +# ColorType.LIGHT_ACCENT: "#c9b0fa", +# ColorType.DARK_ACCENT: "#3a1860", +# }, +# TagColor.PURPLE: { +# ColorType.PRIMARY: "#bb4ff0", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#c364f2", +# ColorType.LIGHT_ACCENT: "#dda7f7", +# ColorType.DARK_ACCENT: "#531862", +# }, +# TagColor.PEACH: { +# ColorType.PRIMARY: "#f1c69c", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#f4d4b4", +# ColorType.LIGHT_ACCENT: "#fbeee1", +# ColorType.DARK_ACCENT: "#613f2f", +# }, +# TagColor.BROWN: { +# ColorType.PRIMARY: "#823216", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#8a3e22", +# ColorType.LIGHT_ACCENT: "#cd9d83", +# ColorType.DARK_ACCENT: "#3a1804", +# }, +# TagColor.LAVENDER: { +# ColorType.PRIMARY: "#ad8eef", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#b99ef2", +# ColorType.LIGHT_ACCENT: "#d5c7fa", +# ColorType.DARK_ACCENT: "#492b65", +# }, +# TagColor.BLONDE: { +# ColorType.PRIMARY: "#efc664", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#f3d387", +# ColorType.LIGHT_ACCENT: "#faebc6", +# ColorType.DARK_ACCENT: "#6d461e", +# }, +# TagColor.AUBURN: { +# ColorType.PRIMARY: "#a13220", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#aa402f", +# ColorType.LIGHT_ACCENT: "#d98a7f", +# ColorType.DARK_ACCENT: "#3d100a", +# }, +# TagColor.LIGHT_BROWN: { +# ColorType.PRIMARY: "#be5b2d", +# ColorType.TEXT: ColorType.DARK_ACCENT, +# ColorType.BORDER: "#c4693d", +# ColorType.LIGHT_ACCENT: "#e5b38c", +# ColorType.DARK_ACCENT: "#4c290e", +# }, +# TagColor.DARK_BROWN: { +# ColorType.PRIMARY: "#4c2315", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#542a1c", +# ColorType.LIGHT_ACCENT: "#b78171", +# ColorType.DARK_ACCENT: "#211006", +# }, +# TagColor.COOL_GRAY: { +# ColorType.PRIMARY: "#515768", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#5b6174", +# ColorType.LIGHT_ACCENT: "#9ea1c3", +# ColorType.DARK_ACCENT: "#181a37", +# }, +# TagColor.WARM_GRAY: { +# ColorType.PRIMARY: "#625550", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#6c5e57", +# ColorType.LIGHT_ACCENT: "#c0a392", +# ColorType.DARK_ACCENT: "#371d18", +# }, +# TagColor.OLIVE: { +# ColorType.PRIMARY: "#4c652e", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#586f36", +# ColorType.LIGHT_ACCENT: "#b4c17a", +# ColorType.DARK_ACCENT: "#23300e", +# }, +# TagColor.BERRY: { +# ColorType.PRIMARY: "#9f2aa7", +# ColorType.TEXT: ColorType.LIGHT_ACCENT, +# ColorType.BORDER: "#aa43b4", +# ColorType.LIGHT_ACCENT: "#cc8fdc", +# ColorType.DARK_ACCENT: "#41114a", +# }, +#} -UI_COLORS: dict[UiColor, dict[ColorType, Any]] = { - UiColor.DEFAULT: { - ColorType.PRIMARY: "#333333", - ColorType.BORDER: "#555555", - ColorType.LIGHT_ACCENT: "#FFFFFF", - ColorType.DARK_ACCENT: "#1e1e1e", - }, - UiColor.RED: { - ColorType.PRIMARY: "#e22c3c", - ColorType.BORDER: "#e54252", - ColorType.LIGHT_ACCENT: "#f39caa", - ColorType.DARK_ACCENT: "#440d12", - }, - UiColor.GREEN: { - ColorType.PRIMARY: "#28bb48", - ColorType.BORDER: "#43c568", - ColorType.LIGHT_ACCENT: "#DDFFCC", - ColorType.DARK_ACCENT: "#0d3828", - }, - UiColor.PURPLE: { - ColorType.PRIMARY: "#C76FF3", - ColorType.BORDER: "#c364f2", - ColorType.LIGHT_ACCENT: "#EFD4FB", - ColorType.DARK_ACCENT: "#3E1555", - }, - UiColor.THEME_DARK: { - ColorType.PRIMARY: "#333333", - ColorType.BORDER: "#555555", - ColorType.LIGHT_ACCENT: "#FFFFFF", - ColorType.DARK_ACCENT: "#1e1e1e", - }, - UiColor.THEME_LIGHT: { - ColorType.PRIMARY: "#FFFFFF", - ColorType.BORDER: "#333333", - ColorType.LIGHT_ACCENT: "#999999", - ColorType.DARK_ACCENT: "#888888", - }, -} +#UI_COLORS: dict[UiColor, dict[ColorType, Any]] = { +# UiColor.DEFAULT: { +# ColorType.PRIMARY: "#333333", +# ColorType.BORDER: "#555555", +# ColorType.LIGHT_ACCENT: "#FFFFFF", +# ColorType.DARK_ACCENT: "#1e1e1e", +# }, +# UiColor.RED: { +# ColorType.PRIMARY: "#e22c3c", +# ColorType.BORDER: "#e54252", +# ColorType.LIGHT_ACCENT: "#f39caa", +# ColorType.DARK_ACCENT: "#440d12", +# }, +# UiColor.GREEN: { +# ColorType.PRIMARY: "#28bb48", +# ColorType.BORDER: "#43c568", +# ColorType.LIGHT_ACCENT: "#DDFFCC", +# ColorType.DARK_ACCENT: "#0d3828", +# }, +# UiColor.PURPLE: { +# ColorType.PRIMARY: "#C76FF3", +# ColorType.BORDER: "#c364f2", +# ColorType.LIGHT_ACCENT: "#EFD4FB", +# ColorType.DARK_ACCENT: "#3E1555", +# }, +# UiColor.THEME_DARK: { +# ColorType.PRIMARY: "#333333", +# ColorType.BORDER: "#555555", +# ColorType.LIGHT_ACCENT: "#FFFFFF", +# ColorType.DARK_ACCENT: "#1e1e1e", +# }, +# UiColor.THEME_LIGHT: { +# ColorType.PRIMARY: "#FFFFFF", +# ColorType.BORDER: "#333333", +# ColorType.LIGHT_ACCENT: "#999999", +# ColorType.DARK_ACCENT: "#888888", +# }, +#} -def get_tag_color(color_type: ColorType, color_id: TagColor) -> str: - """Return a hex value given a tag color name and ColorType. - - Args: - color_type (ColorType): The ColorType category to retrieve from. - color_id (ColorType): The color name enum to retrieve from. - - Return: - A hex value string representing a color with a leading "#". - """ - try: - if color_type == ColorType.TEXT: - text_account: ColorType = TAG_COLORS[color_id][color_type] - return get_tag_color(text_account, color_id) - - return TAG_COLORS[color_id][color_type] - except KeyError: - traceback.print_stack() - logger.error("[PALETTE] Tag color not found.", color_id=color_id) - return "#FF00FF" - - -def get_ui_color(color_type: ColorType, color_id: UiColor) -> str: - """Return a hex value given a UI color name and ColorType. - - Args: - color_type (ColorType): The ColorType category to retrieve from. - color_id (UiColor): The color name enum to retrieve from. - - Return: - A hex value string representing a color with a leading "#". - """ - try: - return UI_COLORS[color_id][color_type] - except KeyError: - traceback.print_stack() - logger.error("[PALETTE] UI color not found", color_id=color_id) - return "#FF00FF" +#def get_tag_color(color_type: ColorType, color_id: TagColor) -> str: +# """Return a hex value given a tag color name and ColorType. +# +# Args: +# color_type (ColorType): The ColorType category to retrieve from. +# color_id (ColorType): The color name enum to retrieve from. +# +# Return: +# A hex value string representing a color with a leading "#". +# """ +# try: +# if color_type == ColorType.TEXT: +# text_account: ColorType = TAG_COLORS[color_id][color_type] +# return get_tag_color(text_account, color_id) +# +# return TAG_COLORS[color_id][color_type] +# except KeyError: +# traceback.print_stack() +# logger.error("[PALETTE] Tag color not found.", color_id=color_id) +# return "#FF00FF" +# +# +#def get_ui_color(color_type: ColorType, color_id: UiColor) -> str: +# """Return a hex value given a UI color name and ColorType. +# +# Args: +# color_type (ColorType): The ColorType category to retrieve from. +# color_id (UiColor): The color name enum to retrieve from. +# +# Return: +# A hex value string representing a color with a leading "#". +# """ +# try: +# return UI_COLORS[color_id][color_type] +# except KeyError: +# traceback.print_stack() +# logger.error("[PALETTE] UI color not found", color_id=color_id) +# return "#FF00FF" diff --git a/tagstudio/src/core/utils/color.py b/tagstudio/src/core/utils/color.py new file mode 100644 index 000000000..c82d624d5 --- /dev/null +++ b/tagstudio/src/core/utils/color.py @@ -0,0 +1,15 @@ +from src.core.library.alchemy.models import Color, ColorNamespace +from src.core.palette import ColorType + +def get_hex_color(color: Color, color_type: ColorType) -> str: + #TODO: everything + if color_type == ColorType.PRIMARY: + return color.hex_value + elif color_type == ColorType.TEXT: + return color.hex_value + elif color_type == ColorType.BORDER: + return color.hex_value + elif color_type == ColorType.LIGHT_ACCENT: + return color.hex_value + elif color_type == ColorType.DARK_ACCENT: + return color.hex_value \ No newline at end of file