widgets fixes

This commit is contained in:
ingvar1995 2018-05-15 13:40:59 +03:00
parent e21a9355e7
commit 98dbe6a493
6 changed files with 28 additions and 27 deletions

View File

@ -303,12 +303,12 @@ class App:
self._contacts_provider = ContactProvider(self._tox, self._friend_factory) self._contacts_provider = ContactProvider(self._tox, self._friend_factory)
self._contacts_manager = ContactsManager(self._tox, self._settings, self._ms, self._profile_manager, self._contacts_manager = ContactsManager(self._tox, self._settings, self._ms, self._profile_manager,
self._contacts_provider, db, self._tox_dns) self._contacts_provider, db, self._tox_dns)
self._messenger = Messenger(self._tox, self._plugin_loader, self._ms, self._contacts_manager,
self._contacts_provider, items_factory, profile)
self._file_transfer_handler = FileTransfersHandler(self._tox, self._settings, self._contacts_provider) self._file_transfer_handler = FileTransfersHandler(self._tox, self._settings, self._contacts_provider)
widgets_factory = WidgetsFactory(self._settings, profile, self._profile_manager, self._contacts_manager, widgets_factory = WidgetsFactory(self._settings, profile, self._profile_manager, self._contacts_manager,
self._file_transfer_handler, self._smiley_loader, self._plugin_loader, self._file_transfer_handler, self._smiley_loader, self._plugin_loader,
self._toxes, self._version) self._toxes, self._version)
self._messenger = Messenger(self._tox, self._plugin_loader, self._ms, self._contacts_manager,
self._contacts_provider, items_factory, profile)
self._tray = tray.init_tray(profile, self._settings, self._ms) self._tray = tray.init_tray(profile, self._settings, self._ms)
self._ms.set_dependencies(widgets_factory, self._tray, self._contacts_manager, self._messenger, profile, self._ms.set_dependencies(widgets_factory, self._tray, self._contacts_manager, self._messenger, profile,
self._plugin_loader) self._plugin_loader)

View File

@ -43,7 +43,7 @@ class ContactsManager:
self._profile_manager.save_profile(data) self._profile_manager.save_profile(data)
def is_friend_active(self, friend_number): def is_friend_active(self, friend_number):
if not self._is_active_a_friend(): if not self.is_active_a_friend():
return False return False
return self.get_curr_contact().number == friend_number return self.get_curr_contact().number == friend_number
@ -148,6 +148,8 @@ class ContactsManager:
util.log('Error in set active: ' + str(ex)) util.log('Error in set active: ' + str(ex))
raise raise
active_friend = property(get_active, set_active)
def set_active_by_number_and_type(self, number, is_friend): def set_active_by_number_and_type(self, number, is_friend):
for i in range(len(self._contacts)): for i in range(len(self._contacts)):
c = self._contacts[i] c = self._contacts[i]
@ -155,12 +157,13 @@ class ContactsManager:
self._active_contact = i self._active_contact = i
break break
active_friend = property(get_active, set_active)
def update(self): def update(self):
if self._active_contact + 1: if self._active_contact + 1:
self.set_active(self._active_contact) self.set_active(self._active_contact)
def is_active_a_friend(self):
return type(self.get_curr_contact()) is Friend
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Filtration # Filtration
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
@ -174,7 +177,7 @@ class ContactsManager:
# TODO: simplify? # TODO: simplify?
filter_str = filter_str.lower() filter_str = filter_str.lower()
number = self.get_active_number() number = self.get_active_number()
is_friend = self._is_active_a_friend() is_friend = self.is_active_a_friend()
if sorting > 1: if sorting > 1:
if sorting & 2: if sorting & 2:
self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True) self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True)
@ -424,9 +427,6 @@ class ContactsManager:
# Private methods # Private methods
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
def _is_active_a_friend(self):
return type(self.get_curr_contact()) is Friend
def _load_contacts(self): def _load_contacts(self):
self._load_friends() self._load_friends()
self._load_groups() self._load_groups()

View File

@ -179,25 +179,23 @@ class FileTransfersHandler:
self._get_friend_by_number(friend_number).update_transfer_data(file_number, self._get_friend_by_number(friend_number).update_transfer_data(file_number,
TOX_FILE_TRANSFER_STATE['RUNNING']) TOX_FILE_TRANSFER_STATE['RUNNING'])
def send_screenshot(self, data): def send_screenshot(self, data, friend_number):
""" """
Send screenshot to current active friend Send screenshot to current active friend
:param data: raw data - png :param data: raw data - png
""" """
self.send_inline(data, 'toxygen_inline.png') self.send_inline(data, 'toxygen_inline.png', friend_number)
def send_sticker(self, path): def send_sticker(self, path, friend_number):
with open(path, 'rb') as fl: with open(path, 'rb') as fl:
data = fl.read() data = fl.read()
self.send_inline(data, 'sticker.png') self.send_inline(data, 'sticker.png', friend_number)
def send_inline(self, data, file_name, friend_number=None, is_resend=False): def send_inline(self, data, file_name, friend_number, is_resend=False):
friend_number = friend_number or self.get_active_number()
friend = self._get_friend_by_number(friend_number) friend = self._get_friend_by_number(friend_number)
if friend.status is None and not is_resend: if friend.status is None and not is_resend:
m = UnsentFile(file_name, data, time.time()) m = UnsentFile(file_name, data, time.time())
friend.append_message(m) friend.append_message(m)
self.update()
return return
elif friend.status is None and is_resend: elif friend.status is None and is_resend:
raise RuntimeError() raise RuntimeError()

View File

@ -542,7 +542,7 @@ class MainWindow(QtWidgets.QMainWindow):
def send_sticker(self): def send_sticker(self):
self.menu.hide() self.menu.hide()
if self._contacts_manager.is_active_a_friend(): if self._contacts_manager.is_active_a_friend():
self.sticker = self._widget_factory.create_sticker_window(self) self.sticker = self._widget_factory.create_sticker_window()
self.sticker.setGeometry(QtCore.QRect(self.x() if self._settings['mirror_mode'] else 270 + self.x(), self.sticker.setGeometry(QtCore.QRect(self.x() if self._settings['mirror_mode'] else 270 + self.x(),
self.y() + self.height() - 200, self.y() + self.height() - 200,
self.sticker.width(), self.sticker.width(),

View File

@ -81,7 +81,8 @@ class MessageArea(QtWidgets.QPlainTextEdit):
else: else:
self.insertPlainText(text) self.insertPlainText(text)
def parse_file_name(self, file_name): @staticmethod
def parse_file_name(file_name):
if file_name.endswith('\r\n'): if file_name.endswith('\r\n'):
file_name = file_name[:-2] file_name = file_name[:-2]
file_name = urllib.parse.unquote(file_name) file_name = urllib.parse.unquote(file_name)
@ -90,9 +91,10 @@ class MessageArea(QtWidgets.QPlainTextEdit):
class ScreenShotWindow(RubberBandWindow): class ScreenShotWindow(RubberBandWindow):
def __init__(self, file_transfer_handler, *args): def __init__(self, file_transfer_handler, contacts_manager, *args):
super().__init__(*args) super().__init__(*args)
self._file_transfer_handler = file_transfer_handler self._file_transfer_handler = file_transfer_handler
self._contacts_manager = contacts_manager
def closeEvent(self, *args): def closeEvent(self, *args):
if self.parent.isHidden(): if self.parent.isHidden():
@ -113,7 +115,8 @@ class ScreenShotWindow(RubberBandWindow):
buffer = QtCore.QBuffer(byte_array) buffer = QtCore.QBuffer(byte_array)
buffer.open(QtCore.QIODevice.WriteOnly) buffer.open(QtCore.QIODevice.WriteOnly)
p.save(buffer, 'PNG') p.save(buffer, 'PNG')
self._file_transfer_handler.send_screenshot(bytes(byte_array.data())) friend = self._contacts_manager.get_curr_contact()
self._file_transfer_handler.send_screenshot(bytes(byte_array.data(), friend.number))
self.close() self.close()
@ -267,9 +270,10 @@ class StickerItem(QtWidgets.QWidget):
class StickerWindow(QtWidgets.QWidget): class StickerWindow(QtWidgets.QWidget):
"""Sticker selection window""" """Sticker selection window"""
def __init__(self, parent, file_transfer_handler): def __init__(self, file_transfer_handler, contacts_manager):
super().__init__() super().__init__()
self._file_transfer_handler = file_transfer_handler self._file_transfer_handler = file_transfer_handler
self._contacts_manager = contacts_manager
self.setWindowFlags(QtCore.Qt.FramelessWindowHint) self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setMaximumSize(250, 200) self.setMaximumSize(250, 200)
self.setMinimumSize(250, 200) self.setMinimumSize(250, 200)
@ -285,11 +289,11 @@ class StickerWindow(QtWidgets.QWidget):
self.list.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) self.list.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
self.list.setSpacing(3) self.list.setSpacing(3)
self.list.clicked.connect(self.click) self.list.clicked.connect(self.click)
self.parent = parent
def click(self, index): def click(self, index):
num = index.row() num = index.row()
self._file_transfer_handler.send_sticker(self._stickers[num]) friend = self._contacts_manager.get_curr_contact()
self._file_transfer_handler.send_sticker(self._stickers[num], friend.number)
self.close() self.close()
def leaveEvent(self, event): def leaveEvent(self, event):
@ -465,7 +469,6 @@ class SearchScreen(QtWidgets.QWidget):
self.not_found(text) self.not_found(text)
def closeEvent(self, *args): def closeEvent(self, *args):
Profile.get_instance().update()
self._messages.setGeometry(0, 0, self._messages.width(), self._messages.height() + 40) self._messages.setGeometry(0, 0, self._messages.width(), self._messages.height() + 40)
super().closeEvent(*args) super().closeEvent(*args)

View File

@ -17,7 +17,7 @@ class WidgetsFactory:
self._version = version self._version = version
def create_screenshot_window(self, *args): def create_screenshot_window(self, *args):
return ScreenShotWindow(self._file_transfer_handler, *args) return ScreenShotWindow(self._file_transfer_handler, self._contacts_manager, *args)
def create_smiley_window(self, parent): def create_smiley_window(self, parent):
return SmileyWindow(parent, self._smiley_loader) return SmileyWindow(parent, self._smiley_loader)
@ -61,5 +61,5 @@ class WidgetsFactory:
def create_smiley_window(self, parent): def create_smiley_window(self, parent):
return SmileyWindow(parent, self._smiley_loader) return SmileyWindow(parent, self._smiley_loader)
def create_sticker_window(self, parent): def create_sticker_window(self):
return StickerWindow(parent, self._file_transfer_handler) return StickerWindow(self._file_transfer_handler, self._contacts_manager)