35 lines
782 B
Python
35 lines
782 B
Python
import queue
|
|
|
|
|
|
class Intercom:
|
|
def __init__(self, window, handler):
|
|
self.window = window
|
|
self.queue = queue.Queue()
|
|
self.handler = handler
|
|
|
|
self.window.bind("<<intercom>>", self._event)
|
|
|
|
def clear(self):
|
|
try:
|
|
while True:
|
|
self.queue.get(block=False)
|
|
except queue.Empty:
|
|
pass
|
|
|
|
def put(self, purpose, content):
|
|
self.queue.put(
|
|
(
|
|
purpose,
|
|
content,
|
|
)
|
|
)
|
|
self.window.event_generate("<<intercom>>", when="tail", state=1)
|
|
|
|
def _event(self, event):
|
|
try:
|
|
purpose, content = self.queue.get(block=False)
|
|
except queue.Empty:
|
|
return
|
|
|
|
self.handler(purpose, content)
|