Skip to content

Commit

Permalink
Port to QT6 with PySide6 (#453)
Browse files Browse the repository at this point in the history
Not as bad as anticipated but the QObject inheritance order swap took a while to figure out though...

While I was there, I did some code linting on all files changed by the QT6 port. Since we will test a lot, now is the time to do it.
  • Loading branch information
obilodeau authored Dec 6, 2023
1 parent 7e9ae84 commit 7ee1f30
Show file tree
Hide file tree
Showing 32 changed files with 116 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Install setuptools
run: sudo apt install python3-setuptools
- name: Install PyRDP dependencies
run: sudo apt install libgl1-mesa-glx git python3-dev
run: sudo apt install libgl1-mesa-glx libegl1 git python3-dev
- name: Install wheel
working-directory: .
run: pip install wheel
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends python3 \
# Required for the setup.py install and progressbar (required by pyrdp-convert)
python3-distutils \
# GUI and notifications stuff
libgl1-mesa-glx libxcb-xinerama0 \
libgl1-mesa-glx libegl1 libxcb-xinerama0 \
libxcb-icccm4 libxcb-image0 libxcb-util1 libxcb-keysyms1 \
libxcb-randr0 libxcb-render-util0 \
libxkbcommon-x11-0 \
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies = [
full = [
'wheel>=0.34.2',
'av>=8,<12',
'PySide2>=5.12,<6',
'PySide6>=6.3,<7',
'qimage2ndarray>=1.6,<2',
'py-notifier>=0.3.0',
'win10toast>=0.9;platform_system=="Windows"',
Expand Down
6 changes: 3 additions & 3 deletions pyrdp/bin/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def main():
sys.exit(1)
elif HAS_GUI and args.format == "mp4":
# Initialize QT because QBitmap will segfault without it (#378, #428)
from PySide2.QtWidgets import QApplication
app = QApplication()
from PySide6.QtWidgets import QApplication
QApplication()

logging.basicConfig(level=logging.CRITICAL)
logging.getLogger("scapy").setLevel(logging.ERROR)
Expand Down Expand Up @@ -100,4 +100,4 @@ def main():
sys.exit(exitCode)

if __name__ == "__main__":
main()
main()
6 changes: 3 additions & 3 deletions pyrdp/bin/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
os.environ['QT_MAC_WANTS_LAYER']='1'
if HAS_GUI:
from pyrdp.player import MainWindow
from PySide2.QtWidgets import QApplication
from PySide6.QtWidgets import QApplication


def enableNotifications(logger):
Expand Down Expand Up @@ -85,8 +85,8 @@ def main():
enableNotifications(logger)

if not HAS_GUI and not args.headless:
logger.error('Headless mode is not specified and PySide2 is not installed.'
' Install PySide2 to use the graphical user interface.')
logger.error('Headless mode is not specified and PySide6 is not installed.'
' Install PySide6 to use the graphical user interface.')
sys.exit(127)

if not args.headless:
Expand Down
4 changes: 2 additions & 2 deletions pyrdp/convert/MP4EventHandler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2020-2021 GoSecure Inc.
# Copyright (C) 2020-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

Expand All @@ -13,7 +13,7 @@

import av
import qimage2ndarray
from PySide2.QtGui import QImage, QPainter, QColor
from PySide6.QtGui import QImage, QPainter, QColor


class MP4Image(ImageHandler):
Expand Down
6 changes: 3 additions & 3 deletions pyrdp/player/AttackerBar.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019 GoSecure Inc.
# Copyright (C) 2019-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import logging

from PySide2.QtCore import Signal
from PySide2.QtWidgets import QHBoxLayout, QWidget, QSpacerItem, QSizePolicy
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QHBoxLayout, QWidget, QSpacerItem, QSizePolicy

from pyrdp.logging import LOGGER_NAMES
from pyrdp.ui import PlayPauseButton
Expand Down
6 changes: 3 additions & 3 deletions pyrdp/player/BaseTab.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2018-2020 GoSecure Inc.
# Copyright (C) 2018-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import logging

from PySide2.QtCore import Qt
from PySide2.QtWidgets import QScrollArea, QTextEdit, QVBoxLayout, QWidget
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QScrollArea, QTextEdit, QVBoxLayout, QWidget

from pyrdp.logging import LOGGER_NAMES
from pyrdp.ui import QRemoteDesktop
Expand Down
13 changes: 9 additions & 4 deletions pyrdp/player/BaseWindow.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2018, 2019 GoSecure Inc.
# Copyright (C) 2018-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import logging
from typing import Dict

from PySide2.QtGui import QKeySequence
from PySide2.QtWidgets import QShortcut, QTabWidget, QWidget
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import QTabWidget, QWidget

from pyrdp.logging import LOGGER_NAMES

Expand All @@ -26,7 +26,12 @@ def __init__(self, options: Dict[str, object], parent: QWidget = None, maxTabCou
self.tabCloseRequested.connect(self.onTabCloseRequest)
self.log = logging.getLogger(LOGGER_NAMES.PLAYER)
self.options = options
self.closeTabShortcut = QShortcut(QKeySequence("Ctrl+W"), self, self.onCtrlW)

# close Tab
closeTabAction = QAction("Close Tab", self)
closeTabAction.setShortcut(QKeySequence("Ctrl+W"))
closeTabAction.triggered.connect(self.onCtrlW)
self.addAction(closeTabAction)

def onTabClosed(self, index: int):
"""
Expand Down
10 changes: 5 additions & 5 deletions pyrdp/player/FileDownloadDialog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019 GoSecure Inc.
# Copyright (C) 2019, 2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#
from PySide2.QtCore import QObject, Qt
from PySide2.QtGui import QCloseEvent
from PySide2.QtWidgets import QDialog, QLabel, QMessageBox, QProgressBar, QPushButton, QVBoxLayout
from PySide6.QtCore import QObject, Qt
from PySide6.QtGui import QCloseEvent
from PySide6.QtWidgets import QDialog, QLabel, QMessageBox, QProgressBar, QPushButton, QVBoxLayout


class FileDownloadDialog(QDialog):
Expand Down Expand Up @@ -110,4 +110,4 @@ def reportCompletion(self, error: int):

def closeEvent(self, event: QCloseEvent):
if not self.isComplete:
event.ignore()
event.ignore()
10 changes: 5 additions & 5 deletions pyrdp/player/FileSystemItem.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019 GoSecure Inc.
# Copyright (C) 2019, 2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#
from typing import Dict

from PySide2.QtCore import QObject
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QFileIconProvider, QListWidgetItem
from PySide6.QtCore import QObject
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QFileIconProvider, QListWidgetItem

from pyrdp.player.filesystem import FileSystemItemType

Expand Down Expand Up @@ -51,4 +51,4 @@ def __lt__(self, other: 'FileSystemItem'):
if self.isDirectory() != other.isDirectory():
return self.isDirectory()

return self.text().upper() < other.text().upper()
return self.text().upper() < other.text().upper()
11 changes: 6 additions & 5 deletions pyrdp/player/FileSystemWidget.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019 GoSecure Inc.
# Copyright (C) 2019, 2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

from pathlib import Path
from typing import Optional

from PySide2.QtCore import QObject, QPoint, Qt, Signal
from PySide2.QtWidgets import QAction, QFileDialog, QFrame, QLabel, QListWidget, QMenu, QMessageBox, QVBoxLayout, QWidget
from PySide6.QtCore import QObject, QPoint, Qt, Signal
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QFileDialog, QFrame, QLabel, QListWidget, QMenu, QMessageBox, QVBoxLayout, QWidget

from pyrdp.player.FileDownloadDialog import FileDownloadDialog
from pyrdp.player.filesystem import Directory, DirectoryObserver, File, FileSystemItemType
Expand Down Expand Up @@ -217,15 +218,15 @@ def downloadDirectoryRecursively(self):

dialog = None
if directoryPath == "":
QMessageBox.critical(self, "Download folder", f"Please select a valid folder. Aborting download.")
QMessageBox.critical(self, "Download folder", "Please select a valid folder. Aborting download.")
return

directoryPath += f"/{selectedFolder.name}"

try:
os.mkdir(directoryPath)
except FileExistsError:
QMessageBox.critical(self, "Download folder", f"Folder already exist. Make sure to select an empty directory. Aborting download.")
QMessageBox.critical(self, "Download folder", "Folder already exist. Make sure to select an empty directory. Aborting download.")
return

dialog = FileDownloadDialog(remotePath, directoryPath, True, self)
Expand Down
8 changes: 4 additions & 4 deletions pyrdp/player/LiveEventHandler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019 GoSecure Inc.
# Copyright (C) 2019, 2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#
from logging import LoggerAdapter
from pathlib import Path, PosixPath
from typing import BinaryIO, Dict, Union

from PySide2.QtCore import Signal
from PySide2.QtWidgets import QTextEdit
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QTextEdit

from pyrdp.enum import DeviceType, PlayerPDUType
from pyrdp.layer import PlayerLayer
Expand Down Expand Up @@ -96,7 +96,7 @@ def addToDownloadQueue(self, item: Union[File, Directory], targetPath: str, dial

self.jobsQueue.add(job)

if self.currentDownload == None:
if self.currentDownload is None:
self.dispatchDownload()

def dispatchDownload(self):
Expand Down
6 changes: 3 additions & 3 deletions pyrdp/player/LiveTab.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2018-2020 GoSecure Inc.
# Copyright (C) 2018-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import asyncio

from PySide2.QtCore import Qt
from PySide2.QtWidgets import QHBoxLayout, QWidget
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QHBoxLayout, QWidget

from pyrdp.mitm.PlayerLayerSet import AsyncIOPlayerLayerSet
from pyrdp.player.AttackerBar import AttackerBar
Expand Down
6 changes: 3 additions & 3 deletions pyrdp/player/LiveThread.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2018 GoSecure Inc.
# Copyright (C) 2018, 2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import asyncio
import logging
from typing import Callable

from PySide2.QtCore import QThread
from PySide6.QtCore import QThread

from pyrdp.logging import LOGGER_NAMES

Expand Down Expand Up @@ -43,4 +43,4 @@ def stop(self):
self.loop.call_soon_threadsafe(self.stopLoop)

def stopLoop(self):
self.loop.stop()
self.loop.stop()
6 changes: 3 additions & 3 deletions pyrdp/player/LiveWindow.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019, 2020 GoSecure Inc.
# Copyright (C) 2019-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import asyncio
from queue import Queue
from typing import Dict

from PySide2.QtCore import Qt, Signal
from PySide2.QtWidgets import QApplication, QFileIconProvider, QMessageBox, QWidget
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QApplication, QFileIconProvider, QMessageBox, QWidget

from pyrdp.player.BaseWindow import BaseWindow
from pyrdp.player.LiveTab import LiveTab
Expand Down
7 changes: 4 additions & 3 deletions pyrdp/player/MainWindow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2018-2020 GoSecure Inc.
# Copyright (C) 2018-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#
from typing import List

from PySide2.QtCore import Qt, Signal
from PySide2.QtWidgets import QAction, QFileDialog, QInputDialog, QMainWindow, QTabWidget
from PySide6.QtCore import Qt, Signal
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QFileDialog, QInputDialog, QMainWindow, QTabWidget

from pyrdp.player import BaseTab
from pyrdp.player.LiveWindow import LiveWindow
Expand Down
10 changes: 5 additions & 5 deletions pyrdp/player/PlayerEventHandler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2018-2020 GoSecure Inc.
# Copyright (C) 2018-2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

from PySide2.QtCore import QObject
from PySide2.QtGui import QTextCursor
from PySide2.QtWidgets import QTextEdit
from PySide6.QtCore import QObject
from PySide6.QtGui import QTextCursor
from PySide6.QtWidgets import QTextEdit

from pyrdp.pdu import PlayerPDU
from pyrdp.enum import CapabilityType
Expand All @@ -15,7 +15,7 @@
from pyrdp.logging import log


class PlayerEventHandler(QObject, RenderingEventHandler):
class PlayerEventHandler(RenderingEventHandler, QObject):
"""
Qt Rendering Sink.
Expand Down
6 changes: 3 additions & 3 deletions pyrdp/player/QTimerSequencer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# This file is part of the PyRDP project.
# Copyright (C) 2019 GoSecure Inc.
# Copyright (C) 2019, 2023 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

from PySide2.QtCore import QTimer
from PySide6.QtCore import QTimer

from pyrdp.core import Sequencer

Expand All @@ -15,4 +15,4 @@ class QTimerSequencer(Sequencer):
"""

def wait(self, waitTime: int):
QTimer.singleShot(waitTime, self.run)
QTimer.singleShot(waitTime, self.run)
Loading

0 comments on commit 7ee1f30

Please sign in to comment.