Hello Guest it is April 25, 2024, 10:28:32 PM

Author Topic: Dialog in m6 Macro not Modal  (Read 644 times)

0 Members and 1 Guest are viewing this topic.

Dialog in m6 Macro not Modal
« on: April 16, 2020, 10:45:14 AM »
Hi, am trying to show a dialog during the Toolchange, to gin ethe user some option amd a status feedback. I Already tested the Macro in Debugger, and everthing works fine ...
The Problem nu is if GCode Contains an T1 M6 (for example) the Macro is called, but the dialog ist not shown Modal. If i Run the eyaple in Debugger it Shows first MessageBox, opens the dialog and after closing the dialog it shows up MessageBox 2.


During a Toolchange caused by a GCODE T1 M6 it shows First Messagebox, Dialog and Second Messagebox as soon i cloed the first one ....

I also tryed to open the dialog moda by using  dialog:ShowModal(true) which works also fine in debugger but causes an error in GCODE ...

function m6()
   dialog = wx.wxDialog(wx.NULL, wx.wxID_ANY, "Mach4 Auto Caculate Motor Counts Per Units", wx.wxDefaultPosition, wx.wxDefaultSize)
   panel = wx.wxPanel(dialog, wx.wxID_ANY)
   dialog:Connect(wx.wxEVT_CLOSE_WINDOW,
      function (event)
         dialog:Destroy()
         event:Skip()
      end)
   
   
   inst = mc.mcGetInstance()
   wx.wxMessageBox("before Toolchange Dialog")
   dialog:Centre()
   -- Show the dialog
   dialog:Show(true)
   wx.wxGetApp():MainLoop()
   
   wx.wxMessageBox("after ToolChange Dialog")
end

if (mc.mcInEditor() == 1) then
    m6()
end

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Dialog in m6 Macro not Modal
« Reply #1 on: April 16, 2020, 01:28:40 PM »
You cannot run GUI elements in a M code macro script.  The exception being wxMessageBox() which is a special GUI function under Windows.  The reason is the thread context.  The M code script is being run by the G code interpreter thread, which is NOT the main ppplication thread running the GUI.   And yes, it will crash. 

The way you would have to do this is via the PLC script, which IS run by the main application thread.  The macro would need to set a flag (register) and the PLC script would have to watch that flag.  When the flag is set, launch the dialog from the PLC script.  Meanwhile, the macro is waiting on that flag to become unset.  When the dialog is ended, unset the flag in the PLC script. 

Steve