|
@@ -148,6 +148,25 @@ async function libreofficeWinId(): Promise<string> {
|
|
|
|
|
|
|
|
// Navigate via UNO — separate script per action to avoid indentation issues
|
|
// Navigate via UNO — separate script per action to avoid indentation issues
|
|
|
function pyUnoNav(direction: "next" | "prev" | "start" | "end"): Promise<string> {
|
|
function pyUnoNav(direction: "next" | "prev" | "start" | "end"): Promise<string> {
|
|
|
|
|
+ // Helper snippet reused in next/prev to read position after nav
|
|
|
|
|
+ const readPos = `
|
|
|
|
|
+current = 0
|
|
|
|
|
+controller = comp.getCurrentController()
|
|
|
|
|
+draw = comp.DrawPages
|
|
|
|
|
+total = draw.Count
|
|
|
|
|
+if hasattr(controller, 'getCurrentSlideIndex'):
|
|
|
|
|
+ current = controller.getCurrentSlideIndex() + 1
|
|
|
|
|
+ print(f"[nav] slideshow mode, index={current}", file=sys.stderr)
|
|
|
|
|
+else:
|
|
|
|
|
+ page = controller.getCurrentPage()
|
|
|
|
|
+ for i in range(draw.Count):
|
|
|
|
|
+ if draw.getByIndex(i) == page:
|
|
|
|
|
+ current = i + 1
|
|
|
|
|
+ break
|
|
|
|
|
+ print(f"[nav] editor mode, index={current}", file=sys.stderr)
|
|
|
|
|
+print(f"{current}/{total}")
|
|
|
|
|
+`;
|
|
|
|
|
+
|
|
|
const scripts: Record<string, string> = {
|
|
const scripts: Record<string, string> = {
|
|
|
next: `
|
|
next: `
|
|
|
import sys, time
|
|
import sys, time
|
|
@@ -160,29 +179,22 @@ try:
|
|
|
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
|
|
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
|
|
|
comp = desktop.getCurrentComponent()
|
|
comp = desktop.getCurrentComponent()
|
|
|
controller = comp.getCurrentController()
|
|
controller = comp.getCurrentController()
|
|
|
- print(f"[nav] controller: {type(controller).__name__}", file=sys.stderr)
|
|
|
|
|
|
|
+ draw = comp.DrawPages
|
|
|
|
|
+ print(f"[nav] next, controller: {type(controller).__name__}", file=sys.stderr)
|
|
|
if hasattr(controller, 'gotoNextSlide'):
|
|
if hasattr(controller, 'gotoNextSlide'):
|
|
|
controller.gotoNextSlide()
|
|
controller.gotoNextSlide()
|
|
|
- elif hasattr(controller, 'gotoNextEffect'):
|
|
|
|
|
- controller.gotoNextEffect()
|
|
|
|
|
- else:
|
|
|
|
|
- print("[nav] no next method, trying DrawController", file=sys.stderr)
|
|
|
|
|
- controller.CurrentPage = comp.DrawPages.getByIndex(min(controller.CurrentPage.PageIndex + 1, comp.DrawPages.Count - 1))
|
|
|
|
|
- time.sleep(0.3)
|
|
|
|
|
- controller = comp.getCurrentController()
|
|
|
|
|
- draw = comp.DrawPages
|
|
|
|
|
- total = draw.Count
|
|
|
|
|
- current = 0
|
|
|
|
|
- if hasattr(controller, 'getCurrentSlideIndex'):
|
|
|
|
|
- current = controller.getCurrentSlideIndex() + 1
|
|
|
|
|
else:
|
|
else:
|
|
|
page = controller.getCurrentPage()
|
|
page = controller.getCurrentPage()
|
|
|
|
|
+ idx = 0
|
|
|
for i in range(draw.Count):
|
|
for i in range(draw.Count):
|
|
|
if draw.getByIndex(i) == page:
|
|
if draw.getByIndex(i) == page:
|
|
|
- current = i + 1
|
|
|
|
|
|
|
+ idx = i
|
|
|
break
|
|
break
|
|
|
- print(f"[nav] next -> {current}/{total}", file=sys.stderr)
|
|
|
|
|
- print(f"{current}/{total}")
|
|
|
|
|
|
|
+ next_idx = min(idx + 1, draw.Count - 1)
|
|
|
|
|
+ print(f"[nav] setCurrentPage {idx} -> {next_idx}", file=sys.stderr)
|
|
|
|
|
+ controller.setCurrentPage(draw.getByIndex(next_idx))
|
|
|
|
|
+ time.sleep(0.3)
|
|
|
|
|
+ ${readPos}
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
import traceback; traceback.print_exc(file=sys.stderr)
|
|
import traceback; traceback.print_exc(file=sys.stderr)
|
|
|
print("0/0")
|
|
print("0/0")
|
|
@@ -198,29 +210,22 @@ try:
|
|
|
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
|
|
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
|
|
|
comp = desktop.getCurrentComponent()
|
|
comp = desktop.getCurrentComponent()
|
|
|
controller = comp.getCurrentController()
|
|
controller = comp.getCurrentController()
|
|
|
- print(f"[nav] controller: {type(controller).__name__}", file=sys.stderr)
|
|
|
|
|
|
|
+ draw = comp.DrawPages
|
|
|
|
|
+ print(f"[nav] prev, controller: {type(controller).__name__}", file=sys.stderr)
|
|
|
if hasattr(controller, 'gotoPreviousSlide'):
|
|
if hasattr(controller, 'gotoPreviousSlide'):
|
|
|
controller.gotoPreviousSlide()
|
|
controller.gotoPreviousSlide()
|
|
|
- elif hasattr(controller, 'gotoPreviousEffect'):
|
|
|
|
|
- controller.gotoPreviousEffect()
|
|
|
|
|
- else:
|
|
|
|
|
- print("[nav] no prev method, trying DrawController", file=sys.stderr)
|
|
|
|
|
- controller.CurrentPage = comp.DrawPages.getByIndex(max(controller.CurrentPage.PageIndex - 1, 0))
|
|
|
|
|
- time.sleep(0.3)
|
|
|
|
|
- controller = comp.getCurrentController()
|
|
|
|
|
- draw = comp.DrawPages
|
|
|
|
|
- total = draw.Count
|
|
|
|
|
- current = 0
|
|
|
|
|
- if hasattr(controller, 'getCurrentSlideIndex'):
|
|
|
|
|
- current = controller.getCurrentSlideIndex() + 1
|
|
|
|
|
else:
|
|
else:
|
|
|
page = controller.getCurrentPage()
|
|
page = controller.getCurrentPage()
|
|
|
|
|
+ idx = 0
|
|
|
for i in range(draw.Count):
|
|
for i in range(draw.Count):
|
|
|
if draw.getByIndex(i) == page:
|
|
if draw.getByIndex(i) == page:
|
|
|
- current = i + 1
|
|
|
|
|
|
|
+ idx = i
|
|
|
break
|
|
break
|
|
|
- print(f"[nav] prev -> {current}/{total}", file=sys.stderr)
|
|
|
|
|
- print(f"{current}/{total}")
|
|
|
|
|
|
|
+ prev_idx = max(idx - 1, 0)
|
|
|
|
|
+ print(f"[nav] setCurrentPage {idx} -> {prev_idx}", file=sys.stderr)
|
|
|
|
|
+ controller.setCurrentPage(draw.getByIndex(prev_idx))
|
|
|
|
|
+ time.sleep(0.3)
|
|
|
|
|
+ ${readPos}
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
import traceback; traceback.print_exc(file=sys.stderr)
|
|
import traceback; traceback.print_exc(file=sys.stderr)
|
|
|
print("0/0")
|
|
print("0/0")
|
|
@@ -240,10 +245,10 @@ try:
|
|
|
pres.start()
|
|
pres.start()
|
|
|
time.sleep(1.5)
|
|
time.sleep(1.5)
|
|
|
controller = comp.getCurrentController()
|
|
controller = comp.getCurrentController()
|
|
|
- print(f"[nav] controller after start: {type(controller).__name__}", file=sys.stderr)
|
|
|
|
|
draw = comp.DrawPages
|
|
draw = comp.DrawPages
|
|
|
total = draw.Count
|
|
total = draw.Count
|
|
|
current = 0
|
|
current = 0
|
|
|
|
|
+ print(f"[nav] controller after start: {type(controller).__name__}", file=sys.stderr)
|
|
|
if hasattr(controller, 'getCurrentSlideIndex'):
|
|
if hasattr(controller, 'getCurrentSlideIndex'):
|
|
|
current = controller.getCurrentSlideIndex() + 1
|
|
current = controller.getCurrentSlideIndex() + 1
|
|
|
else:
|
|
else:
|
|
@@ -272,7 +277,7 @@ try:
|
|
|
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
|
|
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
|
|
|
comp = desktop.getCurrentComponent()
|
|
comp = desktop.getCurrentComponent()
|
|
|
controller = comp.getCurrentController()
|
|
controller = comp.getCurrentController()
|
|
|
- print(f"[nav] ending presentation, controller: {type(controller).__name__}", file=sys.stderr)
|
|
|
|
|
|
|
+ print(f"[nav] ending, controller: {type(controller).__name__}", file=sys.stderr)
|
|
|
if hasattr(controller, 'deactivate'):
|
|
if hasattr(controller, 'deactivate'):
|
|
|
controller.deactivate()
|
|
controller.deactivate()
|
|
|
else:
|
|
else:
|