toxygen_plugins/MarqueeStatus/mrq.py

69 lines
1.9 KiB
Python
Raw Normal View History

2016-05-28 20:08:40 +00:00
import plugin_super_class
import threading
import time
from PySide import QtCore
class InvokeEvent(QtCore.QEvent):
EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())
def __init__(self, fn, *args, **kwargs):
QtCore.QEvent.__init__(self, InvokeEvent.EVENT_TYPE)
self.fn = fn
self.args = args
self.kwargs = kwargs
class Invoker(QtCore.QObject):
def event(self, event):
event.fn(*event.args, **event.kwargs)
return True
_invoker = Invoker()
def invoke_in_main_thread(fn, *args, **kwargs):
QtCore.QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs))
class MarqueeStatus(plugin_super_class.PluginSuperClass):
def __init__(self, *args):
super(MarqueeStatus, self).__init__('MarqueeStatus', 'mrq', *args)
2016-06-03 18:56:59 +00:00
self._thread = None
2016-05-28 20:08:40 +00:00
self._exec = None
self.active = False
def close(self):
self.stop()
def stop(self):
self._exec = False
if self.active:
self._thread.join()
def start(self):
self._exec = True
2016-06-03 18:56:59 +00:00
self._thread = threading.Thread(target=self.change_status)
2016-05-28 20:08:40 +00:00
self._thread.start()
def set_status_message(self):
2016-06-03 18:56:59 +00:00
message = self._profile.status_message
2016-06-27 14:08:07 +00:00
self._profile.set_status_message(bytes(message[1:] + message[0], 'utf-8'))
2016-05-28 20:08:40 +00:00
def init_status(self):
2016-06-27 14:08:07 +00:00
self._profile.status_message = bytes(self._profile.status_message.strip() + ' ', 'utf-8')
2016-05-28 20:08:40 +00:00
def change_status(self):
self.active = True
tmp = self._profile.status_message
time.sleep(10)
invoke_in_main_thread(self.init_status)
while self._exec:
time.sleep(1)
if self._profile.status is not None:
invoke_in_main_thread(self.set_status_message)
2016-07-07 10:00:28 +00:00
invoke_in_main_thread(self._profile.set_status_message, bytes(tmp, 'utf-8'))
2016-05-28 20:08:40 +00:00
self.active = False