Strip ANSI colors from Mac GUI output to preventing crashing, and fix Mac docker path

This commit is contained in:
Micah Lee 2021-06-22 13:34:15 -07:00
parent b92ae1c592
commit d3d417ee84
4 changed files with 35 additions and 3 deletions

View file

@ -9,7 +9,7 @@ import os
# What is the container runtime for this platform?
if platform.system() == "Darwin":
container_tech = "docker"
container_runtime = shutil.which("docker")
container_runtime = "/usr/local/bin/docker"
elif platform.system() == "Windows":
container_tech = "docker"
container_runtime = shutil.which("docker.exe")

View file

@ -5,6 +5,7 @@ import platform
import click
import uuid
from PySide2 import QtCore, QtWidgets
from strip_ansi import strip_ansi
from .common import GuiCommon
from .main_window import MainWindow
@ -48,10 +49,28 @@ class ApplicationWrapper(QtCore.QObject):
@click.option("--custom-container") # Use this container instead of flmcode/dangerzone
@click.argument("filename", required=False)
def gui_main(custom_container, filename):
# Required for macOS Big Sur: https://stackoverflow.com/a/64878899
if platform.system() == "Darwin":
# Required for macOS Big Sur: https://stackoverflow.com/a/64878899
os.environ["QT_MAC_WANTS_LAYER"] = "1"
# Strip ANSI colors from stdout output, to prevent terminal colors from breaking
# the macOS GUI app
class StdoutFilter:
def __init__(self, stream):
self.stream = stream
def __getattr__(self, attr_name):
return getattr(self.stream, attr_name)
def write(self, data):
self.stream.write(strip_ansi(data))
def flush(self):
self.stream.flush()
sys.stdout = StdoutFilter(sys.stdout)
sys.stderr = StdoutFilter(sys.stderr)
# Create the Qt app
app_wrapper = ApplicationWrapper()
app = app_wrapper.app

14
poetry.lock generated
View file

@ -296,6 +296,14 @@ category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.10"
[[package]]
name = "strip-ansi"
version = "0.1.1"
description = "Strip ANSI escape sequences from a string"
category = "main"
optional = false
python-versions = ">=3.6,<4.0"
[[package]]
name = "termcolor"
version = "1.1.0"
@ -374,7 +382,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt
[metadata]
lock-version = "1.1"
python-versions = ">=3.7,<3.10"
content-hash = "72592722794667cf7cb6bea727b31eb60d710c90d488be9d10a13bbbcaa56688"
content-hash = "6db74c36125b2d3ad4d04c864c24ecbcf376d5ac75ee7402d950010cade5de96"
[metadata.files]
altgraph = [
@ -551,6 +559,10 @@ shiboken2 = [
{file = "shiboken2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-none-win32.whl", hash = "sha256:89c157a0e2271909330e1655892e7039249f7b79a64a443d52c512337065cde0"},
{file = "shiboken2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-none-win_amd64.whl", hash = "sha256:14a33169cf1bd919e4c4c4408fffbcd424c919a3f702df412b8d72b694e4c1d5"},
]
strip-ansi = [
{file = "strip-ansi-0.1.1.tar.gz", hash = "sha256:5d60f239cc8a37fdd52b43c3e66e893d45ba0423115db59eca0d2eef83b07729"},
{file = "strip_ansi-0.1.1-py3-none-any.whl", hash = "sha256:9f55280e1b0ba84dac49d4f18aa6b51b90ff766b22e4918ffc01cc87b394ecd1"},
]
termcolor = [
{file = "termcolor-1.1.0.tar.gz", hash = "sha256:1d6d69ce66211143803fbc56652b41d73b4a400a2891d7bf7a1cdf4c02de613b"},
]

View file

@ -19,6 +19,7 @@ pyxdg = {version = "*", platform = "linux"}
pyobjc-core = {version = "*", platform = "darwin"}
pyobjc-framework-launchservices = {version = "*", platform = "darwin"}
colorama = "^0.4.4"
strip-ansi = "^0.1.1"
[tool.poetry.dev-dependencies]
pyinstaller = {version = "*", platform = "darwin"}