Page 1 of 1
Change «OutlineNumbering» format with UNO
Posted: Sun Aug 16, 2015 12:51 pm
by Hi-Angel
I already a few hours wandering, but couldn't figure it out — how do I change an Outline Numbering format? E.g. in the picture you could see a button «Format» — it allows to choose between various "Untitled" styles. For some reason for convertation process that I am doing it being dropped to an unknown value, so I need to get it back.
So, how do I set the current «OutlineNumbering» to e.g. "Untitled 1" with UNO API?
I found various properties with MRI that mention in various ways the word "numbering", but nowhere mentioned e.g. "Untitled 1" when it being set, or at least something resembling.
Re: Change «OutlineNumbering» format with UNO
Posted: Sun Aug 16, 2015 1:41 pm
by Villeroy
- First paragraph, property NumberingStyleName = "Untitled1"
Re: Change «OutlineNumbering» format with UNO
Posted: Sun Aug 16, 2015 2:22 pm
by Hi-Angel
No, that doesn't work ☹ I just tested it in MRI — set the Property Value "NumberingStyleName" to "Untitled 1" in the first paragraph; however when I go to «Tools → Outline Numbering…», I can see that numbering doesn't seem to be changed. But I can choose there «Format… → Untitled 1» by hand, and I see that then number style changed.
Anyway, why would the outline numbering for the whole document be set in the first paragraph?
UPD: or perhaps what the Office actually does after one chooses the option — is just iterates for every paragraph and changes the value?
Re: Change «OutlineNumbering» format with UNO
Posted: Sun Aug 16, 2015 2:49 pm
by Villeroy
Hi-Angel wrote:No, that doesn't work ☹ I just tested it in MRI — set the Property Value "NumberingStyleName" to "Untitled 1"
Are you sure its "Untitled 1" and not "Untitled1" without space?
Hi-Angel wrote:
Anyway, why would the outline numbering for the whole document be set in the first paragraph?
Because I set it up this way for testing.
Re: Change «OutlineNumbering» format with UNO
Posted: Sun Aug 16, 2015 2:58 pm
by Hi-Angel
Villeroy wrote:
Are you sure its "Untitled 1" and not "Untitled1" without space?
Yep, you can check it with the screenshot of the first post. I need to say that actually the style of the first paragraph indeed seems to be changed — I could inspect the change with MRI. But I wanted to make a global change
(like the option «Tools → Outline Numbering…» does), and it doesn't work this way. I think however if UNO API has no an according method, I could indeed just iterate through every paragraph. That would be sad a bit, though.
UPD: meanwhile I found the reason why I hadn't the style set. When I produce a document from Markdown, it's just like this. And the currently set outline numbering not being copied when I load a styles from a file even if the file has it.
(I mean it copies the outline numbering styles, but not the currently set one)
Re: Change «OutlineNumbering» format with UNO
Posted: Sat Aug 22, 2015 8:57 am
by Hi-Angel
Okay, I made a script that saves some properties to a file.
Code: Select all
import uno
import unohelper
import string
from com.sun.star.beans import PropertyValue
def writeProps(file, propsOwner):
"""First arg is an opened file to write, the second is the property owner"""
for p in propsOwner.PropertySetInfo.Properties:
file.write("•••••••••••\nProperty is:\n" + str(p).replace(',','\n') + "\n")
try: #Omg, why the hell UNO throws exception instead of None return
file.write("Property value is:\n" + str(propsOwner.getPropertyValue(p.Name)) + "\n")
except Exception: #uno.RuntimeException: wtf, why can't I handle it?
pass
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
smgr = resolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)
#document
doc = desktop.loadComponentFromURL("file:///tmp/test.odt" ,"_blank", 0, ())
file = open('/tmp/log', 'w')
writeProps(file, doc)
#doc.Text
file.write("•••••••••••Doc.Text")
writeProps(file, doc.Text)
#every paragraph
enum = doc.Text.createEnumeration()
while enum.hasMoreElements():
nextPar = enum.nextElement()
writeProps(file, nextPar)
#every paragraph 2?
file.write("•••••••••••TextCursor")
cursor = doc.Text.createTextCursor()
while cursor.gotoNextParagraph(False):
writeProps(file, cursor)
file.close()
Next I made a simple test document, and wrote its properties before and after the «Outline Numbering» was changed. The interesting thing is that «NumberingStyleName» haven't changed — it was always set to "Outline" in some paragraphs.
In fact after I compared files with
vimdiff, the only thing that changed besides of [word,char] counters and
ids — is the «ListLabelString»
(just a string of heading counter). But the script doesn't write all existing properties, though, I think I am missing something.
Re: Change «OutlineNumbering» format with UNO
Posted: Sun Aug 23, 2015 8:54 am
by Hi-Angel
I wrote a function to print recursively all properties for some maximum level
(it also checks that it doesn't go into the same location where it was).
Code: Select all
def printUNO(parent, listChecked, maxLevel):
"""First arg is the element where to start, second is a list of elements that were checked, and the third is
a maximum depth"""
try:
for propName in dir(parent):
if str(propName)[0].islower(): #function, skip
continue
try:
property = getattr(parent, propName)
except Exception: #inspect.UnknownPropertyException: wtf, that doesn't work
continue
if str(property).startswith('pyuno'):
if ( not any(propName == s for s in listChecked)
and len(listChecked) < maxLevel):
l = list(listChecked)
l.append(propName)
printUNO(property, l, maxLevel)
continue
print(propName + ': ' + str(property) + '\n')
except Exception:
return
Use like
printUNO(myDocument, [], 5) Still I didn't found anything changed after a global change of OutlineNumbering
(except of things like id's, characters counts, etc).