From e257d8f96f3bda87364dcc4ea860bce0361cc517 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 13 Apr 2017 19:22:46 +0300 Subject: [PATCH] signals && imports fixes --- .travis.yml | 2 +- toxygen/basecontact.py | 5 +---- toxygen/callbacks.py | 5 +---- toxygen/contact.py | 5 +---- toxygen/items_factory.py | 5 +---- toxygen/list_items.py | 4 ++-- toxygen/loginscreen.py | 2 +- toxygen/mainscreen.py | 6 +++--- toxygen/mainscreen_widgets.py | 15 ++++++++------- toxygen/notifications.py | 11 ++++------- toxygen/passwordscreen.py | 2 +- toxygen/profile.py | 17 +++++++---------- toxygen/smileys.py | 5 +---- toxygen/updater.py | 5 +---- toxygen/widgets.py | 4 ++-- 15 files changed, 35 insertions(+), 58 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e9b6df..700b449 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_install: - sudo apt-get install -y checkinstall build-essential - sudo apt-get install portaudio19-dev - sudo apt-get install libconfig-dev libvpx-dev check -qq - - sudo apt-get install python3-pyqt5 + - sudo apt-get install -y python3-pyqt5 install: - pip install pyaudio before_script: diff --git a/toxygen/basecontact.py b/toxygen/basecontact.py index 2086977..e1243a4 100644 --- a/toxygen/basecontact.py +++ b/toxygen/basecontact.py @@ -1,8 +1,5 @@ from settings import * -try: - from PyQt5 import QtCore, QtGui -except ImportError: - from PyQt4 import QtCore, QtGui +from PyQt5 import QtCore, QtGui from toxcore_enums_and_consts import TOX_PUBLIC_KEY_SIZE diff --git a/toxygen/callbacks.py b/toxygen/callbacks.py index 69b43ef..fb9e697 100644 --- a/toxygen/callbacks.py +++ b/toxygen/callbacks.py @@ -1,7 +1,4 @@ -try: - from PyQt5 import QtCore -except ImportError: - from PyQt4 import QtCore +from PyQt5 import QtCore, QtGui, QtWidgets from notifications import * from settings import Settings from profile import Profile diff --git a/toxygen/contact.py b/toxygen/contact.py index d525477..4475e53 100644 --- a/toxygen/contact.py +++ b/toxygen/contact.py @@ -1,7 +1,4 @@ -try: - from PyQt5 import QtCore, QtGui -except ImportError: - from PyQt4 import QtCore, QtGui +from PyQt5 import QtCore, QtGui from history import * import basecontact import util diff --git a/toxygen/items_factory.py b/toxygen/items_factory.py index 12044dd..44a00ad 100644 --- a/toxygen/items_factory.py +++ b/toxygen/items_factory.py @@ -1,7 +1,4 @@ -try: - from PyQt5 import QtCore, QtGui -except ImportError: - from PyQt4 import QtCore, QtGui +from PyQt5 import QtWidgets, QtCore from list_items import * diff --git a/toxygen/list_items.py b/toxygen/list_items.py index af373f9..9ef4e84 100644 --- a/toxygen/list_items.py +++ b/toxygen/list_items.py @@ -162,7 +162,7 @@ class MessageItem(QtWidgets.QWidget): if event.button() == QtCore.Qt.RightButton and event.x() > self.time.x(): self.listMenu = QtWidgets.QMenu() delete_item = self.listMenu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Delete message')) - self.connect(delete_item, QtCore.pyqtSignal("triggered()"), self.delete) + delete_item.triggered.connect(self.delete) parent_position = self.time.mapToGlobal(QtCore.QPoint(0, 0)) self.listMenu.move(parent_position) self.listMenu.show() @@ -428,7 +428,7 @@ class FileTransferItem(QtWidgets.QListWidget): self.accept_or_pause.setIcon(icon) self.accept_or_pause.setIconSize(QtCore.QSize(30, 30)) - def update(self, state, progress, time): + def update_transfer_state(self, state, progress, time): self.pb.setValue(int(progress * 100)) if time + 1: m, s = divmod(time, 60) diff --git a/toxygen/loginscreen.py b/toxygen/loginscreen.py index 0fe5fd0..77aa5ba 100644 --- a/toxygen/loginscreen.py +++ b/toxygen/loginscreen.py @@ -1,4 +1,4 @@ -from PyQt5 import QtWidgets, QtGui +from PyQt5 import QtWidgets, QtCore from widgets import * diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index 5d72c5f..9847d01 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -1,7 +1,7 @@ from menu import * from profile import * from list_items import * -from widgets import MultilineEdit, LineEdit, ComboBox +from widgets import MultilineEdit, ComboBox import plugin_support from mainscreen_widgets import * import settings @@ -370,7 +370,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): s.save() QtWidgets.QApplication.closeAllWindows() event.accept() - elif QtGui.QSystemTrayIcon.isSystemTrayAvailable(): + elif QtWidgets.QSystemTrayIcon.isSystemTrayAvailable(): event.ignore() self.hide() @@ -400,7 +400,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.profile.update() def keyPressEvent(self, event): - if event.key() == QtCore.Qt.Key_Escape and QtGui.QSystemTrayIcon.isSystemTrayAvailable(): + if event.key() == QtCore.Qt.Key_Escape and QtWidgets.QSystemTrayIcon.isSystemTrayAvailable(): self.hide() elif event.key() == QtCore.Qt.Key_C and event.modifiers() & QtCore.Qt.ControlModifier and self.messages.selectedIndexes(): rows = list(map(lambda x: self.messages.row(x), self.messages.selectedItems())) diff --git a/toxygen/mainscreen_widgets.py b/toxygen/mainscreen_widgets.py index 53d969b..d4e474f 100644 --- a/toxygen/mainscreen_widgets.py +++ b/toxygen/mainscreen_widgets.py @@ -106,11 +106,12 @@ class ScreenShotWindow(QtWidgets.QWidget): self.rubberband.hide() rect = self.rubberband.geometry() if rect.width() and rect.height(): - p = QtGui.QPixmap.grabWindow(QtWidgets.QApplication.desktop().winId(), - rect.x() + 4, - rect.y() + 4, - rect.width() - 8, - rect.height() - 8) + screen = QtWidgets.QApplication.primaryScreen() + p = screen.grabWindow(0, + rect.x() + 4, + rect.y() + 4, + rect.width() - 8, + rect.height() - 8) byte_array = QtCore.QByteArray() buffer = QtCore.QBuffer(byte_array) buffer.open(QtCore.QIODevice.WriteOnly) @@ -260,7 +261,7 @@ class DropdownMenu(QtWidgets.QWidget): self.fileTransferButton.clicked.connect(parent.send_file) self.screenshotButton.clicked.connect(parent.send_screenshot) - self.rightClicked.connect(lambda: parent.send_screenshot(True)) + self.screenshotButton.rightClicked.connect(lambda: parent.send_screenshot(True)) self.smileyButton.clicked.connect(parent.send_smiley) self.stickerButton.clicked.connect(parent.send_sticker) @@ -414,7 +415,7 @@ class SearchScreen(QtWidgets.QWidget): self.search_button.setScaledContents(False) self.search_button.setAlignment(QtCore.Qt.AlignCenter) self.search_button.setPixmap(pixmap) - self.connect(self.search_button, QtCore.SIGNAL('clicked()'), self.search) + self.search_button.clicked.connect(self.search) font = QtGui.QFont() font.setPointSize(32) diff --git a/toxygen/notifications.py b/toxygen/notifications.py index 710e3fe..26a29ec 100644 --- a/toxygen/notifications.py +++ b/toxygen/notifications.py @@ -1,7 +1,4 @@ -try: - from PyQt5 import QtCore, QtGui -except ImportError: - from PyQt4 import QtCore, QtGui +from PyQt5 import QtCore, QtWidgets from util import curr_directory import wave import pyaudio @@ -23,16 +20,16 @@ def tray_notification(title, text, tray, window): :param tray: ref to tray icon :param window: main window """ - if QtGui.QSystemTrayIcon.isSystemTrayAvailable(): + if QtWidgets.QSystemTrayIcon.isSystemTrayAvailable(): if len(text) > 30: text = text[:27] + '...' - tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000) + tray.showMessage(title, text, QtWidgets.QSystemTrayIcon.NoIcon, 3000) QtWidgets.QApplication.alert(window, 0) def message_clicked(): window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) window.activateWindow() - tray.connect(tray, QtCore.SIGNAL("messageClicked()"), message_clicked) + tray.messageClicked.connect(message_clicked) class AudioFile: diff --git a/toxygen/passwordscreen.py b/toxygen/passwordscreen.py index 6d872b6..ca721e5 100644 --- a/toxygen/passwordscreen.py +++ b/toxygen/passwordscreen.py @@ -1,5 +1,5 @@ from widgets import CenteredWidget, LineEdit -from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5 import QtCore, QtWidgets class PasswordArea(LineEdit): diff --git a/toxygen/profile.py b/toxygen/profile.py index 41e4752..053242a 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -1,8 +1,5 @@ from list_items import * -try: - from PyQt5 import QtCore, QtGui -except ImportError: - from PyQt4 import QtCore, QtGui +from PyQt5 import QtGui, QtWidgets from friend import * from settings import * from toxcore_enums_and_consts import * @@ -244,7 +241,7 @@ class Profile(basecontact.BaseContact, Singleton): if message.get_status() in ACTIVE_FILE_TRANSFERS: # active file transfer try: ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())] - ft.set_state_changed_handler(item.update) + ft.set_state_changed_handler(item.update_transfer_state) ft.signal() except: print('Incoming not started transfer - no info found') @@ -564,7 +561,7 @@ class Profile(basecontact.BaseContact, Singleton): if message.get_status() in ACTIVE_FILE_TRANSFERS: # active file transfer try: ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())] - ft.set_state_changed_handler(item.update) + ft.set_state_changed_handler(item.update_transfer_state) ft.signal() except: print('Incoming not started transfer - no info found') @@ -938,7 +935,7 @@ class Profile(basecontact.BaseContact, Singleton): if friend_number == self.get_active_number(): item = self.create_file_transfer_item(tm) if accepted: - self._file_transfers[(friend_number, file_number)].set_state_changed_handler(item.update) + self._file_transfers[(friend_number, file_number)].set_state_changed_handler(item.update_transfer_state) self._messages.scrollToBottom() else: friend.actions = True @@ -1027,7 +1024,7 @@ class Profile(basecontact.BaseContact, Singleton): self._file_transfers[(friend_number, file_number)] = rt self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME']) if item is not None: - rt.set_state_changed_handler(item.update) + rt.set_state_changed_handler(item.update_transfer_state) self.get_friend_by_number(friend_number).update_transfer_data(file_number, TOX_FILE_TRANSFER_STATE['RUNNING']) @@ -1066,7 +1063,7 @@ class Profile(basecontact.BaseContact, Singleton): st.get_file_number()) item = self.create_file_transfer_item(tm) friend.append_message(tm) - st.set_state_changed_handler(item.update) + st.set_state_changed_handler(item.update_transfer_state) self._messages.scrollToBottom() def send_file(self, path, number=None, is_resend=False, file_id=None): @@ -1099,7 +1096,7 @@ class Profile(basecontact.BaseContact, Singleton): st.get_file_number()) if friend_number == self.get_active_number(): item = self.create_file_transfer_item(tm) - st.set_state_changed_handler(item.update) + st.set_state_changed_handler(item.update_transfer_state) self._messages.scrollToBottom() self._contacts[friend_number].append_message(tm) diff --git a/toxygen/smileys.py b/toxygen/smileys.py index d104d53..52cb603 100644 --- a/toxygen/smileys.py +++ b/toxygen/smileys.py @@ -2,10 +2,7 @@ import util import json import os from collections import OrderedDict -try: - from PyQt5 import QtCore -except ImportError: - from PyQt4 import QtCore +from PyQt5 import QtCore class SmileyLoader(util.Singleton): diff --git a/toxygen/updater.py b/toxygen/updater.py index f985cba..ba5d1c9 100644 --- a/toxygen/updater.py +++ b/toxygen/updater.py @@ -3,10 +3,7 @@ import os import settings import platform import urllib -try: - from PyQt5 import QtNetwork, QtCore -except ImportError: - from PyQt4 import QtNetwork, QtCore +from PyQt5 import QtNetwork, QtCore import subprocess diff --git a/toxygen/widgets.py b/toxygen/widgets.py index 6e68047..3894782 100644 --- a/toxygen/widgets.py +++ b/toxygen/widgets.py @@ -48,14 +48,14 @@ class QRightClickButton(QtWidgets.QPushButton): Button with right click support """ - right_clicked = QtCore.pyqtSignal() + rightClicked = QtCore.pyqtSignal() def __init__(self, parent): super(QRightClickButton, self).__init__(parent) def mousePressEvent(self, event): if event.button() == QtCore.Qt.RightButton: - self.right_clicked.emit() + self.rightClicked.emit() else: super(QRightClickButton, self).mousePressEvent(event)