blob: 016b46283919a7a6c108dec8c4cb9be3117ca1e4 (
plain)
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
|
import threading
import time
PLUGIN_DEFAULTS = {'freq': 1, 'hide_ok': True}
class PluginThreadCommon:
def __init__(self, config, defaults=None):
self.status = dict()
self.conf = dict()
self.conf.update(PLUGIN_DEFAULTS)
if defaults:
self.conf.update(defaults)
self.conf.update(config)
self.hide = False
self.thread = threading.Thread(target=self.run)
self.thread.daemon = True
def format_status(self, status, urgent=False):
if 'title' in self.conf:
full_text = '{}: {}'.format(self.conf['title'], status)
else:
full_text = status
self.status.update({'full_text': full_text, 'urgent': urgent})
def start(self):
self.thread.start()
def main(self):
pass
def run(self):
while True:
self.main()
time.sleep(self.conf['freq'])
|