-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
73 lines (54 loc) · 1.87 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
bl_info = {
"name": "Addon Reload Helper",
"author": "Tomasz Dysinski",
"version": (1, 0, 1),
"blender": (2, 91, 0),
"location": "Properties > Scene > Addon Reload Helper",
"description": "Help reload addons with an operator, some UI, and a hotkey (OSKey + Shift + R)",
"warning": "",
"doc_url": "",
"category": "System",
}
import bpy
from bpy.types import Operator
class AddonReloadHelperUI(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Addon Reload Helper"
bl_idname = "horizon.addon_reload_helper"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
row = layout.row()
row.scale_y = 2.0
row.operator("addon_reload_helper.reload")
class ReloadAddons(Operator):
"""Reload Addons"""
bl_idname = "addon_reload_helper.reload"
bl_label = "Reload Addons"
bl_options = {'REGISTER'}
def execute(self, context):
result = bpy.ops.script.reload()
return {'FINISHED'}
# store keymaps here to access after registration
addon_keymaps = []
def register():
bpy.utils.register_class(AddonReloadHelperUI)
bpy.utils.register_class(ReloadAddons)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(ReloadAddons.bl_idname, 'R', 'PRESS', oskey=True, shift=True)
# kmi.properties.total = 4
addon_keymaps.append((km, kmi))
def unregister():
bpy.utils.unregister_class(AddonReloadHelperUI)
bpy.utils.unregister_class(ReloadAddons)
# handle the keymap
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
if __name__ == "__main__":
register()