Skip to content

Commit

Permalink
Merge pull request bitcraze#676 from bitcraze/krichardsson/qt6-v2
Browse files Browse the repository at this point in the history
Switch to Qt6
  • Loading branch information
krichardsson authored Sep 11, 2023
2 parents d387b70 + 09ac6f4 commit 0bb1dc7
Show file tree
Hide file tree
Showing 40 changed files with 315 additions and 2,781 deletions.
2 changes: 1 addition & 1 deletion docs/development/dev_info_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ same kind of information is available here for the Crazyflie Python API.

Here\'s a quick overview:

- The GUI is made in QT5 (using QTDesigner 4 and loading the .ui files
- The GUI is made in QT6 (using QTDesigner and loading the .ui files
at runtime)
- It uses the SDL2 to read input devices on Windows/Mac OSX and raw
jsdevs on Linux. It also supports custom input from
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ def relative(lst, base=''):
'pyzmq~=25.0',
'pyqtgraph~=0.11',
'PyYAML~=6.0.1',
'qasync~=0.23.0',
'qtm~=2.1.1',
'numpy>=1.20,<1.25',
'vispy~=0.13.0',
'pyserial~=3.5',
'pyqt5~=5.15.0',
'PyQt5-sip>=12.9.0',
'pyqt6~=6.5',
'PyQt6-sip~=13.5',

'pysdl2~=0.9.14 ; platform_system=="Windows" or platform_system=="Darwin"',
'pysdl2-dll==2.24.0 ; platform_system=="Windows" or platform_system=="Darwin"'],
Expand Down
22 changes: 8 additions & 14 deletions src/cfclient/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2011-2013 Bitcraze AB
# Copyright (C) 2011-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand All @@ -29,14 +29,12 @@
import platform
import sys
import os
import asyncio
import argparse
import datetime
import signal

import logging

from qasync import QEventLoop
import cfclient

__author__ = 'Bitcraze AB'
Expand Down Expand Up @@ -69,8 +67,8 @@ def main():
os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = os.path.dirname(
sys.executable)

# Set ERROR level for PyQt5 logger
qtlogger = logging.getLogger('PyQt5')
# Set ERROR level for PyQt logger
qtlogger = logging.getLogger('PyQt6')
qtlogger.setLevel(logging.ERROR)

parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -125,9 +123,9 @@ def main():
sys.exit(1)

try:
import PyQt5 # noqa
import PyQt6 # noqa
except ImportError:
logger.critical("No PyQT5 installation found, exiting!")
logger.critical("No PyQT6 installation found, exiting!")
sys.exit(1)

# Disable printouts from STL
Expand Down Expand Up @@ -162,8 +160,8 @@ def main():

# Start up the main user-interface
from .ui.main import MainUI
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon
from PyQt6.QtWidgets import QApplication
from PyQt6.QtGui import QIcon

if os.name == 'posix':
logger.info('If startup fails because of "xcb", install dependency with `sudo apt install libxcb-xinerama0`.')
Expand All @@ -172,10 +170,6 @@ def main():
app.setStyle("Fusion")
from cfclient.utils.ui import UiUtils

# Create and set an event loop that combines qt and asyncio
loop = QEventLoop(app)
asyncio.set_event_loop(loop)

app.setWindowIcon(QIcon(cfclient.module_path + "/ui/icons/icon-256.png"))
app.setApplicationName("Crazyflie client")
# Make sure the right icon is set in Windows 7+ taskbar
Expand All @@ -193,7 +187,7 @@ def main():
app.setFont(UiUtils.FONT)
main_window.show()
main_window.set_default_theme()
sys.exit(app.exec_())
sys.exit(app.exec())


if __name__ == "__main__":
Expand Down
12 changes: 6 additions & 6 deletions src/cfclient/ui/connectivity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2021 Bitcraze AB
# Copyright (C) 2021-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand All @@ -26,7 +26,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
from collections import namedtuple
from PyQt5.QtCore import pyqtSignal, QObject
from PyQt6.QtCore import pyqtSignal, QObject

__author__ = 'Bitcraze AB'
__all__ = ['ConnectivityManager']
Expand Down Expand Up @@ -66,8 +66,7 @@ def register_ui_elements(self, ui_elements):
ui_elements.address_spinner.valueChanged.connect(self._address_changed_handler)
ui_elements.address_spinner.editingFinished.connect(self._address_edited_handler)

ui_elements.interface_combo.currentIndexChanged['QString'].connect(
self._interface_combo_current_index_changed_handler)
ui_elements.interface_combo.currentIndexChanged.connect(self._interface_combo_current_index_changed_handler)

def set_state(self, state):
if self._state != state:
Expand Down Expand Up @@ -149,11 +148,12 @@ def _address_edited_handler(self):
ui_elements.address_spinner.setValue(value)

def _interface_combo_current_index_changed_handler(self, interface):
interface_s = str(interface)
can_connect = interface != self.INTERFACE_PROMPT_TEXT
for ui_elements in self._ui_elements:
combo = ui_elements.interface_combo
if combo.currentText != interface:
combo.setCurrentText(interface)
if combo.currentText != interface_s:
combo.setCurrentText(interface_s)
ui_elements.connect_button.setEnabled(can_connect)

def _update_ui(self):
Expand Down
12 changes: 6 additions & 6 deletions src/cfclient/ui/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2011-2013 Bitcraze AB
# Copyright (C) 2011-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand All @@ -31,11 +31,11 @@

import cfclient
import cflib.crtp
from PyQt5.QtCore import QT_VERSION_STR
from PyQt5.QtCore import PYQT_VERSION_STR
from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.QtCore import pyqtSignal
from PyQt6.QtCore import QT_VERSION_STR
from PyQt6.QtCore import PYQT_VERSION_STR
from PyQt6 import QtWidgets
from PyQt6 import uic
from PyQt6.QtCore import pyqtSignal
from cflib.crazyflie.mem import MemoryElement

__author__ = 'Bitcraze AB'
Expand Down
42 changes: 21 additions & 21 deletions src/cfclient/ui/dialogs/anchor_position_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2018 Bitcraze AB
# Copyright (C) 2018-2023 Bitcraze AB
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -29,11 +29,11 @@

import cfclient
from cfclient.utils.logconfigreader import FILE_REGEX_YAML
from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.QtCore import QAbstractTableModel, QVariant, Qt
from PyQt5.QtGui import QBrush, QColor
from PyQt5.QtWidgets import QInputDialog, QFileDialog
from PyQt6 import QtWidgets
from PyQt6 import uic
from PyQt6.QtCore import QAbstractTableModel, QVariant, Qt
from PyQt6.QtGui import QBrush, QColor
from PyQt6.QtWidgets import QInputDialog, QFileDialog
import yaml
import os

Expand Down Expand Up @@ -68,30 +68,30 @@ def data(self, index, role=None):
value = self._anchor_positions[index.row()][index.column()]
if index.isValid():
if index.column() == 0:
if role == Qt.CheckStateRole:
if role == Qt.ItemDataRole.CheckStateRole:
return QVariant(value)
elif index.column() == 1:
if role == Qt.DisplayRole:
if role == Qt.ItemDataRole.DisplayRole:
return QVariant(value)
else:
if role == Qt.DisplayRole:
if role == Qt.ItemDataRole.DisplayRole:
return QVariant('%.2f' % (value))
elif role == Qt.EditRole:
elif role == Qt.ItemDataRole.EditRole:
return QVariant(value)
elif role == Qt.BackgroundRole:
elif role == Qt.ItemDataRole.BackgroundRole:
return self._get_background(index.row(), index.column())

return QVariant()

def setData(self, index, value, role=Qt.EditRole):
def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
if not index.isValid():
return False

self._anchor_positions[index.row()][index.column()] = value
return True

def headerData(self, col, orientation, role=None):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
if orientation == Qt.Orientation.Horizontal and role == Qt.ItemDataRole.DisplayRole:
return QVariant(self._headers[col])
return QVariant()

Expand All @@ -100,11 +100,11 @@ def flags(self, index):
return None

if index.column() == 0:
return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable
return Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsUserCheckable
elif index.column() == 1:
return Qt.ItemIsEnabled
return Qt.ItemFlag.ItemIsEnabled
else:
return Qt.ItemIsEnabled | Qt.ItemIsEditable
return Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsEditable

def add_anchor(self, anchor_id, x=0.0, y=0.0, z=0.0):
if not self._id_exist(anchor_id):
Expand Down Expand Up @@ -176,11 +176,11 @@ def __init__(self, lps_tab, helper):
self._table_view.verticalHeader().setVisible(False)

header = self._table_view.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(3, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(4, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(4, QtWidgets.QHeaderView.ResizeMode.Stretch)

self._add_anchor_button.clicked.connect(
self._add_anchor_button_clicked)
Expand Down
10 changes: 5 additions & 5 deletions src/cfclient/ui/dialogs/basestation_mode_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2011-2013 Bitcraze AB
# Copyright (C) 2011-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand All @@ -27,9 +27,9 @@
Toolbox used to interact with the Basestation to set it in a certain channel
"""

from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt6 import QtWidgets
from PyQt6 import uic
from PyQt6.QtCore import Qt

import io
import serial
Expand Down Expand Up @@ -154,7 +154,7 @@ def disable(self):
return

def preferedDockArea(self):
return Qt.RightDockWidgetArea
return Qt.DockWidgetArea.RightDockWidgetArea

def _find_basestation(self):
ports = comports()
Expand Down
6 changes: 3 additions & 3 deletions src/cfclient/ui/dialogs/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2011-2013 Bitcraze AB
# Copyright (C) 2011-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand Down Expand Up @@ -44,8 +44,8 @@
from urllib.error import URLError
import zipfile

from PyQt5 import QtWidgets, uic
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QThread
from PyQt6 import QtWidgets, uic
from PyQt6.QtCore import pyqtSlot, pyqtSignal, QThread

import cfclient
import cflib.crazyflie
Expand Down
8 changes: 4 additions & 4 deletions src/cfclient/ui/dialogs/cf2config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2011-2013 Bitcraze AB
# Copyright (C) 2011-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand All @@ -32,9 +32,9 @@
import cfclient
from cflib.crazyflie.mem import MemoryElement

from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.QtCore import pyqtSignal
from PyQt6 import QtWidgets
from PyQt6 import uic
from PyQt6.QtCore import pyqtSignal

__author__ = 'Bitcraze AB'
__all__ = ['Cf2ConfigDialog']
Expand Down
19 changes: 9 additions & 10 deletions src/cfclient/ui/dialogs/inputconfigdialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2011-2017 Bitcraze AB
# Copyright (C) 2011-2023 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
Expand All @@ -30,15 +30,14 @@
import logging

import cfclient
from PyQt5.QtCore import QThread
from PyQt5.QtCore import QTimer
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QMessageBox
from PyQt6.QtCore import Qt
from PyQt6.QtCore import QThread
from PyQt6.QtCore import QTimer
from PyQt6.QtCore import pyqtSignal
from PyQt6.QtWidgets import QMessageBox
from cfclient.utils.config_manager import ConfigManager
from PyQt5 import Qt
from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.Qt import * # noqa
from PyQt6 import QtWidgets
from PyQt6 import uic

__author__ = 'Bitcraze AB'
__all__ = ['InputConfigDialogue']
Expand Down Expand Up @@ -213,7 +212,7 @@ def _show_config_popup(self, caption, message, directions=[]):
self.cancelButton = QtWidgets.QPushButton('Cancel')
self._popup.addButton(self.cancelButton, QMessageBox.DestructiveRole)
self._popup.setWindowTitle(caption)
self._popup.setWindowFlags(Qt.Dialog | Qt.MSWindowsFixedSizeDialogHint)
self._popup.setWindowFlags(Qt.WindowType.Dialog | Qt.WindowType.MSWindowsFixedSizeDialogHint)
if len(directions) > 1:
self._popup.originalMessage = message
message = self._popup.originalMessage % directions[0]
Expand Down
Loading

0 comments on commit 0bb1dc7

Please sign in to comment.