gws-cli 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gws/services/slides.py ADDED
@@ -0,0 +1,2845 @@
1
+ """Google Slides service operations."""
2
+
3
+ import uuid
4
+ from typing import Any
5
+
6
+ from googleapiclient.errors import HttpError
7
+
8
+ from gws.services.base import BaseService
9
+ import json
10
+ from gws.output import output_success, output_error, output_external_content
11
+ from gws.exceptions import ExitCode
12
+
13
+
14
+ class SlidesService(BaseService):
15
+ """Google Slides operations."""
16
+
17
+ SERVICE_NAME = "slides"
18
+ VERSION = "v1"
19
+
20
+ PREDEFINED_LAYOUTS = {
21
+ "BLANK": "BLANK",
22
+ "TITLE": "TITLE",
23
+ "TITLE_AND_BODY": "TITLE_AND_BODY",
24
+ "TITLE_AND_TWO_COLUMNS": "TITLE_AND_TWO_COLUMNS",
25
+ "TITLE_ONLY": "TITLE_ONLY",
26
+ "SECTION_HEADER": "SECTION_HEADER",
27
+ "ONE_COLUMN_TEXT": "ONE_COLUMN_TEXT",
28
+ "MAIN_POINT": "MAIN_POINT",
29
+ "BIG_NUMBER": "BIG_NUMBER",
30
+ }
31
+
32
+ def _generate_object_id(self) -> str:
33
+ """Generate a unique object ID for new elements."""
34
+ return f"gws_{uuid.uuid4().hex[:12]}"
35
+
36
+ def metadata(self, presentation_id: str) -> dict[str, Any]:
37
+ """Get presentation metadata."""
38
+ try:
39
+ presentation = self.execute(
40
+ self.service.presentations()
41
+ .get(presentationId=presentation_id)
42
+ )
43
+
44
+ slides = [
45
+ {
46
+ "object_id": slide["objectId"],
47
+ "index": i,
48
+ "element_count": len(slide.get("pageElements", [])),
49
+ }
50
+ for i, slide in enumerate(presentation.get("slides", []))
51
+ ]
52
+
53
+ output_success(
54
+ operation="slides.metadata",
55
+ presentation_id=presentation_id,
56
+ title=presentation.get("title", ""),
57
+ slide_count=len(slides),
58
+ slides=slides,
59
+ )
60
+ return presentation
61
+ except HttpError as e:
62
+ output_error(
63
+ error_code="API_ERROR",
64
+ operation="slides.metadata",
65
+ message=f"Google Slides API error: {e.reason}",
66
+ )
67
+ raise SystemExit(ExitCode.API_ERROR)
68
+
69
+ def read(
70
+ self,
71
+ presentation_id: str,
72
+ page_object_id: str | None = None,
73
+ ) -> dict[str, Any]:
74
+ """Read presentation or page content."""
75
+ try:
76
+ if page_object_id:
77
+ page = self.execute(
78
+ self.service.presentations()
79
+ .pages()
80
+ .get(presentationId=presentation_id, pageObjectId=page_object_id)
81
+ )
82
+
83
+ elements = []
84
+ for elem in page.get("pageElements", []):
85
+ elem_info = {
86
+ "object_id": elem["objectId"],
87
+ "type": self._get_element_type(elem),
88
+ }
89
+ if "shape" in elem and "text" in elem["shape"]:
90
+ elem_info["text"] = self._extract_text(elem["shape"]["text"])
91
+ elements.append(elem_info)
92
+
93
+ output_external_content(
94
+ operation="slides.read",
95
+ source_type="slide",
96
+ source_id=presentation_id,
97
+ content_fields={
98
+ "elements": json.dumps(elements),
99
+ },
100
+ presentation_id=presentation_id,
101
+ page_object_id=page_object_id,
102
+ element_count=len(elements),
103
+ )
104
+ return page
105
+ else:
106
+ presentation = self.execute(
107
+ self.service.presentations()
108
+ .get(presentationId=presentation_id)
109
+ )
110
+
111
+ slides_info = []
112
+ for i, slide in enumerate(presentation.get("slides", [])):
113
+ slide_info = {
114
+ "object_id": slide["objectId"],
115
+ "index": i,
116
+ "elements": [],
117
+ }
118
+ for elem in slide.get("pageElements", []):
119
+ elem_info = {
120
+ "object_id": elem["objectId"],
121
+ "type": self._get_element_type(elem),
122
+ }
123
+ if "shape" in elem and "text" in elem["shape"]:
124
+ elem_info["text"] = self._extract_text(elem["shape"]["text"])
125
+ slide_info["elements"].append(elem_info)
126
+ slides_info.append(slide_info)
127
+
128
+ output_external_content(
129
+ operation="slides.read",
130
+ source_type="slide",
131
+ source_id=presentation_id,
132
+ content_fields={
133
+ "slides": json.dumps(slides_info),
134
+ },
135
+ presentation_id=presentation_id,
136
+ title=presentation.get("title", ""),
137
+ slide_count=len(slides_info),
138
+ )
139
+ return presentation
140
+ except HttpError as e:
141
+ output_error(
142
+ error_code="API_ERROR",
143
+ operation="slides.read",
144
+ message=f"Google Slides API error: {e.reason}",
145
+ )
146
+ raise SystemExit(ExitCode.API_ERROR)
147
+
148
+ def _get_element_type(self, element: dict) -> str:
149
+ """Determine element type."""
150
+ if "shape" in element:
151
+ return element["shape"].get("shapeType", "SHAPE")
152
+ if "image" in element:
153
+ return "IMAGE"
154
+ if "table" in element:
155
+ return "TABLE"
156
+ if "line" in element:
157
+ return "LINE"
158
+ if "video" in element:
159
+ return "VIDEO"
160
+ return "UNKNOWN"
161
+
162
+ def _extract_text(self, text_content: dict) -> str:
163
+ """Extract plain text from text content."""
164
+ parts = []
165
+ for element in text_content.get("textElements", []):
166
+ if "textRun" in element:
167
+ parts.append(element["textRun"].get("content", ""))
168
+ return "".join(parts).strip()
169
+
170
+ def create(
171
+ self,
172
+ title: str,
173
+ folder_id: str | None = None,
174
+ ) -> dict[str, Any]:
175
+ """Create a new presentation."""
176
+ try:
177
+ presentation = self.execute(
178
+ self.service.presentations()
179
+ .create(body={"title": title})
180
+ )
181
+ presentation_id = presentation["presentationId"]
182
+
183
+ # Move to folder if specified
184
+ if folder_id:
185
+ file = self.execute(
186
+ self.drive_service.files().get(
187
+ fileId=presentation_id, fields="parents"
188
+ )
189
+ )
190
+ previous_parents = ",".join(file.get("parents", []))
191
+
192
+ self.execute(
193
+ self.drive_service.files().update(
194
+ fileId=presentation_id,
195
+ addParents=folder_id,
196
+ removeParents=previous_parents,
197
+ fields="id, parents",
198
+ )
199
+ )
200
+
201
+ output_success(
202
+ operation="slides.create",
203
+ presentation_id=presentation_id,
204
+ title=title,
205
+ web_view_link=f"https://docs.google.com/presentation/d/{presentation_id}/edit",
206
+ )
207
+ return presentation
208
+ except HttpError as e:
209
+ output_error(
210
+ error_code="API_ERROR",
211
+ operation="slides.create",
212
+ message=f"Google Slides API error: {e.reason}",
213
+ )
214
+ raise SystemExit(ExitCode.API_ERROR)
215
+
216
+ def add_slide(
217
+ self,
218
+ presentation_id: str,
219
+ layout: str = "BLANK",
220
+ insertion_index: int | None = None,
221
+ ) -> dict[str, Any]:
222
+ """Add a new slide to the presentation."""
223
+ try:
224
+ slide_id = self._generate_object_id()
225
+
226
+ request: dict[str, Any] = {
227
+ "createSlide": {
228
+ "objectId": slide_id,
229
+ "slideLayoutReference": {
230
+ "predefinedLayout": self.PREDEFINED_LAYOUTS.get(layout, layout)
231
+ },
232
+ }
233
+ }
234
+
235
+ if insertion_index is not None:
236
+ request["createSlide"]["insertionIndex"] = insertion_index
237
+
238
+ result = self.execute(
239
+ self.service.presentations()
240
+ .batchUpdate(
241
+ presentationId=presentation_id, body={"requests": [request]}
242
+ )
243
+ )
244
+
245
+ output_success(
246
+ operation="slides.add_slide",
247
+ presentation_id=presentation_id,
248
+ slide_id=slide_id,
249
+ layout=layout,
250
+ )
251
+ return result
252
+ except HttpError as e:
253
+ output_error(
254
+ error_code="API_ERROR",
255
+ operation="slides.add_slide",
256
+ message=f"Google Slides API error: {e.reason}",
257
+ )
258
+ raise SystemExit(ExitCode.API_ERROR)
259
+
260
+ def delete_slide(
261
+ self,
262
+ presentation_id: str,
263
+ slide_id: str,
264
+ ) -> dict[str, Any]:
265
+ """Delete a slide from the presentation."""
266
+ try:
267
+ request = {"deleteObject": {"objectId": slide_id}}
268
+
269
+ result = self.execute(
270
+ self.service.presentations()
271
+ .batchUpdate(
272
+ presentationId=presentation_id, body={"requests": [request]}
273
+ )
274
+ )
275
+
276
+ output_success(
277
+ operation="slides.delete_slide",
278
+ presentation_id=presentation_id,
279
+ deleted_slide_id=slide_id,
280
+ )
281
+ return result
282
+ except HttpError as e:
283
+ output_error(
284
+ error_code="API_ERROR",
285
+ operation="slides.delete_slide",
286
+ message=f"Google Slides API error: {e.reason}",
287
+ )
288
+ raise SystemExit(ExitCode.API_ERROR)
289
+
290
+ def duplicate_slide(
291
+ self,
292
+ presentation_id: str,
293
+ slide_id: str,
294
+ ) -> dict[str, Any]:
295
+ """Duplicate a slide."""
296
+ try:
297
+ new_slide_id = self._generate_object_id()
298
+
299
+ request = {
300
+ "duplicateObject": {
301
+ "objectId": slide_id,
302
+ "objectIds": {slide_id: new_slide_id},
303
+ }
304
+ }
305
+
306
+ result = self.execute(
307
+ self.service.presentations()
308
+ .batchUpdate(
309
+ presentationId=presentation_id, body={"requests": [request]}
310
+ )
311
+ )
312
+
313
+ output_success(
314
+ operation="slides.duplicate_slide",
315
+ presentation_id=presentation_id,
316
+ original_slide_id=slide_id,
317
+ new_slide_id=new_slide_id,
318
+ )
319
+ return result
320
+ except HttpError as e:
321
+ output_error(
322
+ error_code="API_ERROR",
323
+ operation="slides.duplicate_slide",
324
+ message=f"Google Slides API error: {e.reason}",
325
+ )
326
+ raise SystemExit(ExitCode.API_ERROR)
327
+
328
+ def insert_text(
329
+ self,
330
+ presentation_id: str,
331
+ object_id: str,
332
+ text: str,
333
+ insertion_index: int = 0,
334
+ ) -> dict[str, Any]:
335
+ """Insert text into a shape."""
336
+ try:
337
+ request = {
338
+ "insertText": {
339
+ "objectId": object_id,
340
+ "insertionIndex": insertion_index,
341
+ "text": text,
342
+ }
343
+ }
344
+
345
+ result = self.execute(
346
+ self.service.presentations()
347
+ .batchUpdate(
348
+ presentationId=presentation_id, body={"requests": [request]}
349
+ )
350
+ )
351
+
352
+ output_success(
353
+ operation="slides.insert_text",
354
+ presentation_id=presentation_id,
355
+ object_id=object_id,
356
+ text_length=len(text),
357
+ )
358
+ return result
359
+ except HttpError as e:
360
+ output_error(
361
+ error_code="API_ERROR",
362
+ operation="slides.insert_text",
363
+ message=f"Google Slides API error: {e.reason}",
364
+ )
365
+ raise SystemExit(ExitCode.API_ERROR)
366
+
367
+ def replace_text(
368
+ self,
369
+ presentation_id: str,
370
+ find: str,
371
+ replace_with: str,
372
+ match_case: bool = False,
373
+ page_object_ids: list[str] | None = None,
374
+ ) -> dict[str, Any]:
375
+ """Replace text throughout the presentation."""
376
+ try:
377
+ request: dict[str, Any] = {
378
+ "replaceAllText": {
379
+ "containsText": {
380
+ "text": find,
381
+ "matchCase": match_case,
382
+ },
383
+ "replaceText": replace_with,
384
+ }
385
+ }
386
+
387
+ if page_object_ids:
388
+ request["replaceAllText"]["pageObjectIds"] = page_object_ids
389
+
390
+ result = self.execute(
391
+ self.service.presentations()
392
+ .batchUpdate(
393
+ presentationId=presentation_id, body={"requests": [request]}
394
+ )
395
+ )
396
+
397
+ replies = result.get("replies", [{}])
398
+ occurrences = replies[0].get("replaceAllText", {}).get(
399
+ "occurrencesChanged", 0
400
+ )
401
+
402
+ output_success(
403
+ operation="slides.replace_text",
404
+ presentation_id=presentation_id,
405
+ find=find,
406
+ replace_with=replace_with,
407
+ occurrences_changed=occurrences,
408
+ )
409
+ return result
410
+ except HttpError as e:
411
+ output_error(
412
+ error_code="API_ERROR",
413
+ operation="slides.replace_text",
414
+ message=f"Google Slides API error: {e.reason}",
415
+ )
416
+ raise SystemExit(ExitCode.API_ERROR)
417
+
418
+ def create_textbox(
419
+ self,
420
+ presentation_id: str,
421
+ page_object_id: str,
422
+ text: str,
423
+ x: float,
424
+ y: float,
425
+ width: float,
426
+ height: float,
427
+ ) -> dict[str, Any]:
428
+ """Create a text box on a slide."""
429
+ try:
430
+ textbox_id = self._generate_object_id()
431
+
432
+ requests = [
433
+ {
434
+ "createShape": {
435
+ "objectId": textbox_id,
436
+ "shapeType": "TEXT_BOX",
437
+ "elementProperties": {
438
+ "pageObjectId": page_object_id,
439
+ "size": {
440
+ "width": {"magnitude": width, "unit": "PT"},
441
+ "height": {"magnitude": height, "unit": "PT"},
442
+ },
443
+ "transform": {
444
+ "scaleX": 1,
445
+ "scaleY": 1,
446
+ "translateX": x,
447
+ "translateY": y,
448
+ "unit": "PT",
449
+ },
450
+ },
451
+ }
452
+ },
453
+ {
454
+ "insertText": {
455
+ "objectId": textbox_id,
456
+ "insertionIndex": 0,
457
+ "text": text,
458
+ }
459
+ },
460
+ ]
461
+
462
+ result = self.execute(
463
+ self.service.presentations()
464
+ .batchUpdate(
465
+ presentationId=presentation_id, body={"requests": requests}
466
+ )
467
+ )
468
+
469
+ output_success(
470
+ operation="slides.create_textbox",
471
+ presentation_id=presentation_id,
472
+ page_object_id=page_object_id,
473
+ textbox_id=textbox_id,
474
+ position={"x": x, "y": y, "width": width, "height": height},
475
+ )
476
+ return result
477
+ except HttpError as e:
478
+ output_error(
479
+ error_code="API_ERROR",
480
+ operation="slides.create_textbox",
481
+ message=f"Google Slides API error: {e.reason}",
482
+ )
483
+ raise SystemExit(ExitCode.API_ERROR)
484
+
485
+ def insert_image(
486
+ self,
487
+ presentation_id: str,
488
+ page_object_id: str,
489
+ image_url: str,
490
+ x: float,
491
+ y: float,
492
+ width: float | None = None,
493
+ height: float | None = None,
494
+ ) -> dict[str, Any]:
495
+ """Insert an image on a slide."""
496
+ try:
497
+ image_id = self._generate_object_id()
498
+
499
+ element_properties: dict[str, Any] = {
500
+ "pageObjectId": page_object_id,
501
+ "transform": {
502
+ "scaleX": 1,
503
+ "scaleY": 1,
504
+ "translateX": x,
505
+ "translateY": y,
506
+ "unit": "PT",
507
+ },
508
+ }
509
+
510
+ if width is not None and height is not None:
511
+ element_properties["size"] = {
512
+ "width": {"magnitude": width, "unit": "PT"},
513
+ "height": {"magnitude": height, "unit": "PT"},
514
+ }
515
+
516
+ request = {
517
+ "createImage": {
518
+ "objectId": image_id,
519
+ "url": image_url,
520
+ "elementProperties": element_properties,
521
+ }
522
+ }
523
+
524
+ result = self.execute(
525
+ self.service.presentations()
526
+ .batchUpdate(
527
+ presentationId=presentation_id, body={"requests": [request]}
528
+ )
529
+ )
530
+
531
+ output_success(
532
+ operation="slides.insert_image",
533
+ presentation_id=presentation_id,
534
+ page_object_id=page_object_id,
535
+ image_id=image_id,
536
+ image_url=image_url,
537
+ )
538
+ return result
539
+ except HttpError as e:
540
+ output_error(
541
+ error_code="API_ERROR",
542
+ operation="slides.insert_image",
543
+ message=f"Google Slides API error: {e.reason}",
544
+ )
545
+ raise SystemExit(ExitCode.API_ERROR)
546
+
547
+ def delete_element(
548
+ self,
549
+ presentation_id: str,
550
+ object_id: str,
551
+ ) -> dict[str, Any]:
552
+ """Delete an element from a slide."""
553
+ try:
554
+ request = {"deleteObject": {"objectId": object_id}}
555
+
556
+ result = self.execute(
557
+ self.service.presentations()
558
+ .batchUpdate(
559
+ presentationId=presentation_id, body={"requests": [request]}
560
+ )
561
+ )
562
+
563
+ output_success(
564
+ operation="slides.delete_element",
565
+ presentation_id=presentation_id,
566
+ deleted_object_id=object_id,
567
+ )
568
+ return result
569
+ except HttpError as e:
570
+ output_error(
571
+ error_code="API_ERROR",
572
+ operation="slides.delete_element",
573
+ message=f"Google Slides API error: {e.reason}",
574
+ )
575
+ raise SystemExit(ExitCode.API_ERROR)
576
+
577
+ def format_text(
578
+ self,
579
+ presentation_id: str,
580
+ object_id: str,
581
+ bold: bool | None = None,
582
+ italic: bool | None = None,
583
+ underline: bool | None = None,
584
+ font_size: int | None = None,
585
+ foreground_color: str | None = None,
586
+ ) -> dict[str, Any]:
587
+ """Apply formatting to text in an element."""
588
+ try:
589
+ text_style: dict[str, Any] = {}
590
+ fields = []
591
+
592
+ if bold is not None:
593
+ text_style["bold"] = bold
594
+ fields.append("bold")
595
+ if italic is not None:
596
+ text_style["italic"] = italic
597
+ fields.append("italic")
598
+ if underline is not None:
599
+ text_style["underline"] = underline
600
+ fields.append("underline")
601
+ if font_size is not None:
602
+ text_style["fontSize"] = {"magnitude": font_size, "unit": "PT"}
603
+ fields.append("fontSize")
604
+ if foreground_color is not None:
605
+ from gws.utils.colors import parse_hex_color
606
+ rgb = parse_hex_color(foreground_color)
607
+ text_style["foregroundColor"] = {"opaqueColor": {"rgbColor": rgb}}
608
+ fields.append("foregroundColor")
609
+
610
+ if not fields:
611
+ output_error(
612
+ error_code="INVALID_ARGS",
613
+ operation="slides.format_text",
614
+ message="At least one formatting option required",
615
+ )
616
+ raise SystemExit(ExitCode.INVALID_ARGS)
617
+
618
+ request = {
619
+ "updateTextStyle": {
620
+ "objectId": object_id,
621
+ "style": text_style,
622
+ "textRange": {"type": "ALL"},
623
+ "fields": ",".join(fields),
624
+ }
625
+ }
626
+
627
+ result = self.execute(
628
+ self.service.presentations()
629
+ .batchUpdate(
630
+ presentationId=presentation_id, body={"requests": [request]}
631
+ )
632
+ )
633
+
634
+ output_success(
635
+ operation="slides.format_text",
636
+ presentation_id=presentation_id,
637
+ object_id=object_id,
638
+ formatting=fields,
639
+ )
640
+ return result
641
+ except HttpError as e:
642
+ output_error(
643
+ error_code="API_ERROR",
644
+ operation="slides.format_text",
645
+ message=f"Google Slides API error: {e.reason}",
646
+ )
647
+ raise SystemExit(ExitCode.API_ERROR)
648
+
649
+ def format_text_extended(
650
+ self,
651
+ presentation_id: str,
652
+ object_id: str,
653
+ start_index: int | None = None,
654
+ end_index: int | None = None,
655
+ bold: bool | None = None,
656
+ italic: bool | None = None,
657
+ underline: bool | None = None,
658
+ strikethrough: bool | None = None,
659
+ small_caps: bool | None = None,
660
+ font_family: str | None = None,
661
+ font_weight: int | None = None,
662
+ font_size: int | None = None,
663
+ foreground_color: str | None = None,
664
+ background_color: str | None = None,
665
+ baseline_offset: str | None = None,
666
+ link_url: str | None = None,
667
+ ) -> dict[str, Any]:
668
+ """Apply extended formatting to text in an element.
669
+
670
+ Args:
671
+ presentation_id: The presentation ID.
672
+ object_id: The shape/text box object ID.
673
+ start_index: Start character index (0-based). If None, applies to all text.
674
+ end_index: End character index (exclusive). If None, applies to all text.
675
+ bold: Bold formatting.
676
+ italic: Italic formatting.
677
+ underline: Underline formatting.
678
+ strikethrough: Strikethrough formatting.
679
+ small_caps: Small caps formatting.
680
+ font_family: Font family name (e.g., "Arial", "Roboto").
681
+ font_weight: Font weight (100-900, in increments of 100).
682
+ font_size: Font size in points.
683
+ foreground_color: Text color (hex, e.g., "#FF0000").
684
+ background_color: Text background/highlight color (hex).
685
+ baseline_offset: Baseline offset ("SUPERSCRIPT" or "SUBSCRIPT").
686
+ link_url: URL to link the text to.
687
+ """
688
+ try:
689
+ from gws.utils.colors import parse_hex_color
690
+
691
+ text_style: dict[str, Any] = {}
692
+ fields = []
693
+
694
+ if bold is not None:
695
+ text_style["bold"] = bold
696
+ fields.append("bold")
697
+ if italic is not None:
698
+ text_style["italic"] = italic
699
+ fields.append("italic")
700
+ if underline is not None:
701
+ text_style["underline"] = underline
702
+ fields.append("underline")
703
+ if strikethrough is not None:
704
+ text_style["strikethrough"] = strikethrough
705
+ fields.append("strikethrough")
706
+ if small_caps is not None:
707
+ text_style["smallCaps"] = small_caps
708
+ fields.append("smallCaps")
709
+ if font_size is not None:
710
+ text_style["fontSize"] = {"magnitude": font_size, "unit": "PT"}
711
+ fields.append("fontSize")
712
+ if foreground_color is not None:
713
+ rgb = parse_hex_color(foreground_color)
714
+ text_style["foregroundColor"] = {"opaqueColor": {"rgbColor": rgb}}
715
+ fields.append("foregroundColor")
716
+ if background_color is not None:
717
+ rgb = parse_hex_color(background_color)
718
+ text_style["backgroundColor"] = {"opaqueColor": {"rgbColor": rgb}}
719
+ fields.append("backgroundColor")
720
+ if baseline_offset is not None:
721
+ valid_offsets = {"SUPERSCRIPT", "SUBSCRIPT", "NONE"}
722
+ if baseline_offset.upper() not in valid_offsets:
723
+ output_error(
724
+ error_code="INVALID_ARGS",
725
+ operation="slides.format_text_extended",
726
+ message=f"baseline_offset must be one of: {valid_offsets}",
727
+ )
728
+ raise SystemExit(ExitCode.INVALID_ARGS)
729
+ text_style["baselineOffset"] = baseline_offset.upper()
730
+ fields.append("baselineOffset")
731
+ if link_url is not None:
732
+ text_style["link"] = {"url": link_url}
733
+ fields.append("link")
734
+ if font_family is not None or font_weight is not None:
735
+ weighted_font: dict[str, Any] = {}
736
+ if font_family is not None:
737
+ weighted_font["fontFamily"] = font_family
738
+ if font_weight is not None:
739
+ if font_weight < 100 or font_weight > 900 or font_weight % 100 != 0:
740
+ output_error(
741
+ error_code="INVALID_ARGS",
742
+ operation="slides.format_text_extended",
743
+ message="font_weight must be 100-900 in increments of 100",
744
+ )
745
+ raise SystemExit(ExitCode.INVALID_ARGS)
746
+ weighted_font["weight"] = font_weight
747
+ text_style["weightedFontFamily"] = weighted_font
748
+ fields.append("weightedFontFamily")
749
+
750
+ if not fields:
751
+ output_error(
752
+ error_code="INVALID_ARGS",
753
+ operation="slides.format_text_extended",
754
+ message="At least one formatting option required",
755
+ )
756
+ raise SystemExit(ExitCode.INVALID_ARGS)
757
+
758
+ # Build text range
759
+ if start_index is not None and end_index is not None:
760
+ text_range = {
761
+ "type": "FIXED_RANGE",
762
+ "startIndex": start_index,
763
+ "endIndex": end_index,
764
+ }
765
+ else:
766
+ text_range = {"type": "ALL"}
767
+
768
+ request = {
769
+ "updateTextStyle": {
770
+ "objectId": object_id,
771
+ "style": text_style,
772
+ "textRange": text_range,
773
+ "fields": ",".join(fields),
774
+ }
775
+ }
776
+
777
+ result = self.execute(
778
+ self.service.presentations()
779
+ .batchUpdate(
780
+ presentationId=presentation_id, body={"requests": [request]}
781
+ )
782
+ )
783
+
784
+ output_success(
785
+ operation="slides.format_text_extended",
786
+ presentation_id=presentation_id,
787
+ object_id=object_id,
788
+ formatting=fields,
789
+ text_range=text_range,
790
+ )
791
+ return result
792
+ except HttpError as e:
793
+ output_error(
794
+ error_code="API_ERROR",
795
+ operation="slides.format_text_extended",
796
+ message=f"Google Slides API error: {e.reason}",
797
+ )
798
+ raise SystemExit(ExitCode.API_ERROR)
799
+
800
+ def format_paragraph(
801
+ self,
802
+ presentation_id: str,
803
+ object_id: str,
804
+ start_index: int | None = None,
805
+ end_index: int | None = None,
806
+ alignment: str | None = None,
807
+ line_spacing: float | None = None,
808
+ space_above: float | None = None,
809
+ space_below: float | None = None,
810
+ indent_first_line: float | None = None,
811
+ indent_start: float | None = None,
812
+ indent_end: float | None = None,
813
+ ) -> dict[str, Any]:
814
+ """Apply paragraph formatting to text in an element.
815
+
816
+ Args:
817
+ presentation_id: The presentation ID.
818
+ object_id: The shape/text box object ID.
819
+ start_index: Start character index (0-based). If None, applies to all.
820
+ end_index: End character index (exclusive). If None, applies to all.
821
+ alignment: Paragraph alignment (START, CENTER, END, JUSTIFIED).
822
+ line_spacing: Line spacing as percentage (100 = single, 200 = double).
823
+ space_above: Space above paragraph in points.
824
+ space_below: Space below paragraph in points.
825
+ indent_first_line: First line indent in points.
826
+ indent_start: Start (left) indent in points.
827
+ indent_end: End (right) indent in points.
828
+ """
829
+ try:
830
+ paragraph_style: dict[str, Any] = {}
831
+ fields = []
832
+
833
+ if alignment is not None:
834
+ valid_alignments = {"START", "CENTER", "END", "JUSTIFIED"}
835
+ if alignment.upper() not in valid_alignments:
836
+ output_error(
837
+ error_code="INVALID_ARGS",
838
+ operation="slides.format_paragraph",
839
+ message=f"alignment must be one of: {valid_alignments}",
840
+ )
841
+ raise SystemExit(ExitCode.INVALID_ARGS)
842
+ paragraph_style["alignment"] = alignment.upper()
843
+ fields.append("alignment")
844
+ if line_spacing is not None:
845
+ paragraph_style["lineSpacing"] = line_spacing
846
+ fields.append("lineSpacing")
847
+ if space_above is not None:
848
+ paragraph_style["spaceAbove"] = {"magnitude": space_above, "unit": "PT"}
849
+ fields.append("spaceAbove")
850
+ if space_below is not None:
851
+ paragraph_style["spaceBelow"] = {"magnitude": space_below, "unit": "PT"}
852
+ fields.append("spaceBelow")
853
+ if indent_first_line is not None:
854
+ paragraph_style["indentFirstLine"] = {
855
+ "magnitude": indent_first_line,
856
+ "unit": "PT",
857
+ }
858
+ fields.append("indentFirstLine")
859
+ if indent_start is not None:
860
+ paragraph_style["indentStart"] = {
861
+ "magnitude": indent_start,
862
+ "unit": "PT",
863
+ }
864
+ fields.append("indentStart")
865
+ if indent_end is not None:
866
+ paragraph_style["indentEnd"] = {"magnitude": indent_end, "unit": "PT"}
867
+ fields.append("indentEnd")
868
+
869
+ if not fields:
870
+ output_error(
871
+ error_code="INVALID_ARGS",
872
+ operation="slides.format_paragraph",
873
+ message="At least one formatting option required",
874
+ )
875
+ raise SystemExit(ExitCode.INVALID_ARGS)
876
+
877
+ # Build text range
878
+ if start_index is not None and end_index is not None:
879
+ text_range = {
880
+ "type": "FIXED_RANGE",
881
+ "startIndex": start_index,
882
+ "endIndex": end_index,
883
+ }
884
+ else:
885
+ text_range = {"type": "ALL"}
886
+
887
+ request = {
888
+ "updateParagraphStyle": {
889
+ "objectId": object_id,
890
+ "style": paragraph_style,
891
+ "textRange": text_range,
892
+ "fields": ",".join(fields),
893
+ }
894
+ }
895
+
896
+ result = self.execute(
897
+ self.service.presentations()
898
+ .batchUpdate(
899
+ presentationId=presentation_id, body={"requests": [request]}
900
+ )
901
+ )
902
+
903
+ output_success(
904
+ operation="slides.format_paragraph",
905
+ presentation_id=presentation_id,
906
+ object_id=object_id,
907
+ formatting=fields,
908
+ text_range=text_range,
909
+ )
910
+ return result
911
+ except HttpError as e:
912
+ output_error(
913
+ error_code="API_ERROR",
914
+ operation="slides.format_paragraph",
915
+ message=f"Google Slides API error: {e.reason}",
916
+ )
917
+ raise SystemExit(ExitCode.API_ERROR)
918
+
919
+ def create_shape(
920
+ self,
921
+ presentation_id: str,
922
+ page_object_id: str,
923
+ shape_type: str,
924
+ x: float,
925
+ y: float,
926
+ width: float,
927
+ height: float,
928
+ ) -> dict[str, Any]:
929
+ """Create a shape on a slide.
930
+
931
+ Args:
932
+ presentation_id: The presentation ID.
933
+ page_object_id: The slide/page object ID.
934
+ shape_type: Shape type (RECTANGLE, ELLIPSE, ROUND_RECTANGLE, etc.).
935
+ x: X position in points.
936
+ y: Y position in points.
937
+ width: Width in points.
938
+ height: Height in points.
939
+ """
940
+ try:
941
+ shape_id = self._generate_object_id()
942
+
943
+ request = {
944
+ "createShape": {
945
+ "objectId": shape_id,
946
+ "shapeType": shape_type.upper(),
947
+ "elementProperties": {
948
+ "pageObjectId": page_object_id,
949
+ "size": {
950
+ "width": {"magnitude": width, "unit": "PT"},
951
+ "height": {"magnitude": height, "unit": "PT"},
952
+ },
953
+ "transform": {
954
+ "scaleX": 1,
955
+ "scaleY": 1,
956
+ "translateX": x,
957
+ "translateY": y,
958
+ "unit": "PT",
959
+ },
960
+ },
961
+ }
962
+ }
963
+
964
+ result = self.execute(
965
+ self.service.presentations()
966
+ .batchUpdate(
967
+ presentationId=presentation_id, body={"requests": [request]}
968
+ )
969
+ )
970
+
971
+ output_success(
972
+ operation="slides.create_shape",
973
+ presentation_id=presentation_id,
974
+ page_object_id=page_object_id,
975
+ shape_id=shape_id,
976
+ shape_type=shape_type.upper(),
977
+ position={"x": x, "y": y, "width": width, "height": height},
978
+ )
979
+ return result
980
+ except HttpError as e:
981
+ output_error(
982
+ error_code="API_ERROR",
983
+ operation="slides.create_shape",
984
+ message=f"Google Slides API error: {e.reason}",
985
+ )
986
+ raise SystemExit(ExitCode.API_ERROR)
987
+
988
+ def format_shape(
989
+ self,
990
+ presentation_id: str,
991
+ object_id: str,
992
+ fill_color: str | None = None,
993
+ outline_color: str | None = None,
994
+ outline_weight: float | None = None,
995
+ outline_dash_style: str | None = None,
996
+ ) -> dict[str, Any]:
997
+ """Format a shape's appearance.
998
+
999
+ Args:
1000
+ presentation_id: The presentation ID.
1001
+ object_id: The shape object ID.
1002
+ fill_color: Fill color (hex, e.g., "#FF0000").
1003
+ outline_color: Outline color (hex).
1004
+ outline_weight: Outline weight in points.
1005
+ outline_dash_style: Dash style (SOLID, DOT, DASH, DASH_DOT, LONG_DASH).
1006
+ """
1007
+ try:
1008
+ from gws.utils.colors import parse_hex_color
1009
+
1010
+ shape_properties: dict[str, Any] = {}
1011
+ fields = []
1012
+
1013
+ if fill_color is not None:
1014
+ rgb = parse_hex_color(fill_color)
1015
+ shape_properties["shapeBackgroundFill"] = {
1016
+ "solidFill": {"color": {"rgbColor": rgb}}
1017
+ }
1018
+ fields.append("shapeBackgroundFill")
1019
+
1020
+ if (
1021
+ outline_color is not None
1022
+ or outline_weight is not None
1023
+ or outline_dash_style is not None
1024
+ ):
1025
+ outline: dict[str, Any] = {}
1026
+ if outline_color is not None:
1027
+ rgb = parse_hex_color(outline_color)
1028
+ outline["outlineFill"] = {"solidFill": {"color": {"rgbColor": rgb}}}
1029
+ if outline_weight is not None:
1030
+ outline["weight"] = {"magnitude": outline_weight, "unit": "PT"}
1031
+ if outline_dash_style is not None:
1032
+ valid_styles = {"SOLID", "DOT", "DASH", "DASH_DOT", "LONG_DASH"}
1033
+ if outline_dash_style.upper() not in valid_styles:
1034
+ output_error(
1035
+ error_code="INVALID_ARGS",
1036
+ operation="slides.format_shape",
1037
+ message=f"outline_dash_style must be one of: {valid_styles}",
1038
+ )
1039
+ raise SystemExit(ExitCode.INVALID_ARGS)
1040
+ outline["dashStyle"] = outline_dash_style.upper()
1041
+ shape_properties["outline"] = outline
1042
+ fields.append("outline")
1043
+
1044
+ if not fields:
1045
+ output_error(
1046
+ error_code="INVALID_ARGS",
1047
+ operation="slides.format_shape",
1048
+ message="At least one formatting option required",
1049
+ )
1050
+ raise SystemExit(ExitCode.INVALID_ARGS)
1051
+
1052
+ request = {
1053
+ "updateShapeProperties": {
1054
+ "objectId": object_id,
1055
+ "shapeProperties": shape_properties,
1056
+ "fields": ",".join(fields),
1057
+ }
1058
+ }
1059
+
1060
+ result = self.execute(
1061
+ self.service.presentations()
1062
+ .batchUpdate(
1063
+ presentationId=presentation_id, body={"requests": [request]}
1064
+ )
1065
+ )
1066
+
1067
+ output_success(
1068
+ operation="slides.format_shape",
1069
+ presentation_id=presentation_id,
1070
+ object_id=object_id,
1071
+ formatting=fields,
1072
+ )
1073
+ return result
1074
+ except HttpError as e:
1075
+ output_error(
1076
+ error_code="API_ERROR",
1077
+ operation="slides.format_shape",
1078
+ message=f"Google Slides API error: {e.reason}",
1079
+ )
1080
+ raise SystemExit(ExitCode.API_ERROR)
1081
+
1082
+ def insert_table(
1083
+ self,
1084
+ presentation_id: str,
1085
+ page_object_id: str,
1086
+ rows: int,
1087
+ columns: int,
1088
+ x: float,
1089
+ y: float,
1090
+ width: float,
1091
+ height: float,
1092
+ ) -> dict[str, Any]:
1093
+ """Insert a table on a slide.
1094
+
1095
+ Args:
1096
+ presentation_id: The presentation ID.
1097
+ page_object_id: The slide/page object ID.
1098
+ rows: Number of rows.
1099
+ columns: Number of columns.
1100
+ x: X position in points.
1101
+ y: Y position in points.
1102
+ width: Width in points.
1103
+ height: Height in points.
1104
+ """
1105
+ try:
1106
+ table_id = self._generate_object_id()
1107
+
1108
+ request = {
1109
+ "createTable": {
1110
+ "objectId": table_id,
1111
+ "rows": rows,
1112
+ "columns": columns,
1113
+ "elementProperties": {
1114
+ "pageObjectId": page_object_id,
1115
+ "size": {
1116
+ "width": {"magnitude": width, "unit": "PT"},
1117
+ "height": {"magnitude": height, "unit": "PT"},
1118
+ },
1119
+ "transform": {
1120
+ "scaleX": 1,
1121
+ "scaleY": 1,
1122
+ "translateX": x,
1123
+ "translateY": y,
1124
+ "unit": "PT",
1125
+ },
1126
+ },
1127
+ }
1128
+ }
1129
+
1130
+ result = self.execute(
1131
+ self.service.presentations()
1132
+ .batchUpdate(
1133
+ presentationId=presentation_id, body={"requests": [request]}
1134
+ )
1135
+ )
1136
+
1137
+ output_success(
1138
+ operation="slides.insert_table",
1139
+ presentation_id=presentation_id,
1140
+ page_object_id=page_object_id,
1141
+ table_id=table_id,
1142
+ rows=rows,
1143
+ columns=columns,
1144
+ )
1145
+ return result
1146
+ except HttpError as e:
1147
+ output_error(
1148
+ error_code="API_ERROR",
1149
+ operation="slides.insert_table",
1150
+ message=f"Google Slides API error: {e.reason}",
1151
+ )
1152
+ raise SystemExit(ExitCode.API_ERROR)
1153
+
1154
+ def insert_table_row(
1155
+ self,
1156
+ presentation_id: str,
1157
+ table_id: str,
1158
+ row_index: int,
1159
+ insert_below: bool = True,
1160
+ ) -> dict[str, Any]:
1161
+ """Insert a row in a table.
1162
+
1163
+ Args:
1164
+ presentation_id: The presentation ID.
1165
+ table_id: The table object ID.
1166
+ row_index: Row index to insert at.
1167
+ insert_below: Insert below (True) or above (False) the specified row.
1168
+ """
1169
+ try:
1170
+ request = {
1171
+ "insertTableRows": {
1172
+ "tableObjectId": table_id,
1173
+ "cellLocation": {"rowIndex": row_index},
1174
+ "insertBelow": insert_below,
1175
+ "number": 1,
1176
+ }
1177
+ }
1178
+
1179
+ result = self.execute(
1180
+ self.service.presentations()
1181
+ .batchUpdate(
1182
+ presentationId=presentation_id, body={"requests": [request]}
1183
+ )
1184
+ )
1185
+
1186
+ output_success(
1187
+ operation="slides.insert_table_row",
1188
+ presentation_id=presentation_id,
1189
+ table_id=table_id,
1190
+ row_index=row_index,
1191
+ insert_below=insert_below,
1192
+ )
1193
+ return result
1194
+ except HttpError as e:
1195
+ output_error(
1196
+ error_code="API_ERROR",
1197
+ operation="slides.insert_table_row",
1198
+ message=f"Google Slides API error: {e.reason}",
1199
+ )
1200
+ raise SystemExit(ExitCode.API_ERROR)
1201
+
1202
+ def insert_table_column(
1203
+ self,
1204
+ presentation_id: str,
1205
+ table_id: str,
1206
+ column_index: int,
1207
+ insert_right: bool = True,
1208
+ ) -> dict[str, Any]:
1209
+ """Insert a column in a table.
1210
+
1211
+ Args:
1212
+ presentation_id: The presentation ID.
1213
+ table_id: The table object ID.
1214
+ column_index: Column index to insert at.
1215
+ insert_right: Insert to the right (True) or left (False).
1216
+ """
1217
+ try:
1218
+ request = {
1219
+ "insertTableColumns": {
1220
+ "tableObjectId": table_id,
1221
+ "cellLocation": {"columnIndex": column_index},
1222
+ "insertRight": insert_right,
1223
+ "number": 1,
1224
+ }
1225
+ }
1226
+
1227
+ result = self.execute(
1228
+ self.service.presentations()
1229
+ .batchUpdate(
1230
+ presentationId=presentation_id, body={"requests": [request]}
1231
+ )
1232
+ )
1233
+
1234
+ output_success(
1235
+ operation="slides.insert_table_column",
1236
+ presentation_id=presentation_id,
1237
+ table_id=table_id,
1238
+ column_index=column_index,
1239
+ insert_right=insert_right,
1240
+ )
1241
+ return result
1242
+ except HttpError as e:
1243
+ output_error(
1244
+ error_code="API_ERROR",
1245
+ operation="slides.insert_table_column",
1246
+ message=f"Google Slides API error: {e.reason}",
1247
+ )
1248
+ raise SystemExit(ExitCode.API_ERROR)
1249
+
1250
+ def delete_table_row(
1251
+ self,
1252
+ presentation_id: str,
1253
+ table_id: str,
1254
+ row_index: int,
1255
+ ) -> dict[str, Any]:
1256
+ """Delete a row from a table.
1257
+
1258
+ Args:
1259
+ presentation_id: The presentation ID.
1260
+ table_id: The table object ID.
1261
+ row_index: Row index to delete.
1262
+ """
1263
+ try:
1264
+ request = {
1265
+ "deleteTableRow": {
1266
+ "tableObjectId": table_id,
1267
+ "cellLocation": {"rowIndex": row_index},
1268
+ }
1269
+ }
1270
+
1271
+ result = self.execute(
1272
+ self.service.presentations()
1273
+ .batchUpdate(
1274
+ presentationId=presentation_id, body={"requests": [request]}
1275
+ )
1276
+ )
1277
+
1278
+ output_success(
1279
+ operation="slides.delete_table_row",
1280
+ presentation_id=presentation_id,
1281
+ table_id=table_id,
1282
+ row_index=row_index,
1283
+ )
1284
+ return result
1285
+ except HttpError as e:
1286
+ output_error(
1287
+ error_code="API_ERROR",
1288
+ operation="slides.delete_table_row",
1289
+ message=f"Google Slides API error: {e.reason}",
1290
+ )
1291
+ raise SystemExit(ExitCode.API_ERROR)
1292
+
1293
+ def delete_table_column(
1294
+ self,
1295
+ presentation_id: str,
1296
+ table_id: str,
1297
+ column_index: int,
1298
+ ) -> dict[str, Any]:
1299
+ """Delete a column from a table.
1300
+
1301
+ Args:
1302
+ presentation_id: The presentation ID.
1303
+ table_id: The table object ID.
1304
+ column_index: Column index to delete.
1305
+ """
1306
+ try:
1307
+ request = {
1308
+ "deleteTableColumn": {
1309
+ "tableObjectId": table_id,
1310
+ "cellLocation": {"columnIndex": column_index},
1311
+ }
1312
+ }
1313
+
1314
+ result = self.execute(
1315
+ self.service.presentations()
1316
+ .batchUpdate(
1317
+ presentationId=presentation_id, body={"requests": [request]}
1318
+ )
1319
+ )
1320
+
1321
+ output_success(
1322
+ operation="slides.delete_table_column",
1323
+ presentation_id=presentation_id,
1324
+ table_id=table_id,
1325
+ column_index=column_index,
1326
+ )
1327
+ return result
1328
+ except HttpError as e:
1329
+ output_error(
1330
+ error_code="API_ERROR",
1331
+ operation="slides.delete_table_column",
1332
+ message=f"Google Slides API error: {e.reason}",
1333
+ )
1334
+ raise SystemExit(ExitCode.API_ERROR)
1335
+
1336
+ def style_table_cell(
1337
+ self,
1338
+ presentation_id: str,
1339
+ table_id: str,
1340
+ row_index: int,
1341
+ column_index: int,
1342
+ background_color: str | None = None,
1343
+ end_row_index: int | None = None,
1344
+ end_column_index: int | None = None,
1345
+ ) -> dict[str, Any]:
1346
+ """Style table cells.
1347
+
1348
+ Args:
1349
+ presentation_id: The presentation ID.
1350
+ table_id: The table object ID.
1351
+ row_index: Starting row index.
1352
+ column_index: Starting column index.
1353
+ background_color: Cell background color (hex).
1354
+ end_row_index: Ending row index (exclusive). If None, styles single row.
1355
+ end_column_index: Ending column index (exclusive). If None, styles single column.
1356
+ """
1357
+ try:
1358
+ from gws.utils.colors import parse_hex_color
1359
+
1360
+ cell_properties: dict[str, Any] = {}
1361
+ fields = []
1362
+
1363
+ if background_color is not None:
1364
+ rgb = parse_hex_color(background_color)
1365
+ cell_properties["tableCellBackgroundFill"] = {
1366
+ "solidFill": {"color": {"rgbColor": rgb}}
1367
+ }
1368
+ fields.append("tableCellBackgroundFill")
1369
+
1370
+ if not fields:
1371
+ output_error(
1372
+ error_code="INVALID_ARGS",
1373
+ operation="slides.style_table_cell",
1374
+ message="At least one styling option required",
1375
+ )
1376
+ raise SystemExit(ExitCode.INVALID_ARGS)
1377
+
1378
+ # Default to single cell if end indices not provided
1379
+ if end_row_index is None:
1380
+ end_row_index = row_index + 1
1381
+ if end_column_index is None:
1382
+ end_column_index = column_index + 1
1383
+
1384
+ request = {
1385
+ "updateTableCellProperties": {
1386
+ "objectId": table_id,
1387
+ "tableRange": {
1388
+ "location": {
1389
+ "rowIndex": row_index,
1390
+ "columnIndex": column_index,
1391
+ },
1392
+ "rowSpan": end_row_index - row_index,
1393
+ "columnSpan": end_column_index - column_index,
1394
+ },
1395
+ "tableCellProperties": cell_properties,
1396
+ "fields": ",".join(fields),
1397
+ }
1398
+ }
1399
+
1400
+ result = self.execute(
1401
+ self.service.presentations()
1402
+ .batchUpdate(
1403
+ presentationId=presentation_id, body={"requests": [request]}
1404
+ )
1405
+ )
1406
+
1407
+ output_success(
1408
+ operation="slides.style_table_cell",
1409
+ presentation_id=presentation_id,
1410
+ table_id=table_id,
1411
+ row_index=row_index,
1412
+ column_index=column_index,
1413
+ formatting=fields,
1414
+ )
1415
+ return result
1416
+ except HttpError as e:
1417
+ output_error(
1418
+ error_code="API_ERROR",
1419
+ operation="slides.style_table_cell",
1420
+ message=f"Google Slides API error: {e.reason}",
1421
+ )
1422
+ raise SystemExit(ExitCode.API_ERROR)
1423
+
1424
+ def insert_text_in_table_cell(
1425
+ self,
1426
+ presentation_id: str,
1427
+ table_id: str,
1428
+ row_index: int,
1429
+ column_index: int,
1430
+ text: str,
1431
+ ) -> dict[str, Any]:
1432
+ """Insert text into a table cell.
1433
+
1434
+ Args:
1435
+ presentation_id: The presentation ID.
1436
+ table_id: The table object ID.
1437
+ row_index: Row index of the cell.
1438
+ column_index: Column index of the cell.
1439
+ text: Text to insert.
1440
+ """
1441
+ try:
1442
+ request = {
1443
+ "insertText": {
1444
+ "objectId": table_id,
1445
+ "cellLocation": {
1446
+ "rowIndex": row_index,
1447
+ "columnIndex": column_index,
1448
+ },
1449
+ "insertionIndex": 0,
1450
+ "text": text,
1451
+ }
1452
+ }
1453
+
1454
+ result = self.execute(
1455
+ self.service.presentations()
1456
+ .batchUpdate(
1457
+ presentationId=presentation_id, body={"requests": [request]}
1458
+ )
1459
+ )
1460
+
1461
+ output_success(
1462
+ operation="slides.insert_text_in_table_cell",
1463
+ presentation_id=presentation_id,
1464
+ table_id=table_id,
1465
+ row_index=row_index,
1466
+ column_index=column_index,
1467
+ text_length=len(text),
1468
+ )
1469
+ return result
1470
+ except HttpError as e:
1471
+ output_error(
1472
+ error_code="API_ERROR",
1473
+ operation="slides.insert_text_in_table_cell",
1474
+ message=f"Google Slides API error: {e.reason}",
1475
+ )
1476
+ raise SystemExit(ExitCode.API_ERROR)
1477
+
1478
+ # ===== Phase 6: Slides Enhancements =====
1479
+
1480
+ def set_slide_background(
1481
+ self,
1482
+ presentation_id: str,
1483
+ slide_id: str,
1484
+ color: str | None = None,
1485
+ image_url: str | None = None,
1486
+ ) -> dict[str, Any]:
1487
+ """Set slide background to a solid color or image.
1488
+
1489
+ Args:
1490
+ presentation_id: The presentation ID.
1491
+ slide_id: The slide object ID.
1492
+ color: Background color (hex, e.g., "#FFFFFF").
1493
+ image_url: Background image URL (publicly accessible).
1494
+ """
1495
+ try:
1496
+ if not color and not image_url:
1497
+ output_error(
1498
+ error_code="INVALID_ARGS",
1499
+ operation="slides.set_slide_background",
1500
+ message="Either color or image_url must be provided",
1501
+ )
1502
+ raise SystemExit(ExitCode.INVALID_ARGS)
1503
+
1504
+ page_properties: dict[str, Any] = {}
1505
+ fields = []
1506
+
1507
+ if color:
1508
+ from gws.utils.colors import parse_hex_color
1509
+ rgb = parse_hex_color(color)
1510
+ page_properties["pageBackgroundFill"] = {
1511
+ "solidFill": {"color": {"rgbColor": rgb}}
1512
+ }
1513
+ fields.append("pageBackgroundFill")
1514
+ elif image_url:
1515
+ page_properties["pageBackgroundFill"] = {
1516
+ "stretchedPictureFill": {"contentUrl": image_url}
1517
+ }
1518
+ fields.append("pageBackgroundFill")
1519
+
1520
+ request = {
1521
+ "updatePageProperties": {
1522
+ "objectId": slide_id,
1523
+ "pageProperties": page_properties,
1524
+ "fields": ",".join(fields),
1525
+ }
1526
+ }
1527
+
1528
+ result = self.execute(
1529
+ self.service.presentations()
1530
+ .batchUpdate(
1531
+ presentationId=presentation_id, body={"requests": [request]}
1532
+ )
1533
+ )
1534
+
1535
+ output_success(
1536
+ operation="slides.set_slide_background",
1537
+ presentation_id=presentation_id,
1538
+ slide_id=slide_id,
1539
+ background_type="color" if color else "image",
1540
+ )
1541
+ return result
1542
+ except HttpError as e:
1543
+ output_error(
1544
+ error_code="API_ERROR",
1545
+ operation="slides.set_slide_background",
1546
+ message=f"Google Slides API error: {e.reason}",
1547
+ )
1548
+ raise SystemExit(ExitCode.API_ERROR)
1549
+
1550
+ def create_bullets(
1551
+ self,
1552
+ presentation_id: str,
1553
+ object_id: str,
1554
+ bullet_preset: str = "BULLET_DISC_CIRCLE_SQUARE",
1555
+ start_index: int | None = None,
1556
+ end_index: int | None = None,
1557
+ ) -> dict[str, Any]:
1558
+ """Create bullet list formatting for text.
1559
+
1560
+ Args:
1561
+ presentation_id: The presentation ID.
1562
+ object_id: The shape/text box object ID.
1563
+ bullet_preset: Bullet style preset. Options:
1564
+ BULLET_DISC_CIRCLE_SQUARE, BULLET_DIAMONDX_ARROW3D_SQUARE,
1565
+ BULLET_CHECKBOX, BULLET_ARROW_DIAMOND_DISC,
1566
+ BULLET_STAR_CIRCLE_SQUARE, BULLET_ARROW3D_CIRCLE_SQUARE,
1567
+ BULLET_LEFTTRIANGLE_DIAMOND_DISC, NUMBERED_DIGIT_ALPHA_ROMAN,
1568
+ NUMBERED_DIGIT_ALPHA_ROMAN_PARENS, NUMBERED_DIGIT_NESTED,
1569
+ NUMBERED_UPPERALPHA_ALPHA_ROMAN, NUMBERED_UPPERROMAN_UPPERALPHA_DIGIT,
1570
+ NUMBERED_ZERODIGIT_ALPHA_ROMAN
1571
+ start_index: Start character index (0-based). If None, applies to all.
1572
+ end_index: End character index (exclusive). If None, applies to all.
1573
+ """
1574
+ try:
1575
+ if start_index is not None and end_index is not None:
1576
+ text_range = {
1577
+ "type": "FIXED_RANGE",
1578
+ "startIndex": start_index,
1579
+ "endIndex": end_index,
1580
+ }
1581
+ else:
1582
+ text_range = {"type": "ALL"}
1583
+
1584
+ request = {
1585
+ "createParagraphBullets": {
1586
+ "objectId": object_id,
1587
+ "textRange": text_range,
1588
+ "bulletPreset": bullet_preset,
1589
+ }
1590
+ }
1591
+
1592
+ result = self.execute(
1593
+ self.service.presentations()
1594
+ .batchUpdate(
1595
+ presentationId=presentation_id, body={"requests": [request]}
1596
+ )
1597
+ )
1598
+
1599
+ output_success(
1600
+ operation="slides.create_bullets",
1601
+ presentation_id=presentation_id,
1602
+ object_id=object_id,
1603
+ bullet_preset=bullet_preset,
1604
+ )
1605
+ return result
1606
+ except HttpError as e:
1607
+ output_error(
1608
+ error_code="API_ERROR",
1609
+ operation="slides.create_bullets",
1610
+ message=f"Google Slides API error: {e.reason}",
1611
+ )
1612
+ raise SystemExit(ExitCode.API_ERROR)
1613
+
1614
+ def remove_bullets(
1615
+ self,
1616
+ presentation_id: str,
1617
+ object_id: str,
1618
+ start_index: int | None = None,
1619
+ end_index: int | None = None,
1620
+ ) -> dict[str, Any]:
1621
+ """Remove bullet list formatting from text.
1622
+
1623
+ Args:
1624
+ presentation_id: The presentation ID.
1625
+ object_id: The shape/text box object ID.
1626
+ start_index: Start character index (0-based). If None, applies to all.
1627
+ end_index: End character index (exclusive). If None, applies to all.
1628
+ """
1629
+ try:
1630
+ if start_index is not None and end_index is not None:
1631
+ text_range = {
1632
+ "type": "FIXED_RANGE",
1633
+ "startIndex": start_index,
1634
+ "endIndex": end_index,
1635
+ }
1636
+ else:
1637
+ text_range = {"type": "ALL"}
1638
+
1639
+ request = {
1640
+ "deleteParagraphBullets": {
1641
+ "objectId": object_id,
1642
+ "textRange": text_range,
1643
+ }
1644
+ }
1645
+
1646
+ result = self.execute(
1647
+ self.service.presentations()
1648
+ .batchUpdate(
1649
+ presentationId=presentation_id, body={"requests": [request]}
1650
+ )
1651
+ )
1652
+
1653
+ output_success(
1654
+ operation="slides.remove_bullets",
1655
+ presentation_id=presentation_id,
1656
+ object_id=object_id,
1657
+ )
1658
+ return result
1659
+ except HttpError as e:
1660
+ output_error(
1661
+ error_code="API_ERROR",
1662
+ operation="slides.remove_bullets",
1663
+ message=f"Google Slides API error: {e.reason}",
1664
+ )
1665
+ raise SystemExit(ExitCode.API_ERROR)
1666
+
1667
+ def style_table_borders(
1668
+ self,
1669
+ presentation_id: str,
1670
+ table_id: str,
1671
+ row_index: int,
1672
+ column_index: int,
1673
+ row_span: int = 1,
1674
+ column_span: int = 1,
1675
+ color: str = "#000000",
1676
+ weight: float = 1.0,
1677
+ dash_style: str = "SOLID",
1678
+ border_position: str = "ALL",
1679
+ ) -> dict[str, Any]:
1680
+ """Style table cell borders.
1681
+
1682
+ Args:
1683
+ presentation_id: The presentation ID.
1684
+ table_id: The table object ID.
1685
+ row_index: Starting row index.
1686
+ column_index: Starting column index.
1687
+ row_span: Number of rows to style.
1688
+ column_span: Number of columns to style.
1689
+ color: Border color (hex, e.g., "#000000").
1690
+ weight: Border weight in points.
1691
+ dash_style: Dash style (SOLID, DOT, DASH, DASH_DOT, LONG_DASH).
1692
+ border_position: Which borders to style (ALL, INNER, OUTER,
1693
+ INNER_HORIZONTAL, INNER_VERTICAL, LEFT, RIGHT, TOP, BOTTOM).
1694
+ """
1695
+ try:
1696
+ from gws.utils.colors import parse_hex_color
1697
+
1698
+ valid_positions = {
1699
+ "ALL", "INNER", "OUTER", "INNER_HORIZONTAL", "INNER_VERTICAL",
1700
+ "LEFT", "RIGHT", "TOP", "BOTTOM"
1701
+ }
1702
+ if border_position.upper() not in valid_positions:
1703
+ output_error(
1704
+ error_code="INVALID_ARGS",
1705
+ operation="slides.style_table_borders",
1706
+ message=f"border_position must be one of: {valid_positions}",
1707
+ )
1708
+ raise SystemExit(ExitCode.INVALID_ARGS)
1709
+
1710
+ valid_styles = {"SOLID", "DOT", "DASH", "DASH_DOT", "LONG_DASH"}
1711
+ if dash_style.upper() not in valid_styles:
1712
+ output_error(
1713
+ error_code="INVALID_ARGS",
1714
+ operation="slides.style_table_borders",
1715
+ message=f"dash_style must be one of: {valid_styles}",
1716
+ )
1717
+ raise SystemExit(ExitCode.INVALID_ARGS)
1718
+
1719
+ rgb = parse_hex_color(color)
1720
+
1721
+ request = {
1722
+ "updateTableBorderProperties": {
1723
+ "objectId": table_id,
1724
+ "tableRange": {
1725
+ "location": {
1726
+ "rowIndex": row_index,
1727
+ "columnIndex": column_index,
1728
+ },
1729
+ "rowSpan": row_span,
1730
+ "columnSpan": column_span,
1731
+ },
1732
+ "borderPosition": border_position.upper(),
1733
+ "tableBorderProperties": {
1734
+ "tableBorderFill": {
1735
+ "solidFill": {"color": {"rgbColor": rgb}}
1736
+ },
1737
+ "weight": {"magnitude": weight, "unit": "PT"},
1738
+ "dashStyle": dash_style.upper(),
1739
+ },
1740
+ "fields": "tableBorderFill,weight,dashStyle",
1741
+ }
1742
+ }
1743
+
1744
+ result = self.execute(
1745
+ self.service.presentations()
1746
+ .batchUpdate(
1747
+ presentationId=presentation_id, body={"requests": [request]}
1748
+ )
1749
+ )
1750
+
1751
+ output_success(
1752
+ operation="slides.style_table_borders",
1753
+ presentation_id=presentation_id,
1754
+ table_id=table_id,
1755
+ border_position=border_position.upper(),
1756
+ row_index=row_index,
1757
+ column_index=column_index,
1758
+ )
1759
+ return result
1760
+ except HttpError as e:
1761
+ output_error(
1762
+ error_code="API_ERROR",
1763
+ operation="slides.style_table_borders",
1764
+ message=f"Google Slides API error: {e.reason}",
1765
+ )
1766
+ raise SystemExit(ExitCode.API_ERROR)
1767
+
1768
+ def merge_table_cells(
1769
+ self,
1770
+ presentation_id: str,
1771
+ table_id: str,
1772
+ row_index: int,
1773
+ column_index: int,
1774
+ row_span: int,
1775
+ column_span: int,
1776
+ ) -> dict[str, Any]:
1777
+ """Merge table cells.
1778
+
1779
+ Args:
1780
+ presentation_id: The presentation ID.
1781
+ table_id: The table object ID.
1782
+ row_index: Starting row index.
1783
+ column_index: Starting column index.
1784
+ row_span: Number of rows to merge.
1785
+ column_span: Number of columns to merge.
1786
+ """
1787
+ try:
1788
+ request = {
1789
+ "mergeTableCells": {
1790
+ "objectId": table_id,
1791
+ "tableRange": {
1792
+ "location": {
1793
+ "rowIndex": row_index,
1794
+ "columnIndex": column_index,
1795
+ },
1796
+ "rowSpan": row_span,
1797
+ "columnSpan": column_span,
1798
+ },
1799
+ }
1800
+ }
1801
+
1802
+ result = self.execute(
1803
+ self.service.presentations()
1804
+ .batchUpdate(
1805
+ presentationId=presentation_id, body={"requests": [request]}
1806
+ )
1807
+ )
1808
+
1809
+ output_success(
1810
+ operation="slides.merge_table_cells",
1811
+ presentation_id=presentation_id,
1812
+ table_id=table_id,
1813
+ row_index=row_index,
1814
+ column_index=column_index,
1815
+ row_span=row_span,
1816
+ column_span=column_span,
1817
+ )
1818
+ return result
1819
+ except HttpError as e:
1820
+ output_error(
1821
+ error_code="API_ERROR",
1822
+ operation="slides.merge_table_cells",
1823
+ message=f"Google Slides API error: {e.reason}",
1824
+ )
1825
+ raise SystemExit(ExitCode.API_ERROR)
1826
+
1827
+ def unmerge_table_cells(
1828
+ self,
1829
+ presentation_id: str,
1830
+ table_id: str,
1831
+ row_index: int,
1832
+ column_index: int,
1833
+ row_span: int,
1834
+ column_span: int,
1835
+ ) -> dict[str, Any]:
1836
+ """Unmerge table cells.
1837
+
1838
+ Args:
1839
+ presentation_id: The presentation ID.
1840
+ table_id: The table object ID.
1841
+ row_index: Starting row index.
1842
+ column_index: Starting column index.
1843
+ row_span: Number of rows in merged region.
1844
+ column_span: Number of columns in merged region.
1845
+ """
1846
+ try:
1847
+ request = {
1848
+ "unmergeTableCells": {
1849
+ "objectId": table_id,
1850
+ "tableRange": {
1851
+ "location": {
1852
+ "rowIndex": row_index,
1853
+ "columnIndex": column_index,
1854
+ },
1855
+ "rowSpan": row_span,
1856
+ "columnSpan": column_span,
1857
+ },
1858
+ }
1859
+ }
1860
+
1861
+ result = self.execute(
1862
+ self.service.presentations()
1863
+ .batchUpdate(
1864
+ presentationId=presentation_id, body={"requests": [request]}
1865
+ )
1866
+ )
1867
+
1868
+ output_success(
1869
+ operation="slides.unmerge_table_cells",
1870
+ presentation_id=presentation_id,
1871
+ table_id=table_id,
1872
+ row_index=row_index,
1873
+ column_index=column_index,
1874
+ )
1875
+ return result
1876
+ except HttpError as e:
1877
+ output_error(
1878
+ error_code="API_ERROR",
1879
+ operation="slides.unmerge_table_cells",
1880
+ message=f"Google Slides API error: {e.reason}",
1881
+ )
1882
+ raise SystemExit(ExitCode.API_ERROR)
1883
+
1884
+ def create_line(
1885
+ self,
1886
+ presentation_id: str,
1887
+ page_object_id: str,
1888
+ start_x: float,
1889
+ start_y: float,
1890
+ end_x: float,
1891
+ end_y: float,
1892
+ line_category: str = "STRAIGHT",
1893
+ color: str = "#000000",
1894
+ weight: float = 1.0,
1895
+ dash_style: str = "SOLID",
1896
+ start_arrow: str | None = None,
1897
+ end_arrow: str | None = None,
1898
+ ) -> dict[str, Any]:
1899
+ """Create a line or arrow on a slide.
1900
+
1901
+ Args:
1902
+ presentation_id: The presentation ID.
1903
+ page_object_id: The slide/page object ID.
1904
+ start_x: Starting X position in points.
1905
+ start_y: Starting Y position in points.
1906
+ end_x: Ending X position in points.
1907
+ end_y: Ending Y position in points.
1908
+ line_category: Line category (STRAIGHT, BENT, CURVED).
1909
+ color: Line color (hex, e.g., "#000000").
1910
+ weight: Line weight in points.
1911
+ dash_style: Dash style (SOLID, DOT, DASH, DASH_DOT, LONG_DASH).
1912
+ start_arrow: Start arrow type (NONE, STEALTH_ARROW, FILL_ARROW,
1913
+ FILL_CIRCLE, FILL_SQUARE, FILL_DIAMOND, OPEN_ARROW,
1914
+ OPEN_CIRCLE, OPEN_SQUARE, OPEN_DIAMOND).
1915
+ end_arrow: End arrow type (same options as start_arrow).
1916
+ """
1917
+ try:
1918
+ from gws.utils.colors import parse_hex_color
1919
+
1920
+ line_id = self._generate_object_id()
1921
+
1922
+ # Calculate width and height from start/end points
1923
+ width = abs(end_x - start_x) or 1 # Minimum 1pt
1924
+ height = abs(end_y - start_y) or 1
1925
+
1926
+ valid_categories = {"STRAIGHT", "BENT", "CURVED"}
1927
+ if line_category.upper() not in valid_categories:
1928
+ output_error(
1929
+ error_code="INVALID_ARGS",
1930
+ operation="slides.create_line",
1931
+ message=f"line_category must be one of: {valid_categories}",
1932
+ )
1933
+ raise SystemExit(ExitCode.INVALID_ARGS)
1934
+
1935
+ request = {
1936
+ "createLine": {
1937
+ "objectId": line_id,
1938
+ "lineCategory": line_category.upper(),
1939
+ "elementProperties": {
1940
+ "pageObjectId": page_object_id,
1941
+ "size": {
1942
+ "width": {"magnitude": width, "unit": "PT"},
1943
+ "height": {"magnitude": height, "unit": "PT"},
1944
+ },
1945
+ "transform": {
1946
+ "scaleX": 1 if end_x >= start_x else -1,
1947
+ "scaleY": 1 if end_y >= start_y else -1,
1948
+ "translateX": min(start_x, end_x),
1949
+ "translateY": min(start_y, end_y),
1950
+ "unit": "PT",
1951
+ },
1952
+ },
1953
+ }
1954
+ }
1955
+
1956
+ # Create the line first
1957
+ requests = [request]
1958
+
1959
+ # Then update line properties
1960
+ rgb = parse_hex_color(color)
1961
+ line_properties: dict[str, Any] = {
1962
+ "lineFill": {"solidFill": {"color": {"rgbColor": rgb}}},
1963
+ "weight": {"magnitude": weight, "unit": "PT"},
1964
+ "dashStyle": dash_style.upper(),
1965
+ }
1966
+ fields = ["lineFill", "weight", "dashStyle"]
1967
+
1968
+ if start_arrow:
1969
+ line_properties["startArrow"] = start_arrow.upper()
1970
+ fields.append("startArrow")
1971
+ if end_arrow:
1972
+ line_properties["endArrow"] = end_arrow.upper()
1973
+ fields.append("endArrow")
1974
+
1975
+ update_request = {
1976
+ "updateLineProperties": {
1977
+ "objectId": line_id,
1978
+ "lineProperties": line_properties,
1979
+ "fields": ",".join(fields),
1980
+ }
1981
+ }
1982
+ requests.append(update_request)
1983
+
1984
+ result = self.execute(
1985
+ self.service.presentations()
1986
+ .batchUpdate(
1987
+ presentationId=presentation_id, body={"requests": requests}
1988
+ )
1989
+ )
1990
+
1991
+ output_success(
1992
+ operation="slides.create_line",
1993
+ presentation_id=presentation_id,
1994
+ page_object_id=page_object_id,
1995
+ line_id=line_id,
1996
+ line_category=line_category.upper(),
1997
+ )
1998
+ return result
1999
+ except HttpError as e:
2000
+ output_error(
2001
+ error_code="API_ERROR",
2002
+ operation="slides.create_line",
2003
+ message=f"Google Slides API error: {e.reason}",
2004
+ )
2005
+ raise SystemExit(ExitCode.API_ERROR)
2006
+
2007
+ def reorder_slides(
2008
+ self,
2009
+ presentation_id: str,
2010
+ slide_ids: list[str],
2011
+ insertion_index: int,
2012
+ ) -> dict[str, Any]:
2013
+ """Move slides to a new position.
2014
+
2015
+ Args:
2016
+ presentation_id: The presentation ID.
2017
+ slide_ids: List of slide object IDs to move.
2018
+ insertion_index: Target index where slides will be moved (0-based).
2019
+ """
2020
+ try:
2021
+ request = {
2022
+ "updateSlidesPosition": {
2023
+ "slideObjectIds": slide_ids,
2024
+ "insertionIndex": insertion_index,
2025
+ }
2026
+ }
2027
+
2028
+ result = self.execute(
2029
+ self.service.presentations()
2030
+ .batchUpdate(
2031
+ presentationId=presentation_id, body={"requests": [request]}
2032
+ )
2033
+ )
2034
+
2035
+ output_success(
2036
+ operation="slides.reorder_slides",
2037
+ presentation_id=presentation_id,
2038
+ slide_ids=slide_ids,
2039
+ insertion_index=insertion_index,
2040
+ )
2041
+ return result
2042
+ except HttpError as e:
2043
+ output_error(
2044
+ error_code="API_ERROR",
2045
+ operation="slides.reorder_slides",
2046
+ message=f"Google Slides API error: {e.reason}",
2047
+ )
2048
+ raise SystemExit(ExitCode.API_ERROR)
2049
+
2050
+ # =========================================================================
2051
+ # SPEAKER NOTES
2052
+ # =========================================================================
2053
+
2054
+ def get_speaker_notes(
2055
+ self,
2056
+ presentation_id: str,
2057
+ slide_id: str,
2058
+ ) -> dict[str, Any]:
2059
+ """Get speaker notes for a slide.
2060
+
2061
+ Args:
2062
+ presentation_id: The presentation ID.
2063
+ slide_id: The slide object ID.
2064
+ """
2065
+ try:
2066
+ presentation = self.execute(
2067
+ self.service.presentations()
2068
+ .get(presentationId=presentation_id)
2069
+ )
2070
+
2071
+ notes_text = ""
2072
+ notes_page_id = None
2073
+
2074
+ for slide in presentation.get("slides", []):
2075
+ if slide.get("objectId") == slide_id:
2076
+ notes_page = slide.get("slideProperties", {}).get("notesPage", {})
2077
+ notes_page_id = notes_page.get("objectId")
2078
+
2079
+ # Find the notes shape within the notes page
2080
+ for element in notes_page.get("pageElements", []):
2081
+ shape = element.get("shape", {})
2082
+ if shape.get("shapeType") == "TEXT_BOX":
2083
+ placeholder = shape.get("placeholder", {})
2084
+ if placeholder.get("type") == "BODY":
2085
+ text_content = shape.get("text", {})
2086
+ for text_element in text_content.get("textElements", []):
2087
+ if "textRun" in text_element:
2088
+ notes_text += text_element["textRun"].get("content", "")
2089
+ break
2090
+
2091
+ output_success(
2092
+ operation="slides.get_speaker_notes",
2093
+ presentation_id=presentation_id,
2094
+ slide_id=slide_id,
2095
+ notes_page_id=notes_page_id,
2096
+ notes_text=notes_text.strip(),
2097
+ )
2098
+ return {"notes_text": notes_text.strip(), "notes_page_id": notes_page_id}
2099
+ except HttpError as e:
2100
+ output_error(
2101
+ error_code="API_ERROR",
2102
+ operation="slides.get_speaker_notes",
2103
+ message=f"Google Slides API error: {e.reason}",
2104
+ )
2105
+ raise SystemExit(ExitCode.API_ERROR)
2106
+
2107
+ def set_speaker_notes(
2108
+ self,
2109
+ presentation_id: str,
2110
+ slide_id: str,
2111
+ notes_text: str,
2112
+ ) -> dict[str, Any]:
2113
+ """Set speaker notes for a slide.
2114
+
2115
+ Args:
2116
+ presentation_id: The presentation ID.
2117
+ slide_id: The slide object ID.
2118
+ notes_text: The speaker notes text content.
2119
+ """
2120
+ try:
2121
+ # First, get the presentation to find the notes shape ID
2122
+ presentation = self.execute(
2123
+ self.service.presentations()
2124
+ .get(presentationId=presentation_id)
2125
+ )
2126
+
2127
+ notes_shape_id = None
2128
+
2129
+ for slide in presentation.get("slides", []):
2130
+ if slide.get("objectId") == slide_id:
2131
+ notes_page = slide.get("slideProperties", {}).get("notesPage", {})
2132
+
2133
+ for element in notes_page.get("pageElements", []):
2134
+ shape = element.get("shape", {})
2135
+ if shape.get("shapeType") == "TEXT_BOX":
2136
+ placeholder = shape.get("placeholder", {})
2137
+ if placeholder.get("type") == "BODY":
2138
+ notes_shape_id = element.get("objectId")
2139
+ break
2140
+ break
2141
+
2142
+ if not notes_shape_id:
2143
+ output_error(
2144
+ error_code="NOT_FOUND",
2145
+ operation="slides.set_speaker_notes",
2146
+ message=f"Speaker notes shape not found for slide {slide_id}",
2147
+ )
2148
+ raise SystemExit(ExitCode.NOT_FOUND)
2149
+
2150
+ # Build requests: only delete existing text if notes are non-empty
2151
+ requests: list[dict[str, Any]] = []
2152
+
2153
+ # Check if notes shape has existing text content
2154
+ for slide in presentation.get("slides", []):
2155
+ if slide.get("objectId") == slide_id:
2156
+ notes_page = slide.get("slideProperties", {}).get("notesPage", {})
2157
+ for element in notes_page.get("pageElements", []):
2158
+ if element.get("objectId") == notes_shape_id:
2159
+ text_content = element.get("shape", {}).get("text", {})
2160
+ text_elements = text_content.get("textElements", [])
2161
+ has_text = any(
2162
+ te.get("textRun", {}).get("content", "").strip()
2163
+ for te in text_elements
2164
+ )
2165
+ if has_text:
2166
+ requests.append({
2167
+ "deleteText": {
2168
+ "objectId": notes_shape_id,
2169
+ "textRange": {"type": "ALL"},
2170
+ }
2171
+ })
2172
+ break
2173
+ break
2174
+
2175
+ requests.append({
2176
+ "insertText": {
2177
+ "objectId": notes_shape_id,
2178
+ "insertionIndex": 0,
2179
+ "text": notes_text,
2180
+ }
2181
+ })
2182
+
2183
+ result = self.execute(
2184
+ self.service.presentations()
2185
+ .batchUpdate(
2186
+ presentationId=presentation_id, body={"requests": requests}
2187
+ )
2188
+ )
2189
+
2190
+ output_success(
2191
+ operation="slides.set_speaker_notes",
2192
+ presentation_id=presentation_id,
2193
+ slide_id=slide_id,
2194
+ notes_shape_id=notes_shape_id,
2195
+ text_length=len(notes_text),
2196
+ )
2197
+ return result
2198
+ except HttpError as e:
2199
+ output_error(
2200
+ error_code="API_ERROR",
2201
+ operation="slides.set_speaker_notes",
2202
+ message=f"Google Slides API error: {e.reason}",
2203
+ )
2204
+ raise SystemExit(ExitCode.API_ERROR)
2205
+
2206
+ # =========================================================================
2207
+ # VIDEO INSERTION
2208
+ # =========================================================================
2209
+
2210
+ def insert_video(
2211
+ self,
2212
+ presentation_id: str,
2213
+ page_object_id: str,
2214
+ video_url: str,
2215
+ x: float,
2216
+ y: float,
2217
+ width: float,
2218
+ height: float,
2219
+ ) -> dict[str, Any]:
2220
+ """Insert a video on a slide.
2221
+
2222
+ Args:
2223
+ presentation_id: The presentation ID.
2224
+ page_object_id: The slide/page object ID.
2225
+ video_url: YouTube video URL (e.g., https://www.youtube.com/watch?v=VIDEO_ID).
2226
+ x: X position in points.
2227
+ y: Y position in points.
2228
+ width: Width in points.
2229
+ height: Height in points.
2230
+ """
2231
+ try:
2232
+ import re
2233
+
2234
+ # Extract YouTube video ID from URL
2235
+ video_id = None
2236
+ patterns = [
2237
+ r'(?:youtube\.com/watch\?v=|youtu\.be/|youtube\.com/embed/)([a-zA-Z0-9_-]{11})',
2238
+ ]
2239
+ for pattern in patterns:
2240
+ match = re.search(pattern, video_url)
2241
+ if match:
2242
+ video_id = match.group(1)
2243
+ break
2244
+
2245
+ if not video_id:
2246
+ output_error(
2247
+ error_code="INVALID_ARGS",
2248
+ operation="slides.insert_video",
2249
+ message="Invalid YouTube URL. Please provide a valid YouTube video URL.",
2250
+ )
2251
+ raise SystemExit(ExitCode.INVALID_ARGS)
2252
+
2253
+ object_id = self._generate_object_id()
2254
+
2255
+ request = {
2256
+ "createVideo": {
2257
+ "objectId": object_id,
2258
+ "source": "YOUTUBE",
2259
+ "id": video_id,
2260
+ "elementProperties": {
2261
+ "pageObjectId": page_object_id,
2262
+ "size": {
2263
+ "width": {"magnitude": width, "unit": "PT"},
2264
+ "height": {"magnitude": height, "unit": "PT"},
2265
+ },
2266
+ "transform": {
2267
+ "scaleX": 1,
2268
+ "scaleY": 1,
2269
+ "translateX": x,
2270
+ "translateY": y,
2271
+ "unit": "PT",
2272
+ },
2273
+ },
2274
+ }
2275
+ }
2276
+
2277
+ result = self.execute(
2278
+ self.service.presentations()
2279
+ .batchUpdate(
2280
+ presentationId=presentation_id, body={"requests": [request]}
2281
+ )
2282
+ )
2283
+
2284
+ output_success(
2285
+ operation="slides.insert_video",
2286
+ presentation_id=presentation_id,
2287
+ page_object_id=page_object_id,
2288
+ video_object_id=object_id,
2289
+ video_id=video_id,
2290
+ position={"x": x, "y": y, "width": width, "height": height},
2291
+ )
2292
+ return result
2293
+ except HttpError as e:
2294
+ output_error(
2295
+ error_code="API_ERROR",
2296
+ operation="slides.insert_video",
2297
+ message=f"Google Slides API error: {e.reason}",
2298
+ )
2299
+ raise SystemExit(ExitCode.API_ERROR)
2300
+
2301
+ def update_video_properties(
2302
+ self,
2303
+ presentation_id: str,
2304
+ video_object_id: str,
2305
+ autoplay: bool | None = None,
2306
+ start_time: int | None = None,
2307
+ end_time: int | None = None,
2308
+ mute: bool | None = None,
2309
+ ) -> dict[str, Any]:
2310
+ """Update video playback properties.
2311
+
2312
+ Args:
2313
+ presentation_id: The presentation ID.
2314
+ video_object_id: The video object ID.
2315
+ autoplay: Whether the video autoplays when presenting.
2316
+ start_time: Start time in seconds.
2317
+ end_time: End time in seconds.
2318
+ mute: Whether the video is muted.
2319
+ """
2320
+ try:
2321
+ video_properties: dict[str, Any] = {}
2322
+ fields = []
2323
+
2324
+ if autoplay is not None:
2325
+ video_properties["autoPlay"] = autoplay
2326
+ fields.append("autoPlay")
2327
+
2328
+ if start_time is not None:
2329
+ video_properties["start"] = start_time
2330
+ fields.append("start")
2331
+
2332
+ if end_time is not None:
2333
+ video_properties["end"] = end_time
2334
+ fields.append("end")
2335
+
2336
+ if mute is not None:
2337
+ video_properties["mute"] = mute
2338
+ fields.append("mute")
2339
+
2340
+ if not fields:
2341
+ output_error(
2342
+ error_code="INVALID_ARGS",
2343
+ operation="slides.update_video_properties",
2344
+ message="At least one video property required",
2345
+ )
2346
+ raise SystemExit(ExitCode.INVALID_ARGS)
2347
+
2348
+ request = {
2349
+ "updateVideoProperties": {
2350
+ "objectId": video_object_id,
2351
+ "videoProperties": video_properties,
2352
+ "fields": ",".join(fields),
2353
+ }
2354
+ }
2355
+
2356
+ result = self.execute(
2357
+ self.service.presentations()
2358
+ .batchUpdate(
2359
+ presentationId=presentation_id, body={"requests": [request]}
2360
+ )
2361
+ )
2362
+
2363
+ output_success(
2364
+ operation="slides.update_video_properties",
2365
+ presentation_id=presentation_id,
2366
+ video_object_id=video_object_id,
2367
+ properties_updated=fields,
2368
+ )
2369
+ return result
2370
+ except HttpError as e:
2371
+ output_error(
2372
+ error_code="API_ERROR",
2373
+ operation="slides.update_video_properties",
2374
+ message=f"Google Slides API error: {e.reason}",
2375
+ )
2376
+ raise SystemExit(ExitCode.API_ERROR)
2377
+
2378
+ # =========================================================================
2379
+ # ELEMENT TRANSFORMS
2380
+ # =========================================================================
2381
+
2382
+ def transform_element(
2383
+ self,
2384
+ presentation_id: str,
2385
+ object_id: str,
2386
+ scale_x: float | None = None,
2387
+ scale_y: float | None = None,
2388
+ translate_x: float | None = None,
2389
+ translate_y: float | None = None,
2390
+ rotate: float | None = None,
2391
+ apply_mode: str = "RELATIVE",
2392
+ ) -> dict[str, Any]:
2393
+ """Transform a page element (scale, translate, rotate).
2394
+
2395
+ Args:
2396
+ presentation_id: The presentation ID.
2397
+ object_id: The element object ID.
2398
+ scale_x: Horizontal scale factor.
2399
+ scale_y: Vertical scale factor.
2400
+ translate_x: Horizontal translation in EMU.
2401
+ translate_y: Vertical translation in EMU.
2402
+ rotate: Rotation angle in degrees.
2403
+ apply_mode: 'RELATIVE' (add to current) or 'ABSOLUTE' (replace).
2404
+ """
2405
+ try:
2406
+ # Build transform matrix — always set scaleX/scaleY to ensure
2407
+ # the matrix is invertible (determinant != 0)
2408
+ transform: dict[str, Any] = {
2409
+ "unit": "EMU",
2410
+ "scaleX": scale_x if scale_x is not None else 1.0,
2411
+ "scaleY": scale_y if scale_y is not None else 1.0,
2412
+ }
2413
+ if translate_x is not None:
2414
+ transform["translateX"] = translate_x
2415
+ if translate_y is not None:
2416
+ transform["translateY"] = translate_y
2417
+
2418
+ # Rotation requires converting degrees to affine transform
2419
+ # For simplicity, we handle rotation as shearX/shearY if provided
2420
+ if rotate is not None:
2421
+ import math
2422
+ rad = math.radians(rotate)
2423
+ cos_r = math.cos(rad)
2424
+ sin_r = math.sin(rad)
2425
+ transform["scaleX"] = transform.get("scaleX", 1.0) * cos_r
2426
+ transform["scaleY"] = transform.get("scaleY", 1.0) * cos_r
2427
+ transform["shearX"] = -sin_r
2428
+ transform["shearY"] = sin_r
2429
+
2430
+ if len(transform) == 1: # Only 'unit'
2431
+ output_error(
2432
+ error_code="INVALID_ARGUMENT",
2433
+ operation="slides.transform_element",
2434
+ message="At least one transform parameter required",
2435
+ )
2436
+ raise SystemExit(ExitCode.INVALID_ARGS)
2437
+
2438
+ request = {
2439
+ "updatePageElementTransform": {
2440
+ "objectId": object_id,
2441
+ "transform": transform,
2442
+ "applyMode": apply_mode,
2443
+ }
2444
+ }
2445
+
2446
+ result = self.execute(
2447
+ self.service.presentations()
2448
+ .batchUpdate(
2449
+ presentationId=presentation_id, body={"requests": [request]}
2450
+ )
2451
+ )
2452
+
2453
+ output_success(
2454
+ operation="slides.transform_element",
2455
+ presentation_id=presentation_id,
2456
+ object_id=object_id,
2457
+ apply_mode=apply_mode,
2458
+ )
2459
+ return result
2460
+ except HttpError as e:
2461
+ output_error(
2462
+ error_code="API_ERROR",
2463
+ operation="slides.transform_element",
2464
+ message=f"Google Slides API error: {e.reason}",
2465
+ )
2466
+ raise SystemExit(ExitCode.API_ERROR)
2467
+
2468
+ # =========================================================================
2469
+ # IMAGE PROPERTIES
2470
+ # =========================================================================
2471
+
2472
+ def update_image_properties(
2473
+ self,
2474
+ presentation_id: str,
2475
+ object_id: str,
2476
+ transparency: float | None = None,
2477
+ outline_color: str | None = None,
2478
+ outline_weight: float | None = None,
2479
+ ) -> dict[str, Any]:
2480
+ """Update image properties.
2481
+
2482
+ Args:
2483
+ presentation_id: The presentation ID.
2484
+ object_id: The image element object ID.
2485
+ transparency: Image transparency (0.0 = opaque, 1.0 = fully transparent).
2486
+ outline_color: Outline color (hex, e.g., '#000000').
2487
+ outline_weight: Outline weight in points.
2488
+ """
2489
+ try:
2490
+ from gws.utils.colors import parse_hex_color
2491
+
2492
+ image_properties: dict[str, Any] = {}
2493
+ fields = []
2494
+
2495
+ if transparency is not None:
2496
+ image_properties["transparency"] = transparency
2497
+ fields.append("transparency")
2498
+
2499
+ if outline_color is not None or outline_weight is not None:
2500
+ outline: dict[str, Any] = {}
2501
+ if outline_color:
2502
+ rgb = parse_hex_color(outline_color)
2503
+ outline["outlineFill"] = {
2504
+ "solidFill": {
2505
+ "color": {"rgbColor": rgb}
2506
+ }
2507
+ }
2508
+ fields.append("outline.outlineFill.solidFill.color")
2509
+ if outline_weight is not None:
2510
+ outline["weight"] = {"magnitude": outline_weight, "unit": "PT"}
2511
+ fields.append("outline.weight")
2512
+ image_properties["outline"] = outline
2513
+
2514
+ if not fields:
2515
+ output_error(
2516
+ error_code="INVALID_ARGUMENT",
2517
+ operation="slides.update_image_properties",
2518
+ message="At least one image property required",
2519
+ )
2520
+ raise SystemExit(ExitCode.INVALID_ARGS)
2521
+
2522
+ request = {
2523
+ "updateImageProperties": {
2524
+ "objectId": object_id,
2525
+ "imageProperties": image_properties,
2526
+ "fields": ",".join(fields),
2527
+ }
2528
+ }
2529
+
2530
+ result = self.execute(
2531
+ self.service.presentations()
2532
+ .batchUpdate(
2533
+ presentationId=presentation_id, body={"requests": [request]}
2534
+ )
2535
+ )
2536
+
2537
+ output_success(
2538
+ operation="slides.update_image_properties",
2539
+ presentation_id=presentation_id,
2540
+ object_id=object_id,
2541
+ )
2542
+ return result
2543
+ except HttpError as e:
2544
+ output_error(
2545
+ error_code="API_ERROR",
2546
+ operation="slides.update_image_properties",
2547
+ message=f"Google Slides API error: {e.reason}",
2548
+ )
2549
+ raise SystemExit(ExitCode.API_ERROR)
2550
+
2551
+ # =========================================================================
2552
+ # GROUPING
2553
+ # =========================================================================
2554
+
2555
+ def group_objects(
2556
+ self,
2557
+ presentation_id: str,
2558
+ children_object_ids: list[str],
2559
+ group_object_id: str | None = None,
2560
+ ) -> dict[str, Any]:
2561
+ """Group multiple page elements.
2562
+
2563
+ Args:
2564
+ presentation_id: The presentation ID.
2565
+ children_object_ids: List of object IDs to group.
2566
+ group_object_id: Optional ID for the new group (auto-generated if not provided).
2567
+ """
2568
+ import uuid
2569
+
2570
+ try:
2571
+ request: dict[str, Any] = {
2572
+ "groupObjects": {
2573
+ "groupObjectId": group_object_id or f"group_{uuid.uuid4().hex[:8]}",
2574
+ "childrenObjectIds": children_object_ids,
2575
+ }
2576
+ }
2577
+
2578
+ result = self.execute(
2579
+ self.service.presentations()
2580
+ .batchUpdate(
2581
+ presentationId=presentation_id, body={"requests": [request]}
2582
+ )
2583
+ )
2584
+
2585
+ output_success(
2586
+ operation="slides.group_objects",
2587
+ presentation_id=presentation_id,
2588
+ group_object_id=request["groupObjects"]["groupObjectId"],
2589
+ children_count=len(children_object_ids),
2590
+ )
2591
+ return result
2592
+ except HttpError as e:
2593
+ output_error(
2594
+ error_code="API_ERROR",
2595
+ operation="slides.group_objects",
2596
+ message=f"Google Slides API error: {e.reason}",
2597
+ )
2598
+ raise SystemExit(ExitCode.API_ERROR)
2599
+
2600
+ def ungroup_objects(
2601
+ self,
2602
+ presentation_id: str,
2603
+ group_object_ids: list[str],
2604
+ ) -> dict[str, Any]:
2605
+ """Ungroup one or more groups.
2606
+
2607
+ Args:
2608
+ presentation_id: The presentation ID.
2609
+ group_object_ids: List of group object IDs to ungroup.
2610
+ """
2611
+ try:
2612
+ requests = [
2613
+ {"ungroupObjects": {"objectIds": group_object_ids}}
2614
+ ]
2615
+
2616
+ result = self.execute(
2617
+ self.service.presentations()
2618
+ .batchUpdate(
2619
+ presentationId=presentation_id, body={"requests": requests}
2620
+ )
2621
+ )
2622
+
2623
+ output_success(
2624
+ operation="slides.ungroup_objects",
2625
+ presentation_id=presentation_id,
2626
+ ungrouped_count=len(group_object_ids),
2627
+ )
2628
+ return result
2629
+ except HttpError as e:
2630
+ output_error(
2631
+ error_code="API_ERROR",
2632
+ operation="slides.ungroup_objects",
2633
+ message=f"Google Slides API error: {e.reason}",
2634
+ )
2635
+ raise SystemExit(ExitCode.API_ERROR)
2636
+
2637
+ # =========================================================================
2638
+ # SHAPE REPLACEMENT
2639
+ # =========================================================================
2640
+
2641
+ def replace_shapes_with_image(
2642
+ self,
2643
+ presentation_id: str,
2644
+ contains_text: str,
2645
+ image_url: str,
2646
+ image_replace_method: str = "CENTER_INSIDE",
2647
+ page_object_ids: list[str] | None = None,
2648
+ ) -> dict[str, Any]:
2649
+ """Replace all shapes containing specific text with an image.
2650
+
2651
+ Args:
2652
+ presentation_id: The presentation ID.
2653
+ contains_text: Text to search for in shapes.
2654
+ image_url: URL of the image to insert.
2655
+ image_replace_method: How to replace ('CENTER_INSIDE' or 'CENTER_CROP').
2656
+ page_object_ids: Optional list of page IDs to limit the search.
2657
+ """
2658
+ try:
2659
+ request: dict[str, Any] = {
2660
+ "replaceAllShapesWithImage": {
2661
+ "containsText": {
2662
+ "text": contains_text,
2663
+ "matchCase": False,
2664
+ },
2665
+ "imageUrl": image_url,
2666
+ "imageReplaceMethod": image_replace_method,
2667
+ }
2668
+ }
2669
+
2670
+ if page_object_ids:
2671
+ request["replaceAllShapesWithImage"]["pageObjectIds"] = page_object_ids
2672
+
2673
+ result = self.execute(
2674
+ self.service.presentations()
2675
+ .batchUpdate(
2676
+ presentationId=presentation_id, body={"requests": [request]}
2677
+ )
2678
+ )
2679
+
2680
+ # Get replacement count from response
2681
+ replies = result.get("replies", [{}])
2682
+ occurrences = replies[0].get("replaceAllShapesWithImage", {}).get("occurrencesChanged", 0)
2683
+
2684
+ output_success(
2685
+ operation="slides.replace_shapes_with_image",
2686
+ presentation_id=presentation_id,
2687
+ contains_text=contains_text,
2688
+ occurrences_replaced=occurrences,
2689
+ )
2690
+ return result
2691
+ except HttpError as e:
2692
+ output_error(
2693
+ error_code="API_ERROR",
2694
+ operation="slides.replace_shapes_with_image",
2695
+ message=f"Google Slides API error: {e.reason}",
2696
+ )
2697
+ raise SystemExit(ExitCode.API_ERROR)
2698
+
2699
+ # =========================================================================
2700
+ # ACCESSIBILITY
2701
+ # =========================================================================
2702
+
2703
+ def set_alt_text(
2704
+ self,
2705
+ presentation_id: str,
2706
+ object_id: str,
2707
+ title: str | None = None,
2708
+ description: str | None = None,
2709
+ ) -> dict[str, Any]:
2710
+ """Set alt text (accessibility text) on a page element.
2711
+
2712
+ Args:
2713
+ presentation_id: The presentation ID.
2714
+ object_id: The element object ID.
2715
+ title: Brief title for the element.
2716
+ description: Detailed description for screen readers.
2717
+ """
2718
+ try:
2719
+ alt_text: dict[str, Any] = {}
2720
+ fields = []
2721
+
2722
+ if title is not None:
2723
+ alt_text["title"] = title
2724
+ fields.append("title")
2725
+ if description is not None:
2726
+ alt_text["description"] = description
2727
+ fields.append("description")
2728
+
2729
+ if not fields:
2730
+ output_error(
2731
+ error_code="INVALID_ARGUMENT",
2732
+ operation="slides.set_alt_text",
2733
+ message="At least one of title or description required",
2734
+ )
2735
+ raise SystemExit(ExitCode.INVALID_ARGS)
2736
+
2737
+ request = {
2738
+ "updatePageElementAltText": {
2739
+ "objectId": object_id,
2740
+ **alt_text,
2741
+ }
2742
+ }
2743
+
2744
+ result = self.execute(
2745
+ self.service.presentations()
2746
+ .batchUpdate(
2747
+ presentationId=presentation_id, body={"requests": [request]}
2748
+ )
2749
+ )
2750
+
2751
+ output_success(
2752
+ operation="slides.set_alt_text",
2753
+ presentation_id=presentation_id,
2754
+ object_id=object_id,
2755
+ updated_fields=fields,
2756
+ )
2757
+ return result
2758
+ except HttpError as e:
2759
+ output_error(
2760
+ error_code="API_ERROR",
2761
+ operation="slides.set_alt_text",
2762
+ message=f"Google Slides API error: {e.reason}",
2763
+ )
2764
+ raise SystemExit(ExitCode.API_ERROR)
2765
+
2766
+ # =========================================================================
2767
+ # EMBEDDED CHARTS
2768
+ # =========================================================================
2769
+
2770
+ def insert_sheets_chart(
2771
+ self,
2772
+ presentation_id: str,
2773
+ page_object_id: str,
2774
+ spreadsheet_id: str,
2775
+ chart_id: int,
2776
+ x: float,
2777
+ y: float,
2778
+ width: float,
2779
+ height: float,
2780
+ linking_mode: str = "LINKED",
2781
+ ) -> dict[str, Any]:
2782
+ """Insert a chart from Google Sheets.
2783
+
2784
+ Args:
2785
+ presentation_id: The presentation ID.
2786
+ page_object_id: The page (slide) to insert on.
2787
+ spreadsheet_id: The source spreadsheet ID.
2788
+ chart_id: The chart ID in the spreadsheet.
2789
+ x: X position in points from top-left.
2790
+ y: Y position in points from top-left.
2791
+ width: Width in points.
2792
+ height: Height in points.
2793
+ linking_mode: 'LINKED' (updates with source) or 'NOT_LINKED_IMAGE' (static).
2794
+ """
2795
+ import uuid
2796
+
2797
+ try:
2798
+ element_id = f"chart_{uuid.uuid4().hex[:8]}"
2799
+
2800
+ request = {
2801
+ "createSheetsChart": {
2802
+ "objectId": element_id,
2803
+ "spreadsheetId": spreadsheet_id,
2804
+ "chartId": chart_id,
2805
+ "linkingMode": linking_mode,
2806
+ "elementProperties": {
2807
+ "pageObjectId": page_object_id,
2808
+ "size": {
2809
+ "width": {"magnitude": width, "unit": "PT"},
2810
+ "height": {"magnitude": height, "unit": "PT"},
2811
+ },
2812
+ "transform": {
2813
+ "scaleX": 1,
2814
+ "scaleY": 1,
2815
+ "translateX": x * 12700, # PT to EMU
2816
+ "translateY": y * 12700, # PT to EMU
2817
+ "unit": "EMU",
2818
+ },
2819
+ },
2820
+ }
2821
+ }
2822
+
2823
+ result = self.execute(
2824
+ self.service.presentations()
2825
+ .batchUpdate(
2826
+ presentationId=presentation_id, body={"requests": [request]}
2827
+ )
2828
+ )
2829
+
2830
+ output_success(
2831
+ operation="slides.insert_sheets_chart",
2832
+ presentation_id=presentation_id,
2833
+ page_object_id=page_object_id,
2834
+ element_id=element_id,
2835
+ spreadsheet_id=spreadsheet_id,
2836
+ chart_id=chart_id,
2837
+ )
2838
+ return result
2839
+ except HttpError as e:
2840
+ output_error(
2841
+ error_code="API_ERROR",
2842
+ operation="slides.insert_sheets_chart",
2843
+ message=f"Google Slides API error: {e.reason}",
2844
+ )
2845
+ raise SystemExit(ExitCode.API_ERROR)