Solved

How to pass an array of objects in python?

Posted on 2010-11-24
2
731 Views
Last Modified: 2012-05-10
My ultimate goal is to insert an image in doc that is open in writer.

Right now I have the following code:

 
import Danny.OOo.OOoLib as OOoLib
import unohelper
import os.path
import glob
from com.sun.star.beans import PropertyValue
from array import array



#dim args1(3) as new com.sun.star.beans.PropertyValue
#args1(0).Name = "FileName"
#args1(0).Value = "file://tesla/images/674.png"
#args1(1).Name = "FilterName"
#args1(1).Value = "<All formats>"
#args1(2).Name = "AsLink"
#args1(2).Value = false
#args1(3).Name = "Style"
#args1(3).Value = "Graphics"

L =  [ PropertyValue() for i in range(4)]


L[0].Name="FileName"
L[0].Value="file://home/ollie/Desktop/Screenshot.png"
L[1].Name="FilterName"
L[1].Value="<All formats>"
L[2].Name = "AsLink"
L[2].Value = False
L[3].Name="Style"
L[3].Value="Graphics"



desktop = OOoLib.getDesktop()
doc=desktop.getCurrentComponent()
dispatcher = OOoLib.getServiceManager().createInstance('com.sun.star.frame.DispatchHelper') 
dispatcher.executeDispatch(doc, ".uno:InsertGraphic", "", 0, L)

Open in new window


The executeDispatch call fails with the following error:

Traceback (most recent call last):
  File "test.py", line 43, in ?
    dispatcher.executeDispatch(doc, ".uno:InsertGraphic", "", 0, L)
uno.com.sun.star.uno.RuntimeException: exceptions.AttributeError: 'list' object has no attribute 'getTypes', traceback follows\nno traceback available

I think the problem is that I'm passing a python list when the called function is expecting the equivalent of a java array. How do I convert the list to something that has an attribute getTypes? Or do I need to create my own class and implement a getTypes method?
0
Comment
Question by:opike
2 Comments
 
LVL 2

Accepted Solution

by:
markoilic earned 500 total points
ID: 34210046
Hi,

last line of your code should be

dispatcher.executeDispatch(doc.getCurrentController(), '.uno:InsertGraphic', '', 0, tuple(L))

and it will work
0
 

Author Comment

by:opike
ID: 34212693
Thanks that got me past that issue but it's still not quite working yet. :) I'll open another thread for the new message.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now