11
11
12
12
13
13
def ppt2video (pptx , video , timing , duration ,
14
- resolution , frames , quality , input_list ):
14
+ resolution , frames , quality , input_list , dict ):
15
15
16
16
# Check if system requirements are met.
17
17
if sys .platform == "win32" :
18
18
pass
19
19
else :
20
- print ("Sorry, this script can be run only on Windows." )
20
+ print ("Sorry, this script can be run only on Windows." )
21
21
22
- # Create fill pathes for the ppt and video files.
22
+ # Create files pathes for the ppt and video files.
23
23
ppt_path = os .path .abspath (pptx )
24
24
video_path = os .path .abspath (video )
25
25
@@ -30,26 +30,75 @@ def ppt2video(pptx, video, timing, duration,
30
30
# Open presentation
31
31
presentation = ppt .Presentations .Open (ppt_path , WithWindow = False )
32
32
33
- slides_len = len (presentation .Slides )
34
-
35
- while input_list :
36
- if len (input_list ) == slides_len :
37
- n = 1 # To track the slide number to be created
38
- x = 0 # Index in the user input list
39
- while x < slides_len :
40
- # Create slide and insert it at n position with
41
- # input_list[x] text
42
- slide = presentation .Slides .Add (n , ppLayoutText )
43
- slide .Shapes .addShape (
44
- msoShapeRectangle , 150 , 150 , 250 , 250 ). \
45
- TextFrame .TextRange .Text = input_list [x ]
46
- n += 2
47
- x += 1
48
- break
49
- else :
50
- print ("The length of input data should be equal to the \
51
- slides count" )
52
- break
33
+ # slides_len = len(presentation.Slides)
34
+
35
+ # powerpoint = win32com.client.Dispatch('PowerPoint.Application')
36
+ # new_presentation = ppt.Presentations.Add(WithWindow=False)
37
+ # list_slides = [e for e in presentation.Slides]
38
+ # # for each in presentation.Slides:
39
+ # for key, value in dict.items():
40
+ # if presentation.Slides[int(key)] and value != "":
41
+ # slide = new_presentation.Slides.Add(int(key)+1, ppLayoutText)
42
+ # slide.Shapes.addShape(
43
+ # msoShapeRectangle, 150, 150, 250, 250). \
44
+ # TextFrame.TextRange.Text = value
45
+ # # print(presentation.Slides[int(key)], key, value)
46
+ # else:
47
+ # print("NO value", presentation.Slides[int(key)], key, value)
48
+ # if presentation.Slides[int(key)]:
49
+ # slide = new_presentation.Slides.Add(int(key), ppLayoutText)
50
+ # slide.Shapes.addShape(
51
+ # msoShapeRectangle, 150, 150, 250, 250). \
52
+ # TextFrame.TextRange.Text = value
53
+ # for key, value in dict.items():
54
+ # print("key for dict", key)
55
+
56
+ # Unpack the dict keys and values
57
+ # for key, value in dict.items():
58
+ # old_slides = [each for each in presentation.Slides]
59
+ # if presentation.Slides[int(key)]:
60
+ # slide = new_presentation.Slides.Add(int(key), ppLayoutText)
61
+ # slide.Shapes.addShape(
62
+ # msoShapeRectangle, 150, 150, 250, 250). \
63
+ # TextFrame.TextRange.Text = value
64
+ # new_presentation.Slides.Add(int(key), old_slides[int(key)+1])
65
+
66
+ # if old_slides[int(key)]:
67
+ # slide = presentation.Slides.Add(int(key), ppLayoutText)
68
+ # slide.Shapes.addShape(
69
+ # msoShapeRectangle, 150, 150, 250, 250). \
70
+ # TextFrame.TextRange.Text = value
71
+
72
+
73
+ # for key, value in dict.items():
74
+ # if value =="":
75
+ # print("No value given", key)
76
+ # n = key # slide number to be created,
77
+ # x = value
78
+ # slide = presentation.Slides.Add(n, ppLayoutText)
79
+ # slide.Shapes.addShape(
80
+ # msoShapeRectangle, 150, 150, 250, 250). \
81
+ # TextFrame.TextRange.Text = x
82
+ # slides_len = len(presentation.Slides)
83
+
84
+ # while input_list:
85
+ # if len(input_list) == slides_len:
86
+ # n = 1 # To track the slide number to be created
87
+ # x = 0 # Index in the user input list
88
+ # while x < slides_len:
89
+ # # Create slide and insert it at n position with
90
+ # # input_list[x] text
91
+ # slide = presentation.Slides.Add(n, ppLayoutText)
92
+ # slide.Shapes.addShape(
93
+ # msoShapeRectangle, 150, 150, 250, 250). \
94
+ # TextFrame.TextRange.Text = input_list[x]
95
+ # n += 2
96
+ # x += 1
97
+ # break
98
+ # else:
99
+ # print("The length of input data should be equal to the \
100
+ # slides count")
101
+ # break
53
102
54
103
# Presentation.CreateVideo method (PowerPoint)
55
104
# https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.createvideo
@@ -80,8 +129,9 @@ def ppt2video(pptx, video, timing, duration,
80
129
# the first slide. You can leave it blank and no additional
81
130
# slides will be inserted in the video.
82
131
user_input_list = []
132
+ input_dict = {"0" :"0" , "1" :"1" , "2" :"2" ,"3" :"3" ,"4" :"4" ,"5" :"" ,"6" :"" ,"7" :"" ,"8" :"" ,"9" :"" }
83
133
84
134
ppt2video (f"./{ file_name } " , f"./{ video_name } .mp4" ,
85
135
UseTimingsAndNarrations ,
86
136
DefaultSlideDuration , VertResolution ,
87
- FramesPerSecond , Quality , user_input_list )
137
+ FramesPerSecond , Quality , user_input_list , input_dict )
0 commit comments