blender-voicevox-pl/operators_reference.py

57 lines
2.0 KiB
Python

"""
リファレンステキストストリップ管理用オペレーター
"""
import bpy
from bpy.types import Operator
class VOICEVOX_OT_set_reference_text(Operator):
"""選択したテキストストリップをリファレンスとして設定"""
bl_idname = "voicevox.set_reference_text"
bl_label = "Set as Reference"
bl_description = "選択したテキストストリップをリファレンスとして設定します"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if not context.scene.sequence_editor:
self.report({'ERROR'}, "シーケンスエディタがありません")
return {'CANCELLED'}
seq_editor = context.scene.sequence_editor
props = context.scene.voicevox
text_strip = None
if seq_editor.active_strip and seq_editor.active_strip.type == 'TEXT':
text_strip = seq_editor.active_strip
else:
for strip in seq_editor.strips_all:
if strip.select and strip.type == 'TEXT':
text_strip = strip
break
if not text_strip:
self.report({'ERROR'}, "テキストストリップが選択されていません")
return {'CANCELLED'}
props.reference_text_strip = text_strip.name
self.report({'INFO'}, f"リファレンステキスト: '{text_strip.name}'")
return {'FINISHED'}
class VOICEVOX_OT_clear_reference_text(Operator):
"""リファレンステキストストリップをクリア"""
bl_idname = "voicevox.clear_reference_text"
bl_label = "Clear Reference"
bl_description = "リファレンステキストストリップをクリアします"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
props = context.scene.voicevox
props.reference_text_strip = ""
self.report({'INFO'}, "リファレンステキストをクリアしました")
return {'FINISHED'}