bday plugin

This commit is contained in:
ingvar1995 2016-07-07 13:00:28 +03:00
parent 99007aa8fd
commit 8f011cb864
7 changed files with 153 additions and 1 deletions

2
BirthDay/bday.pro Normal file
View File

@ -0,0 +1,2 @@
SOURCES = bday.py
TRANSLATIONS = bday/en_GB.ts bday/ru_RU.ts

86
BirthDay/bday.py Normal file
View File

@ -0,0 +1,86 @@
import plugin_super_class
from PySide import QtGui, QtCore
import json
import importlib
class BirthDay(plugin_super_class.PluginSuperClass):
def __init__(self, *args):
super(BirthDay, self).__init__('BirthDay', 'bday', *args)
self._data = json.loads(self.load_settings())
self._datetime = importlib.import_module('datetime')
self._timers = []
def start(self):
now = self._datetime.datetime.now()
today = {}
x = self._profile.tox_id[:64]
for key in self._data:
if key != x and key != 'send_date':
arr = self._data[key].split('.')
if int(arr[0]) == now.day and int(arr[1]) == now.month:
today[key] = now.year - int(arr[2])
if len(today):
msgbox = QtGui.QMessageBox()
title = QtGui.QApplication.translate('BirthDay', "Birthday!", None,
QtGui.QApplication.UnicodeUTF8)
msgbox.setWindowTitle(title)
text = ', '.join(self._profile.get_friend_by_number(self._tox.friend_by_public_key(x)).name + ' ({})'.format(today[x]) for x in today)
msgbox.setText('Birthdays: ' + text)
msgbox.exec_()
def get_window(self):
inst = self
x = self._profile.tox_id[:64]
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(QtCore.QRect(450, 300, 350, 150))
self.send = QtGui.QCheckBox(self)
self.send.setGeometry(QtCore.QRect(20, 10, 310, 25))
self.send.setText(QtGui.QApplication.translate('BirthDay', "Send my birthday date to contacts", None, QtGui.QApplication.UnicodeUTF8))
self.setWindowTitle(QtGui.QApplication.translate('BirthDay', "Birthday", None, QtGui.QApplication.UnicodeUTF8))
self.send.clicked.connect(self.update)
self.send.setChecked(inst._data['send_date'])
self.date = QtGui.QLineEdit(self)
self.date.setGeometry(QtCore.QRect(20, 50, 310, 25))
self.date.setPlaceholderText(QtGui.QApplication.translate('BirthDay', "Date in format dd.mm.yyyy", None, QtGui.QApplication.UnicodeUTF8))
self.set_date = QtGui.QPushButton(self)
self.set_date.setGeometry(QtCore.QRect(20, 90, 310, 25))
self.set_date.setText(QtGui.QApplication.translate('BirthDay', "Save date", None, QtGui.QApplication.UnicodeUTF8))
self.set_date.clicked.connect(self.save_curr_date)
self.date.setText(inst._data[x] if x in inst._data else '')
def save_curr_date(self):
inst._data[x] = self.date.text()
inst.save_settings(json.dumps(inst._data))
self.close()
def update(self):
inst._data['send_date'] = self.send.isChecked()
inst.save_settings(json.dumps(inst._data))
return Window()
def lossless_packet(self, data, friend_number):
if len(data):
friend = self._profile.get_friend_by_number(friend_number)
self._data[friend.tox_id] = data
self.save_settings(json.dumps(self._data))
elif self._data['send_date'] and self._profile.tox_id[:64] in self._data:
self.send_lossless(self._data[self._profile.tox_id[:64]], friend_number)
def friend_connected(self, friend_number):
timer = QtCore.QTimer()
timer.timeout.connect(lambda: self.timer(friend_number))
timer.start(10000)
self._timers.append(timer)
def timer(self, friend_number):
timer = self._timers.pop()
timer.stop()
if self._profile.get_friend_by_number(friend_number).tox_id not in self._data:
self.send_lossless('', friend_number)

31
BirthDay/bday/en_GB.ts Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1">
<context>
<name>BirthDay</name>
<message>
<location filename="bday.py" line="28"/>
<source>Birthday!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="bday.py" line="44"/>
<source>Send my birthday date to contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="bday.py" line="45"/>
<source>Birthday</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="bday.py" line="50"/>
<source>Date in format dd.mm.yyyy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="bday.py" line="53"/>
<source>Save date</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

BIN
BirthDay/bday/ru_RU.qm Normal file

Binary file not shown.

32
BirthDay/bday/ru_RU.ts Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="ru_RU">
<context>
<name>BirthDay</name>
<message>
<location filename="bday.py" line="28"/>
<source>Birthday!</source>
<translation>День рождения!</translation>
</message>
<message>
<location filename="bday.py" line="44"/>
<source>Send my birthday date to contacts</source>
<translation>Отправлять дату моего рождения контактам</translation>
</message>
<message>
<location filename="bday.py" line="45"/>
<source>Birthday</source>
<translation>День рождения</translation>
</message>
<message>
<location filename="bday.py" line="50"/>
<source>Date in format dd.mm.yyyy</source>
<translation>Дата в формате дд.мм.гггг</translation>
</message>
<message>
<location filename="bday.py" line="53"/>
<source>Save date</source>
<translation>Сохранить дату</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1 @@
{"send_date": true}

View File

@ -64,5 +64,5 @@ class MarqueeStatus(plugin_super_class.PluginSuperClass):
time.sleep(1)
if self._profile.status is not None:
invoke_in_main_thread(self.set_status_message)
invoke_in_main_thread(self._profile.set_status_message, tmp)
invoke_in_main_thread(self._profile.set_status_message, bytes(tmp, 'utf-8'))
self.active = False