Skip to content

Commit 477ec07

Browse files
committed
feat: console output on patching page
1 parent 2f0d2b5 commit 477ec07

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

modules/widgets.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
from PySide6.QtWidgets import QWidget, QToolButton, QFrame, QVBoxLayout, QLabel
2-
from PySide6.QtCore import Qt, Signal
1+
import sys
2+
3+
from PySide6.QtWidgets import (
4+
QWidget,
5+
QToolButton,
6+
QFrame,
7+
QVBoxLayout,
8+
QLabel,
9+
QTextEdit,
10+
)
11+
from PySide6.QtCore import Qt, Signal, QObject
12+
from PySide6.QtGui import QTextCursor
313

414

515
class CollapsibleBox(QWidget):
@@ -45,3 +55,30 @@ def __init__(self, text="", parent=None):
4555
def mousePressEvent(self, event):
4656
if event.button() == Qt.MouseButton.LeftButton:
4757
self.clicked.emit()
58+
59+
60+
class ConsoleOutput(QObject):
61+
new_text = Signal(str)
62+
63+
def __init__(self, text_edit: QTextEdit, console: sys):
64+
super().__init__()
65+
self.text_edit = text_edit
66+
self.console = console
67+
68+
# We use a signal here because it otherwise crashes when
69+
# the text comes from a QThread for some reason
70+
self.new_text.connect(self._append_text)
71+
72+
def write(self, message):
73+
self.console.write(message)
74+
self.console.flush()
75+
self.new_text.emit(message)
76+
77+
def flush(self):
78+
pass
79+
80+
def _append_text(self, message):
81+
cursor = self.text_edit.textCursor()
82+
cursor.movePosition(QTextCursor.MoveOperation.End)
83+
cursor.insertText(message)
84+
self.text_edit.setTextCursor(cursor)

setup/patch.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import pathlib
2+
import sys
3+
24
import libWiiPy
35
import tempfile
46
import bsdiff4
@@ -11,8 +13,11 @@
1113
QProgressBar,
1214
QVBoxLayout,
1315
QWizard,
16+
QTextEdit,
17+
QPushButton,
1418
)
1519

20+
from modules.widgets import ConsoleOutput
1621
from .enums import *
1722
from .download import (
1823
download_patch,
@@ -178,6 +183,21 @@ def __init__(self, patches_json: dict, parent=None):
178183
layout.addSpacing(10)
179184
layout.addWidget(self.news_box)
180185

186+
self.console = QTextEdit()
187+
self.console.setReadOnly(True)
188+
self.console.setHidden(True)
189+
190+
# Redirect outputs to the console
191+
sys.stdout = ConsoleOutput(self.console, sys.__stdout__)
192+
sys.stderr = ConsoleOutput(self.console, sys.__stderr__)
193+
194+
layout.addWidget(self.console)
195+
196+
self.toggle_console_button = QPushButton(self.tr("Toggle Console"))
197+
self.toggle_console_button.clicked.connect(self.toggle_console)
198+
199+
layout.addWidget(self.toggle_console_button)
200+
181201
self.setLayout(layout)
182202

183203
QTimer.singleShot(0, lambda: NewsRenderer.getNews(self, self.news_box))
@@ -259,6 +279,10 @@ def handle_error(self, error: str):
259279
f"An exception was encountered while patching.<br><br>Exception:<br>{error}<br><br>Please report this issue in the WiiLink Discord Server (<a href='https://discord.gg/wiilink'>discord.gg/wiilink</a>).",
260280
)
261281

282+
def toggle_console(self):
283+
self.console.setHidden(self.console.isVisible())
284+
self.news_box.setHidden(self.news_box.isVisible())
285+
262286

263287
class PatchingWorker(QObject):
264288
platform: Platforms
@@ -288,7 +312,6 @@ def patching_functions(self):
288312
for channel_key in self.selected_channels:
289313
channel_indexes = channel_key.split("_")
290314
try:
291-
raise ValueError("penis 2")
292315
category_index = int(channel_indexes[0])
293316
channel_index = int(channel_indexes[1])
294317
channel_category = self.find_category(category_index)

style.qss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,9 @@ QScrollArea > QWidget > QScrollBar { background: palette(base); padding:0px; mar
338338

339339
QMessageBox {
340340
background-color: #222222;
341+
}
342+
343+
QTextEdit {
344+
background-color: #111111;
345+
color: #FFFFFF;
341346
}

0 commit comments

Comments
 (0)