OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Python and OOo: do you have some links?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Jan 05, 2004 7:26 am    Post subject: Python and OOo: do you have some links? Reply with quote

Hi all,

I've been using OOo in some small Visual Basic programs.
Lately however, I'm wondering if VB is the language to use:
* VB6 is the last 'real' VB, VB.NET is just C# with a different look.
* VB is platform specific.
* VB is not open source.
* VB is sometimes just s**t. You really have to work around the problems of VB.

Python however seems to solve all these objections!
Now, I'm not a Python guru (yet! Very Happy ), so do you have any clues on how to work with OOo in it?
I hear about the Python UNO bridge, but completely don't understand what it is and how it works.
Is Python in OOo already finished, mature?

So basically, if you could give me some pointers to start, I would be very grateful.

Greets,

Chris

BTW: does anybody have any clue on how to compare documents in a program?
see also http://www.oooforum.org/forum/viewtopic.php?t=2853
Back to top
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Jan 05, 2004 8:34 am    Post subject: Reply with quote

I had been meaning to learn Python for a couple years. It was OOo that finally pushed me to expend the effort.

I have done a limited amount of coding in Python, and most of it for OOo. I have ended up spending far more time in OOo Basic than I would like. Several reasons. Basic is easily accessible, and seems to be best for giving OOo examples.

Everyone who has OOo 1.1 has the option to install an integrated Python implementation.

Python code can be run in two forms.
1. External to OOo.
2. Installed as a component.

Number 2 means you could write a true component, with new Services that are part of the office. You would of course, have to install them with pkgchk. But I'm working on that. I'm thinking it may be possible to install a Python component into the office from a Basic macro document -- no pkgchk.

Number 1 means that you have to configure OOo to listen for Uno connections. I have a macro document that trivially accomplishes this configuration step. It used to be a major pain to hand edit an XCU file. The macro document is available at OOoMacros.org. I think it is called UnoConnectionListener. You open it, and can configure OOo to listen for a connection on any TCP/IP port, such as port 8100.

Then your python or java program, even from a different computer, can connect to your computer on port 8100 and drive the OOo to do things. (I have done the different computer / different OS thing to OOo from Java, but not from python.)

If you jump through some hoops, you can even use Python with IDLE, I've done it. IDLE is a GUI IDE for doing python development. Using IDLE makes python development much easier. Using this, you get a level of interactivity that niether Basic nor Java offers. You can create OOo objects from the command line. You could do something like....
Code:
oDrawDoc = oDesktop.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, (,) )

from IDLE's interactive command shell, and up pops a new draw document. (You must have the Desktop object in oDesktop first.) But then, interactively you could do things, like put a rectangle onto the drawing....
Code:
oShape = oDrawDoc.createInstance( "com.sun.star.drawing.RectangleShape" )
oDrawDoc.add( oShape )
oShape.Position = MakePoint( 3000, 4000 )
oShape.Size = MakeSize( 4000, 5000 )
oShape.FillColor = 0


As you type in each of the above lines, you would see its effect immediately and instantly reflected in the drawing document window.

In some of my old messages posted here I have described how to get Python with IDLE running on Windows. Since then I've also done it on Linux.

As for Python language issues, the biggest one I can think of is how sequences in UNO are mapped to tupples in Python. Understand how to use tupples.

Right now, I'm going to dig around in some of my old postings to find some useful information.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Jan 05, 2004 9:30 am    Post subject: Reply with quote

Okay, at long last, I am going to write a guide to setting up Python for OOo on Windows. I'll post it in the Macros and API section when I have it sufficiently written up. I'll try to include some examples.

Perhaps once it is posted here on OOoForum, someone could could pester the maintainer of the python-uno web page at OpenOffice.org to include a link to this information there. (Or even a complete copy if they prefer. I will give whatever formal permission they feel is necessary if they think that is an issue, which they have in the past.)

Since Python comes with every OOo 1.1, it would be really cold if more people would use it instead of Basic.


In the meantime, while I'm writing a guide, here are some links to get you started. Ask you first asked for.

http://www.oooforum.org/forum/viewtopic.php?p=13501#13501
http://www.oooforum.org/forum/viewtopic.php?t=3451

My UnoConnectionListener document can be obtained from OOoMacros.org.

http://ooomacros.org/files.php?type=macro#UNOConnectionListener

http://sourceforge.net/project/showfiles.php?group_id=87718&package_id=100069

You can try Googling...
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=site%3Aoooforum.org+DannyB+Python&btnG=Google+Search
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Chris_147
General User
General User


Joined: 28 Aug 2003
Posts: 27

PostPosted: Tue Jan 06, 2004 1:56 am    Post subject: Reply with quote

DannyB,

again you come with some good answers.
Thanks.

I'll try them.
Installing Python is no problem. Just the interaction with OOo.
As I see it I can use it like with VB (number 1: external in your post) Only Python allows to do it also from the commandline...

Number 2 (component) in your post is extra, but is more difficult I understood.

Well, thanks anyway. Now finding the time to learn Python Smile

Chris
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Tue Jan 06, 2004 10:24 am    Post subject: Reply with quote

Chris_147 wrote:
Installing Python is no problem. Just the interaction with OOo.


You must use the Python that comes with OOo. I will explain all this in my guide.

If installing OOo for first time, pick Custom installation, and make sure Python-UNO bridge is installed.

If OOo is already installed, then quit OOo, run Setup, and pick Modify, then make sure Python-UNO bridge is selected.

Everyone who has OOo 1.1 can install OOo's custom-compiled Python this easily. (Custom compiled because OOo uses a different StdCLib from the commonly available precompiled python distributions.)
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
nom
OOo Enthusiast
OOo Enthusiast


Joined: 17 Dec 2003
Posts: 153
Location: NSW, Australia

PostPosted: Tue Jan 06, 2004 6:13 pm    Post subject: Reply with quote

Danny,

Thanks a lot! Can't wait to get my hands on your documentation... I tried getting python to work with OOo a few months back and never had any success.

Cheers,

Nom
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Jan 07, 2004 10:46 am    Post subject: Reply with quote

Try this to get started.
http://www.oooforum.org/forum/viewtopic.php?t=4818

Good luck.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group