From 111d72ceaa8557ea0ea7e64551ea08108e3eb487 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 2 Apr 2016 14:41:06 +0300 Subject: [PATCH] screenshots creating update --- src/file_transfers.py | 5 ++++- src/mainscreen.py | 35 +++++++++++++++++++++-------------- src/notifications.py | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/file_transfers.py b/src/file_transfers.py index 33c6089..8e41c21 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -160,11 +160,14 @@ class ReceiveTransfer(FileTransfer): class ReceiveAvatar(ReceiveTransfer): + MAX_AVATAR_SIZE = 512 * 1024 def __init__(self, tox, friend_number, size, file_number): path = profile.ProfileHelper.get_path() + '/avatars/{}.png'.format(tox.friend_get_public_key(friend_number)) super(ReceiveAvatar, self).__init__(path, tox, friend_number, size, file_number) - if exists(path): + if size > self.MAX_AVATAR_SIZE: + self.send_control(TOX_FILE_CONTROL['CANCEL']) + elif exists(path): if not size: self.send_control(TOX_FILE_CONTROL['CANCEL']) self.state = TOX_FILE_TRANSFER_STATE['CANCELED'] diff --git a/src/mainscreen.py b/src/mainscreen.py index 80c2dc2..f02a0c9 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -21,7 +21,7 @@ class MessageArea(QtGui.QPlainTextEdit): elif event.key() == QtCore.Qt.Key_Up and not self.toPlainText(): self.appendPlainText(Profile.get_instance().get_last_message()) else: - super(self.__class__, self).keyPressEvent(event) + super(MessageArea, self).keyPressEvent(event) class MainWindow(QtGui.QMainWindow): @@ -391,28 +391,29 @@ class MainWindow(QtGui.QMainWindow): class ScreenShotWindow(QtGui.QWidget): - # TODO: make selected area transparent + def __init__(self): super(ScreenShotWindow, self).__init__() self.setMouseTracking(True) self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) self.showFullScreen() - self.setWindowOpacity(0.01) + self.setWindowOpacity(0.4) self.rubberband = QtGui.QRubberBand(QtGui.QRubberBand.Rectangle, None) def mousePressEvent(self, event): self.origin = event.pos() - self.rubberband.setGeometry( - QtCore.QRect(self.origin, QtCore.QSize())) + self.rubberband.setGeometry(QtCore.QRect(self.origin, QtCore.QSize())) self.rubberband.show() QtGui.QWidget.mousePressEvent(self, event) def mouseMoveEvent(self, event): if self.rubberband.isVisible(): - self.rubberband.setGeometry( - QtCore.QRect(self.origin, event.pos()).normalized()) - QtGui.QWidget.mouseMoveEvent(self, event) - self.repaint() + self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized()) + left = QtGui.QRegion(QtCore.QRect(0, 0, self.rubberband.x(), self.height())) + right = QtGui.QRegion(QtCore.QRect(self.rubberband.x() + self.rubberband.width(), 0, self.width(), self.height())) + top = QtGui.QRegion(0, 0, self.width(), self.rubberband.y()) + bottom = QtGui.QRegion(0, self.rubberband.y() + self.rubberband.height(), self.width(), self.height()) + self.setMask(left + right + top + bottom) def mouseReleaseEvent(self, event): if self.rubberband.isVisible(): @@ -420,17 +421,23 @@ class ScreenShotWindow(QtGui.QWidget): rect = self.rubberband.geometry() print rect p = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId(), - rect.x() + 3, - rect.y() + 3, - rect.width() - 6, - rect.height() - 6) + 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) p.save(buffer, 'PNG') - Profile.get_instance().send_screenshot(''.join(byte_array[i] for i in xrange(byte_array.length()))) + Profile.get_instance().send_screenshot(str(byte_array.data())) self.close() + def keyPressEvent(self, event): + if event.key() == QtCore.Qt.Key_Escape: + self.rubberband.setHidden(True) + self.close() + else: + super(ScreenShotWindow, self).keyPressEvent(event) diff --git a/src/notifications.py b/src/notifications.py index 294e558..3987e63 100644 --- a/src/notifications.py +++ b/src/notifications.py @@ -2,7 +2,7 @@ from PySide import QtGui, QtCore from PySide.phonon import Phonon from util import curr_directory # TODO: make app icon active -# TODO: add all sound notifications +# TODO: rewrite sound notifications SOUND_NOTIFICATION = {