]> danix's work - publisher.git/commitdiff
feat: hugo server panel with start/stop and log streaming
authorDanilo M. <redacted>
Sun, 3 May 2026 08:43:31 +0000 (10:43 +0200)
committerDanilo M. <redacted>
Sun, 3 May 2026 08:43:31 +0000 (10:43 +0200)
ui/hugo_panel.py [new file with mode: 0644]
ui/main_window.py

diff --git a/ui/hugo_panel.py b/ui/hugo_panel.py
new file mode 100644 (file)
index 0000000..4305b79
--- /dev/null
@@ -0,0 +1,71 @@
+from __future__ import annotations
+from pathlib import Path
+from PyQt6.QtWidgets import (
+    QWidget, QVBoxLayout, QHBoxLayout,
+    QLabel, QPushButton, QPlainTextEdit,
+)
+from PyQt6.QtCore import QUrl
+from PyQt6.QtGui import QDesktopServices
+from workers.hugo_worker import HugoWorker
+
+class HugoPanel(QWidget):
+    def __init__(self, repo_path: Path, parent=None):
+        super().__init__(parent)
+        self._worker = HugoWorker(repo_path, parent=self)
+        self._worker.log_line.connect(self._on_log)
+        self._worker.started.connect(self._on_started)
+        self._worker.stopped.connect(self._on_stopped)
+        self._worker.error.connect(lambda e: self._log.appendPlainText(f"[ERRORE] {e}"))
+        self._build_ui()
+
+    def _build_ui(self):
+        layout = QVBoxLayout(self)
+
+        top = QHBoxLayout()
+        self._status_label = QLabel("🔴 Hugo server: fermo")
+        self._status_label.setStyleSheet("color:#ff6b6b;font-weight:bold;")
+        top.addWidget(self._status_label)
+        top.addStretch()
+
+        self._start_btn = QPushButton("▶ Avvia")
+        self._start_btn.clicked.connect(self._worker.start)
+        self._stop_btn = QPushButton("⏹ Ferma")
+        self._stop_btn.clicked.connect(self._worker.stop)
+        self._stop_btn.setEnabled(False)
+        top.addWidget(self._start_btn)
+        top.addWidget(self._stop_btn)
+
+        self._url_btn = QPushButton("🌐 http://localhost:1313")
+        self._url_btn.setFlat(True)
+        self._url_btn.setStyleSheet("color:#60a5fa;text-decoration:underline;")
+        self._url_btn.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("http://localhost:1313")))
+        self._url_btn.setVisible(False)
+        top.addWidget(self._url_btn)
+
+        layout.addLayout(top)
+
+        self._log = QPlainTextEdit()
+        self._log.setReadOnly(True)
+        self._log.setStyleSheet("background:#0a0a12;color:#00ff88;font-family:monospace;font-size:11px;")
+        layout.addWidget(self._log)
+
+    def _on_log(self, line: str):
+        self._log.appendPlainText(line)
+
+    def _on_started(self):
+        self._status_label.setText("🟢 Hugo server: in esecuzione")
+        self._status_label.setStyleSheet("color:#00ff88;font-weight:bold;")
+        self._start_btn.setEnabled(False)
+        self._stop_btn.setEnabled(True)
+        self._url_btn.setVisible(True)
+
+    def _on_stopped(self):
+        self._status_label.setText("🔴 Hugo server: fermo")
+        self._status_label.setStyleSheet("color:#ff6b6b;font-weight:bold;")
+        self._start_btn.setEnabled(True)
+        self._stop_btn.setEnabled(False)
+        self._url_btn.setVisible(False)
+
+    def closeEvent(self, event):
+        self._worker.stop()
+        super().closeEvent(event)
index ad7134fa33b3c3c791f7688160ed3b91a976fbd5..463c3dca6528bd18a58e2c388eecf846ee0d5889 100644 (file)
@@ -98,8 +98,14 @@ class MainWindow(QMainWindow):
         self._stack.addWidget(self._git_view)
         self._page_git = self._stack.count() - 1
 
+        from ui.hugo_panel import HugoPanel
+
+        self._hugo_panel = HugoPanel(Path(self.config.blog_repo), parent=self)
+        self._stack.addWidget(self._hugo_panel)
+        self._page_hugo = self._stack.count() - 1
+
         # Remaining placeholders
-        for name in ["taxonomy", "media", "hugo"]:
+        for name in ["taxonomy", "media"]:
             w = QLabel(f"[{name}]")
             w.setAlignment(Qt.AlignmentFlag.AlignCenter)
             self._stack.addWidget(w)
@@ -249,3 +255,7 @@ class MainWindow(QMainWindow):
 
     def _on_fs_change(self, _path: str):
         self._refresh_articles()
+
+    def closeEvent(self, event):
+        self._hugo_panel._worker.stop()
+        super().closeEvent(event)