PPTAgent's representation of a presentation. Aiming at a more readable and editable interface.
| 1161 | |
| 1162 | |
| 1163 | class Presentation: |
| 1164 | """ |
| 1165 | PPTAgent's representation of a presentation. |
| 1166 | Aiming at a more readable and editable interface. |
| 1167 | """ |
| 1168 | |
| 1169 | def __init__( |
| 1170 | self, |
| 1171 | slides: list[SlidePage], |
| 1172 | error_history: list[str], |
| 1173 | slide_width: float, |
| 1174 | slide_height: float, |
| 1175 | file_path: str, |
| 1176 | num_pages: int, |
| 1177 | ) -> None: |
| 1178 | """ |
| 1179 | Initialize the Presentation. |
| 1180 | """ |
| 1181 | self.slides = slides |
| 1182 | self.error_history = error_history |
| 1183 | self.slide_width = slide_width |
| 1184 | self.slide_height = slide_height |
| 1185 | self.num_pages = num_pages |
| 1186 | self.source_file = file_path |
| 1187 | self.prs = PPTXPre(self.source_file) |
| 1188 | self.layout_mapping = {layout.name: layout for layout in self.prs.slide_layouts} |
| 1189 | self.prs.core_properties.last_modified_by = "PPTAgent" |
| 1190 | |
| 1191 | @classmethod |
| 1192 | def from_file(cls, file_path: str, config: Config): |
| 1193 | """ |
| 1194 | Parse a Presentation from a file. |
| 1195 | """ |
| 1196 | prs = PPTXPre(file_path) |
| 1197 | slide_width = prs.slide_width |
| 1198 | slide_height = prs.slide_height |
| 1199 | slides = [] |
| 1200 | error_history = [] |
| 1201 | slide_idx = 0 |
| 1202 | layouts = [layout.name for layout in prs.slide_layouts] |
| 1203 | num_pages = len(prs.slides) |
| 1204 | for slide in prs.slides: |
| 1205 | if slide._element.get("show") == "0": |
| 1206 | continue # will not be printed to pdf |
| 1207 | |
| 1208 | slide_idx += 1 |
| 1209 | try: |
| 1210 | if slide.slide_layout.name not in layouts: |
| 1211 | raise ValueError( |
| 1212 | f"slide layout {slide.slide_layout.name} not found" |
| 1213 | ) |
| 1214 | slides.append( |
| 1215 | SlidePage.from_slide( |
| 1216 | slide, |
| 1217 | slide_idx - len(error_history), |
| 1218 | slide_idx, |
| 1219 | slide_width.pt, |
| 1220 | slide_height.pt, |
no outgoing calls
no test coverage detected