-
Notifications
You must be signed in to change notification settings - Fork 0
/
effects.py
126 lines (114 loc) · 5.07 KB
/
effects.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
from pptx.oxml import parse_xml
def images_appear_on_click_effect(images, slide):
# start ids for images and xml containers
imgId = 2
cTnID = 3
xmlAlternateContent = """
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<mc:Choice xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" Requires="p14">
<p:transition xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" spd="slow" p14:dur="2000"></p:transition>
</mc:Choice>
<mc:Fallback>
<p:transition xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" spd="slow"></p:transition>
</mc:Fallback>
</mc:AlternateContent>
"""
xml = """
<p:timing xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<p:tnLst><p:par><p:cTn id="1" dur="indefinite" restart="never" nodeType="tmRoot">
<p:childTnLst><p:seq><p:cTn id="2" dur="indefinite" nodeType="mainSeq"><p:childTnLst>
"""
for img in images:
xml += f"""
<p:par><p:cTn id="{cTnID}" fill="hold"><p:stCondLst>
<p:cond delay="indefinite" /></p:stCondLst><p:childTnLst>
<p:par><p:cTn id="{cTnID + 1}" fill="hold"><p:stCondLst>
<p:cond delay="0" /></p:stCondLst><p:childTnLst><p:par>
<p:cTn id="{cTnID + 2}" nodeType="clickEffect" fill="hold" presetClass="entr" presetID="1">
<p:stCondLst><p:cond delay="0" /></p:stCondLst>
<p:childTnLst><p:set><p:cBhvr><p:cTn id="{cTnID + 3}" dur="1" fill="hold">
<p:stCondLst><p:cond delay="0" /></p:stCondLst></p:cTn>
<p:tgtEl><p:spTgt spid="{imgId}"></p:spTgt></p:tgtEl>
<p:attrNameLst><p:attrName>style.visibility</p:attrName>
</p:attrNameLst></p:cBhvr><p:to><p:strVal val="visible" />
</p:to></p:set></p:childTnLst></p:cTn></p:par></p:childTnLst>
</p:cTn></p:par></p:childTnLst></p:cTn></p:par>
"""
imgId += 1
cTnID += 4
xml += """
</p:childTnLst></p:cTn><p:prevCondLst><p:cond evt="onPrev">
<p:tgtEl><p:sldTgt /></p:tgtEl></p:cond></p:prevCondLst>
<p:nextCondLst><p:cond evt="onNext"><p:tgtEl><p:sldTgt />
</p:tgtEl></p:cond></p:nextCondLst></p:seq></p:childTnLst>
</p:cTn></p:par></p:tnLst></p:timing>
"""
xmlFragmentAlternateContent = parse_xml(xmlAlternateContent)
slide.element.insert(-1, xmlFragmentAlternateContent)
xmlFragment = parse_xml(xml)
slide.element.insert(-1, xmlFragment)
def images_appear_after_click_effect(images, delay, slide):
# start ids for images and xml containers
imgId = 2
cTnID = 4
sum_delay = 1
xmlAlternateContent = """
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<mc:Choice xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" Requires="p14">
<p:transition xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" spd="slow" p14:dur="2000"></p:transition>
</mc:Choice>
<mc:Fallback>
<p:transition xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" spd="slow"></p:transition>
</mc:Fallback>
</mc:AlternateContent>
"""
xml = """
<p:timing xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<p:tnLst><p:par><p:cTn id="1" dur="indefinite" restart="never" nodeType="tmRoot">
<p:childTnLst><p:seq><p:cTn id="2" dur="indefinite" nodeType="mainSeq"><p:childTnLst>
<p:par><p:cTn id="3" fill="hold"><p:stCondLst><p:cond delay="indefinite" /></p:stCondLst>
<p:childTnLst>
"""
for i in range(len(images)):
xml += f"""<p:par><p:cTn id="{cTnID}" fill="hold">"""
if i == 0:
xml += """<p:stCondLst><p:cond delay="0" /></p:stCondLst>"""
else:
xml += f"""<p:stCondLst><p:cond delay="{sum_delay}" /></p:stCondLst>"""
xml += """<p:childTnLst><p:par>"""
if i == 0:
xml += f"""
<p:cTn id="{cTnID + 1}" nodeType="clickEffect" fill="hold" presetClass="entr" presetID="1">
<p:stCondLst><p:cond delay="0" /></p:stCondLst>
"""
else:
xml += f"""
<p:cTn id="{cTnID + 1}" nodeType="afterEffect" fill="hold" presetClass="entr" presetID="1">
<p:stCondLst><p:cond delay="{delay}" /></p:stCondLst>
"""
xml += f"""
<p:childTnLst><p:set><p:cBhvr><p:cTn id="{cTnID + 2}" dur="1" fill="hold">
<p:stCondLst><p:cond delay="0" /></p:stCondLst></p:cTn>
<p:tgtEl><p:spTgt spid="{imgId}"></p:spTgt></p:tgtEl>
<p:attrNameLst><p:attrName>style.visibility</p:attrName>
</p:attrNameLst></p:cBhvr><p:to><p:strVal val="visible" />
</p:to></p:set></p:childTnLst></p:cTn></p:par></p:childTnLst>
</p:cTn></p:par>
"""
imgId += 1
cTnID += 3
if i != 0:
sum_delay += delay + 1
xml += """
</p:childTnLst></p:cTn></p:par></p:childTnLst></p:cTn>
<p:prevCondLst><p:cond evt="onPrev">
<p:tgtEl><p:sldTgt /></p:tgtEl></p:cond></p:prevCondLst>
<p:nextCondLst><p:cond evt="onNext"><p:tgtEl><p:sldTgt />
</p:tgtEl></p:cond></p:nextCondLst></p:seq></p:childTnLst>
</p:cTn></p:par></p:tnLst></p:timing>
"""
xmlFragmentAlternateContent = parse_xml(xmlAlternateContent)
slide.element.insert(-1, xmlFragmentAlternateContent)
xmlFragment = parse_xml(xml)
slide.element.insert(-1, xmlFragment)
slide.element.remove_all("p:clrMapOvr")