Skip to content

Commit 4b7f2a5

Browse files
committed
Aadded more coments.
1 parent f8e2db2 commit 4b7f2a5

File tree

2 files changed

+17
-57
lines changed

2 files changed

+17
-57
lines changed

ppt2video/convertor.py

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def ppt2video(pptx, video, timing, duration,
15-
resolution, frames, quality, input_list, dict):
15+
resolution, frames, quality, dict):
1616

1717
# Check if system requirements are met.
1818
if sys.platform == "win32":
@@ -31,78 +31,35 @@ def ppt2video(pptx, video, timing, duration,
3131
# Open presentation
3232
presentation = ppt.Presentations.Open(ppt_path, WithWindow=False)
3333

34-
# slides_len = len(presentation.Slides)
35-
36-
# powerpoint = win32com.client.Dispatch('PowerPoint.Application')
3734
new_presentation = ppt.Presentations.Add(WithWindow=False)
38-
# slides = new_presentation.Slides
39-
# presentation.Slides[1].Copy()
40-
# new_presentation.Slides.Paste(1)
41-
# graphSlideID = gslides.Add(2, ppLayoutChart).SlideID
42-
# slides.FindBySlideID(graphSlideID)
4335

36+
# Compare input and slides by indexes, creating lists and comparing them
4437
keys = [int(key) for key, value in dict.items()]
4538
slides = [slide.SlideIndex for slide in presentation.Slides]
4639
# List of indexes with user input texts.
4740
list = [key for key in keys if key in slides]
4841

4942
# Slides indexes start with 1
5043
for slide in presentation.Slides:
44+
# Checking if user provided input
5145
if slide.SlideIndex in list:
52-
# print(slide.SlideIndex)
53-
# print(dict.get(str(slide.SlideIndex)))
46+
# Create new slide with new text
5447
len_new_ppt = len(new_presentation.Slides)
5548
new_slide = new_presentation.Slides.Add(
5649
len_new_ppt+1, ppLayoutText)
5750
new_slide.Shapes.addShape(
5851
msoShapeRectangle, 150, 150, 250, 250). \
5952
TextFrame.TextRange.Text = dict.get(str(slide.SlideIndex))
53+
# Copying slide from original presentation and adding it new one.
6054
slide.Copy()
6155
len_new_ppt = len(new_presentation.Slides)
6256
new_presentation.Slides.Paste(len_new_ppt+1)
6357
else:
64-
# print("no input", slide.SlideIndex)
58+
# Adding slide to new presentation without user provided text
6559
slide.Copy()
6660
len_new_ppt = len(new_presentation.Slides)
6761
new_presentation.Slides.Paste(len_new_ppt+1)
6862

69-
70-
# for key, value in dict.items():
71-
# if slide.SlideIndex == int(key) and value != "":
72-
# len_new_ppt = len(new_presentation.Slides)
73-
# new_slide = new_presentation.Slides.Add(
74-
# len_new_ppt+1, ppLayoutText)
75-
# new_slide.Shapes.addShape(
76-
# msoShapeRectangle, 150, 150, 250, 250). \
77-
# TextFrame.TextRange.Text = value
78-
# slide.Copy()
79-
# len_new_ppt = len(new_presentation.Slides)
80-
# new_presentation.Slides.Paste(len_new_ppt+1)
81-
# else:
82-
# print(slide.SlideIndex)
83-
84-
# print(slide.SlideIndex)
85-
print("new presentation", len(new_presentation.Slides))
86-
87-
# while input_list:
88-
# if len(input_list) == slides_len:
89-
# n = 1 # To track the slide number to be created
90-
# x = 0 # Index in the user input list
91-
# while x < slides_len:
92-
# # Create slide and insert it at n position with
93-
# # input_list[x] text
94-
# slide = presentation.Slides.Add(n, ppLayoutText)
95-
# slide.Shapes.addShape(
96-
# msoShapeRectangle, 150, 150, 250, 250). \
97-
# TextFrame.TextRange.Text = input_list[x]
98-
# n += 2
99-
# x += 1
100-
# break
101-
# else:
102-
# print("The length of input data should be equal to the \
103-
# slides count")
104-
# break
105-
10663
# Presentation.CreateVideo method (PowerPoint)
10764
# https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.createvideo
10865
new_presentation.CreateVideo(video_path, timing, duration,
@@ -129,17 +86,20 @@ def ppt2video(pptx, video, timing, duration,
12986
VertResolution = 720 # Int
13087
FramesPerSecond = 24 # Int
13188
Quality = 60 # Int
132-
# A list of user input text to insert before slides, starts with
133-
# the first slide. You can leave it blank and no additional
134-
# slides will be inserted in the video.
135-
user_input_list = []
136-
# key in the dict represents the index of the slides in the presentation
137-
# to be converted into video. Slides indexes start with 1, "first slide".
89+
90+
# User Input is in dictionary format. The keys in the dict represent the
91+
# number of the slides in the presentation.
92+
# Slides indexes, and input_dict as well, start with 1, "first slide", e.g.
93+
# {"1":"input before slide number 1, the first slide",
94+
# "2":"input before slide number 2, the second slide",
95+
# "4":"input before slide number 4, the forth slide"}
96+
# You can choose to what slides to add precending text and what slides
97+
# to leave without additional input.
13898
input_dict = { "1":"input index 1",
13999
"2":"input index 2", "4":"input index 4", "5":"input index 5",
140-
"10":"input index 10",}
100+
"10":"input index 10"}
141101

142102
ppt2video(f"./{file_name}", f"./{video_name}.mp4",
143103
UseTimingsAndNarrations,
144104
DefaultSlideDuration, VertResolution,
145-
FramesPerSecond, Quality, user_input_list, input_dict)
105+
FramesPerSecond, Quality, input_dict)

ppt2video/presentation_video.mp4

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)