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

Adds PySide 6 Support For Windows and MacOS #296

Merged
merged 3 commits into from
Feb 7, 2023
Merged
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
11 changes: 10 additions & 1 deletion dangerzone/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
import platform
import signal
import sys
import typing
import uuid
from typing import Dict, List, Optional

import click
import colorama
from PySide2 import QtCore, QtGui, QtWidgets

# FIXME: See https://github.com/freedomofpress/dangerzone/issues/320 for more details.
if typing.TYPE_CHECKING:
from PySide2 import QtCore, QtGui, QtWidgets
else:
try:
from PySide6 import QtCore, QtGui, QtWidgets
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets

from .. import args, errors
from ..document import Document
Expand Down
15 changes: 12 additions & 3 deletions dangerzone/gui/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
import platform
import shlex
import subprocess
import typing
from pathlib import Path
from typing import Dict

from colorama import Fore
from PySide2 import QtCore, QtGui, QtWidgets

# FIXME: See https://github.com/freedomofpress/dangerzone/issues/320 for more details.
if typing.TYPE_CHECKING:
from PySide2 import QtCore, QtGui, QtWidgets
else:
try:
from PySide6 import QtCore, QtGui, QtWidgets
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets

if platform.system() == "Linux":
from xdg.DesktopEntry import DesktopEntry
Expand Down Expand Up @@ -176,13 +185,13 @@ def __init__(
self.setLayout(layout)

def clicked_ok(self) -> None:
self.done(QtWidgets.QDialog.Accepted)
self.done(int(QtWidgets.QDialog.Accepted))

def clicked_extra(self) -> None:
self.done(2)

def clicked_cancel(self) -> None:
self.done(QtWidgets.QDialog.Rejected)
self.done(int(QtWidgets.QDialog.Rejected))

def launch(self) -> int:
return self.exec_()
25 changes: 17 additions & 8 deletions dangerzone/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
import shutil
import subprocess
import tempfile
import typing
from multiprocessing.pool import ThreadPool
from typing import List, Optional

from colorama import Fore, Style
from PySide2 import QtCore, QtGui, QtWidgets

# FIXME: See https://github.com/freedomofpress/dangerzone/issues/320 for more details.
if typing.TYPE_CHECKING:
from PySide2 import QtCore, QtGui, QtWidgets
else:
try:
from PySide6 import QtCore, QtGui, QtWidgets
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets

from .. import errors
from ..document import SAFE_EXTENSION, Document
Expand Down Expand Up @@ -46,7 +55,7 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
header_label.setFont(self.dangerzone.fixed_font)
header_label.setStyleSheet("QLabel { font-weight: bold; font-size: 50px; }")
header_version_label = QtWidgets.QLabel(get_version())
header_version_label.setProperty("class", "version") # type: ignore [arg-type]
header_version_label.setProperty("class", "version")
header_version_label.setAlignment(QtCore.Qt.AlignBottom)

header_layout = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -363,7 +372,7 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
self.docs_selected_label = QtWidgets.QLabel("No documents selected")
self.docs_selected_label.setAlignment(QtCore.Qt.AlignCenter)
self.docs_selected_label.setContentsMargins(0, 0, 0, 20)
self.docs_selected_label.setProperty("class", "docs-selection") # type: ignore [arg-type]
self.docs_selected_label.setProperty("class", "docs-selection")

# Save safe version
self.save_checkbox = QtWidgets.QCheckBox()
Expand All @@ -373,9 +382,7 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
self.safe_extension_label = QtWidgets.QLabel("Save as")
self.safe_extension_filename = QtWidgets.QLabel("document")
self.safe_extension_filename.setAlignment(QtCore.Qt.AlignRight)
self.safe_extension_filename.setProperty(
"style", "safe_extension_filename" # type: ignore
)
self.safe_extension_filename.setProperty("style", "safe_extension_filename")
self.safe_extension = QtWidgets.QLineEdit()
self.safe_extension.setStyleSheet("margin-left: -6px;") # no left margin
self.safe_extension.textChanged.connect(self.update_ui)
Expand All @@ -387,8 +394,10 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
self.safe_extension_name_layout.addWidget(self.safe_extension_filename)
self.safe_extension_name_layout.addWidget(self.safe_extension)

dot_pdf_regex = QtCore.QRegExp(r".*\.[Pp][Dd][Ff]")
self.safe_extension.setValidator(QtGui.QRegExpValidator(dot_pdf_regex))
dot_pdf_regex = QtCore.QRegularExpression(r".*\.[Pp][Dd][Ff]")
self.safe_extension.setValidator(
QtGui.QRegularExpressionValidator(dot_pdf_regex)
)
self.safe_extension_layout = QtWidgets.QHBoxLayout()
self.safe_extension_layout.addWidget(self.save_checkbox)
self.safe_extension_layout.addWidget(self.safe_extension_label)
Expand Down
4 changes: 0 additions & 4 deletions install/windows/build-wxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def build_data(dirname, dir_prefix, id_, name):
else:
id_prefix = id_

# Skip lib/Pyside2/Examples folder
if "\\build\\exe.win-amd64-3.10\\lib\\PySide2\\examples" in dirname:
continue

id_value = f"{id_prefix}{basename.capitalize().replace('-', '_')}"
data["dirs"].append(
build_data(
Expand Down
92 changes: 80 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ license = "MIT"
python = ">=3.7,<3.11"
click = "*"
appdirs = "*"
PySide2 = "5.15.2.1"
PySide2 = {version = "5.15.2.1", platform = "linux"}
PySide6 = {version = "^6.4.1", markers = "sys_platform == 'win32' or sys_platform == 'darwin'"}
colorama = "*"
pyxdg = {version = "*", platform = "linux"}

Expand All @@ -30,7 +31,7 @@ pyinstaller = {version = "*", platform = "darwin"}
black = "*"
isort = "*"
mypy = "*"
PySide2-stubs = "*"
types-PySide2 = "*"

# Dependencies required for testing the code.
[tool.poetry.group.test.dependencies]
Expand Down