Wizards update

Discuss the creation and usage of Wizards

Re: Wizards update

Postby Dan911 » Fri Jun 01, 2018 4:35 pm

dezsoe wrote:I think the difference is in the sample code:

Code: Select all
        // The bool onscreen parameter is true if the button was pressed on the GUI and is false if the Callbutton function was called.
        public void Buttonpress_event(int buttonnumber, bool onscreen)
        {
            if (onscreen)
            {
                if (buttonnumber == 128)
                {
                   
                }
            }
        }

If you check the onscreen value then Callbutton won't work. :) I did the same some time ago, reported to Balázs as an error. He told me to read the comment before the function declaration... :)

Edit: Hotkeys also make GUI calls.



Also If a macro number between 20000-21999 is used with a callbutton(???) that bool check is ignored.

Dan
Dan911
 
Posts: 425
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Wizards update

Postby dezsoe » Fri Jun 01, 2018 6:49 pm

I didn't try that range, because that's for the macros. I use the Button_event to prevent writing macros to start (or do anything) in a plugin. For me the Button_event is the best way to start a plugin when reset is active. In my plugins I have no Button_event check exept the SwLED plugin, which calls other stuff, because this way if I want to change the buttonnumber I don't have to recompile the plugin(s).
dezsoe
 
Posts: 545
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Wizards update

Postby Dan911 » Sat Jun 02, 2018 12:23 pm

Hi Dezsoe,

Using ##20000-21999 is just something I observed testing/experimenting with the do's and don'ts for the Macro Menu plugin I'm working on.
I agree, I been using the button event from the start of creating any plugin that required a form to be called.

Dan
Dan911
 
Posts: 425
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Wizards update

Postby Dan911 » Sun Jun 10, 2018 9:05 pm

dezsoe wrote:To prevent key code collision you could have a key in the profile to define the button code. E.g.:

Code: Select all
[MyPlugins]
Wiz1button=44444

On startup the plugin could read this key (in Init_event) and check the read code in Buttonpress_event.


Hi Dezsoe,

I tried your suggested solution and many others with no success, I'm not convinced it is a Directory issue. QuickCam works fine with a created button or hotkey(GUI) but when opened with the CallButton()
inside UCCNC macro class it will only allow the first 2 Forms created to open regardless of order and will get the STAthread exemption on the other 3 when tried to open.

I did find a solution to open it with a M code, I added a informsplugin event to plugin and call button event there. I used exec.informsplugin to call from macro and all works like it should.

Ultimately I would prefer to use informplugin(Quickcam, button#) and not write to all plugins but can't get around that function needing a return. Any idea's?

Thanks, your help is always very much appreciated.

Dan
Dan911
 
Posts: 425
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Wizards update

Postby cncdrive » Sun Jun 10, 2018 9:19 pm

Hi Dan,

It's up to you what you return from the informplugin function and how you handle the returned value in the caller macro or plugin.
If you don't want to raturn anything then you can return null and you do not even have to handle it in the caller function.

The idea behind the return object is that you could send any type of data to a plugin and it can use that data and can return another data.
For example you can send a string like:

string mydata = "hey!";
exec.Informplugin("myplugin.dll", (object)mydata);

And in the receiver plugin you can do a return null.
Or you can return another object if needed like: return (object)newdata;
And then you can test the return type in the caller function with:

object newdata = exec.Informplugin("myplugin.dll", (object)mydata);
if (newdata is string)
{
string returnedstring = newdata as string;
//Do something with the string...
}

This was ofcourse just an example when the data object is string type, but it could be other types too. This is why we used the generic object type as parameter and as return types, because this way you are not limited in what object type you sending and returning.
cncdrive
Site Admin
 
Posts: 2263
Joined: Tue Aug 12, 2014 11:17 pm

Re: Wizards update

Postby dezsoe » Mon Jun 11, 2018 10:25 am

Hi Dan, Could you compile me a version without the onscreen check, so I could test the Callbutton problem?
dezsoe
 
Posts: 545
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Wizards update

Postby Dan911 » Mon Jun 11, 2018 2:10 pm

dezsoe wrote:Hi Dan, Could you compile me a version without the onscreen check, so I could test the Callbutton problem?


Sure, take note when opened with callbutton that Cut or pocket a circle wizard works(form2) and all others you will get the STAthread exemption. I can use any wizard with form2.

This also has the informplugins event in it. If you replace CallButton(6333) in macro with....

Code: Select all
string button = "6333";
exec.Informplugins((object)button);


You will see it eliminates the problem, thanks for taking a look.

Dan

***Edit***

LOL... forgot to upload

Dezsoe.zip
(118.01 KiB) Downloaded 28 times
Dan911
 
Posts: 425
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Wizards update

Postby cncdrive » Mon Jun 11, 2018 2:36 pm

Hi Dan,

The exeption is probably because you are in another thread and trying to invoke a form element.
E.g. in Windows programming if you will try to set the value of a label on the screen from anything other than the UI thread then you can randomly get an exception like that.
To avoid this problem do not update Form items from other than the UI thread.
You can Invoke your Form with a function, like:

Code: Select all
myform.Invoke(new MethodInvoker(() => Myfunction()));


The invoke will make your caller thread to wait until the called function returns and you will not get an illegal cross thread exception.
Or you could use BeginInvoke instead of Invoke in case you don't want the caller thread to wait for your function to return.

And you can always check the SynchronizationContext.Current variable value to see if you are in the UI thread with your code or not.
The value is null if you are not in the UI thread but in a different thread.
cncdrive
Site Admin
 
Posts: 2263
Joined: Tue Aug 12, 2014 11:17 pm

Re: Wizards update

Postby dezsoe » Mon Jun 11, 2018 2:37 pm

Thanks! I've just wanted to ask for the file... :)
dezsoe
 
Posts: 545
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Wizards update

Postby Dan911 » Mon Jun 11, 2018 3:13 pm

cncdrive wrote:Hi Dan,

The exeption is probably because you are in another thread and trying to invoke a form element.
E.g. in Windows programming if you will try to set the value of a label on the screen from anything other than the UI thread then you can randomly get an exception like that.
To avoid this problem do not update Form items from other than the UI thread.
You can Invoke your Form with a function, like:

Code: Select all
myform.Invoke(new MethodInvoker(() => Myfunction()));


The invoke will make your caller thread to wait until the called function returns and you will not get an illegal cross thread exception.
Or you could use BeginInvoke instead of Invoke in case you don't want the caller thread to wait for your function to return.

And you can always check the SynchronizationContext.Current variable value to see if you are in the UI thread with your code or not.
The value is null if you are not in the UI thread but in a different thread.


Thanks Balázs for the point in direction, I would certainly prefer to find my error than using a work around. I am definitely in another thread when invoking the new form.
I guess calling from GUI is less sensitive to my error than the Macro Class. I will definitely report back if a find a solution and exactly what caused it.

Thanks again,
Dan
Dan911
 
Posts: 425
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

PreviousNext

Return to Conversational Wizards

Who is online

Users browsing this forum: No registered users and 0 guests