MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / add_textbox

Function add_textbox

utils/pptx_utils.py:1298–1373  ·  view source on GitHub ↗

Create a textbox shape on the given slide, optionally fill its background with a color if fill_color is specified as (r, g, b). :param slide: Slide object to place the textbox on. :param name: Name for the shape (shape.name). :param left_inch: Left coordinate (in inches).

(
    slide, 
    name, 
    left_inch, 
    top_inch, 
    width_inch, 
    height_inch, 
    text="", 
    word_wrap=True,
    font_size=40,
    bold=False,
    italic=False,
    alignment="left",
    fill_color=None,
    font_name="Arial"
)

Source from the content-addressed store, hash-verified

1296 shape.fill.fore_color.rgb = RGBColor(*fill_color)
1297
1298def add_textbox(
1299 slide,
1300 name,
1301 left_inch,
1302 top_inch,
1303 width_inch,
1304 height_inch,
1305 text="",
1306 word_wrap=True,
1307 font_size=40,
1308 bold=False,
1309 italic=False,
1310 alignment="left",
1311 fill_color=None,
1312 font_name="Arial"
1313):
1314 """
1315 Create a textbox shape on the given slide, optionally fill its background with
1316 a color if fill_color is specified as (r, g, b).
1317
1318 :param slide: Slide object to place the textbox on.
1319 :param name: Name for the shape (shape.name).
1320 :param left_inch: Left coordinate (in inches).
1321 :param top_inch: Top coordinate (in inches).
1322 :param width_inch: Width (in inches).
1323 :param height_inch: Height (in inches).
1324 :param text: Text to display in the textbox.
1325 :param word_wrap: If True, wrap text in the textbox.
1326 :param font_size: Numeric font size (e.g. 40).
1327 :param bold: Boolean to set run.font.bold.
1328 :param italic: Boolean to set run.font.italic.
1329 :param alignment: String alignment: "left", "center", "right", or "justify".
1330 :param fill_color: (r, g, b) tuple for solid fill background color, or None to skip.
1331 :param font_name: String font name (e.g., "Arial").
1332 :return: The newly created textbox shape.
1333 """
1334 shape = slide.shapes.add_textbox(
1335 Inches(left_inch), Inches(top_inch),
1336 Inches(width_inch), Inches(height_inch)
1337 )
1338
1339 shape.name = name
1340
1341 # If a fill color is specified, apply a solid fill
1342 if fill_color is not None:
1343 shape.fill.solid()
1344 shape.fill.fore_color.rgb = RGBColor(*fill_color)
1345 else:
1346 # Otherwise, set "no fill" if you want it transparent
1347 shape.fill.background()
1348
1349 text_frame = shape.text_frame
1350 # Turn off auto-size to ensure stable font size, etc.
1351 text_frame.auto_size = MSO_AUTO_SIZE.NONE
1352 text_frame.word_wrap = word_wrap
1353
1354 # Clear any default paragraphs
1355 text_frame.clear()

Callers

nothing calls this directly

Calls 3

_parse_alignmentFunction · 0.70
_parse_font_sizeFunction · 0.70
clearMethod · 0.45

Tested by

no test coverage detected