Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to pass an array of objects in python?

Posted on 2010-11-24
2
Medium Priority
?
793 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
markoilic earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This is about my first experience with programming Arduino.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Six Sigma Control Plans

610 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