IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
--- 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)