From c9fb52e29cc70581c7227715f40ecd706788f464 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 2 Apr 2016 21:31:59 +0300 Subject: [PATCH] notifications #3 + docs update --- src/callbacks.py | 22 +++++++++++++++++----- src/list_items.py | 4 ++-- src/notifications.py | 8 +++++++- tests/tests.py | 7 ------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index c7b7831..0338314 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -36,8 +36,7 @@ def invoke_in_main_thread(fn, *args, **kwargs): def self_connection_status(tox_link): """ - :param tox_link: tox instance - :return: function for tox.callback_self_connection_status + Current user changed connection status (offline, UDP, TCP) """ def wrapped(tox, connection, user_data): print 'Connection status: ', str(connection) @@ -85,6 +84,9 @@ def friend_connection_status(tox, friend_num, new_status, user_data): def friend_name(tox, friend_num, name, size, user_data): + """ + Friend changed his name + """ profile = Profile.get_instance() friend = profile.get_friend_by_number(friend_num) print 'New name: ', str(friend_num), str(name) @@ -108,9 +110,7 @@ def friend_status_message(tox, friend_num, status_message, size, user_data): def friend_message(window, tray): """ - :param window: main window - :param tray: tray - :return: function for tox.callback_friend_message. Adds new message to list + New message from friend """ def wrapped(tox, friend_number, message_type, message, size, user_data): profile = Profile.get_instance() @@ -139,6 +139,9 @@ def friend_request(tox, public_key, message, message_size, user_data): def tox_file_recv(window, tray): + """ + New incoming file + """ def wrapped(tox, friend_number, file_number, file_type, size, file_name, file_name_size, user_data): profile = Profile.get_instance() settings = Settings.get_instance() @@ -166,6 +169,9 @@ def tox_file_recv(window, tray): def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, user_data): + """ + Incoming chunk + """ invoke_in_main_thread(Profile.get_instance().incoming_chunk, friend_number, file_number, @@ -174,6 +180,9 @@ def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, us def file_chunk_request(tox, friend_number, file_number, position, size, user_data): + """ + Outgoing chunk + """ Profile.get_instance().outgoing_chunk( friend_number, file_number, @@ -182,6 +191,9 @@ def file_chunk_request(tox, friend_number, file_number, position, size, user_dat def file_recv_control(tox, friend_number, file_number, file_control, user_data): + """ + Friend cancelled, paused or resumed file transfer + """ if file_control == TOX_FILE_CONTROL['CANCEL']: Profile.get_instance().cancel_transfer(friend_number, file_number, True) diff --git a/src/list_items.py b/src/list_items.py index f15b157..35cc6dd 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -85,7 +85,7 @@ class ContactItem(QtGui.QWidget): self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64)) self.avatar_label.setScaledContents(True) self.name = DataLabel(self) - self.name.setGeometry(QtCore.QRect(70, 10, 170, 25)) + self.name.setGeometry(QtCore.QRect(70, 10, 160, 25)) font = QtGui.QFont() font.setFamily("Times New Roman") font.setPointSize(12) @@ -99,7 +99,7 @@ class ContactItem(QtGui.QWidget): self.status_message.setFont(font) self.status_message.setObjectName("status_message") self.connection_status = StatusCircle(self) - self.connection_status.setGeometry(QtCore.QRect(230, 5, 32, 32)) + self.connection_status.setGeometry(QtCore.QRect(220, 5, 32, 32)) self.connection_status.setObjectName("connection_status") diff --git a/src/notifications.py b/src/notifications.py index 3987e63..d129538 100644 --- a/src/notifications.py +++ b/src/notifications.py @@ -1,7 +1,6 @@ from PySide import QtGui, QtCore from PySide.phonon import Phonon from util import curr_directory -# TODO: make app icon active # TODO: rewrite sound notifications @@ -14,6 +13,8 @@ SOUND_NOTIFICATION = { def tray_notification(title, text, tray, window): """ + Show tray notification and activate window icon + NOTE: different behaviour on different OS :param title: Name of user who sent message or file :param text: text of message or file info :param tray: ref to tray icon @@ -23,6 +24,7 @@ def tray_notification(title, text, tray, window): if len(text) > 30: text = text[:27] + '...' tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000) + QtGui.QApplication.alert(window, 0) def message_clicked(): window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) @@ -31,6 +33,10 @@ def tray_notification(title, text, tray, window): def sound_notification(t): + """ + Plays sound notification + :param t: type of notification + """ if t == SOUND_NOTIFICATION['MESSAGE']: f = curr_directory() + '/sounds/message.wav' elif t == SOUND_NOTIFICATION['FILE_TRANSFER']: diff --git a/tests/tests.py b/tests/tests.py index b14bd26..cf31f08 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -2,13 +2,6 @@ from src.bootstrap import node_generator from src.profile import * from src.tox_dns import tox_dns -class TestSettings(): - - def test_creation(self): - s = Settings() - assert s['ipv6_enabled'] is not None - assert s['notifications'] is not None - class TestProfile():