screenstreamer/screenstreamer/gui.py

66 lines
2.0 KiB
Python

from PySide6 import QtCore, QtWidgets
from generated.mainwindow import Ui_ScreenStreamer
from streamer import Streamer
from Xlib import display
from Xlib.ext import randr
class ScreenStreamerGUI(QtWidgets.QMainWindow):
def __init__(self, parent = None) -> None:
QtWidgets.QMainWindow.__init__(self, parent)
self.ui = Ui_ScreenStreamer()
self.ui.setupUi(self)
displays = self.get_displays()
print(displays)
for disp in displays:
self.ui.displaySelect.addItem("{} ({}x{})".format(disp['name'], disp['width'], disp['height']), userData=disp)
def get_displays(self):
disp = display.Display()
screen = disp.screen()
window = screen.root
res = randr.get_screen_resources(window)
result = list()
allwidth = 0
allheight = 0
for output in res.outputs:
params = disp.xrandr_get_output_info(output, res.config_timestamp)
if not params.crtc:
continue # non connected display ports
crtc = disp.xrandr_get_crtc_info(params.crtc, res.config_timestamp)
result.append({'name': params.name , 'width': crtc.width, 'height': crtc.height, 'x': crtc.x, 'y': crtc.y})
if crtc.width + crtc.x > allwidth:
allwidth = crtc.width + crtc.x
if crtc.height + crtc.y > allheight:
allheight = crtc.height + crtc.y
result.append({'name': 'All', 'width': allwidth, 'height': allheight, 'x': 0, 'y': 0})
return result
def format_display(self, displayinfo):
return ":0.0+{},{}".format(displayinfo['x'], displayinfo['y'])
def format_screensize(self, displayinfo):
return "{}:{}".format(displayinfo['width'], displayinfo['height'])
@QtCore.Slot()
def stream_pressed(self):
displaydata = self.ui.displaySelect.currentData()
self.streamer = Streamer(self.format_display(displaydata), self.format_screensize(displaydata), self.ui.sendto.text())
self.streamer.start()
# TODO: add button to stop and feedback on error
print('stream started')
self.ui.statusbar.showMessage('stream started')
@QtCore.Slot()
def recieve_pressed(self):
# TODO
print('recieve')