Hi Jeremy,
I wrote a tool plugin as you suggested, and it worked. But in my opinion
my code is not very efficient, because the tool plugin calls the import
plugin and then reopens the data file in order read the constants... but
it works!
I tried also to return a constant from the import plugin (using the
development version in the repository) but probably something was wrong
in my code, because I got an error.
My code for the import plugin is:
def doImport(self, params):
#bla bla bla
return [ImportConstant("constName","10")]
And the traceback is:
Traceback (most recent call last):
File "D:\Valerio
Mussi\Documents\Python\veusz\dialogs\importdialog.py", line 950, in
slotImport
prefix, suffix)
File "D:\Valerio
Mussi\Documents\Python\veusz\dialogs\importdialog.py", line 745, in
doImport
results = doc.applyOperation(op)
File "D:\Valerio Mussi\Documents\Python\veusz\document\doc.py",
line 162, in applyOperation
retn = operation.do(self)
File "D:\Valerio
Mussi\Documents\Python\veusz\document\operations.py", line 1287, in do
ds.linked = linked
UnboundLocalError: local variable 'ds' referenced before assignment
Doing my trials I noticed two things:
1.
In the on-line manual the documentation for AddCustom says:
AddCustom(name, type, value) but I think It should be AddCustom(type,
name, value)
2.
I was a bit silly, but writing my importplugin I used a string with a
whitespace ("Split Datasets") as the "name" of an ImportFieldCheck. The
plugin worked well, but when I saved the document containing the
imported data, and tried to reopen it I got an error, because of this
line of document:
ImportFilePlugin(u'MUSP furnace import plugin',
u'2011-05-10_Spezzone 04.txt', linked=True, encoding='latin_1',
name=u'name', split Datasets=False)
The problem is that my "Split Dataset" is not a valid variable name, it
is not a bug. In my opinion it could be useful to add a note in the
documentation of the importfields explaining that the string "name" has
to be a valid variable name.
Thanks,
Valerio Mussi.
On 06/09/2011 10:22, Jeremy Sanders wrote:
mimisa...@gmail.com wrote:
Hi Jeremy,
I used the workaround you suggested and it works fine.
Another little question: in the header of my data file I have some rows,
useful for plotting and manipulating data, stored in the form:
SampleFrequency = xxxyyyHy
I'd like to use them in order to crate Vuesz constants. Is there a way
to create constants programmatically in an importPlugin?
I've added some code which mostly works for returning constants from an
import plugin as extra dataset-like objects. It's in the development
version:
https://github.com/jeremysanders/veusz/commit/4b9905c4c696f507556a0541a2bba77f4fa34fa6
At the moment you could write a tools plugin which does the import and then
calls AddCustom to add your variables.
There is an issue with that API I notice, however. Adding multiple
definitions with the same name leaves the originals intact, though the later
ones override the earlier ones. I ought to fix that...
Jeremy
_______________________________________________
Veusz-discuss mailing list
Veusz-discuss@gna.org
https://mail.gna.org/listinfo/veusz-discuss
_______________________________________________
Veusz-discuss mailing list
Veusz-discuss@gna.org
https://mail.gna.org/listinfo/veusz-discuss