Solved

How to pass an array of objects in python?

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 63
Programming Codes 2 46
Adding a countdown to HTA 12 99
Python to .bat or Powershell 2 33
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

726 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