-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
__init__.py
219 lines (181 loc) · 7.19 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
"name": "Screencast Keys",
"author": "Paulo Gomes, Bart Crouch, John E. Herrenyo, "
"Gaia Clary, Pablo Vazquez, chromoly, Nutti, Hawkpath, "
"CheeryLee, Kureii",
"version": (3, 12, 0),
"blender": (2, 80, 0),
"location": "3D View > Sidebar > Screencast Keys",
"warning": "",
"description": "Display keys pressed in Blender",
"wiki_url": "https://github.com/nutti/Screencast-Keys",
"doc_url": "https://github.com/nutti/Screencast-Keys",
"tracker_url": "https://github.com/nutti/Screencast-Keys",
"category": "System",
}
if "bpy" in locals():
import importlib
# pylint: disable=E0601
importlib.reload(gpu_utils)
importlib.reload(utils)
importlib.reload(c_structure)
utils.bl_class_registry.BlClassRegistry.cleanup()
importlib.reload(preferences)
importlib.reload(ops)
importlib.reload(ui)
importlib.reload(common)
else:
import bpy
from . import gpu_utils
from . import utils
from . import c_structure
from . import preferences
from . import ops
from . import ui
from . import common
# pylint: disable=C0413
import os
addon_keymaps = []
# pylint: disable=C0103
is_startup = True
@bpy.app.handlers.persistent
def load_post_handler(_):
# pylint: disable=W0603
global is_startup
context = bpy.context
user_prefs = context.preferences
prefs = user_prefs.addons[__package__].preferences
enable_on_startup = prefs.enable_on_startup and is_startup
is_running = not is_startup and ops.SK_OT_ScreencastKeys.is_running()
if enable_on_startup or is_running:
bpy.ops.wm.sk_wait_blender_initialized_and_start_screencast_keys()
is_startup = False
def register_updater(info):
config = utils.addon_updater.AddonUpdaterConfig()
config.owner = "nutti"
config.repository = "Screencast-Keys"
config.current_addon_path = os.path.dirname(os.path.realpath(__file__))
config.branches = ["master", "develop"]
ridx = config.current_addon_path.rfind(utils.addon_updater.get_separator())
config.addon_directory = config.current_addon_path[:ridx]
config.min_release_version = info["version"]
config.default_target_addon_path = "screencast_keys"
config.target_addon_path = {
"master": "src{}screencast_keys".format(
utils.addon_updater.get_separator()),
"develop": "src{}screencast_keys".format(
utils.addon_updater.get_separator()),
}
updater = utils.addon_updater.AddonUpdaterManager.get_instance()
updater.init(config)
def register_shortcut_key():
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
km = kc.keymaps.new(name="3D View", space_type='VIEW_3D')
kmi = km.keymap_items.new("wm.sk_screencast_keys", 'C', 'PRESS',
shift=True, alt=True)
addon_keymaps.append((km, kmi))
def unregister_shortcut_key():
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
def call_silently(fn, *args):
try:
fn(*args)
# pylint: disable=W0702
except: # noqa
pass
def register_addon_enable_property():
def get_func(_):
return ops.SK_OT_ScreencastKeys.is_running()
def set_func(_, __):
pass
def update_func(_, __):
bpy.ops.wm.sk_screencast_keys('INVOKE_REGION_WIN')
if not hasattr(bpy.types.WindowManager, "enable_screencast_keys"):
bpy.types.WindowManager.enable_screencast_keys = \
bpy.props.BoolProperty(
name="Screencast Keys",
get=get_func,
set=set_func,
update=update_func,
)
def unregister_addon_enable_property():
if hasattr(bpy.types.WindowManager, "enable_screencast_keys"):
del bpy.types.WindowManager.enable_screencast_keys
def register():
gpu_utils.shader.ShaderManager.register_shaders()
register_updater(bl_info)
# Register Screencast Key's enable property at here to use it in the
# both SK_PT_ScreencastKeys Panel and SK_PT_ScreencastKeys_Overlay Panel.
# TODO: This registration should be handled by BlClassRegistry to add
# the priority feature.
register_addon_enable_property()
# TODO: Register by BlClassRegistry
bpy.utils.register_class(preferences.DisplayEventTextAliasProperties)
bpy.utils.register_class(ui.SK_PT_ScreencastKeys)
bpy.utils.register_class(ui.SK_PT_ScreencastKeys_Overlay)
utils.bl_class_registry.BlClassRegistry.register()
register_shortcut_key()
bpy.app.handlers.load_post.append(load_post_handler)
# Apply preferences of UI.
context = bpy.context
user_prefs = context.preferences
prefs = user_prefs.addons[__package__].preferences
# Only default panel location is available in < 2.80
if utils.compatibility.check_version(2, 80, 0) < 0:
prefs.panel_space_type = 'VIEW_3D'
prefs.panel_category = "Screencast Key"
prefs.show_ui_in_sidebar = True
prefs.show_ui_in_overlay = False
preferences.SK_Preferences.ui_in_sidebar_update_fn(prefs, context)
preferences.SK_Preferences.ui_in_overlay_update_fn(prefs, context)
for event in list(ops.EventType):
item = prefs.display_event_text_aliases_props.add()
item.event_id = event.name
if event in ops.SK_OT_ScreencastKeys.MODIFIER_EVENT_TYPES:
item.default_text = common.fix_modifier_display_text(
ops.EventType.names[event.name]
)
else:
item.default_text = ops.EventType.names[event.name]
try:
common.reload_custom_mouse_image(prefs, context)
# pylint: disable=W0702
except: # noqa
pass
def unregister():
context = bpy.context
user_prefs = context.preferences
prefs = user_prefs.addons[__package__].preferences
preferences.remove_custom_mouse_image(prefs, context)
bpy.app.handlers.load_post.remove(load_post_handler)
unregister_shortcut_key()
# TODO: Unregister by BlClassRegistry
utils.bl_class_registry.BlClassRegistry.unregister()
call_silently(bpy.utils.unregister_class, ui.SK_PT_ScreencastKeys_Overlay)
call_silently(bpy.utils.unregister_class, ui.SK_PT_ScreencastKeys)
bpy.utils.unregister_class(preferences.DisplayEventTextAliasProperties)
unregister_addon_enable_property()
gpu_utils.shader.ShaderManager.unregister_shaders()
if __name__ == "__main__":
register()