annotate libervia/cli/call_gui.py @ 4321:2246eeeccc74

tests (unit): fix tests: - test_ap-gateway: fix missing implementation of `client.is_local` - test_plugin_xep_0215: fix missing return value of `has_feature`
author Goffi <goffi@goffi.org>
date Mon, 30 Sep 2024 14:15:47 +0200
parents 0d7bb4df2343
children 00837fa13e5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia CLI
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import asyncio
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from functools import partial
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from pathlib import Path
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from typing import Callable, cast
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from PyQt6.QtCore import QPoint, QSize, Qt
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from PyQt6.QtGui import (
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 QCloseEvent,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 QColor,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 QIcon,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 QImage,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 QPainter,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 QPen,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 QPixmap,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 QResizeEvent,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 QTransform,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from PyQt6.QtWidgets import (
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 QApplication,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 QDialog,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 QDialogButtonBox,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 QHBoxLayout,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 QLabel,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 QListWidget,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 QListWidgetItem,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 QMainWindow,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 QPushButton,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 QSizePolicy,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 QVBoxLayout,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 QWidget,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 )
4210
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
50 import gi
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
51
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
52 from libervia.backend.core.i18n import _
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
53 from libervia.frontends.tools import aio, display_servers, webrtc
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
54
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
55 gi.require_versions({"Gst": "1.0", "GstWebRTC": "1.0"})
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 from gi.repository import Gst
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 ICON_SIZE = QSize(45, 45)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 BUTTON_SIZE = QSize(50, 50)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 running = False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
63
4233
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
64 aio.install_glib_asyncio_iteration()
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
65
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
66
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 class ActivableButton(QPushButton):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def __init__(self, text, parent=None):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 super().__init__(parent)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self._activated = True
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self._activated_colour = "#47c68e"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self._deactivated_colour = "#ffe089"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self._line_colour = "#ff0000"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self._update_background_color()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 @property
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def activated_colour(self) -> str:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 return self._activated_colour
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
79
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 @activated_colour.setter
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def activated_colour(self, new_colour: str) -> None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 if new_colour != self._activated_colour:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self._activated_colour = new_colour
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self._update_background_color()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
85
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 @property
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def deactivated_colour(self) -> str:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 return self._deactivated_colour
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 @deactivated_colour.setter
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def deactivated_colour(self, new_colour: str) -> None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if new_colour != self._deactivated_colour:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self._deactivated_colour = new_colour
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self._update_background_color()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 @property
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 def line_colour(self) -> str:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 return self._line_colour
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
99
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 @line_colour.setter
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 def line_colour(self, new_colour: str) -> None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 if new_colour != self._line_colour:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 self._line_colour = new_colour
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.update()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def paintEvent(self, a0):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 super().paintEvent(a0)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 if not self._activated:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 painter = QPainter(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 painter.setRenderHint(QPainter.RenderHint.Antialiasing)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 line_color = QColor(self._line_colour)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 line_width = 4
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 cap_style = Qt.PenCapStyle.RoundCap
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 pen = QPen(line_color, line_width, Qt.PenStyle.SolidLine)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 pen.setCapStyle(cap_style)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 painter.setPen(pen)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 margin = 5
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 start_point = QPoint(margin, self.height() - margin)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 end_point = QPoint(self.width() - margin, margin)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 painter.drawLine(start_point, end_point)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 def _update_background_color(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 if self._activated:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 self.setStyleSheet(f"background-color: {self._activated_colour};")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 else:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 self.setStyleSheet(f"background-color: {self._deactivated_colour};")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.update()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 @property
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def activated(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 return self._activated
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 @activated.setter
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 def activated(self, value):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 if self._activated != value:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self._activated = value
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 self._update_background_color()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
143
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 class X11DesktopScreenDialog(QDialog):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 def __init__(self, windows_data, parent=None):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 super().__init__(parent)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self.__a_result = asyncio.get_running_loop().create_future()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 self.setWindowTitle("Please select a window to share:")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 self.resize(400, 300)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 self.list_widget = QListWidget(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 for window_data in windows_data:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 item = QListWidgetItem(window_data["title"])
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 item.setData(Qt.ItemDataRole.UserRole, window_data)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self.list_widget.addItem(item)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
155
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 self.buttonBox = QDialogButtonBox(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 self.buttonBox.accepted.connect(self.on_accepted)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 self.buttonBox.rejected.connect(self.on_rejected)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
161
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 layout = QVBoxLayout(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 layout.addWidget(self.list_widget)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 layout.addWidget(self.buttonBox)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 def get_selected_window(self) -> dict | None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 selectedItem = self.list_widget.currentItem()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 if selectedItem:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 return selectedItem.data(Qt.ItemDataRole.UserRole)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 return None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
171
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 def on_accepted(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self.__a_result.set_result(self.get_selected_window())
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.close()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
175
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 def on_rejected(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 self.__a_result.set_result(None)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.close()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
179
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 def closeEvent(self, a0):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 super().closeEvent(a0)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 if not self.__a_result.done():
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.__a_result.set_result(None)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 async def a_show(self) -> dict | None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 self.open()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 return await self.__a_result
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
188
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
189
4210
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
190 class AVCallUI(QMainWindow):
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 def __init__(self, host, icons_path: Path):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 super().__init__()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 self.host = host
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 self.webrtc_call = None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self.icons_path = icons_path
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 self.initUI()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 @staticmethod
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 async def run_qt_loop(app):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 while running:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 app.sendPostedEvents()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 await asyncio.sleep(0.1)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 @classmethod
4210
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
205 async def run(cls, parent, call_data):
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 """Run PyQt loop and show the app"""
4210
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
207 media_dir = Path(await parent.host.bridge.config_get("", "media_dir"))
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
208 icons_path = media_dir / "fonts/fontello/svg"
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 app = QApplication([])
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 av_call_gui = cls(parent.host, icons_path)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 av_call_gui.show()
4233
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
212 webrtc_call = await webrtc.WebRTCCall.make_webrtc_call(
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
213 parent.host.bridge,
4210
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
214 parent.profile,
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 call_data,
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4233
diff changeset
216 sinks_data=webrtc.SinksApp(
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 local_video_cb=partial(av_call_gui.on_new_sample, video_stream="local"),
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 remote_video_cb=partial(av_call_gui.on_new_sample, video_stream="remote"),
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 ),
4233
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
220 # we want to be sure that call is ended if user presses `Ctrl + c` or anything
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
221 # else stops the session.
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
222 on_call_setup_cb=lambda sid, profile: parent.host.add_on_quit_callback(
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
223 parent.host.bridge.call_end, sid, "", profile
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
224 ),
d01b8d002619 cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents: 4210
diff changeset
225 on_call_ended_cb=lambda sid, profile: parent.host.a_quit(),
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 av_call_gui.webrtc_call = webrtc_call
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
228
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 global running
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 running = True
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 await cls.run_qt_loop(app)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 await parent.host.a_quit()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
233
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 def initUI(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 self.setGeometry(100, 100, 800, 600)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 self.setWindowTitle("Call")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
237
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 # Main layouts
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 self.background_widget = QWidget(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 self.foreground_widget = QWidget(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 self.setCentralWidget(self.background_widget)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 back_layout = QVBoxLayout(self.background_widget)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 front_layout = QVBoxLayout(self.foreground_widget)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
244
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 # Remote video
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 self.remote_video_widget = QLabel(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 self.remote_video_widget.setSizePolicy(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 QSizePolicy.Policy.Ignored, QSizePolicy.Policy.Ignored
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 back_layout.addWidget(self.remote_video_widget)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
251
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 # Fullscreen button
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 fullscreen_layout = QHBoxLayout()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 front_layout.addLayout(fullscreen_layout)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 fullscreen_layout.addStretch()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 self.fullscreen_btn = QPushButton("", self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 self.fullscreen_btn.setFixedSize(BUTTON_SIZE)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 self.fullscreen_icon_normal = QIcon(str(self.icons_path / "resize-full.svg"))
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 self.fullscreen_icon_fullscreen = QIcon(str(self.icons_path / "resize-small.svg"))
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 self.fullscreen_btn.setIcon(self.fullscreen_icon_normal)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 self.fullscreen_btn.setIconSize(ICON_SIZE)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self.fullscreen_btn.clicked.connect(self.toggle_fullscreen)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 fullscreen_layout.addWidget(self.fullscreen_btn)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
264
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 # Control buttons
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 self.control_buttons_layout = QHBoxLayout()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 self.control_buttons_layout.setSpacing(40)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 self.toggle_video_btn = cast(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 ActivableButton, self.add_control_button("videocam", self.toggle_video)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 self.toggle_audio_btn = cast(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 ActivableButton, self.add_control_button("volume-up", self.toggle_audio)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 self.share_desktop_btn = cast(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 ActivableButton, self.add_control_button("desktop", self.share_desktop)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 self.share_desktop_btn.deactivated_colour = "#47c68e"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 self.share_desktop_btn.activated_colour = "#f24468"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 self.share_desktop_btn.line_colour = "#666666"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 self.share_desktop_btn.activated = False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 self.hang_up_btn = self.add_control_button(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 "phone", self.hang_up, rotate=135, background="red", activable=False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
284
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 controls_widget = QWidget(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 controls_widget.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 controls_widget.setLayout(self.control_buttons_layout)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 front_layout.addStretch()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
289
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 bottom_layout = QHBoxLayout()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 bottom_layout.addStretch()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 front_layout.addLayout(bottom_layout)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 bottom_layout.addWidget(controls_widget, alignment=Qt.AlignmentFlag.AlignBottom)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
294
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 # Local video feedback
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 bottom_layout.addStretch()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 self.local_video_widget = QLabel(self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 bottom_layout.addWidget(self.local_video_widget)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
299
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 # we update sizes on resize event
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 self.background_widget.resizeEvent = self.adjust_sizes
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 self.adjust_sizes()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
303
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 def add_control_button(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 self,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 icon_name: str,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 callback: Callable,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 rotate: float | None = None,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 background: str | None = None,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 activable: bool = True,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 ) -> QPushButton | ActivableButton:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 if activable:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 button = ActivableButton("", self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 else:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 button = QPushButton("", self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 icon_path = self.icons_path / f"{icon_name}.svg"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 button.setIcon(QIcon(str(icon_path)))
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 button.setIconSize(ICON_SIZE)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 button.setFixedSize(BUTTON_SIZE)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 if rotate is not None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 pixmap = button.icon().pixmap(ICON_SIZE)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 transform = QTransform()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 transform.rotate(rotate)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 rotated_pixmap = pixmap.transformed(transform)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 button.setIcon(QIcon(rotated_pixmap))
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 if background:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 button.setStyleSheet(f"background-color: {background};")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 button.clicked.connect(callback)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 self.control_buttons_layout.addWidget(button)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 return button
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
331
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 def adjust_sizes(self, a0: QResizeEvent | None = None) -> None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 self.foreground_widget.setGeometry(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 0, 0, self.background_widget.width(), self.background_widget.height()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 self.local_video_widget.setFixedSize(QSize(self.width() // 3, self.height() // 3))
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 if a0 is not None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 super().resizeEvent(a0)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
339
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 def on_new_sample(self, video_sink, video_stream: str) -> bool:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 sample = video_sink.emit("pull-sample")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 if sample is None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 return False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
344
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 video_pad = video_sink.get_static_pad("sink")
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 assert video_pad is not None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 s = video_pad.get_current_caps().get_structure(0)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 stream_size = (s.get_value("width"), s.get_value("height"))
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 self.host.loop.loop.call_soon_threadsafe(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 self.update_sample, sample, stream_size, video_stream
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
352
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 return False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
354
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 def update_sample(self, sample, stream_size, video_stream: str) -> None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 if sample is None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 return
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
358
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 video_widget = (
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 self.remote_video_widget
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 if video_stream == "remote"
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 else self.local_video_widget
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
364
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 buf = sample.get_buffer()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 result, mapinfo = buf.map(Gst.MapFlags.READ)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 if result:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 buffer = mapinfo.data
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 width, height = stream_size
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 qimage = QImage(buffer, width, height, QImage.Format.Format_RGB888)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 pixmap = QPixmap.fromImage(qimage).scaled(
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 QSize(video_widget.width(), video_widget.height()),
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 Qt.AspectRatioMode.KeepAspectRatio,
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 )
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 video_widget.setPixmap(pixmap)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 video_widget.setAlignment(Qt.AlignmentFlag.AlignCenter)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
377
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 buf.unmap(mapinfo)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
379
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 def toggle_fullscreen(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 fullscreen = not self.isFullScreen()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 if fullscreen:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 self.fullscreen_btn.setIcon(self.fullscreen_icon_fullscreen)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 self.showFullScreen()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 else:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 self.fullscreen_btn.setIcon(self.fullscreen_icon_normal)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 self.showNormal()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
388
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
389 def closeEvent(self, a0: QCloseEvent | None) -> None:
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 super().closeEvent(a0)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 global running
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 running = False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
393
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 def toggle_video(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 assert self.webrtc_call is not None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
396 self.webrtc_call.webrtc.video_muted = not self.webrtc_call.webrtc.video_muted
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
397 self.toggle_video_btn.activated = not self.webrtc_call.webrtc.video_muted
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
398
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 def toggle_audio(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
400 assert self.webrtc_call is not None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
401 self.webrtc_call.webrtc.audio_muted = not self.webrtc_call.webrtc.audio_muted
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 self.toggle_audio_btn.activated = not self.webrtc_call.webrtc.audio_muted
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
403
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 def share_desktop(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
405 assert self.webrtc_call is not None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
406 if self.webrtc_call.webrtc.desktop_sharing:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
407 self.webrtc_call.webrtc.desktop_sharing = False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
408 self.share_desktop_btn.activated = False
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
409 elif display_servers.detect() == display_servers.X11:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
410 aio.run_async(self.show_X11_screen_dialog())
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
411 else:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
412 self.webrtc_call.webrtc.desktop_sharing = True
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
413
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 def hang_up(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
415 self.close()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
416
4210
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
417 @staticmethod
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
418 def can_run():
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
419 # if a known display server is detected, we should be able to run
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
420 return display_servers.detect() is not None
9218d4331bb2 cli (call): `tui` output implementation:
Goffi <goffi@goffi.org>
parents: 4206
diff changeset
421
4206
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
422 async def show_X11_screen_dialog(self):
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 assert self.webrtc_call is not None
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
424 windows_data = display_servers.x11_list_windows()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
425 dialog = X11DesktopScreenDialog(windows_data, self)
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
426 selected = await dialog.a_show()
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
427 if selected is not None:
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
428 xid = selected["id"]
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
429 self.webrtc_call.webrtc.desktop_sharing_data = {"xid": xid}
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
430 self.webrtc_call.webrtc.desktop_sharing = True
0f8ea0768a3b cli (call): implement GUI output:
Goffi <goffi@goffi.org>
parents:
diff changeset
431 self.share_desktop_btn.activated = True