fixes for smileys selection and file transfers
This commit is contained in:
parent
9a58082496
commit
9f7de204d4
5 changed files with 63 additions and 53 deletions
|
@ -4,6 +4,7 @@ from os import remove, rename, chdir
|
||||||
from time import time
|
from time import time
|
||||||
from wrapper.tox import Tox
|
from wrapper.tox import Tox
|
||||||
from common.event import Event
|
from common.event import Event
|
||||||
|
from middleware.threads import invoke_in_main_thread
|
||||||
|
|
||||||
|
|
||||||
FILE_TRANSFER_STATE = {
|
FILE_TRANSFER_STATE = {
|
||||||
|
@ -120,10 +121,10 @@ class FileTransfer:
|
||||||
t = -1
|
t = -1
|
||||||
else:
|
else:
|
||||||
t = ((time() - self._creation_time) / percentage) * (1 - percentage)
|
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):
|
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
|
# Send file
|
||||||
|
|
|
@ -40,10 +40,11 @@ class FileTransfersMessagesService:
|
||||||
return tm
|
return tm
|
||||||
|
|
||||||
def add_inline_message(self, transfer, index):
|
def add_inline_message(self, transfer, index):
|
||||||
if self._is_friend_active(transfer.friend_number):
|
if not self._is_friend_active(transfer.friend_number):
|
||||||
count = self._messages.count()
|
return
|
||||||
if count + index + 1 >= 0:
|
count = self._messages.count()
|
||||||
self._create_inline_item(transfer.data, count + index + 1)
|
if count + index + 1 >= 0:
|
||||||
|
self._create_inline_item(transfer.data, count + index + 1)
|
||||||
|
|
||||||
def add_unsent_file_message(self, friend, file_path, data):
|
def add_unsent_file_message(self, friend, file_path, data):
|
||||||
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
|
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
|
||||||
|
|
|
@ -106,7 +106,7 @@ class ToxAVIterateThread(BaseQThread):
|
||||||
# File transfers thread
|
# File transfers thread
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class FileTransfersThread(BaseThread):
|
class FileTransfersThread(BaseQThread):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
|
@ -18,6 +18,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
self._plugins_loader = None
|
self._plugins_loader = None
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self._saved = False
|
self._saved = False
|
||||||
|
self._smiley_window = None
|
||||||
self._profile = self._toxes = self._messenger = None
|
self._profile = self._toxes = self._messenger = None
|
||||||
self._file_transfer_handler = self._history_loader = self._groups_service = self._calls_manager = None
|
self._file_transfer_handler = self._history_loader = self._groups_service = self._calls_manager = None
|
||||||
self._should_show_group_peers_list = False
|
self._should_show_group_peers_list = False
|
||||||
|
@ -556,13 +557,15 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
def send_smiley(self):
|
def send_smiley(self):
|
||||||
self.menu.hide()
|
self.menu.hide()
|
||||||
if self._contacts_manager.get_curr_contact() is not None:
|
if self._contacts_manager.get_curr_contact() is None:
|
||||||
self.smiley = self._widget_factory.create_smiley_window(self)
|
return
|
||||||
self.smiley.setGeometry(QtCore.QRect(self.x() if self._settings['mirror_mode'] else 200 + self.x(),
|
self._smiley_window = self._widget_factory.create_smiley_window(self)
|
||||||
self.y() + self.height() - 400,
|
rect = QtCore.QRect(self.menu.x(),
|
||||||
self.smiley.width(),
|
self.menu.y() - self.menu.height(),
|
||||||
self.smiley.height()))
|
self._smiley_window.width(),
|
||||||
self.smiley.show()
|
self._smiley_window.height())
|
||||||
|
self._smiley_window.setGeometry(rect)
|
||||||
|
self._smiley_window.show()
|
||||||
|
|
||||||
def send_sticker(self):
|
def send_sticker(self):
|
||||||
self.menu.hide()
|
self.menu.hide()
|
||||||
|
|
|
@ -141,57 +141,62 @@ class SmileyWindow(QtWidgets.QWidget):
|
||||||
def __init__(self, parent, smiley_loader):
|
def __init__(self, parent, smiley_loader):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
|
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
|
||||||
self.data = smiley_loader.get_smileys()
|
self._parent = parent
|
||||||
count = len(self.data)
|
self._data = smiley_loader.get_smileys()
|
||||||
|
|
||||||
|
count = len(self._data)
|
||||||
if not count:
|
if not count:
|
||||||
self.close()
|
self.close()
|
||||||
self.page_size = int(pow(count / 8, 0.5) + 1) * 8 # smileys per page
|
|
||||||
if count % self.page_size == 0:
|
self._page_size = int(pow(count / 8, 0.5) + 1) * 8 # smileys per page
|
||||||
self.page_count = count // self.page_size
|
if count % self._page_size == 0:
|
||||||
|
self._page_count = count // self._page_size
|
||||||
else:
|
else:
|
||||||
self.page_count = round(count / self.page_size + 0.5)
|
self._page_count = round(count / self._page_size + 0.5)
|
||||||
self.page = -1
|
self._page = -1
|
||||||
self.radio = []
|
self._radio = []
|
||||||
self.parent = parent
|
|
||||||
for i in range(self.page_count): # buttons with smileys
|
for i in range(self._page_count): # pages - radio buttons
|
||||||
elem = QtWidgets.QRadioButton(self)
|
elem = QtWidgets.QRadioButton(self)
|
||||||
elem.setGeometry(QtCore.QRect(i * 20 + 5, 180, 20, 20))
|
elem.setGeometry(QtCore.QRect(i * 20 + 5, 160, 20, 20))
|
||||||
elem.clicked.connect(lambda c, t=i: self.checked(t))
|
elem.clicked.connect(lambda c, t=i: self._checked(t))
|
||||||
self.radio.append(elem)
|
self._radio.append(elem)
|
||||||
width = max(self.page_count * 20 + 30, (self.page_size + 5) * 8 // 10)
|
|
||||||
|
width = max(self._page_count * 20 + 30, (self._page_size + 5) * 8 // 10)
|
||||||
self.setMaximumSize(width, 200)
|
self.setMaximumSize(width, 200)
|
||||||
self.setMinimumSize(width, 200)
|
self.setMinimumSize(width, 200)
|
||||||
self.buttons = []
|
self._buttons = []
|
||||||
for i in range(self.page_size): # pages - radio buttons
|
|
||||||
|
for i in range(self._page_size): # buttons with smileys
|
||||||
b = QtWidgets.QPushButton(self)
|
b = QtWidgets.QPushButton(self)
|
||||||
b.setGeometry(QtCore.QRect((i // 8) * 20 + 5, (i % 8) * 20, 20, 20))
|
b.setGeometry(QtCore.QRect((i // 8) * 20 + 5, (i % 8) * 20, 20, 20))
|
||||||
b.clicked.connect(lambda c, t=i: self.clicked(t))
|
b.clicked.connect(lambda c, t=i: self._clicked(t))
|
||||||
self.buttons.append(b)
|
self._buttons.append(b)
|
||||||
self.checked(0)
|
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()
|
|
||||||
|
|
||||||
def leaveEvent(self, event):
|
def leaveEvent(self, event):
|
||||||
self.close()
|
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):
|
class MenuButton(QtWidgets.QPushButton):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue