Change «OutlineNumbering» format with UNO

The Application Programming Interface and the OASIS Open Document Format

Change «OutlineNumbering» format with UNO

Postby Hi-Angel » Sun Aug 16, 2015 12:51 pm

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.

Image

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.
OpenOffice 4.1.1, Kubuntu 14.04
Hi-Angel
 
Posts: 7
Joined: Sun Aug 16, 2015 3:47 am

Re: Change «OutlineNumbering» format with UNO

Postby Villeroy » Sun Aug 16, 2015 1:41 pm

MRI_NumberingStyle.png
First paragraph, property NumberingStyleName = "Untitled1"
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change «OutlineNumbering» format with UNO

Postby Hi-Angel » Sun Aug 16, 2015 2:22 pm

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?
OpenOffice 4.1.1, Kubuntu 14.04
Hi-Angel
 
Posts: 7
Joined: Sun Aug 16, 2015 3:47 am

Re: Change «OutlineNumbering» format with UNO

Postby Villeroy » Sun Aug 16, 2015 2:49 pm

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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change «OutlineNumbering» format with UNO

Postby Hi-Angel » Sun Aug 16, 2015 2:58 pm

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)
OpenOffice 4.1.1, Kubuntu 14.04
Hi-Angel
 
Posts: 7
Joined: Sun Aug 16, 2015 3:47 am

Re: Change «OutlineNumbering» format with UNO

Postby Hi-Angel » Sat Aug 22, 2015 8:57 am

Okay, I made a script that saves some properties to a file.

Code: Select all   Expand viewCollapse view
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.
OpenOffice 4.1.1, Kubuntu 14.04
Hi-Angel
 
Posts: 7
Joined: Sun Aug 16, 2015 3:47 am

Re: Change «OutlineNumbering» format with UNO

Postby Hi-Angel » Sun Aug 23, 2015 8:54 am

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   Expand viewCollapse view
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).
OpenOffice 4.1.1, Kubuntu 14.04
Hi-Angel
 
Posts: 7
Joined: Sun Aug 16, 2015 3:47 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 3 guests