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

Function generate_textbox_code

PosterAgent/gen_pptx_code.py:67–135  ·  view source on GitHub ↗
(
    text_dict,
    utils_functions,
    slide_object_name,
    visible=False,
    content=None,
    theme=None,
    tmp_dir='tmp',
    is_title=False,
)

Source from the content-addressed store, hash-verified

65 return code
66
67def generate_textbox_code(
68 text_dict,
69 utils_functions,
70 slide_object_name,
71 visible=False,
72 content=None,
73 theme=None,
74 tmp_dir='tmp',
75 is_title=False,
76):
77 code = utils_functions
78 raw_name = text_dict["textbox_name"]
79 var_name = sanitize_for_var(raw_name)
80
81 code += fr'''
82# Textbox: {raw_name}
83{var_name} = add_textbox(
84 {slide_object_name},
85 '{var_name}',
86 {text_dict['x']},
87 {text_dict['y']},
88 {text_dict['width']},
89 {text_dict['height']},
90 text="",
91 word_wrap=True,
92 font_size=40,
93 bold=False,
94 italic=False,
95 alignment="left",
96 fill_color=None,
97 font_name="Arial"
98)
99'''
100 if visible:
101 # Extract textbox_theme from full theme if needed
102 textbox_border_theme = None
103 if theme is not None and isinstance(theme, dict):
104 textbox_border_theme = theme.get('textbox_theme')
105
106 if textbox_border_theme is None:
107 code += fr'''
108# Make border visible
109style_shape_border({var_name}, color=(255, 0, 0), thickness=5, line_style="solid")
110'''
111 else:
112 code += fr'''
113# Make border visible
114style_shape_border({var_name}, color={textbox_border_theme['color']}, thickness={textbox_border_theme['thickness']}, line_style="{textbox_border_theme['line_style']}")
115'''
116
117 if content is not None:
118 tmp_name = f'{tmp_dir}/{var_name}_content.json'
119 json.dump(content, open(tmp_name, 'w'), indent=4)
120
121 # Determine vertical alignment
122 vertical_anchor = None
123 if is_title and theme is not None and 'section_title_vertical_align' in theme:
124 vertical_anchor = theme['section_title_vertical_align']

Callers 1

generate_poster_codeFunction · 0.70

Calls 1

sanitize_for_varFunction · 0.70

Tested by

no test coverage detected