From dd4634c1a7794ef8543d9d89c4b8b7eddec241ea Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 29 Oct 2016 17:26:05 +0300 Subject: [PATCH] 2 new plugins --- AutoAnswer/aans.py | 46 +++++++++++++++++++++++++++ AutoAnswer/aans/settings.json | 1 + Garland/garland.py | 60 +++++++++++++++++++++++++++++++++++ README.md | 3 +- 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 AutoAnswer/aans.py create mode 100644 AutoAnswer/aans/settings.json create mode 100644 Garland/garland.py diff --git a/AutoAnswer/aans.py b/AutoAnswer/aans.py new file mode 100644 index 0000000..79aff63 --- /dev/null +++ b/AutoAnswer/aans.py @@ -0,0 +1,46 @@ +import plugin_super_class +from PySide import QtGui, QtCore +import json + + +class AutoAnswer(plugin_super_class.PluginSuperClass): + + def __init__(self, *args): + super(AutoAnswer, self).__init__('AutoAnswer', 'aans', *args) + self._data = json.loads(self.load_settings()) + self._tmp = None + + def get_description(self): + return QtGui.QApplication.translate("aans", 'Plugin which allows you to auto answer on calls.', None, QtGui.QApplication.UnicodeUTF8) + + def start(self): + self._tmp = self._profile.incoming_call + + def func(audio, video, friend_number): + if self._profile.get_friend_by_number(friend_number).tox_id in self._data['id']: + self._profile.accept_call(friend_number, audio, video) + else: + self._tmp(friend_number, audio, video) + + self._profile.incoming_call = func + + def stop(self): + self._profile.incoming_call = self._tmp + + def get_menu(self, menu, num): + friend = self._profile.get_friend(num) + if friend.tox_id in self._data['id']: + text = 'Disallow auto answer' + else: + text = 'Allow auto answer' + act = QtGui.QAction(QtGui.QApplication.translate("aans", text, None, QtGui.QApplication.UnicodeUTF8), menu) + act.connect(act, QtCore.SIGNAL("triggered()"), lambda: self.toggle(friend.tox_id)) + return [act] + + def toggle(self, tox_id): + if tox_id in self._data['id']: + self._data['id'].remove(tox_id) + else: + self._data['id'].append(tox_id) + self.save_settings(json.dumps(self._data)) + diff --git a/AutoAnswer/aans/settings.json b/AutoAnswer/aans/settings.json new file mode 100644 index 0000000..fd74b36 --- /dev/null +++ b/AutoAnswer/aans/settings.json @@ -0,0 +1 @@ +{"id": ["20E3E1DEB598C1A6B49B2D2F6BF1C181F4FE9C977B9098903F176269F32CEF1D"]} \ No newline at end of file diff --git a/Garland/garland.py b/Garland/garland.py new file mode 100644 index 0000000..7b0d66c --- /dev/null +++ b/Garland/garland.py @@ -0,0 +1,60 @@ +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 Garland(plugin_super_class.PluginSuperClass): + + def __init__(self, *args): + super(Garland, self).__init__('Garland', 'grlnd', *args) + self._thread = None + self._exec = None + self._time = 3 + + def close(self): + self.stop() + + def stop(self): + self._exec = False + self._thread.join() + + def start(self): + self._exec = True + self._thread = threading.Thread(target=self.change_status) + self._thread.start() + + def command(self, command): + if command.startswith('time'): + self._time = max(int(command.split(' ')[1]), 0) / 1000 + else: + super().command(command) + + def change_status(self): + time.sleep(5) + while self._exec: + invoke_in_main_thread(self._profile.change_status) + time.sleep(self._time) diff --git a/README.md b/README.md index 0b13833..eb3cd0f 100644 --- a/README.md +++ b/README.md @@ -14,5 +14,6 @@ For more info visit [plugins.md](https://github.com/toxygen-project/toxygen/blob - AutoAwayStatusLinux - sets "Away" status when user is inactive (Linux only). - AutoAwayStatusWindows - sets "Away" status when user is inactive (Windows only). - Chess - play chess with your friends using Tox. - +- Garland - changes your status like it's garland. +- AutoAnswer - calls auto answering.