From 23b045070a814ac3cc59590c2b9e918402303866 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 17 Jun 2016 22:35:05 +0300 Subject: [PATCH] ft fixes --- src/avwidgets.py | 28 ++++++++++++++++++++++++++++ src/callbacks.py | 5 ++--- src/file_transfers.py | 11 +++++------ src/list_items.py | 4 ++-- src/profile.py | 14 ++++++++++++-- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/avwidgets.py b/src/avwidgets.py index 9e95a96..fd0c614 100644 --- a/src/avwidgets.py +++ b/src/avwidgets.py @@ -109,3 +109,31 @@ class IncomingCallWidget(widgets.CenteredWidget): def set_pixmap(self, pixmap): self.avatar_label.setPixmap(pixmap) + + +class AudioMessageRecorder(widgets.CenteredWidget): + + def __init__(self, friend_number, name): + super(AudioMessageRecorder, self).__init__() + self.label = QtGui.QLabel(self) + self.label.setGeometry(QtCore.QRect(10, 20, 250, 20)) + text = QtGui.QApplication.translate("MenuWindow", "Send audio message to friend {}", None, QtGui.QApplication.UnicodeUTF8) + self.label.setText(text.format(name)) + self.record = QtGui.QPushButton(self) + self.record.setGeometry(QtCore.QRect(20, 100, 150, 150)) + + self.record.setText(QtGui.QApplication.translate("MenuWindow", "Start recording", None, + QtGui.QApplication.UnicodeUTF8)) + self.record.clicked.connect(self.start_or_stop_recording) + self.recording = False + self.friend_num = friend_number + + def start_or_stop_recording(self): + if not self.recording: + self.recording = True + self.record.setText(QtGui.QApplication.translate("MenuWindow", "Stop recording", None, + QtGui.QApplication.UnicodeUTF8)) + else: + self.close() + + diff --git a/src/callbacks.py b/src/callbacks.py index 6c094b8..070a39b 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -94,9 +94,8 @@ def friend_name(tox, friend_num, name, size, user_data): Friend changed his name """ profile = Profile.get_instance() - print 'New name: ', str(friend_num), str(name) - if profile.get_active_number() == friend_num: - invoke_in_main_thread(profile.new_name, friend_num, name) + print 'New name: ', friend_num, name + invoke_in_main_thread(profile.new_name, friend_num, name) def friend_status_message(tox, friend_num, status_message, size, user_data): diff --git a/src/file_transfers.py b/src/file_transfers.py index 32c3cb9..556f86b 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -224,15 +224,14 @@ class ReceiveTransfer(FileTransfer): if data is None: self._file.close() self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] - self._state_changed.signal.emit(self.state, 1) - else: # TODO: improve - data = ''.join(chr(x) for x in data) + self.signal() + else: + data = bytearray(data) if self._file_size < position: self._file.seek(0, 2) self._file.write('\0' * (position - self._file_size)) self._file.seek(position) self._file.write(data) - self._file.flush() l = len(data) if position + l > self._file_size: self._file_size = position + l @@ -258,9 +257,9 @@ class ReceiveToBuffer(FileTransfer): self._creation_time = time() if data is None: self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] - self._state_changed.signal.emit(self.state, 1) + self.signal() else: - data = ''.join(chr(x) for x in data) + data = bytearray(data) l = len(data) if self._data_size < position: self._data += ('\0' * (position - self._data_size)) diff --git a/src/list_items.py b/src/list_items.py index 36fd80b..fca7024 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -291,7 +291,7 @@ class FileTransferItem(QtGui.QListWidget): self.pb.setVisible(state in SHOW_PROGRESS_BAR) self.file_name = DataLabel(self) - self.file_name.setGeometry(QtCore.QRect(210, 7, width - 440, 20)) + self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20)) font.setPointSize(12) self.file_name.setFont(font) file_size = size / 1024 @@ -306,7 +306,7 @@ class FileTransferItem(QtGui.QListWidget): self.file_name.setToolTip(file_name) self.saved_name = file_name self.time_left = QtGui.QLabel(self) - self.time_left.setGeometry(QtCore.QRect(width - 83, 7, 30, 20)) + self.time_left.setGeometry(QtCore.QRect(width - 87, 7, 30, 20)) font.setPointSize(10) self.time_left.setFont(font) self.time_left.setVisible(state == TOX_FILE_TRANSFER_STATE['RUNNING']) diff --git a/src/profile.py b/src/profile.py index 77e5849..ab0faf6 100644 --- a/src/profile.py +++ b/src/profile.py @@ -77,8 +77,18 @@ class Profile(contact.Contact, Singleton): self._tox.self_set_status(status) def set_name(self, value): + tmp = self.name super(Profile, self).set_name(value) self._tox.self_set_name(self._name.encode('utf-8')) + if tmp != value: + message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, + QtGui.QApplication.UnicodeUTF8) + message = message.format(tmp, value) + for friend in self._friends: + friend.append_message(InfoMessage(message, time.time())) + if self._active_friend + 1: + self.create_message_item(message, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE']) + self._messages.scrollToBottom() def set_status_message(self, value): super(Profile, self).set_status_message(value) @@ -104,7 +114,7 @@ class Profile(contact.Contact, Singleton): filter_str = filter_str.lower() for index, friend in enumerate(self._friends): friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name.lower()) - friend.visibility = friend.visibility or friend.messages + friend.visibility = friend.visibility or friend.messages or friend.actions if friend.visibility: self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 70)) else: @@ -237,7 +247,7 @@ class Profile(contact.Contact, Singleton): message = message.format(tmp, name) friend.append_message(InfoMessage(message, time.time())) friend.actions = True - if friend.number == self.get_active_number(): + if number == self.get_active_number(): self.create_message_item(message, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE']) self._messages.scrollToBottom() self.set_active(None)