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