From ace663804e21c4b3b33e2b9dd2d24f4b137b73f7 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 13 Jul 2017 21:02:42 +0300 Subject: [PATCH] screen sharing - area selection --- toxygen/mainscreen_widgets.py | 37 ++--------------------------------- toxygen/menu.py | 36 +++++++++++++++++++++++++++++++++- toxygen/widgets.py | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/toxygen/mainscreen_widgets.py b/toxygen/mainscreen_widgets.py index 7632af0..b6d4b0c 100644 --- a/toxygen/mainscreen_widgets.py +++ b/toxygen/mainscreen_widgets.py @@ -1,5 +1,5 @@ from PyQt5 import QtCore, QtGui, QtWidgets -from widgets import RubberBand, create_menu, QRightClickButton, CenteredWidget, LineEdit +from widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit from profile import Profile import smileys import util @@ -71,38 +71,12 @@ class MessageArea(QtWidgets.QPlainTextEdit): self.insertPlainText(text) -class ScreenShotWindow(QtWidgets.QWidget): - - def __init__(self, parent): - super(ScreenShotWindow, self).__init__() - self.parent = parent - self.setMouseTracking(True) - self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) - self.showFullScreen() - self.setWindowOpacity(0.5) - self.rubberband = RubberBand() - self.rubberband.setWindowFlags(self.rubberband.windowFlags() | QtCore.Qt.FramelessWindowHint) - self.rubberband.setAttribute(QtCore.Qt.WA_TranslucentBackground) +class ScreenShotWindow(RubberBandWindow): def closeEvent(self, *args): if self.parent.isHidden(): self.parent.show() - def mousePressEvent(self, event): - self.origin = event.pos() - self.rubberband.setGeometry(QtCore.QRect(self.origin, QtCore.QSize())) - self.rubberband.show() - QtWidgets.QWidget.mousePressEvent(self, event) - - def mouseMoveEvent(self, event): - if self.rubberband.isVisible(): - 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(): self.rubberband.hide() @@ -121,13 +95,6 @@ class ScreenShotWindow(QtWidgets.QWidget): Profile.get_instance().send_screenshot(bytes(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) - class SmileyWindow(QtWidgets.QWidget): """ diff --git a/toxygen/menu.py b/toxygen/menu.py index 547d721..b361154 100644 --- a/toxygen/menu.py +++ b/toxygen/menu.py @@ -2,7 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets from settings import * from profile import Profile from util import curr_directory, copy -from widgets import CenteredWidget, DataLabel, LineEdit +from widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow import pyaudio import toxes import plugin_support @@ -802,6 +802,18 @@ class AudioSettings(CenteredWidget): settings.save() +class DesktopAreaSelectionWindow(RubberBandWindow): + + def mouseReleaseEvent(self, event): + if self.rubberband.isVisible(): + self.rubberband.hide() + rect = self.rubberband.geometry() + width, height = rect.width(), rect.height() + if width >= 8 and height >= 8: + self.parent.save(width, height) + self.close() + + class VideoSettings(CenteredWidget): """ Audio calls settings form @@ -812,6 +824,7 @@ class VideoSettings(CenteredWidget): self.initUI() self.retranslateUi() self.center() + self.desktopAreaSelection = None def initUI(self): self.setObjectName("videoSettingsForm") @@ -831,6 +844,9 @@ class VideoSettings(CenteredWidget): self.input = QtWidgets.QComboBox(self) self.input.setGeometry(QtCore.QRect(25, 30, 350, 30)) self.input.currentIndexChanged.connect(self.selectionChanged) + self.button = QtWidgets.QPushButton(self) + self.button.clicked.connect(self.button_clicked) + self.button.setGeometry(QtCore.QRect(25, 70, 350, 30)) import cv2 self.devices = [-1] screen = QtWidgets.QApplication.primaryScreen() @@ -859,6 +875,10 @@ class VideoSettings(CenteredWidget): def retranslateUi(self): self.setWindowTitle(QtWidgets.QApplication.translate("videoSettingsForm", "Video settings")) self.in_label.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Device:")) + self.button.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Select region")) + + def button_clicked(self): + self.desktopAreaSelection = DesktopAreaSelectionWindow(self) def closeEvent(self, event): try: @@ -871,7 +891,21 @@ class VideoSettings(CenteredWidget): except Exception as ex: print('Saving video settings error: ' + str(ex)) + def save(self, width, height): + self.desktopAreaSelection = None + settings = Settings.get_instance() + settings.video['device'] = -1 + settings.video['width'] = width + settings.video['height'] = height + settings.save() + def selectionChanged(self): + if self.input.currentIndex() == 0: + self.button.setVisible(True) + self.video_size.setVisible(False) + else: + self.button.setVisible(False) + self.video_size.setVisible(True) width, height = self.frame_max_sizes[self.input.currentIndex()] self.video_size.clear() dims = [ diff --git a/toxygen/widgets.py b/toxygen/widgets.py index 2cc97cf..b63deb0 100644 --- a/toxygen/widgets.py +++ b/toxygen/widgets.py @@ -77,6 +77,42 @@ class RubberBand(QtWidgets.QRubberBand): self.painter.end() +class RubberBandWindow(QtWidgets.QWidget): + + def __init__(self, parent): + super().__init__() + self.parent = parent + self.setMouseTracking(True) + self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) + self.showFullScreen() + self.setWindowOpacity(0.5) + self.rubberband = RubberBand() + self.rubberband.setWindowFlags(self.rubberband.windowFlags() | QtCore.Qt.FramelessWindowHint) + self.rubberband.setAttribute(QtCore.Qt.WA_TranslucentBackground) + + def mousePressEvent(self, event): + self.origin = event.pos() + self.rubberband.setGeometry(QtCore.QRect(self.origin, QtCore.QSize())) + self.rubberband.show() + QtWidgets.QWidget.mousePressEvent(self, event) + + def mouseMoveEvent(self, event): + if self.rubberband.isVisible(): + 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 keyPressEvent(self, event): + if event.key() == QtCore.Qt.Key_Escape: + self.rubberband.setHidden(True) + self.close() + else: + super().keyPressEvent(event) + + def create_menu(menu): """ :return translated menu