fixes for smileys selection and file transfers

This commit is contained in:
ingvar1995 2018-09-14 18:35:07 +03:00
parent 9a58082496
commit 9f7de204d4
5 changed files with 63 additions and 53 deletions

View File

@ -4,6 +4,7 @@ from os import remove, rename, chdir
from time import time
from wrapper.tox import Tox
from common.event import Event
from middleware.threads import invoke_in_main_thread
FILE_TRANSFER_STATE = {
@ -120,10 +121,10 @@ class FileTransfer:
t = -1
else:
t = ((time() - self._creation_time) / percentage) * (1 - percentage)
self._state_changed_event(self.state, percentage, int(t))
invoke_in_main_thread(self._state_changed_event, self.state, percentage, int(t))
def _finished(self):
self._finished_event(self._friend_number, self._file_number)
invoke_in_main_thread(self._finished_event, self._friend_number, self._file_number)
# -----------------------------------------------------------------------------------------------------------------
# Send file

View File

@ -40,7 +40,8 @@ class FileTransfersMessagesService:
return tm
def add_inline_message(self, transfer, index):
if self._is_friend_active(transfer.friend_number):
if not self._is_friend_active(transfer.friend_number):
return
count = self._messages.count()
if count + index + 1 >= 0:
self._create_inline_item(transfer.data, count + index + 1)

View File

@ -106,7 +106,7 @@ class ToxAVIterateThread(BaseQThread):
# File transfers thread
# -----------------------------------------------------------------------------------------------------------------
class FileTransfersThread(BaseThread):
class FileTransfersThread(BaseQThread):
def __init__(self):
super().__init__()

View File

@ -18,6 +18,7 @@ class MainWindow(QtWidgets.QMainWindow):
self._plugins_loader = None
self.setAcceptDrops(True)
self._saved = False
self._smiley_window = None
self._profile = self._toxes = self._messenger = None
self._file_transfer_handler = self._history_loader = self._groups_service = self._calls_manager = None
self._should_show_group_peers_list = False
@ -556,13 +557,15 @@ class MainWindow(QtWidgets.QMainWindow):
def send_smiley(self):
self.menu.hide()
if self._contacts_manager.get_curr_contact() is not None:
self.smiley = self._widget_factory.create_smiley_window(self)
self.smiley.setGeometry(QtCore.QRect(self.x() if self._settings['mirror_mode'] else 200 + self.x(),
self.y() + self.height() - 400,
self.smiley.width(),
self.smiley.height()))
self.smiley.show()
if self._contacts_manager.get_curr_contact() is None:
return
self._smiley_window = self._widget_factory.create_smiley_window(self)
rect = QtCore.QRect(self.menu.x(),
self.menu.y() - self.menu.height(),
self._smiley_window.width(),
self._smiley_window.height())
self._smiley_window.setGeometry(rect)
self._smiley_window.show()
def send_sticker(self):
self.menu.hide()

View File

@ -141,57 +141,62 @@ class SmileyWindow(QtWidgets.QWidget):
def __init__(self, parent, smiley_loader):
super().__init__(parent)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.data = smiley_loader.get_smileys()
count = len(self.data)
self._parent = parent
self._data = smiley_loader.get_smileys()
count = len(self._data)
if not count:
self.close()
self.page_size = int(pow(count / 8, 0.5) + 1) * 8 # smileys per page
if count % self.page_size == 0:
self.page_count = count // self.page_size
self._page_size = int(pow(count / 8, 0.5) + 1) * 8 # smileys per page
if count % self._page_size == 0:
self._page_count = count // self._page_size
else:
self.page_count = round(count / self.page_size + 0.5)
self.page = -1
self.radio = []
self.parent = parent
for i in range(self.page_count): # buttons with smileys
self._page_count = round(count / self._page_size + 0.5)
self._page = -1
self._radio = []
for i in range(self._page_count): # pages - radio buttons
elem = QtWidgets.QRadioButton(self)
elem.setGeometry(QtCore.QRect(i * 20 + 5, 180, 20, 20))
elem.clicked.connect(lambda c, t=i: self.checked(t))
self.radio.append(elem)
width = max(self.page_count * 20 + 30, (self.page_size + 5) * 8 // 10)
elem.setGeometry(QtCore.QRect(i * 20 + 5, 160, 20, 20))
elem.clicked.connect(lambda c, t=i: self._checked(t))
self._radio.append(elem)
width = max(self._page_count * 20 + 30, (self._page_size + 5) * 8 // 10)
self.setMaximumSize(width, 200)
self.setMinimumSize(width, 200)
self.buttons = []
for i in range(self.page_size): # pages - radio buttons
self._buttons = []
for i in range(self._page_size): # buttons with smileys
b = QtWidgets.QPushButton(self)
b.setGeometry(QtCore.QRect((i // 8) * 20 + 5, (i % 8) * 20, 20, 20))
b.clicked.connect(lambda c, t=i: self.clicked(t))
self.buttons.append(b)
self.checked(0)
def checked(self, pos): # new page opened
self.radio[self.page].setChecked(False)
self.radio[pos].setChecked(True)
self.page = pos
start = self.page * self.page_size
for i in range(self.page_size):
try:
self.buttons[i].setVisible(True)
pixmap = QtGui.QPixmap(self.data[start + i][1])
icon = QtGui.QIcon(pixmap)
self.buttons[i].setIcon(icon)
except:
self.buttons[i].setVisible(False)
def clicked(self, pos): # smiley selected
pos += self.page * self.page_size
smiley = self.data[pos][0]
self.parent.messageEdit.insertPlainText(smiley)
self.close()
b.clicked.connect(lambda c, t=i: self._clicked(t))
self._buttons.append(b)
self._checked(0)
def leaveEvent(self, event):
self.close()
def _checked(self, pos): # new page opened
self._radio[self._page].setChecked(False)
self._radio[pos].setChecked(True)
self._page = pos
start = self._page * self._page_size
for i in range(self._page_size):
try:
self._buttons[i].setVisible(True)
pixmap = QtGui.QPixmap(self._data[start + i][1])
icon = QtGui.QIcon(pixmap)
self._buttons[i].setIcon(icon)
except:
self._buttons[i].setVisible(False)
def _clicked(self, pos): # smiley selected
pos += self._page * self._page_size
smiley = self._data[pos][0]
self._parent.messageEdit.insertPlainText(smiley)
self.close()
class MenuButton(QtWidgets.QPushButton):