Page 1 of 1

Plugin show on user defined button press & wierd behavior

PostPosted: Thu Dec 17, 2020 2:04 am
by eabrust
This is a question for Dezsoe, Balazs, or any other plugin writer, I seek help on something that shouldn't be hard :)

I've been messing around with how to setup a plugin to fire off of a button code that isn't hard coded, but is user configurable. The attached is a demo plugin that allows the user to setup the user assigned button code using the 'config plugin' button in the plugins menu. I've included the whole 'project' file as well as the compiled .dll so it is apparent what I'm doing, using 'my.settings' to hold the user assigned button code.

Assignable button code open test.zip
(64.55 KiB) Downloaded 576 times

buttoncodeDemo.JPG


The basic functionality of using a user saved number and firing off the plugin works fine, but I'm having a weird issue I can't figure out.

When ever I 'show' a plugin using the button code (either from a screenset button, or from assigned hotkey), the plugin show up event obviously triggers, but as soon as the form appears, it disappears like UCCNC hid the window. If I'm in the plugin menu and use the 'show' button (showup_event), I can open/close the plugin repeatedly without issue. But as soon as I go back to using a buttoncode to open the plugin, it disappears and I can't get it back until I restart UCCNC.

While troubleshooting this on one of my real plugins, I put msgboxes all over the initial 'form_load' proceedure. When I open the plugin using the button code, it fully loads, and returns back to the main plugin 'Buttonpress_event' (based on all message boxes I set for trouble shooting firing off), and then after that the form window disappears as soon as the 'buttonpress_event' routine completes. I know the plugin is running, because I can call up the 'config' form, and also because it has multiple forms, and sometimes one of the other forms will remain open, but the main form has disappeared with no way to get it back... I've tried adding myform.visible=true, myform.bringtofront... nothing works

I have identical simple 'form.show' code in both 'showup_event' and in 'buttonpress_event'... so what is UCCNC doing different between those two methods that's making the main/initial form disappear after a 'buttonpress_event' complets? I've played with this on V 1.2009 and 1.2112 and 1.2113...and two computers, and am losing my mind. (not that I had much to start with... :lol: )

I've not used the 'button press' method of opening plugins previously, and I have a goal to cleanup some of the rough edges on some of my plugins so that 'load on startup' doesn't need to be checked, but I've not liked the thought of hard coded 'button codes' that could conflict with other user settings

Would greatly appreciate any thoughts or ideas on what is going on...

regards
Eric

Re: Plugin show on user defined button press & wierd behavio

PostPosted: Thu Dec 17, 2020 10:09 am
by dezsoe
Hi Eric,

You should use

Code: Select all
if (ButtonNumber == 10000)
  UC.Pluginshowup("AssignButtonCode.dll");

to show the main plugin form. Also, you can open the form with OpenDialog, but it's a good practice to do it in a new thread to let the Buttonpress_Event finish:

Code: Select all
if (ButtonNumber == 10001)
  {
    Thread thrShowForm = new Thread(new ThreadStart(ShowForm));
    thrShowForm.CurrentCulture = Thread.CurrentThread.CurrentCulture;
    thrShowForm.Start();
  }


and
Code: Select all
        private void ShowForm()
        {
            if (myform.IsDisposed)
            {
                myform = new PluginForm(this);
            }
            myform.ShowDialog();
        }

Re: Plugin show on user defined button press & wierd behavio

PostPosted: Thu Dec 17, 2020 1:57 pm
by eabrust
Dezsoe,

As always, thank you for the quick and informative response :D

I tried both methods, and the 'pluginshowup' works fine, however doing a form.show even in a new thread results in the same disappearing act as not using a new thread.

Before asking the initial question, I should have clarified I was referencing this thread from 2018: http://www.forum.cncdrive.com/viewtopic.php?f=14&t=1609

Back then (at least in that forum thread which is missing a few posts...) it wasn't implied that one had to use pluginshowup or a thread. Not that it matters if something has changed since then or not, I'm just trying to make sure I learn and understand what I'm doing, and why it works or doesn't.


Thanks again!!
Eric

Re: Plugin show on user defined button press & wierd behavio

PostPosted: Thu Dec 17, 2020 2:33 pm
by dezsoe
Yes, because that is ShowDialog(), which waits for the form to close! I've tried before posting. :)

Re: Plugin show on user defined button press & wierd behavio

PostPosted: Thu Dec 17, 2020 2:49 pm
by eabrust
Insert embarrassed face here... :oops: Also need to add a 'slapping the forehead' emoji....

Thanks Dezsoe

Re: Plugin show on user defined button press & wierd behavio

PostPosted: Thu Dec 17, 2020 2:53 pm
by dezsoe
:D I copied the snippets from the test project, that's why I was sure...