|
1 | | -import bpy.utils |
2 | | -from bpy.props import BoolProperty, IntProperty, StringProperty, CollectionProperty |
3 | | -from bpy.types import AddonPreferences |
| 1 | +import bpy |
4 | 2 |
|
5 | | -from .public import PublicClass |
6 | | -from .tool import (auto_reload_script, |
7 | | - custom_key, |
8 | | - fast_open_addon_code, |
9 | | - restart_blender, |
10 | | - addon_search, |
11 | | - ) |
| 3 | +from .tool import update_by_tool_name |
| 4 | +from .tool.auto_reload_script import AutoReloadScriptPreferences |
12 | 5 |
|
13 | | -tool_mod = {'fast_open_addon_code': fast_open_addon_code, |
14 | | - 'enabled_reload_script': auto_reload_script, |
15 | | - 'restart_blender': restart_blender, |
16 | | - 'custom_key': custom_key, |
17 | | - 'save_addon_search': addon_search |
18 | | - } |
19 | 6 |
|
| 7 | +class ShowExpandedItem(bpy.types.PropertyGroup): |
| 8 | + """Used to record the expansion status of the addon""" |
| 9 | + show_expanded: bpy.props.BoolProperty(default=False) |
20 | 10 |
|
21 | | -def update_tool(un_register=False): |
22 | | - pref = PublicClass.pref_() |
23 | | - for prop_name, tool in tool_mod.items(): |
24 | | - is_enable = getattr(pref, prop_name, False) |
25 | | - if un_register or (not is_enable): |
26 | | - tool.unregister() |
27 | | - elif is_enable: |
28 | | - tool.register() |
29 | 11 |
|
30 | | - |
31 | | -class ShowExpanded(bpy.types.PropertyGroup): |
32 | | - show_expanded: BoolProperty(default=False) |
33 | | - |
34 | | - |
35 | | -class ToolPreferences(AddonPreferences): |
| 12 | +class ToolPreferences(bpy.types.AddonPreferences, AutoReloadScriptPreferences): |
36 | 13 | bl_idname = __package__ |
37 | 14 |
|
38 | | - @staticmethod |
39 | | - def update_by_tool_name(tool_name): |
40 | | - """Change prop update tool""" |
41 | | - |
42 | | - def update(self, context): |
43 | | - prop = getattr(self, tool_name, None) |
44 | | - if prop: |
45 | | - tool_mod[tool_name].register() |
46 | | - elif prop is False: |
47 | | - tool_mod[tool_name].unregister() |
| 15 | + activate_auto_reload_script: bpy.props.BoolProperty( |
| 16 | + default=True, |
| 17 | + name="ReLoad Script", |
| 18 | + description="Automatically reload scripts and run them", |
| 19 | + update=update_by_tool_name("auto_reload_script"), |
| 20 | + ) |
48 | 21 |
|
49 | | - return update |
| 22 | + activate_development_key: bpy.props.BoolProperty( |
| 23 | + default=True, |
| 24 | + name="Development Keymap", |
| 25 | + description="Commonly used Keymaps to speed up the development process", |
| 26 | + update=update_by_tool_name("development_key"), |
| 27 | + ) |
50 | 28 |
|
51 | | - fast_open_addon_code: BoolProperty( |
| 29 | + activate_open_addon_script: bpy.props.BoolProperty( |
52 | 30 | default=False, |
53 | | - name='Feat Open Addon Script or Folder', |
54 | | - description='Rewrite the drawing method of the addon section,' |
55 | | - ' and display it in the expansion of the addon', |
56 | | - update=update_by_tool_name('fast_open_addon_code'), ) |
57 | | - restart_blender: BoolProperty( |
58 | | - default=True, |
59 | | - name='Restart Blender', |
60 | | - description='Enabled Multiple Blender,or Restart Blender', |
61 | | - update=update_by_tool_name('restart_blender'), |
| 31 | + name="Addon Open", |
| 32 | + description="Rewrite the drawing method of the addon section, and display it in the expansion of the addon", |
| 33 | + update=update_by_tool_name("open_addon_script") |
62 | 34 | ) |
63 | | - custom_key: BoolProperty( |
| 35 | + activate_remember_addon_expanded: bpy.props.BoolProperty( |
64 | 36 | default=True, |
65 | | - name='Development Key', |
66 | | - description='alt+Space Toggle Full Screen' |
67 | | - 'ctrl+alt+MiddleMouse Show Console' |
68 | | - 'ctrl+alt+RightMouse Switch User Translate Interface' |
69 | | - 'ctrl+alt+AccentGrave Save Home File', |
70 | | - update=update_by_tool_name('custom_key'), |
| 37 | + name="Remember addon expanded", |
| 38 | + description="Record the expanded Addon and restore it the next time you open Blender", |
| 39 | + update=update_by_tool_name("remember_addon_expanded"), |
71 | 40 | ) |
72 | | - save_addon_search: BoolProperty( |
| 41 | + |
| 42 | + activate_remember_addon_search: bpy.props.BoolProperty( |
73 | 43 | default=True, |
74 | | - name='Save addon search', |
75 | | - description='', |
76 | | - update=update_by_tool_name('save_addon_search'), |
| 44 | + name="Remember addon search", |
| 45 | + description="Record the Addon search and restore it the next time you start Blender", |
| 46 | + update=update_by_tool_name("remember_addon_search"), |
77 | 47 | ) |
78 | | - addon_search: StringProperty() |
79 | | - addon_show_expanded: CollectionProperty(type=ShowExpanded) |
80 | 48 |
|
81 | | - enabled_reload_script: BoolProperty( |
| 49 | + activate_restart_blender: bpy.props.BoolProperty( |
82 | 50 | default=True, |
83 | | - name='ReLoad Script Tool', |
84 | | - description='', |
85 | | - update=update_by_tool_name('enabled_reload_script'), |
| 51 | + name="Restart Blender", |
| 52 | + description="Enable multiple Blenders or restart Blender, please be careful to save the edit file!!!!", |
| 53 | + update=update_by_tool_name("restart_blender"), |
86 | 54 | ) |
87 | 55 |
|
88 | | - # Auto Reload |
89 | | - def update_reload_script(self, context): |
90 | | - text = context.space_data.text |
91 | | - try: |
92 | | - bpy.ops.text.reload() |
93 | | - if self.auto_run_script: |
94 | | - try: |
95 | | - bpy.ops.text.run_script() |
96 | | - print(f'Reload Script {text.name},and Run Script!!!') |
97 | | - except Exception as e: |
98 | | - print('Run Error!!', e.args) |
99 | | - except Exception as e: |
100 | | - print(f'Reload Script {text.name} Error,Perhaps this script does not exist', e.args) |
101 | | - self.auto_reload_script = False |
102 | | - |
103 | | - reload_script_number: IntProperty(default=True, |
104 | | - update=update_reload_script) |
105 | | - auto_run_script: BoolProperty(name='Auto run script switch, only when auto reload script is turned on can it run', |
106 | | - options={'SKIP_SAVE'}, |
107 | | - default=False) |
108 | | - |
109 | | - auto_reload_script: BoolProperty(name="Whether to automatically reload scripts", default=True, ) |
| 56 | + # Other Property |
| 57 | + addon_show_expanded: bpy.props.CollectionProperty(type=ShowExpandedItem) |
| 58 | + addon_search: bpy.props.StringProperty(default="") |
110 | 59 |
|
111 | 60 | def draw(self, context): |
112 | | - for i in ('fast_open_addon_code', |
113 | | - 'enabled_reload_script', |
114 | | - 'restart_blender', |
115 | | - 'custom_key', |
116 | | - 'save_addon_search', |
117 | | - ): |
118 | | - self.layout.prop(self, i) |
| 61 | + from .keymap import draw_key |
| 62 | + |
| 63 | + column = self.layout.column(align=True) |
| 64 | + for prop in self.bl_rna.properties: |
| 65 | + if prop.identifier.startswith("activate_"): |
| 66 | + self.draw_prop(column, prop.identifier) |
| 67 | + |
| 68 | + if self.activate_development_key: |
| 69 | + column.separator() |
| 70 | + col = column.box().column(align=True) |
| 71 | + col.label(text="Keymap") |
| 72 | + draw_key(col) |
| 73 | + |
| 74 | + def draw_prop(self, layout, identifier) -> None: |
| 75 | + split = layout.row(align=True).split(factor=.2, align=True) |
| 76 | + prop = self.bl_rna.properties[identifier] |
| 77 | + split.prop(self, identifier, toggle=True, expand=True) |
| 78 | + split.label(text=prop.description) |
119 | 79 |
|
120 | 80 |
|
121 | 81 | def register(): |
122 | | - bpy.utils.register_class(ShowExpanded) |
| 82 | + bpy.utils.register_class(ShowExpandedItem) |
123 | 83 | bpy.utils.register_class(ToolPreferences) |
124 | | - update_tool() |
125 | 84 |
|
126 | 85 |
|
127 | 86 | def unregister(): |
128 | 87 | bpy.utils.unregister_class(ToolPreferences) |
129 | | - bpy.utils.unregister_class(ShowExpanded) |
130 | | - update_tool(un_register=True) |
| 88 | + bpy.utils.unregister_class(ShowExpandedItem) |
0 commit comments