I can already do this using pyuno (the 'import uno' statement that loads the uno python module) - I want to see the differences.
The really cool thing about using COM instead of pyuno is that I can use any version of Python I wish...including Python3. It breaks the annoying logjam of matching environment variables and versions and cross-connecting IDEs to work effectively - as long as the COM bridge is stable, which it seems to be.
1) Connecting via COM: How can I do it headless? I know I'm really close, but the document keeps coming up visible.
Code: Select all
import win32.client
OO_ServiceManager = win32com.client.Dispatch("com.sun.star.ServiceManager")
desktop = OO_ServiceManager.CreateInstance("com.sun.star.frame.Desktop")
OO_ServiceManager._FlagAsMethod("Bridge_GetStruct")
hidden = OO_ServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
hidden.Name = "Hidden"
hidden.Value = 1
loading_properties = tuple(hidden)
document = desktop.loadComponentFromUrl("private:factory/swriter", "_blank", 0, loading_properties)
I can already simply *hide* the window, but it's slow - I want to avoid all the uneccesary display overhead.
Code: Select all
document.CurrentController.Frame.ContainerWindow.Visible = False
2) Tab Stops: [SOLVED]
Code: Select all
# Create Tab Stops
if using_uno:
tab_stop1 = uno.createUnoStruct("com.sun.star.style.TabStop")
elif using_com:
OO_Service_Manager._FlagAsMethod("Bridge_GetStruct")
tab_stop1 = OO_Service_Manager.Bridge_GetStruct("com.sun.star.style.TabStop")
tab_stop1.Position = 2550 # Both pyuno and COM
tab_stop1.Alignment = 0 # Both pyuno and COM
3) Italic text: [SOLVED]
Code: Select all
if using_uno:
cursor.CharPosture = "Italic"
cursor.CharPosture = "None"
elif using_com:
cursor.setPropertyValue("CharPosture", 1) # Italic
cursor.setPropertyValue("CharPosture", 0) # Normal
4) Paragraph Breaks: [SOLVED]
Code: Select all
if using_uno:
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
document.text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
elif using_com:
document.text.insertControlCharacter(cursor, 0 , False) # 0 = Paragraph break
- See http://api.openoffice.org/docs/common/r ... acter.html for the numerical value of each control character
5) Page Breaks:[SOLVED]
Code: Select all
if using_uno:
from com.sun.star.style.BreakType import PAGE_AFTER
cursor.BreakType = "PAGE_AFTER"
elif using_com:
cursor.setPropertyValue("BreakType", 5) # 5 = PAGE_AFTER
- See http://api.openoffice.org/docs/common/r ... kType.html for the value of each break type. There are no numbers listed, but I *assumed* they were in numerical order starting with zero (just like control characters above) and I got lucky.