|
1 | 1 | import bpy.utils |
2 | | -from bpy.props import BoolProperty, IntProperty, StringProperty, CollectionProperty |
| 2 | +from bpy.props import BoolProperty, StringProperty, CollectionProperty |
3 | 3 | from bpy.types import AddonPreferences |
4 | 4 |
|
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 | | - ) |
| 5 | +from .tool import update_by_tool_name |
| 6 | +from .tool.auto_reload_script import AutoReloadScriptPreferences |
12 | 7 |
|
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 | 8 |
|
20 | | - |
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 | | - |
30 | | - |
31 | | -class ShowExpanded(bpy.types.PropertyGroup): |
| 9 | +class ShowExpandedItem(bpy.types.PropertyGroup): |
| 10 | + """Used to record the expansion status of the addon""" |
32 | 11 | show_expanded: BoolProperty(default=False) |
33 | 12 |
|
34 | 13 |
|
35 | | -class ToolPreferences(AddonPreferences): |
| 14 | +class ToolPreferences(AddonPreferences, AutoReloadScriptPreferences): |
36 | 15 | bl_idname = __package__ |
37 | 16 |
|
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() |
48 | | - |
49 | | - return update |
50 | | - |
51 | 17 | fast_open_addon_code: BoolProperty( |
52 | 18 | 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'), ) |
| 19 | + name="Feat Open Addon Script or Folder", |
| 20 | + description="Rewrite the drawing method of the addon section," |
| 21 | + " and display it in the expansion of the addon", |
| 22 | + update=update_by_tool_name("fast_open_addon_code")) |
57 | 23 | restart_blender: BoolProperty( |
58 | 24 | default=True, |
59 | | - name='Restart Blender', |
60 | | - description='Enabled Multiple Blender,or Restart Blender', |
61 | | - update=update_by_tool_name('restart_blender'), |
| 25 | + name="Restart Blender", |
| 26 | + description="Enabled Multiple Blender,or Restart Blender", |
| 27 | + update=update_by_tool_name("restart_blender"), |
62 | 28 | ) |
63 | 29 | custom_key: BoolProperty( |
64 | 30 | 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'), |
| 31 | + name="Development Key", |
| 32 | + description="alt+Space Toggle Full Screen" |
| 33 | + "ctrl+alt+MiddleMouse Show Console" |
| 34 | + "ctrl+alt+RightMouse Switch User Translate Interface" |
| 35 | + "ctrl+alt+AccentGrave Save Home File", |
| 36 | + update=update_by_tool_name("custom_key"), |
71 | 37 | ) |
72 | 38 | save_addon_search: BoolProperty( |
73 | 39 | default=True, |
74 | | - name='Save addon search', |
75 | | - description='', |
76 | | - update=update_by_tool_name('save_addon_search'), |
| 40 | + name="Save addon search", |
| 41 | + description="", |
| 42 | + update=update_by_tool_name("save_addon_search"), |
77 | 43 | ) |
78 | 44 | addon_search: StringProperty() |
79 | | - addon_show_expanded: CollectionProperty(type=ShowExpanded) |
80 | 45 |
|
81 | 46 | enabled_reload_script: BoolProperty( |
82 | 47 | default=True, |
83 | | - name='ReLoad Script Tool', |
84 | | - description='', |
85 | | - update=update_by_tool_name('enabled_reload_script'), |
| 48 | + name="ReLoad Script Tool", |
| 49 | + description="", |
| 50 | + update=update_by_tool_name("enabled_reload_script"), |
86 | 51 | ) |
87 | 52 |
|
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, ) |
| 53 | + addon_show_expanded: CollectionProperty(type=ShowExpandedItem) |
110 | 54 |
|
111 | 55 | 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', |
| 56 | + for i in ("fast_open_addon_code", |
| 57 | + "enabled_reload_script", |
| 58 | + "restart_blender", |
| 59 | + "custom_key", |
| 60 | + "save_addon_search", |
117 | 61 | ): |
118 | 62 | self.layout.prop(self, i) |
119 | 63 |
|
120 | 64 |
|
121 | 65 | def register(): |
122 | | - bpy.utils.register_class(ShowExpanded) |
| 66 | + bpy.utils.register_class(ShowExpandedItem) |
123 | 67 | bpy.utils.register_class(ToolPreferences) |
124 | | - update_tool() |
125 | 68 |
|
126 | 69 |
|
127 | 70 | def unregister(): |
128 | 71 | bpy.utils.unregister_class(ToolPreferences) |
129 | | - bpy.utils.unregister_class(ShowExpanded) |
130 | | - update_tool(un_register=True) |
| 72 | + bpy.utils.unregister_class(ShowExpandedItem) |
0 commit comments