J'ai le code macro python qui fonctionne :
Code : Tout sélectionner
def test():
monDocument = XSCRIPTCONTEXT.getDocument()
Pres =monDocument.Presentation
Pres.start()
Pres.Controller.gotoSlideIndex(1)
Cordialement
Modérateur : Vilains modOOs
Code : Tout sélectionner
def test():
monDocument = XSCRIPTCONTEXT.getDocument()
Pres =monDocument.Presentation
Pres.start()
Pres.Controller.gotoSlideIndex(1)
Code : Tout sélectionner
import os, sys, time
import subprocess
#On lance writer en mode serveur
args='"C:\Program Files (x86)\LibreOffice\program\swriter" "-accept=socket,host=localhost,port=2002;urp;"'
myPopen = subprocess.Popen(args, shell=False)
while myPopen.poll()!=0:
time.sleep(1)
if sys.platform == 'win32':
#Adresse d'installation de LibreOffice 6 32 bit
value = "C:\Program Files (x86)\LibreOffice\program"
install_folder = '\\'.join(value.split('\\')[:-1])
os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:{0}\\program\\fundamental.ini'.format(install_folder)
os.environ['UNO_PATH'] = install_folder+'\\program\\'
sys.path.append(install_folder+'\\program')
paths = ''
for path in ("\\URE\\bin;", "\\program;"):
paths += install_folder + path
os.environ['PATH'] = paths+ os.environ['PATH']
import uno
Code : Tout sélectionner
""" Here is the sequence of things the lines do:
1. Get the uno component context from the PyUNO runtime(
2. Create the UnoUrlResolver
3. Get the central desktop object
4. Declare the ServiceManager
5. Get the central desktop object
6. Access the current writer document
7. Access the document's text property
8. Create a cursor
9. Insert the text into the document """
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
#desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model = smgr.createInstanceWithContext( "com.sun.star.script.provider.XScriptContext",ctx)
#model = desktop.getCurrentComponent()
#monDocument = document.getDocument()
monDocument = model.getDocument()
Pres =monDocument.Presentation
Pres.start()
Pres.Controller.gotoSlideIndex(1)
""" Do a nasty thing before exiting the python process. In case the
last call is a one-way call (e.g. see idl-spec of insertString),
it must be forced out of the remote-bridge caches before python
exits the process. Otherwise, the one-way call may or may not reach
the target object.
I do this here by calling a cheap synchronous call (getPropertyValue)."""
ctx.ServiceManager
Code : Tout sélectionner
monDocument = XSCRIPTCONTEXT.getDocument()
Pres =monDocument.Presentation
Pres.start()
Pres.Controller.gotoSlideIndex(1)
Code : Tout sélectionner
import os, sys, time
import subprocess
args='"C:\Program Files (x86)\LibreOffice\program\simpress" "-accept=socket,host=localhost,port=2002;urp;" "D:\MaPrésentation.odp"'
myPopen = subprocess.Popen(args, shell=False)
while myPopen.poll()!=0:
time.sleep(1)
time.sleep(1)
if sys.platform == 'win32':
#This is required in order to make pyuno usable with the default python interpreter under windows
#Some environment varaible must be modified
value = "C:\Program Files (x86)\LibreOffice\program"
install_folder = '\\'.join(value.split('\\')[:-1])
#modify the environment variables
os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:{0}\\program\\fundamental.ini'.format(install_folder)
os.environ['UNO_PATH'] = install_folder+'\\program\\'
sys.path.append(install_folder+'\\program')
paths = ''
for path in ("\\URE\\bin;", "\\program;"):
paths += install_folder + path
os.environ['PATH'] = paths+ os.environ['PATH']
import uno
""" Here is the sequence of things the lines do:
1. Get the uno component context from the PyUNO runtime(
2. Create the UnoUrlResolver
3. Get the central desktop object
4. Declare the ServiceManager
5. Get the central desktop object
6. Access the current impress document"""
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model = desktop.getCurrentComponent()
Pres = model.Presentation
time.sleep(5)
Pres.start()
time.sleep(1)
Pres.Controller.gotoSlideIndex(1)
""" Do a nasty thing before exiting the python process. In case the
last call is a one-way call (e.g. see idl-spec of insertString),
it must be forced out of the remote-bridge caches before python
exits the process. Otherwise, the one-way call may or may not reach
the target object.
I do this here by calling a cheap synchronous call (getPropertyValue)."""
ctx.ServiceManager
pywin32 est disponible ici :khoeds a écrit :Je crois qu'il est possible de le faire via piwin32 et COM, mais je n'arrive pas à le retrouver. Je suis preneur de toutes les pistes. Merci d'avance.
Code : Tout sélectionner
import time
from win32com.client.dynamic import Dispatch
print('connexion au document impress')
objServiceManager = Dispatch('com.sun.star.ServiceManager')
Stardesktop = objServiceManager.CreateInstance('com.sun.star.frame.Desktop')
diaporama = Stardesktop.getCurrentComponent()
Pres = diaporama.Presentation
time.sleep(5)
print('démarrage du diaporama')
Pres.start()
time.sleep(2)
print('passage à la 3ème diapo')
Pres.Controller.gotoSlideIndex(2)
Code : Tout sélectionner
from win32com.client.dynamic import Dispatch
print('ouverture nouveau document writer')
objServiceManager = Dispatch('com.sun.star.ServiceManager')
Stardesktop = objServiceManager.CreateInstance('com.sun.star.frame.Desktop')
doc = Stardesktop.loadComponentfromURL('private:factory/swriter', '_blank', 0, [])
text = doc.getText()
print('écriture de hello World')
text.setString("Hello World")
La modération vous a écrit: Question initiale résolue donc pour tout autre problème : ouvrir un nouveau fil avec un titre explicite.
Code : Tout sélectionner
import pyHook, pythoncom
txt="La barre d'espace est appuyée!!!"
def OnKeyboardEvent(event):
if event.KeyID==32:
print(txt)
return event.KeyID
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()
Code : Tout sélectionner
import time
from win32com.client.dynamic import Dispatch
print('connexion au document impress')
objServiceManager = Dispatch('com.sun.star.ServiceManager')
Stardesktop = objServiceManager.CreateInstance('com.sun.star.frame.Desktop')
diaporama = Stardesktop.getCurrentComponent()
Pres = diaporama.Presentation
time.sleep(5)
print('démarrage du diaporama')
Pres.start()
time.sleep(2)
import pyHook, pythoncom
SlideNo=0
txt="La barre d'espace est appuyée!!!"
def OnKeyboardEvent(event):
global SlideNo
global Pres
if event.KeyID==32:
print(txt)
SlideNo = SlideNo + 1
Pres.Controller.gotoSlideIndex(SlideNo)
return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()