I'm expanding my LineBreakSymbol script to include three options in the options toolbar, a checkbox, a spinbox and a pair of radiobuttons. I'm communicating with the ui using the .prototype.slot<....>Changed = function(value) method. I've taken the method from BreakOutManual.js, and based the ui on BreakOutManual.ui but I am unable to get the script to communicate with the ui to update the variables. I also followed the guidance here -> https://qcad.org/en/tutorial-interactive-script-actions and particularly the Adding Widgets to the Options Toolbar section.
I just can't see what I'm doing wrong. script and ui attached. Please help, brain is aching !!
[solved]Problem with script communicating with ui
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
- petevick
- Premier Member
- Posts: 392
- Joined: Tue May 19, 2020 9:34 am
- Location: North Norfolk coast UK
[solved]Problem with script communicating with ui
- Attachments
-
- LineBreakSymbol.zip
- (2.95 KiB) Downloaded 325 times
Last edited by petevick on Mon Mar 08, 2021 8:27 pm, edited 1 time in total.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
Re: Problem with script communicating with ui
It's the order of things:
The last line here overwrites and essentially removes those methods defined above it.
Make sure that
is directly after the constructor function, before attaching any functions to it:
Code: Select all
LineBreakSymbol.prototype.slotRemoveSegmentChanged = function(value) {
this.removeSegment = value;
};
LineBreakSymbol.prototype.slotBreakHeightChanged = function(value) {
this.breakHeight = value;
this.updatePreview(true);
};
LineBreakSymbol.prototype.slotIncSegChanged = function(value) {
this.incSeg = value;
};
LineBreakSymbol.prototype = new EAction();
Make sure that
Code: Select all
LineBreakSymbol.prototype = new EAction();
Code: Select all
// constructor:
function LineBreakSymbol(guiAction) {...}
// inheritance (defining the prototype):
LineBreakSymbol.prototype = new EAction();
// methods (attaching functions to prototype):
LineBreakSymbol.prototype.myFunction1 = function(...) {...}
LineBreakSymbol.prototype.myFunction2 = function(...) {...}
- petevick
- Premier Member
- Posts: 392
- Joined: Tue May 19, 2020 9:34 am
- Location: North Norfolk coast UK
Re: Problem with script communicating with ui
Thanks for the reply Andrew. I've tried moving the LineBreakSymbol.prototype = new EAction(); to after the function LineBreakSymbol(guiAction) {}, followed by the three .prototype.slot<....>Changed = function(value), but then the script hangs in Qcad.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
Re: Problem with script communicating with ui
If you look at the output in the terminal from which you are starting QCAD, you can see the exception caused by the script:
You might want to check if this.startpt is defined at the start of getOperation and return undefined if not.
Code: Select all
script engine exception: "TypeError: Result of expression 'this.startpt' [undefined] is not an object."
Code: Select all
Warning: "<anonymous>(preview = true) at scripts/Misc/MiscDraw/LineBreakSymbol/LineBreakSymbol.js:143\n<anonymous>(clear = true) at /Users/andrew/data/RibbonSoft/projects/QCAD3/qcad/scripts/EAction.js:1714\n<anonymous>(value = 1) at scripts/Misc/MiscDraw/LineBreakSymbol/LineBreakSymbol.js:53\n<anonymous>(widget = QToolBar, group = 'LineBreakSymbol', signalReceiver = RActionAdapter(0x7fa359c8b600)) at /Users/andrew/data/RibbonSoft/projects/QCAD3/qcad/scripts/WidgetFactory.js:830\n<anonymous>(resume = false) at /Users/andrew/data/RibbonSoft/projects/QCAD3/qcad/scripts/EAction.js:409\n<anonymous>() at /Users/andrew/data/RibbonSoft/projects/QCAD3/qcad/scripts/EAction.js:99\n<anonymous>() at scripts/Misc/MiscDraw/LineBreakSymbol/LineBreakSymbol.js:66\n<native>(RActionAdapter(0x7fa359c8b600)) at -1\n<global>() at 1"
Code: Select all
if (!isVector(this.startpt)) {
return undefined;
}
- petevick
- Premier Member
- Posts: 392
- Joined: Tue May 19, 2020 9:34 am
- Location: North Norfolk coast UK
Re: Problem with script communicating with ui
Thanks Andrew, I'll take a look.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
- petevick
- Premier Member
- Posts: 392
- Joined: Tue May 19, 2020 9:34 am
- Location: North Norfolk coast UK
Re: Problem with script communicating with ui
Thanks Andrew, again, all working now
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6