Update python_pptx/python_pptx.py
Browse files- python_pptx/python_pptx.py +17 -15
python_pptx/python_pptx.py
CHANGED
@@ -4,16 +4,17 @@
|
|
4 |
|
5 |
from pptx import Presentation
|
6 |
from pptx.util import Inches, Pt
|
|
|
7 |
from pptx.enum.text import PP_ALIGN
|
8 |
|
9 |
class PresentationGenerator:
|
10 |
def __init__(self):
|
11 |
-
self.
|
12 |
-
"title":
|
13 |
-
"subtitle":
|
14 |
-
"text":
|
15 |
-
"background":
|
16 |
-
"accent":
|
17 |
}
|
18 |
self.default_font = "Calibri"
|
19 |
|
@@ -59,23 +60,29 @@ class PresentationGenerator:
|
|
59 |
# Set font sizes based on the maximum content length
|
60 |
base_font_size = 32
|
61 |
title_font_size = 44
|
62 |
-
if max_content_length > 300:
|
63 |
base_font_size = 24
|
64 |
title_font_size = 36
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# Title Slide
|
67 |
title_slide = prs.slides.add_slide(prs.slide_layouts[0])
|
68 |
title_slide.shapes.title.text = slides[0]['title']
|
69 |
title_slide.shapes.title.text_frame.paragraphs[0].font.size = Pt(title_font_size)
|
70 |
title_slide.shapes.title.text_frame.paragraphs[0].font.name = self.default_font
|
71 |
-
title_slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = self.
|
72 |
|
73 |
for slide in slides[1:]:
|
74 |
content_slide = prs.slides.add_slide(prs.slide_layouts[1])
|
75 |
content_slide.shapes.title.text = slide['title']
|
76 |
content_slide.shapes.title.text_frame.paragraphs[0].font.size = Pt(title_font_size)
|
77 |
content_slide.shapes.title.text_frame.paragraphs[0].font.name = self.default_font
|
78 |
-
content_slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = self.
|
79 |
|
80 |
if slide['points']:
|
81 |
body = content_slide.shapes.placeholders[1].text_frame
|
@@ -85,11 +92,6 @@ class PresentationGenerator:
|
|
85 |
p.text = point
|
86 |
p.font.size = Pt(base_font_size)
|
87 |
p.font.name = self.default_font
|
88 |
-
p.font.color.rgb = self.
|
89 |
|
90 |
return prs
|
91 |
-
|
92 |
-
def rgb_to_tuple(self, hex_color):
|
93 |
-
# Convert hex color to RGB tuple
|
94 |
-
hex_color = hex_color.lstrip('#')
|
95 |
-
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
|
|
4 |
|
5 |
from pptx import Presentation
|
6 |
from pptx.util import Inches, Pt
|
7 |
+
from pptx.dml.color import RGBColor
|
8 |
from pptx.enum.text import PP_ALIGN
|
9 |
|
10 |
class PresentationGenerator:
|
11 |
def __init__(self):
|
12 |
+
self.default_theme_colors = {
|
13 |
+
"title": RGBColor(31, 78, 121), # Bleu foncé
|
14 |
+
"subtitle": RGBColor(39, 123, 192), # Bleu clair
|
15 |
+
"text": RGBColor(42, 42, 42), # Gris foncé
|
16 |
+
"background": RGBColor(255, 255, 255), # Blanc
|
17 |
+
"accent": RGBColor(152, 193, 217) # Bleu pastel
|
18 |
}
|
19 |
self.default_font = "Calibri"
|
20 |
|
|
|
60 |
# Set font sizes based on the maximum content length
|
61 |
base_font_size = 32
|
62 |
title_font_size = 44
|
63 |
+
if max_content_length > 300:
|
64 |
base_font_size = 24
|
65 |
title_font_size = 36
|
66 |
+
if max_content_length > 400:
|
67 |
+
base_font_size = 20
|
68 |
+
title_font_size = 32
|
69 |
+
if max_content_length > 500:
|
70 |
+
base_font_size = 18
|
71 |
+
title_font_size = 28
|
72 |
|
73 |
# Title Slide
|
74 |
title_slide = prs.slides.add_slide(prs.slide_layouts[0])
|
75 |
title_slide.shapes.title.text = slides[0]['title']
|
76 |
title_slide.shapes.title.text_frame.paragraphs[0].font.size = Pt(title_font_size)
|
77 |
title_slide.shapes.title.text_frame.paragraphs[0].font.name = self.default_font
|
78 |
+
title_slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = self.default_theme_colors["title"]
|
79 |
|
80 |
for slide in slides[1:]:
|
81 |
content_slide = prs.slides.add_slide(prs.slide_layouts[1])
|
82 |
content_slide.shapes.title.text = slide['title']
|
83 |
content_slide.shapes.title.text_frame.paragraphs[0].font.size = Pt(title_font_size)
|
84 |
content_slide.shapes.title.text_frame.paragraphs[0].font.name = self.default_font
|
85 |
+
content_slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = self.default_theme_colors["subtitle"]
|
86 |
|
87 |
if slide['points']:
|
88 |
body = content_slide.shapes.placeholders[1].text_frame
|
|
|
92 |
p.text = point
|
93 |
p.font.size = Pt(base_font_size)
|
94 |
p.font.name = self.default_font
|
95 |
+
p.font.color.rgb = self.default_theme_colors["text"]
|
96 |
|
97 |
return prs
|
|
|
|
|
|
|
|
|
|