Scoring sorted

This commit is contained in:
2025-12-28 17:44:24 +01:00
parent 7e02e57397
commit 86c4bf61c8
11 changed files with 214 additions and 412 deletions

View File

@@ -2,18 +2,18 @@
Configuration management for Tagger
Three levels of configuration:
1. Global config (config.json next to Tagger.py) - app-wide settings
2. Folder config (.tagger.json in project root) - folder-specific settings
3. File tags (.filename.!tag) - per-file metadata (handled in file.py)
1. Global config (.Tagger.!gtag next to Tagger.py) - app-wide settings
2. Folder config (.Tagger.!ftag in project root) - folder-specific settings
3. File tags (.{filename}.!tag) - per-file metadata (handled in file.py)
"""
import json
from pathlib import Path
# Global config file (next to the main script)
GLOBAL_CONFIG_FILE = Path(__file__).parent.parent.parent / "config.json"
GLOBAL_CONFIG_FILE = Path(__file__).parent.parent.parent / ".Tagger.!gtag"
# Folder config filename
FOLDER_CONFIG_NAME = ".tagger.json"
FOLDER_CONFIG_NAME = ".Tagger.!ftag"
# =============================================================================

View File

@@ -46,9 +46,12 @@ class FileManager:
ignore_patterns = folder_config.get("ignore_patterns", [])
for each in list_files(folder):
if each.name.endswith(".!tag"):
# Skip all Tagger metadata files
if each.name.endswith(".!tag"): # File tags: .filename.!tag
continue
if each.name == ".tagger.json":
if each.name.endswith(".!ftag"): # Folder config: .Tagger.!ftag
continue
if each.name.endswith(".!gtag"): # Global config: .Tagger.!gtag
continue
full_path = each.as_posix()

View File

@@ -1,11 +1,17 @@
from .tag import Tag
# Default tags that are always available
# Default tags that are always available (order in list = display order)
DEFAULT_TAGS = {
"Hodnocení": ["", "⭐⭐", "⭐⭐⭐", "⭐⭐⭐⭐", "⭐⭐⭐⭐⭐"],
"Barva": ["🔴 Červená", "🟠 Oranžová", "🟡 Žlutá", "🟢 Zelená", "🔵 Modrá", "🟣 Fialová"],
}
# Tag sort order for default categories (preserves display order)
DEFAULT_TAG_ORDER = {
"Hodnocení": {name: i for i, name in enumerate(DEFAULT_TAGS["Hodnocení"])},
"Barva": {name: i for i, name in enumerate(DEFAULT_TAGS["Barva"])},
}
class TagManager:
def __init__(self):
@@ -46,5 +52,16 @@ class TagManager:
def get_categories(self):
return list(self.tags_by_category.keys())
def get_tags_in_category(self, category: str):
return list(self.tags_by_category.get(category, []))
def get_tags_in_category(self, category: str) -> list[Tag]:
"""Get tags in category, sorted by predefined order for default categories"""
tags = list(self.tags_by_category.get(category, []))
# Use predefined order for default categories
if category in DEFAULT_TAG_ORDER:
order = DEFAULT_TAG_ORDER[category]
tags.sort(key=lambda t: order.get(t.name, 999))
else:
# Sort alphabetically for custom categories
tags.sort(key=lambda t: t.name)
return tags

View File

@@ -11,7 +11,7 @@ from typing import List
from src.core.media_utils import load_icon
from src.core.file_manager import FileManager
from src.core.tag_manager import TagManager
from src.core.tag_manager import TagManager, DEFAULT_TAG_ORDER
from src.core.file import File
from src.core.tag import Tag
from src.core.list_manager import ListManager
@@ -116,6 +116,14 @@ class MultiFileTagAssignDialog(tk.Toplevel):
tags_by_category[tag.category] = []
tags_by_category[tag.category].append((full_path, tag))
# Sort tags within each category
for category in tags_by_category:
if category in DEFAULT_TAG_ORDER:
order = DEFAULT_TAG_ORDER[category]
tags_by_category[category].sort(key=lambda x: order.get(x[1].name, 999))
else:
tags_by_category[category].sort(key=lambda x: x[1].name)
for category in sorted(tags_by_category.keys()):
color = self.category_colors.get(category, "#333333")
is_exclusive = category in EXCLUSIVE_CATEGORIES
@@ -127,7 +135,7 @@ class MultiFileTagAssignDialog(tk.Toplevel):
self.category_checkbuttons[category] = []
for full_path, tag in sorted(tags_by_category[category], key=lambda x: x[1].name):
for full_path, tag in tags_by_category[category]:
have_count = sum(1 for s in file_tag_sets if full_path in s)
if have_count == 0:
init = 0