Skip to content

Commit

Permalink
FIXUP: Put the code in a TracebackWidget class
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Sep 11, 2024
1 parent 763d9b9 commit 857553c
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions dangerzone/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,38 @@ def __init__(self) -> None:
super(WaitingWidget, self).__init__()


class TracebackWidget(QTextEdit):
"""Reusable component to present tracebacks to the user.
By default, the widget is initialized but does not appear.
You need to call `.set_content("traceback")` on it so the
traceback is displayed.
"""

def __init__(self) -> None:
super(TracebackWidget, self).__init__()
# Error
self.setReadOnly(True)
self.setStyleSheet(
"""
QTextEdit {
font-family: Consolas, Monospace;
font-size: 12px;
background-color: #fff;
color: #000;
padding: 10px;
}
"""
)
self.setVisible(False)
# Enable copying
self.setTextInteractionFlags(Qt.TextSelectableByMouse)

def set_content(self, error: str):
self.setPlainText(error)
self.setVisible(True)


class WaitingWidgetContainer(WaitingWidget):
# These are the possible states that the WaitingWidget can show.
#
Expand Down Expand Up @@ -438,29 +470,13 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
self.buttons = QtWidgets.QWidget()
self.buttons.setLayout(buttons_layout)

# Error
self.error_text = QTextEdit()
self.error_text.setReadOnly(True)
self.error_text.setStyleSheet(
"""
QTextEdit {
font-family: Consolas, Monospace;
font-size: 12px;
background-color: #fff;
color: #000;
padding: 10px;
}
"""
)
self.error_text.setVisible(False)
# Enable copying
self.error_text.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.traceback = TracebackWidget()

# Layout
layout = QtWidgets.QVBoxLayout()
layout.addStretch()
layout.addWidget(self.label)
layout.addWidget(self.error_text)
layout.addWidget(self.traceback)
layout.addStretch()
layout.addWidget(self.buttons)
layout.addStretch()
Expand Down Expand Up @@ -529,8 +545,7 @@ def state_change(self, state: str, error: Optional[str] = None) -> None:
"Podman is installed but cannot run properly. See errors below"
)
if error:
self.error_text.setPlainText(error)
self.error_text.setVisible(True)
self.traceback.set_content(error)

self.label.setText(message)

Expand Down

0 comments on commit 857553c

Please sign in to comment.