io_scene_gltf2: quiet error running when context.space is None
[blender-addons.git] / storypencil / __init__.py
blob05b929f10a9849b1cfb5a536bf0e6096bbab0d6e
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # ----------------------------------------------
4 # Define Addon info
5 # ----------------------------------------------
6 bl_info = {
7 "name": "Storypencil - Storyboard Tools",
8 "description": "Storyboard tools",
9 "author": "Antonio Vazquez, Matias Mendiola, Daniel Martinez Lara, Rodrigo Blaas, Samuel Bernou",
10 "version": (1, 1, 3),
11 "blender": (3, 3, 0),
12 "location": "",
13 "warning": "",
14 "category": "Sequencer",
17 # ----------------------------------------------
18 # Import modules
19 # ----------------------------------------------
20 if "bpy" in locals():
21 import importlib
23 importlib.reload(utils)
24 importlib.reload(synchro)
25 importlib.reload(dopesheet_overlay)
26 importlib.reload(scene_tools)
27 importlib.reload(sound)
28 importlib.reload(render)
29 importlib.reload(ui)
30 else:
31 from . import utils
32 from . import synchro
33 from . import dopesheet_overlay
34 from . import scene_tools
35 from . import sound
36 from . import render
37 from . import ui
39 import bpy
40 from bpy.types import (
41 Scene,
42 WindowManager,
43 WorkSpace,
45 from bpy.props import (
46 BoolProperty,
47 IntProperty,
48 PointerProperty,
49 StringProperty,
50 EnumProperty,
53 # --------------------------------------------------------------
54 # Register all operators, props and panels
55 # --------------------------------------------------------------
56 classes = (
57 synchro.STORYPENCIL_PG_Settings,
58 scene_tools.STORYPENCIL_OT_Setup,
59 scene_tools.STORYPENCIL_OT_NewScene,
60 synchro.STORYPENCIL_OT_WindowBringFront,
61 synchro.STORYPENCIL_OT_WindowCloseOperator,
62 synchro.STORYPENCIL_OT_SyncToggleSecondary,
63 synchro.STORYPENCIL_OT_SetSyncMainOperator,
64 synchro.STORYPENCIL_OT_AddSecondaryWindowOperator,
65 synchro.STORYPENCIL_OT_Switch,
66 synchro.STORYPENCIL_OT_TabSwitch,
67 sound.STORYPENCIL_OT_duplicate_sound_in_edit_scene,
68 render.STORYPENCIL_OT_RenderAction,
69 ui.STORYPENCIL_PT_Settings,
70 ui.STORYPENCIL_PT_ModePanel,
71 ui.STORYPENCIL_PT_SettingsNew,
72 ui.STORYPENCIL_PT_RenderPanel,
73 ui.STORYPENCIL_PT_General,
77 def save_mode(self, context):
78 wm = context.window_manager
79 if context.scene.storypencil_mode == 'WINDOW':
80 context.scene.storypencil_use_new_window = True
81 else:
82 context.scene.storypencil_use_new_window = False
84 wm['storypencil_use_new_window'] = context.scene.storypencil_use_new_window
85 # Close all secondary windows
86 if context.scene.storypencil_use_new_window is False:
87 c = context.copy()
88 for win in context.window_manager.windows:
89 # Don't close actual window
90 if win == context.window:
91 continue
92 win_id = str(win.as_pointer())
93 if win_id != wm.storypencil_settings.main_window_id and win.parent is None:
94 c["window"] = win
95 bpy.ops.wm.window_close(c)
98 addon_keymaps = []
99 def register_keymaps():
100 addon = bpy.context.window_manager.keyconfigs.addon
101 km = addon.keymaps.new(name="Sequencer", space_type="SEQUENCE_EDITOR")
102 kmi = km.keymap_items.new(
103 idname="storypencil.tabswitch",
104 type="TAB",
105 value="PRESS",
106 shift=False, ctrl=False, alt = False, oskey=False,
109 addon_keymaps.append((km, kmi))
111 def unregister_keymaps():
112 for km, kmi in addon_keymaps:
113 km.keymap_items.remove(kmi)
114 addon_keymaps.clear()
116 def register():
117 from bpy.utils import register_class
118 for cls in classes:
119 register_class(cls)
120 register_keymaps()
122 Scene.storypencil_scene_duration = IntProperty(
123 name="Scene Duration",
124 description="Default Duration for new Scene",
125 default=48,
126 min=1,
127 soft_max=250,
130 Scene.storypencil_use_new_window = BoolProperty(name="Open in new window",
131 description="Use secondary main window to edit scenes",
132 default=False)
134 Scene.storypencil_main_workspace = PointerProperty(type=WorkSpace,
135 description="Main Workspace used for editing Storyboard")
136 Scene.storypencil_main_scene = PointerProperty(type=Scene,
137 description="Main Scene used for editing Storyboard")
138 Scene.storypencil_edit_workspace = PointerProperty(type=WorkSpace,
139 description="Workspace used for changing drawings")
141 Scene.storypencil_base_scene = PointerProperty(type=Scene,
142 description="Template Scene used for creating new scenes")
144 Scene.storypencil_render_render_path = StringProperty(name="Output Path", subtype='FILE_PATH', maxlen=256,
145 description="Directory/name to save files")
147 Scene.storypencil_name_prefix = StringProperty(name="Scene Name Prefix", maxlen=20, default="")
149 Scene.storypencil_name_suffix = StringProperty(name="Scene Name Suffix", maxlen=20, default="")
151 Scene.storypencil_render_onlyselected = BoolProperty(name="Render only Selected Strips",
152 description="Render only the selected strips",
153 default=True)
155 Scene.storypencil_render_channel = IntProperty(name="Channel",
156 description="Channel to set the new rendered video",
157 default=5, min=1, max=128)
159 Scene.storypencil_add_render_strip = BoolProperty(name="Import Rendered Strips",
160 description="Add a Strip with the render",
161 default=True)
163 Scene.storypencil_render_step = IntProperty(name="Image Steps",
164 description="Minimum frames number to generate images between keyframes (0 to disable)",
165 default=0, min=0, max=128)
167 Scene.storypencil_render_numbering = EnumProperty(name="Image Numbering",
168 items=(
169 ('FRAME', "Frame", "Use real frame number"),
170 ('CONSECUTIVE', "Consecutive", "Use sequential numbering"),
172 description="Defines how frame is named")
174 Scene.storypencil_add_render_byfolder = BoolProperty(name="Folder by Strip",
175 description="Create a separated folder for each strip",
176 default=True)
178 Scene.storypencil_copy_sounds = BoolProperty(name="Copy Sounds",
179 description="Copy automatically the sounds from VSE to edit scene",
180 default=True)
182 Scene.storypencil_mode = EnumProperty(name="Mode",
183 items=(
184 ('SWITCH', "Switch", "Use same window and switch scene"),
185 ('WINDOW', "New Window", "Use a new window for editing"),
187 update=save_mode,
188 description="Defines how frame is named")
189 Scene.storypencil_selected_scn_only = BoolProperty(name='Selected Scene Only',
190 default=False,
191 description='Selected Scenes only')
192 Scene.storypencil_skip_sound_mute = BoolProperty(name='Ignore Muted Sound',
193 default=True,
194 description='Skip muted sound')
196 WindowManager.storypencil_settings = PointerProperty(
197 type=synchro.STORYPENCIL_PG_Settings,
198 name="Storypencil settings",
199 description="Storypencil tool settings",
202 # Append Handlers
203 bpy.app.handlers.frame_change_post.append(synchro.on_frame_changed)
204 bpy.app.handlers.load_post.append(synchro.sync_autoconfig)
206 bpy.context.window_manager.storypencil_settings.active = False
207 bpy.context.window_manager.storypencil_settings.main_window_id = ""
208 bpy.context.window_manager.storypencil_settings.secondary_windows_ids = ""
210 # UI integration in dopesheet header
211 bpy.types.DOPESHEET_HT_header.append(synchro.draw_sync_header)
212 dopesheet_overlay.register()
214 synchro.sync_autoconfig()
216 # UI integration in VSE header
217 bpy.types.SEQUENCER_HT_header.remove(synchro.draw_sync_sequencer_header)
218 bpy.types.SEQUENCER_HT_header.append(synchro.draw_sync_sequencer_header)
220 bpy.types.SEQUENCER_MT_add.append(scene_tools.draw_new_scene)
221 bpy.types.VIEW3D_MT_draw_gpencil.append(scene_tools.setup_storyboard)
224 def unregister():
225 unregister_keymaps()
227 from bpy.utils import unregister_class
228 for cls in reversed(classes):
229 unregister_class(cls)
231 # Remove Handlers
232 bpy.app.handlers.frame_change_post.remove(synchro.on_frame_changed)
233 bpy.app.handlers.load_post.remove(synchro.sync_autoconfig)
235 # remove UI integration
236 bpy.types.DOPESHEET_HT_header.remove(synchro.draw_sync_header)
237 dopesheet_overlay.unregister()
238 bpy.types.SEQUENCER_HT_header.remove(synchro.draw_sync_sequencer_header)
240 bpy.types.SEQUENCER_MT_add.remove(scene_tools.draw_new_scene)
241 bpy.types.VIEW3D_MT_draw_gpencil.remove(scene_tools.setup_storyboard)
243 del Scene.storypencil_scene_duration
244 del WindowManager.storypencil_settings
246 del Scene.storypencil_base_scene
247 del Scene.storypencil_main_workspace
248 del Scene.storypencil_main_scene
249 del Scene.storypencil_edit_workspace
251 del Scene.storypencil_render_render_path
252 del Scene.storypencil_name_prefix
253 del Scene.storypencil_name_suffix
254 del Scene.storypencil_render_onlyselected
255 del Scene.storypencil_render_channel
256 del Scene.storypencil_render_step
257 del Scene.storypencil_add_render_strip
258 del Scene.storypencil_render_numbering
259 del Scene.storypencil_add_render_byfolder
260 del Scene.storypencil_copy_sounds
261 del Scene.storypencil_mode
262 del Scene.storypencil_selected_scn_only
263 del Scene.storypencil_skip_sound_mute
265 if __name__ == '__main__':
266 register()