QCAD

QCAD - 2D CAD System.

Click here for a documentation of the DokuWiki formatting syntax that can be used in reports

Please search for existing tasks (also closed ones) before opening a new task.

Please make sure that you are using the latest Version of QCAD before posting a bug (menu Help - Check for Updates)

Tasklist

FS#103 - Runtime reload script

Attached to Project: QCAD
Opened by Peter (hungerburg) - Wednesday, 25 May 2011, 10:08 GMT+2
Last edited by Andrew (andrew) - Wednesday, 25 May 2011, 11:51 GMT+2
Task Type Feature Request
Category ECMAScript
Status Closed
Assigned To Andrew (andrew)
Operating System All
Severity Low
Priority Normal
Reported Version 3 TP1
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

As of TP1, a script once loaded into the runtime, does reflect changes to the file it was loaded from only after a restart of the whole of QCAD. This adds a considerable time overhead to developing scripts. Therefore I want to suggest a reload mechanism, that works kind of like the one known from a web browser.

As there is no clear separation between users custom scripts and ribbonsoft supplied scripts, checking the modification time for every access to any script might prove a performance hit.

Possibly a user script can be written, to invalidate another certain script and have the runtime reload it from file? I could add that to my menu.

Or as some magic, that can be written to “MyAction.init()”?

This task depends upon

Closed by  Andrew (andrew)
Wednesday, 25 May 2011, 11:51 GMT+2
Reason for closing:  Implemented
Additional comments about closing:  Can be achieved by the script itself (see comment)
Comment by Andrew (andrew) - Wednesday, 25 May 2011, 11:51 GMT+2

You can achieve this by unloading your class at the end of the script by setting it to undefined.

Example:

include("../BaseClass.js");
 
function MyTool(guiAction) {
    BaseClass.call(this, guiAction);
}
 
MyTool.prototype = new BaseClass();
 
MyTool.prototype.beginEvent = function() {
    BaseClass.prototype.beginEvent.call(this);
 
    appWin = EAction.getMainWindow();
    appWin.handleUserWarning("My Message...");
 
    this.terminate();
 
    // unload class. the class will be loaded again on every execution:
    MyTool = undefined;
};
 
MyTool.init = function(basePath) {
    var action = new RGuiAction(qsTr("&My Tool"),
        RMainWindowQt.getMainWindow());
    action.setRequiresDocument(true);
    action.setScriptFile(basePath + "/MyTool.js");
    action.setIcon(basePath + "/MyTool.svg");
    EAction.addGuiActionTo(action, BaseClass, true, true, true);
};
Comment by Peter (hungerburg) - Friday, 27 May 2011, 15:40 GMT+2

Thank you Andrew, this works with the example provided. Yet, as soon as a dialogue is execed() from the script, invalidating the class no longer works; then it will not run again at all. Possibly some ressources have to be freed?

Loading...