Solved

How to pass an array of objects in python?

Posted on 2010-11-24
2
734 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 79
oracle query help 18 99
How can i compile this github project?? 2 75
Filename to be appended with DateTimeof Download 3 46
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

16 Experts available now in Live!

Get 1:1 Help Now