From e26cc4f09f2048f2cd475991cb78fd95236b84e8 Mon Sep 17 00:00:00 2001 From: Joseph HENRY Date: Mon, 1 Dec 2025 17:26:08 +0100 Subject: [PATCH] temp save --- __init__.py | 37 +++++++++++++++++----------------- functions.py | 2 +- operators.py | 14 +++++++++++-- pyproject.toml | 1 + utils.py | 54 ++++++++++++++++++++++---------------------------- uv.lock | 15 +++++++++++++- 6 files changed, 70 insertions(+), 53 deletions(-) diff --git a/__init__.py b/__init__.py index 7181dd7..be91140 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,20 @@ +if "bpy" in locals(): + import importlib + + importlib.reload(operators) + importlib.reload(panels) + importlib.reload(functions) + importlib.reload(properties) + +from .functions import read_shelves +from . import operators +from . import properties +from . import ui +from .properties import CustomShelfSettings, CustomShelfProps + +import bpy +import os + bl_info = { "name": "Custom Shelf", "author": "Christophe Seux", @@ -12,25 +29,6 @@ bl_info = { } -if "bpy" in locals(): - import importlib - - importlib.reload(operators) - importlib.reload(panels) - importlib.reload(functions) - importlib.reload(properties) - -from .utils import report -from .functions import read_shelves -from . import operators -from . import properties -from . import ui -from .properties import CustomShelfSettings, CustomShelfProps - -import bpy -import os - - bl_classes = [ properties.AdditionnalShelves, properties.CustomShelfProps, @@ -42,6 +40,7 @@ bl_classes = [ operators.CSHELF_OT_open_shelf_folder, operators.CSHELF_OT_add_script, operators.CSHELF_OT_set_tag_filter, + operators.CustomShelfAddonPreferences, ui.CSHELF_MT_text_editor, ] diff --git a/functions.py b/functions.py index 818258e..63a3a6f 100644 --- a/functions.py +++ b/functions.py @@ -212,7 +212,7 @@ def read_shelves(): tag_filter_items.sort() tag_filter_items.insert(0, "__clear__") - prefs["tag_filter_items"] = tag_filter_items + # prefs["tag_filter_items"] = tag_filter_items # bpy.utils.unregister_class(CustomShelfPrefs) # bpy.utils.register_class(CustomShelfPrefs) diff --git a/operators.py b/operators.py index e6b48fb..493bd12 100644 --- a/operators.py +++ b/operators.py @@ -1,7 +1,8 @@ from .utils import * from .functions import * -from bpy.types import Operator +from bpy.types import AddonPreferences, Operator, PropertyGroup from bpy.props import * +from bpy.props import CollectionProperty from .properties import CustomShelfSettings @@ -267,7 +268,6 @@ class CSHELF_OT_add_script(Operator): folder_row.prop(bl_props, "category_enum", expand=True) else: - folder_row.prop(self, "new_category", text="") folder_row.prop(self, "add_category", icon="ADD", text="") @@ -392,3 +392,13 @@ class CSHELF_OT_add_script(Operator): bl_props.tab_enum = tab return context.window_manager.invoke_props_dialog(self, width=500) + + +class TagFilterItem(PropertyGroup): + value: StringProperty(name="Tag") + + +class CustomShelfAddonPreferences(AddonPreferences): + bl_idname = __name__ + + tag_filter_items: CollectionProperty(type=TagFilterItem) diff --git a/pyproject.toml b/pyproject.toml index e3f8a24..ee684f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,4 +9,5 @@ dependencies = [] [dependency-groups] dev = [ "black>=25.11.0", + "fake-bpy-module>=20251003", ] diff --git a/utils.py b/utils.py index b9ded5e..cd4df39 100644 --- a/utils.py +++ b/utils.py @@ -1,12 +1,19 @@ +from pathlib import Path +from typing import Any import bpy import os -from os import listdir, mkdir, scandir -from os.path import join, dirname, splitext, isdir, exists, basename -from bpy.types import Operator, Panel, PropertyGroup -from bpy.props import * import subprocess import json +from bpy.props import ( + BoolProperty, + EnumProperty, + FloatProperty, + IntProperty, + PointerProperty, + StringProperty, +) + id_type = { "Action": "actions", @@ -46,47 +53,34 @@ id_type = { } -def report(var, message, type="INFO"): - print([a for a in locals()]) - print([a for a in globals()]) - - if "self" in var: - var["self"].report({type}, message) - - else: - print("") - print(type) - print(message) - - -def read_json(path): +def read_json(path: Path): jsonFile = path if os.path.exists(jsonFile): try: with open(jsonFile) as data_file: return json.load(data_file) - except: + except Exception: print("the file %s not json readable" % jsonFile) return -def search_filter(search, str): +def search_filter(search: str, str: str): return search.lower() in str.lower() -def title(string): +def title(string: str): return string.replace("_", " ").replace("-", " ").title() -def arg_name(string): +def arg_name(string: str): return string.replace(" ", "_").replace("-", "_").lower().strip("_") -def open_folder(path): +def open_folder(path: Path): try: os.startfile(path) - except: - subprocess.Popen(["xdg-open", path]) + except Exception: + _ = subprocess.Popen(["xdg-open", path]) def dic_to_args(dic): @@ -141,7 +135,7 @@ def dic_to_args(dic): return args -def read_info(script_path): +def read_info(script_path: Path): import collections if isinstance(script_path, list): @@ -151,13 +145,13 @@ def read_info(script_path): lines = f.read().splitlines() info = {} - for i, l in enumerate(lines): + for i, line in enumerate(lines): if i >= 10: return info, lines - if l.startswith("info"): + if line.startswith("info"): info_start = i - info_str = l + info_str = line while ( info_str.endswith(",") @@ -202,7 +196,7 @@ def read_info(script_path): return info, lines -def dic_to_str(dic, keys=None, spaces=4): +def dic_to_str(dic: dict[str, Any], keys: list[str] | None = None, spaces: int = 4): # pyright: ignore[reportExplicitAny] if not keys: keys = sorted(dic) diff --git a/uv.lock b/uv.lock index 9c8d7cd..d005345 100644 --- a/uv.lock +++ b/uv.lock @@ -60,12 +60,25 @@ source = { virtual = "." } [package.dev-dependencies] dev = [ { name = "black" }, + { name = "fake-bpy-module" }, ] [package.metadata] [package.metadata.requires-dev] -dev = [{ name = "black", specifier = ">=25.11.0" }] +dev = [ + { name = "black", specifier = ">=25.11.0" }, + { name = "fake-bpy-module", specifier = ">=20251003" }, +] + +[[package]] +name = "fake-bpy-module" +version = "20251003" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/3a/d7/8e34a795715d18497a257929ace8776a94d6c2c744e36b61e75567cbda64/fake_bpy_module-20251003.tar.gz", hash = "sha256:43d7fd082efc34497e238de3ad4d31fb850f2d1a8bb07418ae36eae56c1c7434", size = 973644, upload-time = "2025-10-03T06:19:57.638Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c6/24/d318f51ae1ebe953038984ed26fa0f9cd5466ef83da30c317282645695ec/fake_bpy_module-20251003-py3-none-any.whl", hash = "sha256:424f75fee6f300fc6d8e0d39abb28dbccd8777f611afa47ecdb9a03c00f2f43f", size = 1103011, upload-time = "2025-10-03T06:19:55.524Z" }, +] [[package]] name = "mypy-extensions"