Merge pull request #552 from MikeTheWatchGuy/Dev-latest

Improved RealtimeButton code! Does not require non-blocking reads
This commit is contained in:
MikeTheWatchGuy 2018-10-23 21:46:41 -04:00 committed by GitHub
commit 9714229ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -1225,6 +1225,7 @@ class Button(Element):
self.ParentForm.LastButtonClicked = self.Key
else:
self.ParentForm.LastButtonClicked = self.ButtonText
self.ParentForm.TKroot.quit() # kick out of loop if read was called
# ------- Button Callback ------- #
def ButtonCallBack(self):
@ -2775,6 +2776,18 @@ class Window:
self.Show()
else:
InitializeResults(self)
# if the last button clicked was realtime, emulate a read non-blocking
# the idea is to quickly return realtime buttons without any blocks until released
if self.LastButtonClickedWasRealtime:
try:
rc = self.TKroot.update()
except:
self.TKrootDestroyed = True
_my_windows.Decrement()
results = BuildResults(self, False, self)
if results[0] != None and results[0] != timeout_key:
return results
# normal read blocking code....
if timeout != None:
self.TimerCancelled = False
self.TKAfterID = self.TKroot.after(timeout, self._TimeoutAlarmCallback)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/python
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals