-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnanobot_state.py
53 lines (37 loc) · 1.39 KB
/
nanobot_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time
import sublime
from .sublime_helpers import SublimeHelpers
class NanoBotState:
_instance = None
state = {'status': 'waiting', 'thread': None}
_status_updater = None
@classmethod
def instance(cls):
if cls._instance is None:
cls._instance = cls()
return cls._instance
def stop(self):
if self.state['thread'] is not None:
self.state['thread'].set()
self.state['thread'] = None
self.state['status'] = 'stopped'
def update(self, cartridge, new_state=None):
if new_state is not None:
self.state = new_state
if self.state['status'] != 'pending':
if self._status_updater is not None:
sublime.set_timeout_async(
lambda: sublime.cancel_timeout(self._status_updater), 0)
SublimeHelpers.view().set_status('nano-bots', '')
return
text = ''
if cartridge['meta']['symbol'] is None:
text += '🤖'
else:
text += cartridge['meta']['symbol']
text += ' ' + cartridge['meta']['name'] + '... '
seconds = time.time() - self.state['started_at']
text += '(' + str(int(seconds)) + 's)'
SublimeHelpers.view().set_status('nano-bots', text)
self._status_updater = sublime.set_timeout(
lambda: self.update(cartridge), 1000)