2016-11-19 17:44:40 +02:00
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
2019-03-28 12:21:15 +02:00
|
|
|
PLUGIN_DEFAULTS = {'freq': 1, 'hide_ok': True}
|
2017-12-16 01:55:28 +02:00
|
|
|
|
|
|
|
|
2016-11-19 17:44:40 +02:00
|
|
|
class PluginThreadCommon:
|
2019-03-28 12:21:15 +02:00
|
|
|
def __init__(self, config, defaults=None):
|
2016-11-19 17:44:40 +02:00
|
|
|
self.status = dict()
|
2019-03-28 12:21:15 +02:00
|
|
|
self.conf = dict()
|
|
|
|
self.conf.update(PLUGIN_DEFAULTS)
|
|
|
|
if defaults:
|
|
|
|
self.conf.update(defaults)
|
|
|
|
self.conf.update(config)
|
2016-11-19 17:44:40 +02:00
|
|
|
self.hide = False
|
|
|
|
self.thread = threading.Thread(target=self.run)
|
|
|
|
self.thread.daemon = True
|
|
|
|
|
2019-07-05 18:24:46 +03:00
|
|
|
def format_status(self, status, urgent=False):
|
2019-10-28 10:57:51 +02:00
|
|
|
if 'title' in self.conf and self.conf['title']:
|
2019-07-08 14:19:05 +03:00
|
|
|
full_text = '{}: {}'.format(self.conf['title'], status)
|
2019-07-05 18:24:46 +03:00
|
|
|
else:
|
|
|
|
full_text = status
|
|
|
|
self.status.update({'full_text': full_text, 'urgent': urgent})
|
|
|
|
|
2016-11-19 17:44:40 +02:00
|
|
|
def start(self):
|
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
def main(self):
|
2019-07-05 18:24:46 +03:00
|
|
|
pass
|
2016-11-19 17:44:40 +02:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
self.main()
|
2017-12-16 01:55:28 +02:00
|
|
|
time.sleep(self.conf['freq'])
|