QML plugin and importing
Docs at nokia show an "Import" statement...I'm trying it in one of my scripts, and it's acting like it *wants* to work, but I can't figure out how to get the feature to work...
Is the "Import" feature a part of the MuseScore plugin architecture?
If it is, what are the rules? Are there any examples?
Thanks!
Comments
The
import
(note the lower case 'i') is used to..., well..., import modules available to the framework.The MuseScore QML plugin framework has two modules available (they have to be 'created' by the program before dealing with plugins):
*) QtQuick 1.0
*) MuseScore 1.0
You may import them at the beginning of your plugin with:
import QtQuick 1.0
import MuseScore 1.0
In fact, you must import the first or the plugin would not run and almost certainly you will import the second or your plugin will not have access to any MuseScore object. End result: all MuseScore QML plugins start with the two lines quoted above.
No other module is available for import to MuseScore QML plugins.
If you refer to some other kind of import, please add some other detail.
HTH,
M.
In reply to import by Miwarre
The examples I see online show imporing javascript files...this would be a FANTASTIC feature for making reusable components...like an informational library (I have an object to map durations to duration names, it would great to be able to use the same code in multiple projects without copy-and-paste.
How do I add "Javascript imports" to the plugin feature requests list?
In reply to What about importing javascript files? by theGleep
Ah, that "import". I saw the documentation too, but I assumed it would be rather difficult to make it work and even more to distribute, as the imported file path should either be absolute or relative to whatever the MuseScore current working directory is.
I think it is a feature not intended for scripting, but for stand-alone QML applications (as most of QML seems to be, unfortunately).
If you can get any result, please let us know!
Thanks,
M.
In reply to I see by Miwarre
I played a little bit with the new plugin framework and came to the same question.
using this javascript code (file externJavaScript.js):
Well, using some different selections, it gave reasonable tick values.
So I think the remaining point is: Is there a way to use a relative path in the import statement?
In reply to I played a little bit with by heuchi
On the spot, I would say no:
import
is directly managed by Qt; I don't think an application can alter its behaviourM.
In reply to On the spot, I would say no: by Miwarre
http://doc.qt.nokia.com/qt-maemo/qdeclarativemodules.html says:
I hope that's what we're looking for.
This works for me:
--------------- .qml file -------------
import QtQuick 1.0
import MuseScore 1.0
import "../plugins/musescorelib.js" as MScoreLib;
MuseScore {
version : "1.0";
description : "Identifies chords";
menuPath : "Plugins.Chord Identifier";
onRun : {
MScoreLib.sayHello(curScore);
Qt.quit();
}
}
--------------- musescorelib.js -------------
function sayHello(score) {
console.log(10);
}
=======================================
Apparently, the "current" folder when running is the "bin" folder. Once you know that, relative path works.
In reply to Thank you all for your help! by theGleep
I think something we'll need *RIGHT* away is a way to reset the plugin cache. I can edit my imported script and re-run my plugin...and the changes aren't recognized.
Maybe a "reset" button in the plugin creator?