Spaces:
Sleeping
Sleeping
Relax shape display condition and adjust shape width
Browse files- helpers/pptx_helper.py +19 -2
helpers/pptx_helper.py
CHANGED
|
@@ -222,7 +222,10 @@ def _handle_step_by_step_process(
|
|
| 222 |
if not step.startswith(STEP_BY_STEP_PROCESS_MARKER):
|
| 223 |
no_marker_count += 1
|
| 224 |
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
| 226 |
return False
|
| 227 |
|
| 228 |
shapes = slide.shapes
|
|
@@ -242,10 +245,24 @@ def _handle_step_by_step_process(
|
|
| 242 |
elif 4 < n_steps <= 6:
|
| 243 |
# Vertical display
|
| 244 |
height = pptx.util.Inches(0.65)
|
| 245 |
-
width = pptx.util.Inches(slide_width_inch * 2/ 3)
|
| 246 |
top = pptx.util.Inches(slide_height_inch / 4)
|
| 247 |
left = INCHES_1 # slide_width_inch - width.inches)
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
for step in steps:
|
| 250 |
shape = shapes.add_shape(MSO_AUTO_SHAPE_TYPE.PENTAGON, left, top, width, height)
|
| 251 |
shape.text = step.removeprefix(STEP_BY_STEP_PROCESS_MARKER)
|
|
|
|
| 222 |
if not step.startswith(STEP_BY_STEP_PROCESS_MARKER):
|
| 223 |
no_marker_count += 1
|
| 224 |
|
| 225 |
+
slide_header = slide_json['heading'].lower()
|
| 226 |
+
if (no_marker_count / n_steps > 0.25) and not (
|
| 227 |
+
('step-by-step' in slide_header) or ('step by step' in slide_header)
|
| 228 |
+
):
|
| 229 |
return False
|
| 230 |
|
| 231 |
shapes = slide.shapes
|
|
|
|
| 245 |
elif 4 < n_steps <= 6:
|
| 246 |
# Vertical display
|
| 247 |
height = pptx.util.Inches(0.65)
|
|
|
|
| 248 |
top = pptx.util.Inches(slide_height_inch / 4)
|
| 249 |
left = INCHES_1 # slide_width_inch - width.inches)
|
| 250 |
|
| 251 |
+
# Find the close to median width, based on the length of each text, to be set
|
| 252 |
+
# for the shapes
|
| 253 |
+
width = pptx.util.Inches(slide_width_inch * 2 / 3)
|
| 254 |
+
lengths = [len(step) for step in steps]
|
| 255 |
+
font_size_20pt = pptx.util.Pt(20)
|
| 256 |
+
widths = sorted(
|
| 257 |
+
[
|
| 258 |
+
min(
|
| 259 |
+
pptx.util.Inches(font_size_20pt.inches * a_len),
|
| 260 |
+
width
|
| 261 |
+
) for a_len in lengths
|
| 262 |
+
]
|
| 263 |
+
)
|
| 264 |
+
width = widths[len(widths) // 2]
|
| 265 |
+
|
| 266 |
for step in steps:
|
| 267 |
shape = shapes.add_shape(MSO_AUTO_SHAPE_TYPE.PENTAGON, left, top, width, height)
|
| 268 |
shape.text = step.removeprefix(STEP_BY_STEP_PROCESS_MARKER)
|