-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_presentation.py
More file actions
51 lines (43 loc) · 1.65 KB
/
convert_presentation.py
File metadata and controls
51 lines (43 loc) · 1.65 KB
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
from pptx import Presentation
def get_name(slide):
for shape in slide.shapes:
if shape.is_placeholder:
if shape.placeholder_format.idx == 0:
return shape.text
return "" #Not an exception because this is the *name*, which isn't needed for OBZ
def is_first_inside_second(first,second):
"Finds the centre the first shape and checks if it is in the bounds of the second"
y=first['top']+(first['height']/2)-second['top']
x=first['left']+(first['width']/2)-second['left']
if 0 < y < second['height']:
if 0 < x <second['width']:
return True
return False
def hollow_shape(temp):
hollow_shape={}
hollow_shape['top']=temp.top
hollow_shape['left']=temp.left
hollow_shape['height']=temp.height
hollow_shape['width']=temp.width
return hollow_shape
def get_containers(slide):
comparisions=0
is_container={}
hollow_shapes=[]
for i in range(len(slide.shapes)):
hollow_shapes.append(hollow_shape(slide.shapes[i]))
is_container[0]=True #the one closest to the back is a container.
for shape_num in range(len(slide.shapes)):
potential_container=True
for container_num in is_container.keys():
comparisions+=1
if is_first_inside_second(hollow_shapes[shape_num],hollow_shapes[container_num]):
potential_container=False
break
if potential_container:
is_container[shape_num]=True
containers=[]
for shape_num in is_container.keys():
containers.append(slide.shapes[shape_num])
print "total comparisons {}".format(comparisions)
return containers