From a23a2f6dea1be750fbe9462fce25a49b8f1cb61b Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 14 Nov 2026 10:47:41 +0100 Subject: Toolbar buttons get 32px icons with the label under the icon. sd-cli prints its tile progress bar on stdout, which was never read. Merge stdout and stderr, parse the last "n/m -" step and show it in a status bar progress bar. Before the first step it shows a busy bar, so a long model load does not look like a hang. Co-Authored-By: Claude Opus 5.5 --- test_upscale_qt.py | 7 +++++++ upscale-qt | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/test_upscale_qt.py b/test_upscale_qt.py index 37e0484..7d7307c 100644 --- a/test_upscale_qt.py +++ b/test_upscale_qt.py @@ -60,6 +60,13 @@ def test_args(): '-i', '/in.png', '-o', '/out.png'] +def test_progress(): + out = (b'[I] upscaling\n\r |====> | 1/4 - 1.09it/s\x1b[K' + b'\r |=======> | 2/4 - 3.89it/s\x1b[K') + assert uq.progress(out) == (2, 4) + assert uq.progress(b'[I] load model') is None + + def test_save_over(): path = os.path.join(TMP, 'photo.JPG') # uppercase suffix on purpose small = QImage(4, 4, QImage.Format.Format_RGB32) diff --git a/upscale-qt b/upscale-qt index 5b7ffad..a343439 100755 --- a/upscale-qt +++ b/upscale-qt @@ -16,16 +16,18 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os +import re import sys from dataclasses import dataclass from pathlib import Path -from PyQt6.QtCore import QPointF, QProcess, QRectF, QSettings, QTemporaryDir, Qt +from PyQt6.QtCore import QPointF, QProcess, QRectF, QSettings, QSize, QTemporaryDir, Qt from PyQt6.QtGui import (QAction, QColor, QIcon, QImage, QImageReader, QKeySequence, QPainter, QPen) from PyQt6.QtWidgets import (QApplication, QComboBox, QDialog, QDialogButtonBox, QFileDialog, QFormLayout, - QLineEdit, QMainWindow, QMessageBox, QWidget) + QLineEdit, QMainWindow, QMessageBox, + QProgressBar, QWidget) MODEL_EXTS = ('.pth', '.safetensors', '.gguf') JPEG_QUALITY = 95 @@ -82,6 +84,12 @@ def tail(data, lines=15): return '\n'.join([l for l in text.splitlines() if l.strip()][-lines:]) +def progress(data): + """Last sd-cli progress bar step '| 3/4 -' in data, as (3, 4), or None.""" + m = re.findall(rb'\| *(\d+)/(\d+) -', bytes(data)) + return tuple(map(int, m[-1])) if m else None + + @dataclass class Job: path: str # file the user opened, overwrite target @@ -229,6 +237,8 @@ class Main(QMainWindow): tb = self.addToolBar('main') tb.setMovable(False) + tb.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon) + tb.setIconSize(QSize(32, 32)) def act(text, icon, slot, key=None): # freedesktop names; a theme without the icon shows the text @@ -254,10 +264,17 @@ class Main(QMainWindow): self.a_quit.triggered.connect(self.close) self.addAction(self.a_quit) + self.bar = QProgressBar() + self.bar.setMaximumWidth(250) + self.bar.hide() + self.statusBar().addPermanentWidget(self.bar) + self.proc = QProcess(self) + # sd-cli prints its progress bar on stdout, errors on both + self.proc.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels) self.proc.finished.connect(self.proc_done) self.proc.errorOccurred.connect(self.proc_error) - self.proc.readyReadStandardError.connect(self.proc_stderr) + self.proc.readyReadStandardOutput.connect(self.proc_output) self.reload_models() if path: @@ -326,6 +343,8 @@ class Main(QMainWindow): def run(self, what, prog, args, msg): self.what, self.err = what, b'' self.statusBar().showMessage(msg) + self.bar.setRange(0, 0) # busy until sd-cli reports a step + self.bar.show() self.refresh() self.proc.start(prog, args) @@ -339,14 +358,22 @@ class Main(QMainWindow): job.input, job.out), f'Upscaling with {job.model}...') - def proc_stderr(self): - self.err = (self.err + bytes(self.proc.readAllStandardError()))[-8000:] - last = tail(self.err, 1) - if last: - self.statusBar().showMessage(last) + def proc_output(self): + self.err = (self.err + bytes(self.proc.readAllStandardOutput()))[-8000:] + step = progress(self.err) + if step: + self.bar.setRange(0, step[1]) + self.bar.setValue(step[0]) + self.bar.setFormat('tile %v/%m') + self.statusBar().showMessage(f'Upscaling with {self.job().model}...') + else: + last = tail(self.err, 1) + if last: + self.statusBar().showMessage(last) def proc_done(self, code, status): self.what = None + self.bar.hide() ok = code == 0 and status == QProcess.ExitStatus.NormalExit job = self.job() img = QImage(job.out) if ok else QImage() @@ -365,6 +392,7 @@ class Main(QMainWindow): if err != QProcess.ProcessError.FailedToStart: return # crashes also emit finished, handled there self.what = None + self.bar.hide() prog = self.proc.program() QMessageBox.warning(self, 'upscale-qt', f'Cannot start {prog}: is it installed?') self.statusBar().showMessage(f'Cannot start {prog}') -- cgit v1.2.3