mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2025-04-03 08:32:39 +00:00
Compare commits
5 Commits
chausie-20
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
dc5e26843a | ||
|
e5d0e91e93 | ||
|
e58f0b1d04 | ||
|
ea0fff5662 | ||
|
70f4d666e3 |
@ -27,14 +27,15 @@ class MessageQueueHandler:
|
|||||||
|
|
||||||
def _dispatch_messages(self):
|
def _dispatch_messages(self):
|
||||||
for message in iter(self._queue.get, None):
|
for message in iter(self._queue.get, None):
|
||||||
message['typing'] = not self._queue.empty()
|
is_queue_empty = self._queue.empty()
|
||||||
|
message['typing'] = not is_queue_empty
|
||||||
self.connector.send_message(message)
|
self.connector.send_message(message)
|
||||||
self._sleep(self._get_sleep_time(message))
|
self._sleep(self._get_sleep_time(message, is_queue_empty))
|
||||||
|
|
||||||
def _get_sleep_time(self, message):
|
def _get_sleep_time(self, message, is_queue_empty):
|
||||||
words_per_min = message['wpm'] if 'wpm' in message else self.wpm
|
words_per_min = message['wpm'] if 'wpm' in message else self.wpm
|
||||||
chars_per_min = self.avg_word_len * words_per_min / 60
|
chars_per_min = self.avg_word_len * words_per_min / 60
|
||||||
return len(message['message']) / chars_per_min
|
return 0 if is_queue_empty else len(message['message']) / chars_per_min
|
||||||
|
|
||||||
def _sleep(self, seconds):
|
def _sleep(self, seconds):
|
||||||
poll_freq = self.drain_poll_freq
|
poll_freq = self.drain_poll_freq
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
|
DEFAULT_ORIGINATOR = 'avataobot'
|
||||||
|
|
||||||
|
|
||||||
class MessageSender:
|
class MessageSender:
|
||||||
def __init__(self, uplink):
|
def __init__(self, uplink):
|
||||||
self.uplink = uplink
|
self.uplink = uplink
|
||||||
|
|
||||||
def send(self, message, originator=None):
|
def send(self, message, originator=DEFAULT_ORIGINATOR, buttons=None):
|
||||||
message = {
|
message = {
|
||||||
'key': 'message.send',
|
'key': 'message.send',
|
||||||
'message': message
|
'message': message
|
||||||
}
|
}
|
||||||
if originator:
|
if originator:
|
||||||
message['originator'] = originator
|
message['originator'] = originator
|
||||||
|
if buttons:
|
||||||
|
message['buttons'] = buttons
|
||||||
self.uplink.send_message(message)
|
self.uplink.send_message(message)
|
||||||
|
|
||||||
def queue_messages(self, messages, originator=None):
|
def queue_messages(self, messages, originator=DEFAULT_ORIGINATOR, buttons=None):
|
||||||
message_queue = {
|
message_queue = {
|
||||||
'key': 'message.queue',
|
'key': 'message.queue',
|
||||||
'messages': []
|
'messages': []
|
||||||
@ -21,10 +26,6 @@ class MessageSender:
|
|||||||
if originator:
|
if originator:
|
||||||
next_message['originator'] = originator
|
next_message['originator'] = originator
|
||||||
message_queue['messages'].append(next_message)
|
message_queue['messages'].append(next_message)
|
||||||
|
if buttons and message_queue['messages']:
|
||||||
|
message_queue['messages'][-1]['buttons'] = buttons
|
||||||
self.uplink.send_message(message_queue)
|
self.uplink.send_message(message_queue)
|
||||||
|
|
||||||
def set_originator(self, originator):
|
|
||||||
self.uplink.send_message({
|
|
||||||
'key': 'message.config',
|
|
||||||
'originator': originator
|
|
||||||
})
|
|
||||||
|
@ -79,6 +79,7 @@ class IdeHandler:
|
|||||||
def read(self, message):
|
def read(self, message):
|
||||||
if 'patterns' in message:
|
if 'patterns' in message:
|
||||||
self.filemanager.patterns = message['patterns']
|
self.filemanager.patterns = message['patterns']
|
||||||
|
self.monitor.paths = self.filemanager.parents
|
||||||
try:
|
try:
|
||||||
message['filename'] = self.filemanager.find_file(
|
message['filename'] = self.filemanager.find_file(
|
||||||
message.get('filename') or self.initial_file
|
message.get('filename') or self.initial_file
|
||||||
|
@ -17,7 +17,7 @@ class TerminadoMiniServer:
|
|||||||
url,
|
url,
|
||||||
TerminadoMiniServer.ResetterTermSocket,
|
TerminadoMiniServer.ResetterTermSocket,
|
||||||
{'term_manager': self._term_manager}
|
{'term_manager': self._term_manager}
|
||||||
)])
|
)], websocket_ping_interval=30)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def term_manager(self):
|
def term_manager(self):
|
||||||
@ -33,10 +33,6 @@ class TerminadoMiniServer:
|
|||||||
def check_origin(self, origin):
|
def check_origin(self, origin):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_close(self):
|
|
||||||
self.term_manager.terminal = None
|
|
||||||
self.term_manager.get_terminal()
|
|
||||||
|
|
||||||
def listen(self):
|
def listen(self):
|
||||||
self.application.listen(self.port)
|
self.application.listen(self.port)
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class TFWServer:
|
|||||||
r'/ws', ZMQWebSocketRouter, {
|
r'/ws', ZMQWebSocketRouter, {
|
||||||
'listener': self._listener,
|
'listener': self._listener,
|
||||||
}
|
}
|
||||||
)])
|
)], websocket_ping_interval=30)
|
||||||
|
|
||||||
def listen(self):
|
def listen(self):
|
||||||
self.application.listen(TFWENV.WEB_PORT)
|
self.application.listen(TFWENV.WEB_PORT)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user