screen sharing - area selection
This commit is contained in:
parent
2ff41313f8
commit
ace663804e
3 changed files with 73 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
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
|
from profile import Profile
|
||||||
import smileys
|
import smileys
|
||||||
import util
|
import util
|
||||||
|
@ -71,38 +71,12 @@ class MessageArea(QtWidgets.QPlainTextEdit):
|
||||||
self.insertPlainText(text)
|
self.insertPlainText(text)
|
||||||
|
|
||||||
|
|
||||||
class ScreenShotWindow(QtWidgets.QWidget):
|
class ScreenShotWindow(RubberBandWindow):
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
def closeEvent(self, *args):
|
def closeEvent(self, *args):
|
||||||
if self.parent.isHidden():
|
if self.parent.isHidden():
|
||||||
self.parent.show()
|
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):
|
def mouseReleaseEvent(self, event):
|
||||||
if self.rubberband.isVisible():
|
if self.rubberband.isVisible():
|
||||||
self.rubberband.hide()
|
self.rubberband.hide()
|
||||||
|
@ -121,13 +95,6 @@ class ScreenShotWindow(QtWidgets.QWidget):
|
||||||
Profile.get_instance().send_screenshot(bytes(byte_array.data()))
|
Profile.get_instance().send_screenshot(bytes(byte_array.data()))
|
||||||
self.close()
|
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):
|
class SmileyWindow(QtWidgets.QWidget):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,7 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
from settings import *
|
from settings import *
|
||||||
from profile import Profile
|
from profile import Profile
|
||||||
from util import curr_directory, copy
|
from util import curr_directory, copy
|
||||||
from widgets import CenteredWidget, DataLabel, LineEdit
|
from widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow
|
||||||
import pyaudio
|
import pyaudio
|
||||||
import toxes
|
import toxes
|
||||||
import plugin_support
|
import plugin_support
|
||||||
|
@ -802,6 +802,18 @@ class AudioSettings(CenteredWidget):
|
||||||
settings.save()
|
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):
|
class VideoSettings(CenteredWidget):
|
||||||
"""
|
"""
|
||||||
Audio calls settings form
|
Audio calls settings form
|
||||||
|
@ -812,6 +824,7 @@ class VideoSettings(CenteredWidget):
|
||||||
self.initUI()
|
self.initUI()
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
self.center()
|
self.center()
|
||||||
|
self.desktopAreaSelection = None
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setObjectName("videoSettingsForm")
|
self.setObjectName("videoSettingsForm")
|
||||||
|
@ -831,6 +844,9 @@ class VideoSettings(CenteredWidget):
|
||||||
self.input = QtWidgets.QComboBox(self)
|
self.input = QtWidgets.QComboBox(self)
|
||||||
self.input.setGeometry(QtCore.QRect(25, 30, 350, 30))
|
self.input.setGeometry(QtCore.QRect(25, 30, 350, 30))
|
||||||
self.input.currentIndexChanged.connect(self.selectionChanged)
|
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
|
import cv2
|
||||||
self.devices = [-1]
|
self.devices = [-1]
|
||||||
screen = QtWidgets.QApplication.primaryScreen()
|
screen = QtWidgets.QApplication.primaryScreen()
|
||||||
|
@ -859,6 +875,10 @@ class VideoSettings(CenteredWidget):
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.setWindowTitle(QtWidgets.QApplication.translate("videoSettingsForm", "Video settings"))
|
self.setWindowTitle(QtWidgets.QApplication.translate("videoSettingsForm", "Video settings"))
|
||||||
self.in_label.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Device:"))
|
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):
|
def closeEvent(self, event):
|
||||||
try:
|
try:
|
||||||
|
@ -871,7 +891,21 @@ class VideoSettings(CenteredWidget):
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print('Saving video settings error: ' + str(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):
|
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()]
|
width, height = self.frame_max_sizes[self.input.currentIndex()]
|
||||||
self.video_size.clear()
|
self.video_size.clear()
|
||||||
dims = [
|
dims = [
|
||||||
|
|
|
@ -77,6 +77,42 @@ class RubberBand(QtWidgets.QRubberBand):
|
||||||
self.painter.end()
|
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):
|
def create_menu(menu):
|
||||||
"""
|
"""
|
||||||
:return translated menu
|
:return translated menu
|
||||||
|
|
Loading…
Reference in a new issue