Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Migrate to PySide6 / Qt6 #176

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ clean: semi-clean

# build
build-ui: $(UI_FILES)
$(VENV_BIN)/pyrcc5 $(UI_FILES_PATH)/resources.qrc -o $(UI_FILES_PATH)/resources_rc.py
$(foreach var,$(UI_FILES),$(VENV_BIN)/pyuic5 --from-imports $(var) -o $(subst .ui,.py,$(var));)
#pyside6-rcc $(UI_FILES_PATH)/resources.qrc -o $(UI_FILES_PATH)/resources_rc.py
#$(foreach var,$(UI_FILES),pyside6-uic --from-imports $(var) -o $(subst .ui,.py,$(var));)

build: build-ui
poetry build
Expand Down
2 changes: 1 addition & 1 deletion nitrokeyapp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from types import TracebackType
from typing import Any, Callable, Generator, Optional, Type

from PyQt5 import QtWidgets
from PySide6 import QtWidgets
from qt_material import apply_stylesheet

from nitrokeyapp import get_theme_path
Expand Down
16 changes: 9 additions & 7 deletions nitrokeyapp/about_dialog.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
from PyQt5 import QtWidgets
from PyQt5.QtCore import pyqtSlot
from PySide6 import QtWidgets
from PySide6.QtCore import Slot

from nitrokeyapp import __version__
from nitrokeyapp.logger import save_log
from nitrokeyapp.qt_utils_mix_in import QtUtilsMixIn
from nitrokeyapp.ui.aboutdialog import Ui_AboutDialog


## unused ?


class AboutDialog(QtUtilsMixIn, QtWidgets.QDialog):
def __init__(self, log_file: str, qt_app: QtWidgets.QApplication) -> None:
QtWidgets.QDialog.__init__(self)
QtWidgets.QDialog.__init__(self, parent)
QtUtilsMixIn.__init__(self)

self.log_file = log_file

self.app = qt_app
self.ui = Ui_AboutDialog()
self.ui.setupUi(self)
self.ui = self.load_ui("aboutdialog.ui", parent)

self.ui.ButtonOK.clicked.connect(self.close)
self.ui.buttonSaveLog.pressed.connect(self.save_log)
self.ui.VersionLabel.setText(__version__)

@pyqtSlot()
@Slot()
def save_log(self) -> None:
save_log(self.log_file, self)
16 changes: 8 additions & 8 deletions nitrokeyapp/add_secret_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from base64 import b32decode
from typing import Optional

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QWidget
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QDialog, QDialogButtonBox, QWidget

from nitrokeyapp.qt_utils_mix_in import QtUtilsMixIn
from nitrokeyapp.secrets_tab.data import Credential, OtpKind
from nitrokeyapp.ui.add_secret_dialog import Ui_AddSecretDialog

# TODO:
# - max length
Expand All @@ -16,12 +16,12 @@
DEFAULT_OTP_KIND = OtpKind.TOTP


class AddSecretDialog(QDialog):
class AddSecretDialog(QtUtilsMixIn, QDialog):
def __init__(self, parent: Optional[QWidget] = None) -> None:
super().__init__(parent)
QDialog.__init__(self, parent)
QtUtilsMixIn.__init__(self)

self.ui = Ui_AddSecretDialog()
self.ui.setupUi(self)
self.ui = self.load_ui("add_secret_dialog.ui", self)

for kind in OtpKind:
self.ui.comboBoxOtpType.addItem(str(kind))
Expand All @@ -32,7 +32,7 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:

self.refresh()

@pyqtSlot()
@Slot()
def refresh(self) -> None:
errors = []

Expand Down
8 changes: 4 additions & 4 deletions nitrokeyapp/bak/change_pin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def __init__(self, parent: Optional[QtWidgets.QWidget] = None) -> None:
self.ui = Ui_ChangePinDialog()
self.ui.setupUi(self)
self.current_pin = self.ui.lineEdit_current_pin
self.current_pin.setEchoMode(QtWidgets.QLineEdit.Password)
self.current_pin.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.new_pin = self.ui.lineEdit_new_pin
self.new_pin.setEchoMode(QtWidgets.QLineEdit.Password)
self.new_pin.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.confirm_new_pin = self.ui.lineEdit_confirm_new_pin
self.confirm_new_pin.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirm_new_pin.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
# self.buttons = self.get_widget(QtWidgets.QDialogButtonBox, "buttonBox")
self.btn_ok = self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
self.btn_ok = self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.confirm_new_pin.textChanged.connect(self.same_pin)
self.new_pin.textChanged.connect(self.same_pin)
self.btn_ok.setEnabled(False)
Expand Down
6 changes: 3 additions & 3 deletions nitrokeyapp/bak/clock_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def maximum(self):

def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)

size = min(self.width(), self.height())
progress_radius = size / 4 - 2 - 10
Expand All @@ -35,14 +35,14 @@ def paintEvent(self, event):
progress_x, progress_y, 2 * progress_radius, 2 * progress_radius
)
progress_angle = self._value / self._max * 360
painter.setPen(QPen(Qt.blue, 6, Qt.SolidLine))
painter.setPen(QPen(Qt.GlobalColor.blue, 6, Qt.PenStyle.SolidLine))

path = QPainterPath()
path.arcMoveTo(progress_rect, -90)
path.arcTo(progress_rect, -90, -progress_angle)
painter.drawPath(path)

painter.setPen(Qt.black)
painter.setPen(Qt.GlobalColor.black)
painter.setFont(self.font())

text = str(self._value)
Expand Down
6 changes: 3 additions & 3 deletions nitrokeyapp/bak/key_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ def __init__(self, qt_app: QtWidgets.QApplication):
@pyqtSlot()
def finish_show_hide(self):
if self.with_backup.isChecked():
self.button(QtWidgets.QWizard.FinishButton).setEnabled(False)
self.button(QtWidgets.QWizard.WizardButton.FinishButton).setEnabled(False)
self.lastpage_keygen.cleanupPage()
self.confirm_path.setEnabled(True)
self.back_up_info.show()
else:
self.button(QtWidgets.QWizard.FinishButton).setEnabled(True)
self.button(QtWidgets.QWizard.WizardButton.FinishButton).setEnabled(True)
self.lastpage_keygen.cleanupPage()
self.confirm_path.setEnabled(False)
self.back_up_info.hide()

def finish_show_hide_2(self):
if self.confirm_path.text():
self.button(QtWidgets.QWizard.FinishButton).setEnabled(True)
self.button(QtWidgets.QWizard.WizardButton.FinishButton).setEnabled(True)

def adsettings_func(self):
self.collapse(self.adsettings, self.adsettings_button)
Expand Down
2 changes: 1 addition & 1 deletion nitrokeyapp/bak/loading_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LoadingScreen(QtWidgets.QWidget):
# def __init__(self):
# super().__init__()
# self.setFixedSize(128,128) #128 128
# self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.CustomizeWindowHint)
# self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.CustomizeWindowHint)

# self.label_animation = QLabel(self)
# self.qprogressbar = QProgressBar(self)
Expand Down
4 changes: 2 additions & 2 deletions nitrokeyapp/bak/passwordsafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def table_pws_function(self):
self.qr_code.hide()
self.random_otp.hide()
self.copy_otp.hide()
self.pws_editOTP.setEchoMode(QtWidgets.QLineEdit.Password)
self.pws_editOTP.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.show_hide_btn_2.hide()


Expand Down Expand Up @@ -151,7 +151,7 @@ def add_pws(self):
self.qr_code.show()
self.random_otp.show()
self.copy_otp.show()
self.pws_editOTP.setEchoMode(QtWidgets.QLineEdit.Normal)
self.pws_editOTP.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
self.show_hide_btn_2.show()


Expand Down
4 changes: 2 additions & 2 deletions nitrokeyapp/bak/pin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def invoke(self, opts: dict[str, Any]) -> None:
@pyqtSlot(int)
def checkbox_toggled(self, state: int) -> None:
if state == 0:
self.line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
self.line_edit.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
elif state == 2:
self.line_edit.setEchoMode(QtWidgets.QLineEdit.Normal)
self.line_edit.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)

@pyqtSlot()
def ok_clicked(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions nitrokeyapp/bak/set_pin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def __init__(self, parent=None):
self.ui = Ui_ChangePinDialog()
self.ui.setupUi(self)
self.new_pin = self.ui.lineEdit_new_pin_set
self.new_pin.setEchoMode(QtWidgets.QLineEdit.Password)
self.new_pin.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.confirm_new_pin = self.ui.lineEdit_confirm_new_pin_set
self.confirm_new_pin.setEchoMode(QtWidgets.QLineEdit.Password)
self.btn_ok = self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
self.confirm_new_pin.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.btn_ok = self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.confirm_new_pin.textChanged.connect(self.same_pin)
self.new_pin.textChanged.connect(self.same_pin)
self.btn_ok.setEnabled(False)
Expand Down
14 changes: 7 additions & 7 deletions nitrokeyapp/bak/setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ def __init__(self, qt_app: QtWidgets.QApplication):

def same_setup_wizard(self):
if self.userpin_1.text() != self.userpin_2.text():
self.button(QtWidgets.QWizard.NextButton).setEnabled(False)
self.button(QtWidgets.QWizard.WizardButton.NextButton).setEnabled(False)
else:
self.button(QtWidgets.QWizard.NextButton).setEnabled(True)
self.button(QtWidgets.QWizard.WizardButton.NextButton).setEnabled(True)

def same_setup_wizard_2(self):
if self.adminpin_1.text() != self.adminpin_2.text():
self.button(QtWidgets.QWizard.FinishButton).setEnabled(False)
self.button(QtWidgets.QWizard.WizardButton.FinishButton).setEnabled(False)
else:
self.button(QtWidgets.QWizard.FinishButton).setEnabled(True)
self.button(QtWidgets.QWizard.WizardButton.FinishButton).setEnabled(True)

def closeEvent(self, event):
reply = QtWidgets.QMessageBox.question(
self,
"Message",
"Are you sure to exit?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No,
QtWidgets.QMessageBox.StandardButton.No,
)

if reply == QtWidgets.QMessageBox.Yes:
if reply == QtWidgets.QMessageBox.StandardButton.Yes:
event.accept()

else:
Expand Down
4 changes: 2 additions & 2 deletions nitrokeyapp/bak/storage_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def init_storage(self):

def same_storage(self):
if self.hidden_pw_2.text() != self.hidden_pw_1.text():
self.button(QtWidgets.QWizard.NextButton).setEnabled(False)
self.button(QtWidgets.QWizard.WizardButton.NextButton).setEnabled(False)
else:
self.button(QtWidgets.QWizard.NextButton).setEnabled(True)
self.button(QtWidgets.QWizard.WizardButton.NextButton).setEnabled(True)

@pyqtSlot(int)
# storage wizard
Expand Down
2 changes: 1 addition & 1 deletion nitrokeyapp/device_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, Protocol

from PyQt5.QtWidgets import QWidget
from PySide6.QtWidgets import QWidget

from nitrokeyapp.device_data import DeviceData
from nitrokeyapp.worker import Worker
Expand Down
17 changes: 9 additions & 8 deletions nitrokeyapp/error_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from types import TracebackType
from typing import Optional, Type

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QPushButton, QWidget
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QDialog, QDialogButtonBox, QPushButton, QWidget

from nitrokeyapp.qt_utils_mix_in import QtUtilsMixIn
from nitrokeyapp.logger import save_log
from nitrokeyapp.ui.error_dialog import Ui_ErrorDialog


class ErrorDialog(QDialog):
class ErrorDialog(QtUtilsMixIn, QDialog):
def __init__(self, log_file: str, parent: Optional[QWidget] = None) -> None:
super().__init__(parent)
QDialog.__init__(self, parent)
QtUtilsMixIn.__init__(self)

self.log_file = log_file

self.ui = Ui_ErrorDialog()
self.ui.setupUi(self)
self.ui = self.load_ui("error_dialog.ui", self)

self.button_save_log = QPushButton("Save Log File", self)
self.button_save_log.pressed.connect(self.save_log)
Expand All @@ -33,7 +33,8 @@ def set_exception(
) -> None:
lines = format_exception(ty, e, tb)
self.ui.textEditDetails.setPlainText("".join(lines))
self.show()

@pyqtSlot()
@Slot()
def save_log(self) -> None:
save_log(self.log_file, self)
Loading
Loading