-
Notifications
You must be signed in to change notification settings - Fork 21
/
properties.py
85 lines (65 loc) · 2.36 KB
/
properties.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
import bpy, os
from bpy.props import BoolProperty
from pathlib import Path
def get_space(context):
for area in context.screen.areas:
if area.type == "TEXT_EDITOR":
return area.spaces.active
def text_handler(spc, context):
scene = bpy.context.scene
text = bpy.context.area.spaces.active.text
line = text.current_line.body
space = bpy.context.space_data
current_text = space.text.name
if current_text.strip() == "": return
current_character = bpy.data.texts[current_text].current_character
if not text:
return
if scene.last_line is None and scene.last_line_index != text.current_line_index:
scene.last_line = line
scene.last_line_index = text.current_line_index
if scene.last_character is None: # scene.last_character != current_character:
scene.last_character = current_character
if line != scene.last_line or len(line) != len(scene.last_line):
bpy.ops.scene.preview_fountain()
elif current_character != scene.last_character:
bpy.ops.scene.preview_fountain()
scene.last_line = line
scene.last_character = current_character
def redraw(context):
for window in context.window_manager.windows:
for area in window.screen.areas:
if area.type == 'TEXT_EDITOR':
area.tag_redraw()
def activate_handler(self, context):
global handler
spc = get_space(context)
if not spc:
return
enabled = context.scene.text_replace.enabled
if enabled:
handler = spc.draw_handler_add(text_handler, (
spc,
context,
), "WINDOW", "POST_PIXEL")
else:
if handler is not None:
spc.draw_handler_remove(handler, "WINDOW")
handler = None
class TextReplaceProperties(bpy.types.PropertyGroup):
enabled: BoolProperty(
name="Live Preview",
description="Enables live screenplay preview",
update=activate_handler,
default=False)
@classmethod
def poll(cls, context):
space = bpy.context.space_data
try:
filepath = space.text.name
if filepath.strip() == "": return False
return ((space.type == 'TEXT_EDITOR')
and Path(filepath).suffix == ".fountain")
except AttributeError: return False
def execute(self, context):
return {"FINISHED"}