IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming. wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 29 Mar 2022 08:30:03 +0200
branchwxPython4
changeset 3445 83545348403e
parent 3444 91b2c014494e
child 3446 de8cc85b688a
IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
BeremizIDE.py
--- a/BeremizIDE.py	Tue Mar 29 08:19:46 2022 +0200
+++ b/BeremizIDE.py	Tue Mar 29 08:30:03 2022 +0200
@@ -360,6 +360,8 @@
         self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=inspectorID)
         accels = [wx.AcceleratorEntry(wx.ACCEL_CTRL | wx.ACCEL_ALT, ord('I'), inspectorID)]
 
+        self.methodLock = Lock()
+
         for method, shortcut in [("Stop",     wx.WXK_F4),
                                  ("Run",      wx.WXK_F5),
                                  ("Transfer", wx.WXK_F6),
@@ -369,8 +371,15 @@
             def OnMethodGen(obj, meth):
                 def OnMethod(evt):
                     if obj.CTR is not None:
-                        obj.CTR.CallMethod('_'+meth)
-                    wx.CallAfter(self.RefreshStatusToolBar)
+                        if obj.methodLock.acquire(False):
+                            obj.CTR.CallMethod('_'+meth)
+                            obj.methodLock.release()
+                            wx.CallAfter(obj.RefreshStatusToolBar)
+                        else:
+                            # Postpone call if one of method already running
+                            # can happen because of long method using log, 
+                            # itself calling wx.Yield
+                            wx.CallLater(50, OnMethod, evt)
                 return OnMethod
             newid = wx.NewId()
             self.Bind(wx.EVT_MENU, OnMethodGen(self, method), id=newid)