UDF/User defined function libreoffice basic with built-in help/tip - input

I did a function in LibreOffice calc. It works, but I would like to have a conext help/tip capability, like the built in LibreOffice functions.
Example: when I type "=besselk(" it appaears a tip BESSELK(X; N). Using the function wizard a function and arguments description does also appear.
Besselk
besselk
Let's say I have a function to calculte a rectangle area
function arearect(a, b)
arearect = a * b
end function
I would like to have something like this:
function arearect(a, b)
FUNCTION DESCRIPTION "Compute rectangle area"
ARGUMENT DESCRIPTION "base length"
ARGUMENT DESCRIPTION "height"
arearect = a * b
end function
so, when I type "=arearect(" the argument description would appear and all descriptors would appear on Function Wizard.
thanks

Create the user-defined function as a Spreadsheet Add-In. Then enter the help text in the Description node in the .xcu file that defines the add-in.
For example, I created a function called REVERSE. Here is my CalcAddIns.xcu file:
<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
oor:name="CalcAddIns" oor:package="org.openoffice.Office">
<node oor:name="AddInInfo">
<node oor:name="name.JimK.ReverseStringImpl" oor:op="replace">
<node oor:name="AddInFunctions">
<node oor:name="reverse" oor:op="replace">
<prop oor:name="DisplayName"><value xml:lang="en">reverse</value></prop>
<prop oor:name="Description">
<value xml:lang="en">Flips a string backwards. For example "apple" becomes "elppa".</value>
</prop>
<prop oor:name="Category"><value>Add-In</value></prop>
<!-- This won't help, because there is no reverse() in Excel. -->
<prop oor:name="CompatibilityName"><value xml:lang="en">reverse</value></prop>
<node oor:name="Parameters">
<node oor:name="s" oor:op="replace">
<prop oor:name="DisplayName"><value xml:lang="en">s</value></prop>
<prop oor:name="Description"><value xml:lang="en">The string to reverse.</value></prop>
</node>
</node>
</node>
</node>
</node>
</node>
</oor:component-data>
An Add-In also requires some other files. Here is my XCalcFunctions.idl:
#include <com/sun/star/uno/XInterface.idl>
module name { module JimK { module CalcFunctions {
interface XCalcFunctions
{
string reverse( [in] string s );
};
}; }; };
The actual implementation was simple. I used python:
def reverseString(inString):
s = unicode(inString)
# This is extended slice syntax [begin:end:step]. With a step of -1,
# it will traverse the string elements in descending order.
return s[::-1]
The result:
EDIT:
There is another piece in Components.py for my extension:
class StringReverserAddIn(unohelper.Base, XCalcFunctions):
def __init__(self, ctx):
self.ctx = ctx
#staticmethod
def factory(ctx):
return StringReverserAddIn(ctx)
def reverse(self, inString):
from lingt.app.calcfunctions import reverseString
return reverseString(inString)
g_ImplementationHelper.addImplementation(
StringReverserAddIn.factory,
"name.JimK.LinguisticTools.ReverseStringImpl",
("com.sun.star.sheet.AddIn",),)
The file is declared in manifest.xml:
<!--- The Python code -->
<manifest:file-entry
manifest:full-path="Components.py"
manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
The complete extension: https://extensions.libreoffice.org/extensions/lingtools.

Related

ATL transformation rules not matching nested BPMN2 elements

I am writing an ATL translation from BPMN2 to another model. The problem is that the code does not detect any nested element.
I have posted the atl code and my input here at: https://github.com/behnaaz/BPMN2ATL.git
You can see from the output that the only executed rule is def2mod which has created a Reo module element in the output.
If I remove the first level element in the input bpmn file then the rule mapProcess is kicked in.
Also in the logs the command BPMN20!Process.allInstances() which should give a list of all the Processes only works in the mapProcess rule.
I think there is some issue with parsing my bpmn model. Help much appreciated!
=== ATL CODE ====
-- #path BPMN20=/atttl/BPMN2/BPMN20.ecore
create OUT: reo from IN: BPMN20;
rule def2mod {
from
b: BPMN20!Definitions
to
m: reo!Module
do {
b.debug('definition to module > ' + BPMN20!Process.allInstances());
}
}
rule mapProcess {
from
proc: BPMN20!Process
to
conn: reo!Connector
do {
proc.debug('process to connector ' + proc.name + proc.flowElements);
proc.debug( BPMN20!Process.allInstances());
}
}
=== BPMN input ===
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:Definitions xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI">
<bpmn2:Process id="bpmnid-80c796ae-c11d-42d8-92ae-1d88bab84536" name="Process" isClosed="false" processType="None" xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI">
<bpmn2:serviceTask id="bpmnid-11047880-09d8-4147-8382-523145eeb8b6" name="Task 1"/>
<bpmn2:serviceTask id="bpmnid-2f925dd9-4ec8-45b7-936c-0c14597319a9" name="Task 2"/>
<bpmn2:serviceTask id="bpmnid-21a0fc44-3c02-4a00-9b6e-aa6c058992d3" name="Task 3"/>
<bpmn2:startEvent id="bpmnid-196c656e-baa2-4306-809b-56ba006057b9" name="Start Event"/>
<bpmn2:endEvent id="bpmnid-5cfcf354-ba3f-4b13-a5bf-bdf27ca70acc" name="End Event"/>
<bpmn2:sequenceFlow id="bpmnid-be0a37d4-8054-4367-82ae-b43430d5fc6f" name="Sequence Flow0" sourceRef="bpmnid-11047880-09d8-4147-8382-523145eeb8b6" targetRef="bpmnid-2f925dd9-4ec8-45b7-936c-0c14597319a9"/>
<bpmn2:sequenceFlow id="bpmnid-01d687a3-66ee-40d7-9e17-97aa5724eef7" name="Sequence Flow" sourceRef="bpmnid-196c656e-baa2-4306-809b-56ba006057b9" targetRef="bpmnid-11047880-09d8-4147-8382-523145eeb8b6"/>
<bpmn2:sequenceFlow id="bpmnid-b687d3ec-b6d7-480a-a1e1-57fbe220e579" name="Sequence Flow2" sourceRef="bpmnid-21a0fc44-3c02-4a00-9b6e-aa6c058992d3" targetRef="bpmnid-5cfcf354-ba3f-4b13-a5bf-bdf27ca70acc"/>
<bpmn2:sequenceFlow id="bpmnid-4596a8fb-f1dc-46b3-bc28-9a2e11c26f96" name="Sequence Flow1" sourceRef="bpmnid-2f925dd9-4ec8-45b7-936c-0c14597319a9" targetRef="bpmnid-21a0fc44-3c02-4a00-9b6e-aa6c058992d3"/>
</bpmn2:Process>
</bpmn2:Definitions>
The problem seems not to lie with the ATL transformation but with the input model. It seems like it's not conform to your metamodel.
E.g. Definitions has a relation "rootElements" to Process. This should in the XMI model look like this:
<bpmn2:Definitions
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI">
<rootElements xsi:type="bpmn2:Process" id="bpmnid-80c796ae-c11d-42d8-92ae-1d88bab84536" />
</bpmn2:Definitions>
To quickly get a conform model you can right-click the Definitions element in your ecore metamodel and choose "Create Dynamic Instance". You can then model a quick sample and run your transformation again. I quickly tried it and got following output
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:reo="http://www.cwi.nl/reo">
<reo:Module/>
<reo:Connector/>
</xmi:XMI>

How to extract individual/child nodes from a KML file in VisualBasic?

I need to be able to extract individual nodes from this file into variables for further manipulation. I'm writing to the console to see what information is being pulled, but I am struggling to pull the name or description.
I can successfully print the entire file. I've tried getting individual nodes using placemark.<name>.Value and placemark.Element("name").Value, the second of which throws a NullReferenceException. Any ideas on how to be able to pull out the name and description in this instance?
Imports System.Xml
Imports System.Xml.Linq 'Visual Studio 2015 tells me this isn't needed
Imports System.Core 'Visual Studio 2015 tells me this isn't needed
Dim file As XDocument = XDocument.Load(filePath)
Dim placemarks As IEnumerable(Of XElement) = From test In file.Root.Elements()
For Each placemark As XElement In placemarks
Console.WriteLine(placemark) 'This works
Console.WriteLine(placemark.<name>.Value) 'This prints an empty line
Console.WriteLine(placemark.Element("description").Value) 'This throws a NullReferenceException
Next
This is the structure
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
<Document>
<name>Untitled layer</name>
<Placemark>
<name>Name 1</name>
<description>Description 1</description>
<ExtendedData>
<Data name='Test data one'>
<value>Test data 1</value>
</Data>
</ExtendedData>
<Point>
<coordinates>34725567547</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Name 2</name>
<description>Description 2</description>
<ExtendedData>
<Data name='Test data two'>
<value>Test data 2</value>
</Data>
</ExtendedData>
<Point>
<coordinates>056795763767</coordinates>
</Point>
</Placemark>
If I have understood you correctly, you are trying to fetch the name & description present inside the PlaceMark node. But, since you are only fetching Root.Elements() your query will only fetch the complete XML starting from your root node.
You need to find the Descendants of PlaceMark node because you need to fetch the name & description inside it. Also, since the root node kml consists of namespace you need to specify that as well.
Here is the code:-
Dim ns As XNamespace = "http://www.opengis.net/kml/2.2"
Dim placeMarks = From test In file.Root.Element(ns + "Document")
.Descendants(ns + "Placemark") Select test
For Each pm In placeMarks
Console.WriteLine("Name: {0}", pm.Element(ns + "name").Value)
Console.WriteLine("Description: {0}", pm.Element(ns + "description").Value)
Console.WriteLine()
Next
I am getting following output:-

Get nested element Linq to XML

My XML
<?xml version="1.0" encoding="utf-8"?>
<metadata created="2014-05-15T12:26:07.701Z" xmlns="http://site/cu-2.0#" xmlns:ext="http://site/cu/b-2.0">
<customer-list count="47" offset="0">
<customer id="7123456" type="Cust" ext:mark="1">
<name>Tony Watt</name>
<sort-name>Watt, Tony</sort-name>
<gender>male</gender>
<country>US</country>
<knownAs-list>
<knownAs locale="ko" sort-name="Tony Watt"</knownAs>
<knownAs locale="ja" sort-name="Watt Tony"</knownAs>
</knownAs-list>
<tag-list>
<begin>Country</begin>
<tag count="1">
<name>usa</name>
</tag-list>
</customer>
<customer id="9876543" type="Cust" ext:mark="2">
....
</customer-list>
So i have some code that gets all the data. I went one step further to use Anonymous types and add the values into a class as below
Dim c = From cust As XElement In XDoc.Descendants(ns + "customer")
Select New Customer() With {.Name = cust.Element(ns + "name"),
.Surname = CStr(cust.Element(ns + "surname")),
.Id = cust.Attribute("id"),
.Tag = CStr(cust.Element("tag-list").Element("begin"))}
The above code returns data from the XML, but adding this line of code
.Tag = CStr(cust.Element("tag-list").Element("begin"))
throws an exception, "Object reference not set to an instance of an object". Now theres two possibilities here
I have my code wrong for that particular line (to retrieve 'begin' from the 'tag-list' element)
I know some tag-list elements dont have a nested begin element so that could be adding some confusion. I added Cstr to overcome this but not sure if this is enough?
After reading MSDN it seems using .Descendants (Xdoc.Descendants) would get the all the data from all elements where Elements would return data upto the path i have stated, so as far as i can tell the data 'should' be available with the above code. Could anyone assist me in getting the begin data from tag-list?
The XML namespace declaration is missing. Use
.Tag = CStr(cust.Element(ns + "tag-list").Element(ns + "begin"))

OpenERP custom report filename

I would like to customize reports filename.
For instance, when I download an invoice, I will have something like 'Invoice.pdf' as filename. What I would like is something like 'invoice_number.pdf' but I don't know how to use dynamic file name ?
I found a way for 7.0 and current trunk:
For a quick fix, take a look at the Reports class in:
openerp-7.0\web\addons\web\controllers\main.py
The report name is set in a variable named file_name:
file_name = '%s.%s' % (file_name, report_struct['format'])
Find this line and insert this part before it:
'''
YP: Added proc. to create reports with real object names (the object must have a field named "name"):
eg: "PO00006.pdf" instead of "Request For Quotation.pdf" for a single object report
"PO00006-PO00002.pdf" instead of "Request For Quotation.pdf" for a multiple objects report
'''
# Try to get current object model and their ids from context
if action.has_key('context'):
action_context = action.get('context',{})
if action_context.has_key('active_model') and action_context.has_key('active_id'):
action_active_model = action_context.get('active_model','')
action_active_ids = action_context.get('active_ids', [])
if action_active_model and action_active_ids:
# Use built-in ORM method to get data from DB
m = req.session.model(action_active_model)
r = m.read(action_active_ids, False, context)
# Parse result to create a better filename
for i, item in enumerate(r):
if item.has_key('name'):
if i == 0:
file_name = ('%s') % (item['name'])
else:
file_name = ('%s-%s') % (file_name, item['name'])
For a quick fix, take a look at the Reports class in:
openerp-6.1\web\addons\web\controllers\main.py
The report name is set in a variable named header.
For my needs, I only want the report to be named by the object name (that's suitable in 99% of cases) so I added a new variable named report_name:
report_name = action['report_name']
if action.has_key('context'):
action_context = action.get('context',{})
if action_context.has_key('name'):
report_name = action_context['name']
return req.make_response(report,
headers=[
('Content-Disposition', 'attachment; filename="%s.%s"' % (report_name, report_struct['format'])),
('Content-Type', report_mimetype),
('Content-Length', len(report))],
cookies={'fileToken': int(token)})
I found a solution to set the default filename like the attach file name, using the expression in the attachment attribute in your xml report definition.
Found and modify this file: openerp7/openerp-web/addons/web/controllers/main.py.
Search this sentence:
file_name = '%s.%s' % (file_name, report_struct['format'])
Then add this code before:
'''Code added by Raul Paz to set the default file_name like the attach_name
The attach_name mach with the attachment expresion from your report_xml
<report
id="report_webkit.YourModule_report_id"
model="YourModule.model"
name="Your_report_name"
file="YOUR_MODULE/report/YOUR_MAKO_FILE.mako"
string="Your Text in the print button"
auto="False"
report_type="webkit"
attachment="'Valid_filename_expresion"
usage="default"
/>
And
to modify existing report sale_report.xml to manage the name:
create in your module a file : sale_report.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="sale.report_sale_order" model="ir.actions.report.xml">
<field name="attachment">(object.name or 'Sale Order')</field>
<field name="attachment_use" eval="True"/>
</record>
</data>
</openerp>
'''
try:
if action.get('attachment_use',False) and action['attachment']:
model = context['active_model']
cr = openerp.pooler.get_db(req.session._db).cursor()
uid = context['uid']
ids = context['active_ids']
objects=openerp.pooler.get_pool(req.session._db).get(model).browse(cr,uid,ids,context=context)
file_name=[eval(action['attachment'],{'object':x, 'time':time}) for x in objects][0]
except:
pass
#end code added
Good luky

WCF DataContractSerializer Behavior

I'm seeing some unusual behavior when using the DataContractSerializer. I have defined a message contract like so:
namespace MyNamespace.DataContracts
{
[MessageContract(WrapperName = "order", WrapperNamespace = #"http://example.com/v1/order")]
public class MyOrder
{
[MessageBodyMember(Namespace = #"http://example.com/v1/order", Order = 1)]
public MyStore store;
[MessageBodyMember(Namespace = #"http://example.com/v1/order", Order = 2)]
public MyOrderHeader orderHeader;
[MessageBodyMember(Namespace = #"http://example.com/v1/order", Order = 3)]
public List<MyPayment> payments;
[MessageBodyMember(Namespace = #"http://example.com/v1/order", Order = 4)]
public List<MyShipment> shipments;
}
.
.
I'm sending it an XML message that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<order xmlns="http://example.com/v1/order>
<store>
...
</store>
<orderHeader>
...
</orderHeader>
<payments>
<payment>
...
</payment>
</payments>
<shipments>
<shipment>
...
</shipment>
</shipments>
</order>
My service deserializes this XML as expected. Inside my service, I'm using the DataContractSerializer to create an XML string and that's where things get weird. I'm using the serializer like this:
DataContractSerializer serializer = new DataContractSerializer(typeof(MyOrder));
using (MemoryStream ms = new MemoryStream())
{
serializer.WriteObject(ms, order);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string outputMessage = sr.ReadToEnd();
}
Once this finishes, the outputMessage contains the following XML:
<?xml version="1.0" encoding="utf-8"?>
<MyOrder xmlns="http://example.com/v1/order" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<order>
<store>
...
</store>
<orderHeader>
...
</orderHeader>
<payments>
<payment>
...
</payment>
</payments>
<shipments>
<shipment>
...
</shipment>
</shipments>
</order>
</MyOrder>
Needless to say, anything expecting to receive the original XML message will fail to parse this. So I guess I have two questions:
Why is the DataContractSerializer
adding the extra outer node to my
XML output?
Is there a way to stop it from doing
this?
Thanks.
I should probably add this is with .NET 4.
You could try using WriteObjectContent instead of WriteObject, but I'm unable to reproduce your problem using the code you supplied. All the extra class defintions that are part of your message contract are empty in my definition, but this is the XML I am getting:
<MyOrder xmlns="http://schemas.datacontract.org/2004/07/SandboxApp"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<orderHeader i:nil="true"/>
<payments i:nil="true"/>
<shipments i:nil="true"/>
<store i:nil="true"/>
</MyOrder>
Which also seems odd, since it seems to ignore the WrapperName. Same result in .NET 3.5 SP1 and .NET 4.0.