Skip to content

feat: Support custom user colors in tags #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/library/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Other Tags that make up properties of this tag. Also called "parent tags".

#### `color`

A color name string for customizing the tag's display color
A color hex string for customizing the tag's display color

- String, Optional
- Used for display
Expand Down
82 changes: 43 additions & 39 deletions tagstudio/src/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,45 +124,49 @@
TEXT_FIELDS = ["text_line", "text_box"]
DATE_FIELDS = ["datetime"]

TAG_COLORS = [
"",
"black",
"dark gray",
"gray",
"light gray",
"white",
"light pink",
"pink",
"red",
"red orange",
"orange",
"yellow orange",
"yellow",
"lime",
"light green",
"mint",
"green",
"teal",
"cyan",
"light blue",
"blue",
"blue violet",
"violet",
"purple",
"lavender",
"berry",
"magenta",
"salmon",
"auburn",
"dark brown",
"brown",
"light brown",
"blonde",
"peach",
"warm gray",
"cool gray",
"olive",
]
DEFAULT_TAG_COLOR = "#f2f1f8"
DEFAULT_FAVORITE_COLOR = "#ffd63d"
DEFAULT_ARCHIVED_COLOR = "#e22c3c"

LEGACY_TAG_COLORS: dict = {
"": "#1e1e1e",
"black": "#111018",
"dark gray": "#24232a",
"gray": "#53525a",
"light gray": "#aaa9b0",
"white": "#f2f1f8",
"light pink": "#ff99c4",
"pink": "#ff99c4",
"red": "#e22c3c",
"red orange": "#e83726",
"orange": "#ed6022",
"yellow orange": "#fa9a2c",
"yellow": "#ffd63d",
"lime": "#92e649",
"light green": "#85ec76",
"mint": "#4aed90",
"green": "#28bb48",
"teal": "#1ad9b2",
"cyan": "#49e4d5",
"light blue": "#55bbf6",
"blue": "#3b87f0",
"blue violet": "#5948f2",
"violet": "#874ff5",
"purple": "#bb4ff0",
"lavender": "#ad8eef",
"berry": "#9f2aa7",
"magenta": "#e83726",
"salmon": "#f65848",
"auburn": "#a13220",
"dark brown": "#4c2315",
"brown": "#823216",
"light brown": "#be5b2d",
"blonde": "#efc664",
"peach": "#f1c69c",
"warm gray": "#625550",
"cool gray": "#515768",
"olive": "#4c652e",
}

TAG_FAVORITE = 1
TAG_ARCHIVED = 0
20 changes: 13 additions & 7 deletions tagstudio/src/core/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
TEXT_FIELDS,
TS_FOLDER_NAME,
VERSION,
DEFAULT_FAVORITE_COLOR,
DEFAULT_ARCHIVED_COLOR,
LEGACY_TAG_COLORS,
)

TYPE = ["file", "meta", "alt", "mask"]
Expand Down Expand Up @@ -369,20 +372,20 @@ def __init__(self) -> None:
self._tag_id_to_index_map: dict[int, int] = {}

self.default_tags: list[JsonTag] = [
{"id": 0, "name": "Archived", "aliases": ["Archive"], "color": "Red"},
{
"id": 0,
"name": "Archived",
"aliases": ["Archive"],
"color": DEFAULT_ARCHIVED_COLOR,
},
{
"id": 1,
"name": "Favorite",
"aliases": ["Favorited", "Favorites"],
"color": "Yellow",
"color": DEFAULT_FAVORITE_COLOR,
},
]

# self.default_tags = [
# Tag(id=0, name='Archived', shorthand='', aliases=['Archive'], subtags_ids=[], color='red'),
# Tag(id=1, name='Favorite', shorthand='', aliases=['Favorited, Favorites, Likes, Liked, Loved'], subtags_ids=[], color='yellow'),
# ]

self.default_fields: list[dict] = [
{"id": 0, "name": "Title", "type": "text_line"},
{"id": 1, "name": "Author", "type": "text_line"},
Expand Down Expand Up @@ -551,7 +554,10 @@ def open_library(self, path: str | Path) -> int:
shorthand = tag.get("shorthand", "")
aliases = tag.get("aliases", [])
subtag_ids = tag.get("subtag_ids", [])

color = tag.get("color", "")
if color in LEGACY_TAG_COLORS.keys():
color = LEGACY_TAG_COLORS[color]

t = Tag(
id=id,
Expand Down
Loading