Re: [api-dev] Fwd: How to create a checkbox with UNO

2009-01-20 Thread Oliver Brinzing
Hi

> Is this the only way of doing this because I'd rather keep my dev in only one 
> language ?

it should be possible to script everything in python ...
the basic example will only show the necessary steps to add a form control

> "vnd.sun.star.script:helloworld.py$HelloWorldPython?language=Python&location=share"

this is only an example how to call a script from a form controls event ...

Oliver

-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


Re: [api-dev] Fwd: How to create a checkbox with UNO

2009-01-20 Thread Frédéric Point
Thanks a lot for your help Oliver.

Is this the only way of doing this because I'd rather keep my dev in only
one language ?

2009/1/19 Oliver Brinzing 

> and to call a python script you can use:
>
> oEvents(0).ScriptType = "Python"
> oEvents(0).ScriptCode =
>
> "vnd.sun.star.script:helloworld.py$HelloWorldPython?language=Python&location=share"
>
> you have to change the the first line in  "HelloWorld.py" too:
>
>  -> def HelloWorldPython(evt):
>
> Oliver
> --
>
> GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45
>
>


Re: [api-dev] Fwd: How to create a checkbox with UNO

2009-01-19 Thread Oliver Brinzing
and to call a python script you can use:

oEvents(0).ScriptType = "Python"
oEvents(0).ScriptCode =
"vnd.sun.star.script:helloworld.py$HelloWorldPython?language=Python&location=share"

you have to change the the first line in  "HelloWorld.py" too:

 -> def HelloWorldPython(evt):

Oliver
-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


Re: [api-dev] Fwd: How to create a checkbox with UNO

2009-01-19 Thread Oliver Brinzing
you will find additional information here:

http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Forms/Scripting_and_Events


-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


Re: [api-dev] Fwd: How to create a checkbox with UNO

2009-01-19 Thread Oliver Brinzing
Hi Frédéric,

> I need to create a checkbox in oowriter document with an external script in

here is a starbasic example how to add a command button into a writer document.

HTH

Oliver


Option Explicit

Sub CreateControl

Dim oDocument as Object
Dim oView as Object
Dim oDrawPage as Object
Dim oController as Object
Dim oForm as Object
Dim oEvents(0) as New com.sun.star.script.ScriptEventDescriptor

Dim oControlShape as Object
Dim oControlModel as Object
Dim oSize as New com.sun.star.awt.Size
Dim oPosition as New com.sun.star.awt.Point

oDocument = StarDesktop.getCurrentComponent
oView = oDocument.CurrentController

' calc document's
' oDrawPage = oView.getActiveSheet.DrawPage
oDrawPage = oDocument.getDrawPage() 

oControlShape = 
oDocument.createInstance("com.sun.star.drawing.ControlShape")

oSize.Height = 1000
oSize.Width = 3000
oPosition.X = 2000
oPosition.Y = 3000

oControlShape.setSize(oSize)
oControlShape.SizeProtect = True
oControlShape.setPosition(oPosition)
oControlShape.MoveProtect = True
oControlShape.setPropertyValue("AnchorType", 
com.sun.star.text.TextContentAnchorType.AT_PAGE)
oControlShape.Name("My Shape")  ' optional name for 
identification ...

oControlModel = 
createUNOService("com.sun.star.form.component.CommandButton")
oControlModel.Name = "My Control"
oControlModel.Label = "Test"
oControlModel.FontName = "Arial"
oControlModel.FontHeight = 10
oControlModel.Tag = "Hello World !"
oControlModel.Enabled = True

oControlShape.setControl(oControlModel)
oDrawPage.add(oControlShape)

oController = oView.getControl(oControlModel)
oController.SetFocus()

oForm = oDrawPage.getForms.getByIndex(0)

oEvents(0).ListenerType = "XActionListener"
oEvents(0).EventMethod  = "actionPerformed"
oEvents(0).AddListenerParam = ""
oEvents(0).ScriptType = "StarBasic"
oEvents(0).ScriptCode = "application:Standard.Module1.Test"

oForm.registerScriptEvent(0, oEvents(0))

Call XToggleDesignMode(oDocument)

End Sub


Sub Test(oEvt)

Dim oControlModel as Object

oControlModel = oEvt.Source.Model
MsgBox oControlModel.Tag

End Sub

Sub XToggleDesignMode(oDocument as Object)  ' from the Tools 
Library ...

Dim aTransformer as Object
Dim oDispatch as Object
Dim oFrame as Object

Dim aSwitchMode as New com.sun.star.util.URL
Dim aEmptyArgs() as New com.sun.star.bean.PropertyValue

aSwitchMode.Complete = ".uno:SwitchControlDesignMode"

aTransformer = createUnoService("com.sun.star.util.URLTransformer")
aTransformer.parseStrict(aSwitchMode)

'   Print aTransformer.getPresentation(aSwitchmode, True)
oFrame = oDocument.currentController.Frame

oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name, 63)
oDispatch.dispatch(aSwitchMode, aEmptyArgs())
End Sub

-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


[api-dev] Fwd: How to create a checkbox with UNO

2009-01-19 Thread Frédéric Point
Hi,

I need to create a checkbox in oowriter document with an external script in
python. I think that I manage to create the object with this :

cb1 = doc.createInstance( "com.sun.star.form.component.ChekBox" )

But now I don't know how to insert it into my document. I tried this :

cursor = doc.Text.createTextCursor()
doc.Text.insertTextContent(cursor, cb1, 0)

but it failed with this error : __main__.CannotConvertException: valuehas no
such interface!

I do understand my mistake but how do I insert component in a text document
?

Regards,

Frederic Point