Singleton modeless dialog to execute script SelectContour.js

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
plane
Newbie Member
Posts: 8
Joined: Wed Apr 23, 2014 9:33 am

Singleton modeless dialog to execute script SelectContour.js

Post by plane » Thu May 15, 2014 6:02 pm

I would like to create a script to execute the script Select Contour on the document being edited.
Select Contour.png
Select Contour.png (8.71 KiB) Viewed 29911 times
The script Select Contour should be launched by a push button on my dialog (QDialog).
dialog.png
dialog.png (8.85 KiB) Viewed 29911 times
I have this code in the script but there is not reaction when i push the button
TEST.prototype.beginEvent = function() {
...
button = dialog.findChild("SelectContourButton");
button.setDefaultAction(RGuiAction.getByScriptFile("scripts/Select/SelectContour.js"));
...
Q1) How can i execute the Select Contour by pushing a button on my dialog, please?

If my dialog is Modal then it blocks input to other visible windows in the same application, therefore i think I should execute my dialog as a Modeless dialog to then select the countour.
If the dialog is modeless then it is possible to open many instances of the same dialog, that's something I do not want.
Q2) Is it possible to create a singleton instance of a modeless dialog, please?

Thank you in advance for any advice you may have.

Regards,
Plane

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Re: Singleton modeless dialog to execute script SelectContou

Post by andrew » Tue May 20, 2014 2:52 pm

You can try this instead:
button.triggered.connect(
    function() {
        var action = RGuiAction.getByScriptFile("scripts/Select/SelectContour/SelectContour.js");
        action.trigger();
    }
);
[Edit: correct path to avoid confusion]

plane
Newbie Member
Posts: 8
Joined: Wed Apr 23, 2014 9:33 am

Re: Singleton modeless dialog to execute script SelectContou

Post by plane » Tue May 20, 2014 5:47 pm

Andrew, thank you for the answer.

I have tried the suggestion but I does not work yet, as i get error:
Uncaught exception at scripts/MyScripts/Test/Test.js:77: TypeError: Result of expression 'button.triggered' [undefined] is not an object.

Below is my entire function so far.
Test.prototype.beginEvent = function() {

     MyScripts.prototype.beginEvent.call(this);

     var dialog = WidgetFactory.createDialog( Test.includeBasePath, "Test.ui");

     dialog.show();

     var button = dialog.findChild("SelectContourButton");

     button.triggered.connect( function() {        
	 var action = RGuiAction.getByScriptFile("scripts/Select/SelectContour.js");        
	 action.trigger();
	}
	);
);
Am I missing anything else, please?

Thank you for your great help.

Plane

riverbuoy
Senior Member
Posts: 121
Joined: Thu Oct 03, 2013 5:37 pm

Re: Singleton modeless dialog to execute script SelectContou

Post by riverbuoy » Tue May 20, 2014 6:51 pm

Hi Plane

you need to change the path from:-
"scripts/Select/SelectContour.js"
to
"scripts/Select/SelectContour/SelectContour.js"

Hope this helps

riverbuoy

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Re: Singleton modeless dialog to execute script SelectContou

Post by andrew » Tue May 20, 2014 6:57 pm

Thanks riverbuoy, I copied the wrong part without noticing.

I've corrected my post above to avoid confusion for other users reading this thread.

plane
Newbie Member
Posts: 8
Joined: Wed Apr 23, 2014 9:33 am

Re: Singleton modeless dialog to execute script SelectContou

Post by plane » Wed May 21, 2014 5:44 pm

Andrew. Riverbuoy thank you both for your help.
I modifed the fucntion as you correctly pointed out.

I have also fixed the error "TypeError: Result of expression 'button.triggered' [undefined] is not an object.", by changing the button Class from QPushButton to QToolButton.

Unfortunately when pushing the button ther is no reaction yet.
in the Command Line I am expecting that command selectcontour is executed, but no command is displayed.

Is there any other suggestion I shall follow, please?

Thanks in advance for any advice.

Plane

riverbuoy
Senior Member
Posts: 121
Joined: Thu Oct 03, 2013 5:37 pm

Re: Singleton modeless dialog to execute script SelectContou

Post by riverbuoy » Fri May 23, 2014 12:18 am

Hi Plane

Try this with a QPushButton:-

Code: Select all

button.clicked.connect(function() {
    var action = RGuiAction.getByScriptFile("scripts/Select/SelectContour/SelectContour.js");
    if (!isNull(action)) {
        action.slotTrigger();
    }
});
I have tried this, and it works for me.

riverbuoy

plane
Newbie Member
Posts: 8
Joined: Wed Apr 23, 2014 9:33 am

Re: Singleton modeless dialog to execute script SelectContou

Post by plane » Fri May 23, 2014 1:17 pm

Thank you for the suggestion Riverbuoy.

I can now see the command selectcontour in the Command Line but it appear that it is not executed as the SelectContour.ui widget is not displayed.
SelectContour.png
SelectContour.png (4.13 KiB) Viewed 29809 times
Can you get the above widget displayed, please?

Thank you for your help.
Plane

riverbuoy
Senior Member
Posts: 121
Joined: Thu Oct 03, 2013 5:37 pm

Re: Singleton modeless dialog to execute script SelectContou

Post by riverbuoy » Sat May 24, 2014 3:08 pm

Hi Plane

I think the problem here is the dialog box. SelectContour uses the current document. I think the dialog box is the current document and not MainWindow, which SelectContour expects it to be. I don't know how to handle that.
Without knowing exactly what you are trying to achieve, it is hard to know what to suggest.
Is there a reason why you cannot put your command button in the options toolbar? This would also remove the problem of making the dialog modal or modeless.
Do you want a script to pause while the SelectContour command is active? If so, a standard script can't stop or pause. You would need to write your command as an RGuiAction, (which, going by the 'beginEvent' function name, you may be doing so already). All the built in commands are gui actions and put their options in the options toolbar. So again, the best place for your button would be in the options toolbar.
To get a good idea of how to do this, have a look through all the existing scripts (written by Andrew), and see how things are done. Also look to see if an existing script does something close to what you are trying to do, and if it does, then try modifying that script. (That is mostly what I have done.). Also check out QCad's documentation for the classes to see what methods are available .
Sorry for not being more helpful.

riverbuoy

plane
Newbie Member
Posts: 8
Joined: Wed Apr 23, 2014 9:33 am

Re: Singleton modeless dialog to execute script SelectContou

Post by plane » Mon May 26, 2014 10:31 am

Hello riverbuoy,

Thank you for your help.

I answer to your question
Q1) Is there a reason why you cannot put your command button in the options toolbar?
A) in my widget there are some other ui objects as the example below:
many_ui_objects.png
many_ui_objects.png (6.14 KiB) Viewed 29754 times
In the toolbar all the objects will be horizontally squeezed.
squeezed.png
squeezed.png (5.13 KiB) Viewed 29754 times
Q2) Do you want a script to pause while the SelectContour command is active?
A2) No, i do not want the script to pause.

i agree, the toolbar would be the most convinient area where to place my widget.
Therefore the problem is how to create toolbar widgets that are not squeezed?


Plane

riverbuoy
Senior Member
Posts: 121
Joined: Thu Oct 03, 2013 5:37 pm

Re: Singleton modeless dialog to execute script SelectContou

Post by riverbuoy » Tue May 27, 2014 3:57 pm

Hi Plane

Yes, space on the options toolbar is a problem.
However I notice you are using radiobuttons. As these are usually in a group and only one is active at a time, it might be possible to put the options in a dropdown box. Take a look at 'Snap->Distance Manual' where I used a dropdown box to provide the options for distance, percentage or fraction. My first thought was to use radio buttons, but for some commands there wouldn't be enough space to show the radiobuttons. So instead I used a non-editable dropdown box, and I check the current index to choose how to interpret the value.
Might this be possible?

riverbuoy

plane
Newbie Member
Posts: 8
Joined: Wed Apr 23, 2014 9:33 am

Re: Singleton modeless dialog to execute script SelectContou

Post by plane » Fri May 30, 2014 2:26 pm

Hello Riverbuoy,

Thank you for your help.

Yes, I have radio buttons that i could arrange in a dropdown list.

The main problem is a Table where I need to show all the elements of the selected contour, including their corresponding start and end points.
At last i am afraid I would have to arrange this in a dropdown list, but then too many dropdown lists...

if i could increase the size of the toolbar then i could better arrange my user interface.

Anyway thank you again for your suggestions.

Plane

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”