Compare commits
21 Commits
feature/se
...
fix/pull-p
| Author | SHA1 | Date | |
|---|---|---|---|
| e83769090b | |||
| 6c9789fdf3 | |||
| 85bfb17854 | |||
| 8937cb5e8b | |||
| a53cd52c73 | |||
|
|
c6e187a75c | ||
|
|
2e9bf52082 | ||
|
|
383eefce9c | ||
|
|
1676b3e1a0 | ||
|
|
06cd30e88d | ||
| f9924d35f7 | |||
| 373f3aaa79 | |||
| 66b2baf510 | |||
| 35f33f2079 | |||
|
|
d26bb6da2d | ||
|
|
e5126c913d | ||
| 76973aaae0 | |||
|
|
4ddbf26af7 | ||
| 516116ae9d | |||
|
|
6fa60af5e0 | ||
| fd3c97ff97 |
@@ -47,6 +47,8 @@ class SiloWorkbench(FreeCADGui.Workbench):
|
|||||||
"Separator",
|
"Separator",
|
||||||
"Silo_Settings",
|
"Silo_Settings",
|
||||||
"Silo_Auth",
|
"Silo_Auth",
|
||||||
|
"Silo_StartPanel",
|
||||||
|
"Silo_Diag",
|
||||||
]
|
]
|
||||||
|
|
||||||
self.appendMenu("Silo", self.menu_commands)
|
self.appendMenu("Silo", self.menu_commands)
|
||||||
@@ -54,6 +56,7 @@ class SiloWorkbench(FreeCADGui.Workbench):
|
|||||||
def Activated(self):
|
def Activated(self):
|
||||||
"""Called when workbench is activated."""
|
"""Called when workbench is activated."""
|
||||||
FreeCAD.Console.PrintMessage("Kindred Silo workbench activated\n")
|
FreeCAD.Console.PrintMessage("Kindred Silo workbench activated\n")
|
||||||
|
FreeCADGui.runCommand("Silo_StartPanel", 0)
|
||||||
|
|
||||||
def Deactivated(self):
|
def Deactivated(self):
|
||||||
pass
|
pass
|
||||||
@@ -64,3 +67,31 @@ class SiloWorkbench(FreeCADGui.Workbench):
|
|||||||
|
|
||||||
FreeCADGui.addWorkbench(SiloWorkbench())
|
FreeCADGui.addWorkbench(SiloWorkbench())
|
||||||
FreeCAD.Console.PrintMessage("Silo workbench registered\n")
|
FreeCAD.Console.PrintMessage("Silo workbench registered\n")
|
||||||
|
|
||||||
|
# Override the Start page with Silo-aware version (must happen before
|
||||||
|
# the C++ StartLauncher fires at ~100ms after GUI init)
|
||||||
|
try:
|
||||||
|
import silo_start
|
||||||
|
|
||||||
|
silo_start.register()
|
||||||
|
except Exception as e:
|
||||||
|
FreeCAD.Console.PrintWarning(f"Silo Start page override failed: {e}\n")
|
||||||
|
|
||||||
|
|
||||||
|
# Handle kindred:// URLs passed as command-line arguments on cold start.
|
||||||
|
# Delayed to run after the GUI is fully initialised and the Silo addon has
|
||||||
|
# loaded its client/sync objects.
|
||||||
|
def _handle_startup_urls():
|
||||||
|
"""Process any kindred:// URLs passed as command-line arguments."""
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from silo_commands import handle_kindred_url
|
||||||
|
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
if arg.startswith("kindred://"):
|
||||||
|
handle_kindred_url(arg)
|
||||||
|
|
||||||
|
|
||||||
|
from PySide import QtCore
|
||||||
|
|
||||||
|
QtCore.QTimer.singleShot(500, _handle_startup_urls)
|
||||||
|
|||||||
8
freecad/resources/icons/silo-rollback.svg
Normal file
8
freecad/resources/icons/silo-rollback.svg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#cba6f7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<!-- Counter-clockwise arrow -->
|
||||||
|
<polyline points="1 4 1 10 7 10" stroke="#f38ba8"/>
|
||||||
|
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10" stroke="#cba6f7"/>
|
||||||
|
<!-- Clock hands -->
|
||||||
|
<line x1="12" y1="7" x2="12" y2="12" stroke="#89dceb" stroke-width="1.5"/>
|
||||||
|
<line x1="12" y1="12" x2="15" y2="14" stroke="#89dceb" stroke-width="1.5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 493 B |
7
freecad/resources/icons/silo-status.svg
Normal file
7
freecad/resources/icons/silo-status.svg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#cba6f7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<!-- Shield shape -->
|
||||||
|
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" fill="#313244"/>
|
||||||
|
<!-- Status bars -->
|
||||||
|
<line x1="8" y1="10" x2="16" y2="10" stroke="#a6e3a1" stroke-width="1.5"/>
|
||||||
|
<line x1="8" y1="14" x2="13" y2="14" stroke="#89dceb" stroke-width="1.5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 435 B |
6
freecad/resources/icons/silo-tag.svg
Normal file
6
freecad/resources/icons/silo-tag.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#cba6f7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<!-- Tag shape -->
|
||||||
|
<path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z" fill="#313244"/>
|
||||||
|
<!-- Tag hole -->
|
||||||
|
<circle cx="7" cy="7" r="1.5" fill="#cba6f7" stroke="none"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 373 B |
File diff suppressed because it is too large
Load Diff
@@ -299,9 +299,7 @@ class SiloOrigin:
|
|||||||
Created App.Document or None
|
Created App.Document or None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_New")
|
FreeCADGui.runCommand("Silo_New")
|
||||||
if cmd:
|
|
||||||
cmd.Activated()
|
|
||||||
return FreeCAD.ActiveDocument
|
return FreeCAD.ActiveDocument
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo new document failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo new document failed: {e}\n")
|
||||||
@@ -322,9 +320,7 @@ class SiloOrigin:
|
|||||||
if not identity:
|
if not identity:
|
||||||
# No identity - show search dialog
|
# No identity - show search dialog
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_Open")
|
FreeCADGui.runCommand("Silo_Open")
|
||||||
if cmd:
|
|
||||||
cmd.Activated()
|
|
||||||
return FreeCAD.ActiveDocument
|
return FreeCAD.ActiveDocument
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo open failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo open failed: {e}\n")
|
||||||
@@ -354,9 +350,7 @@ class SiloOrigin:
|
|||||||
Opened App.Document or None
|
Opened App.Document or None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_Open")
|
FreeCADGui.runCommand("Silo_Open")
|
||||||
if cmd:
|
|
||||||
cmd.Activated()
|
|
||||||
return FreeCAD.ActiveDocument
|
return FreeCAD.ActiveDocument
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo open failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo open failed: {e}\n")
|
||||||
@@ -473,10 +467,8 @@ class SiloOrigin:
|
|||||||
True if command was executed
|
True if command was executed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_Commit")
|
FreeCADGui.runCommand("Silo_Commit")
|
||||||
if cmd:
|
return True
|
||||||
cmd.Activated()
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo commit failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo commit failed: {e}\n")
|
||||||
return False
|
return False
|
||||||
@@ -493,10 +485,8 @@ class SiloOrigin:
|
|||||||
True if command was executed
|
True if command was executed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_Pull")
|
FreeCADGui.runCommand("Silo_Pull")
|
||||||
if cmd:
|
return True
|
||||||
cmd.Activated()
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo pull failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo pull failed: {e}\n")
|
||||||
return False
|
return False
|
||||||
@@ -513,10 +503,8 @@ class SiloOrigin:
|
|||||||
True if command was executed
|
True if command was executed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_Push")
|
FreeCADGui.runCommand("Silo_Push")
|
||||||
if cmd:
|
return True
|
||||||
cmd.Activated()
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo push failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo push failed: {e}\n")
|
||||||
return False
|
return False
|
||||||
@@ -530,9 +518,7 @@ class SiloOrigin:
|
|||||||
doc: FreeCAD App.Document
|
doc: FreeCAD App.Document
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_Info")
|
FreeCADGui.runCommand("Silo_Info")
|
||||||
if cmd:
|
|
||||||
cmd.Activated()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo info failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo info failed: {e}\n")
|
||||||
|
|
||||||
@@ -545,9 +531,7 @@ class SiloOrigin:
|
|||||||
doc: FreeCAD App.Document
|
doc: FreeCAD App.Document
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmd = FreeCADGui.Command.get("Silo_BOM")
|
FreeCADGui.runCommand("Silo_BOM")
|
||||||
if cmd:
|
|
||||||
cmd.Activated()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintError(f"Silo BOM failed: {e}\n")
|
FreeCAD.Console.PrintError(f"Silo BOM failed: {e}\n")
|
||||||
|
|
||||||
|
|||||||
667
freecad/silo_start.py
Normal file
667
freecad/silo_start.py
Normal file
@@ -0,0 +1,667 @@
|
|||||||
|
"""Silo Start Page — native Qt start view for Kindred Create.
|
||||||
|
|
||||||
|
Replaces the default Start page with a rich native panel that fetches data
|
||||||
|
from the Silo REST API, shows real-time activity via SSE, and provides quick
|
||||||
|
access to database items and recent local files.
|
||||||
|
|
||||||
|
The command override is activated by calling ``register()`` at module level
|
||||||
|
from InitGui.py, which overwrites the C++ ``Start_Start`` command.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import FreeCAD
|
||||||
|
import FreeCADGui
|
||||||
|
from PySide import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Catppuccin Mocha palette
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
_MOCHA = {
|
||||||
|
"base": "#1e1e2e",
|
||||||
|
"mantle": "#181825",
|
||||||
|
"crust": "#11111b",
|
||||||
|
"surface0": "#313244",
|
||||||
|
"surface1": "#45475a",
|
||||||
|
"surface2": "#585b70",
|
||||||
|
"text": "#cdd6f4",
|
||||||
|
"subtext0": "#a6adc8",
|
||||||
|
"subtext1": "#bac2de",
|
||||||
|
"blue": "#89b4fa",
|
||||||
|
"green": "#a6e3a1",
|
||||||
|
"red": "#f38ba8",
|
||||||
|
"peach": "#fab387",
|
||||||
|
"lavender": "#b4befe",
|
||||||
|
"overlay0": "#6c7086",
|
||||||
|
}
|
||||||
|
|
||||||
|
_PREF_GROUP = "User parameter:BaseApp/Preferences/Mod/KindredSilo"
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Helpers
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def _get_silo_base_url() -> str:
|
||||||
|
"""Return the Silo web UI root URL (without /api)."""
|
||||||
|
param = FreeCAD.ParamGet(_PREF_GROUP)
|
||||||
|
url = param.GetString("ApiUrl", "")
|
||||||
|
if not url:
|
||||||
|
url = os.environ.get("SILO_API_URL", "http://localhost:8080/api")
|
||||||
|
url = url.rstrip("/")
|
||||||
|
if url.endswith("/api"):
|
||||||
|
url = url[:-4]
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def _get_recent_files() -> list:
|
||||||
|
"""Read recent files from FreeCAD preferences."""
|
||||||
|
group = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles")
|
||||||
|
count = group.GetInt("RecentFiles", 0)
|
||||||
|
files = []
|
||||||
|
for i in range(count):
|
||||||
|
path = group.GetString(f"MRU{i}", "")
|
||||||
|
if path and os.path.exists(path):
|
||||||
|
p = Path(path)
|
||||||
|
mtime = datetime.fromtimestamp(p.stat().st_mtime)
|
||||||
|
files.append({"path": str(p), "name": p.name, "modified": mtime})
|
||||||
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
def _relative_time(dt: datetime) -> str:
|
||||||
|
"""Format a datetime as a human-friendly relative string."""
|
||||||
|
now = datetime.now()
|
||||||
|
diff = now - dt
|
||||||
|
seconds = int(diff.total_seconds())
|
||||||
|
if seconds < 60:
|
||||||
|
return "just now"
|
||||||
|
minutes = seconds // 60
|
||||||
|
if minutes < 60:
|
||||||
|
return f"{minutes}m ago"
|
||||||
|
hours = minutes // 60
|
||||||
|
if hours < 24:
|
||||||
|
return f"{hours}h ago"
|
||||||
|
days = hours // 24
|
||||||
|
if days < 30:
|
||||||
|
return f"{days}d ago"
|
||||||
|
return dt.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Stylesheet
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_STYLESHEET = f"""
|
||||||
|
SiloStartView {{
|
||||||
|
background-color: {_MOCHA["base"]};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Status banner --- */
|
||||||
|
#SiloStatusBanner {{
|
||||||
|
background-color: {_MOCHA["surface0"]};
|
||||||
|
border-radius: 8px;
|
||||||
|
}}
|
||||||
|
#SiloStatusBanner QLabel {{
|
||||||
|
color: {_MOCHA["text"]};
|
||||||
|
font-size: 13px;
|
||||||
|
}}
|
||||||
|
#SiloStatusBanner QPushButton {{
|
||||||
|
background-color: {_MOCHA["blue"]};
|
||||||
|
color: {_MOCHA["crust"]};
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 12px;
|
||||||
|
}}
|
||||||
|
#SiloStatusBanner QPushButton:hover {{
|
||||||
|
background-color: {_MOCHA["lavender"]};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Section headers --- */
|
||||||
|
.SiloSectionHeader {{
|
||||||
|
color: {_MOCHA["text"]};
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Search field --- */
|
||||||
|
#SiloSearchField {{
|
||||||
|
background-color: {_MOCHA["surface0"]};
|
||||||
|
border: 1px solid {_MOCHA["surface1"]};
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
color: {_MOCHA["text"]};
|
||||||
|
font-size: 13px;
|
||||||
|
}}
|
||||||
|
#SiloSearchField:focus {{
|
||||||
|
border-color: {_MOCHA["blue"]};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- List widgets --- */
|
||||||
|
.SiloList {{
|
||||||
|
background-color: {_MOCHA["mantle"]};
|
||||||
|
border: 1px solid {_MOCHA["surface0"]};
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px;
|
||||||
|
}}
|
||||||
|
.SiloList::item {{
|
||||||
|
padding: 8px 10px;
|
||||||
|
border-bottom: 1px solid {_MOCHA["surface0"]};
|
||||||
|
color: {_MOCHA["text"]};
|
||||||
|
}}
|
||||||
|
.SiloList::item:last {{
|
||||||
|
border-bottom: none;
|
||||||
|
}}
|
||||||
|
.SiloList::item:hover {{
|
||||||
|
background-color: {_MOCHA["surface0"]};
|
||||||
|
}}
|
||||||
|
.SiloList::item:selected {{
|
||||||
|
background-color: {_MOCHA["surface1"]};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Activity feed --- */
|
||||||
|
#SiloActivityFeed {{
|
||||||
|
background-color: {_MOCHA["mantle"]};
|
||||||
|
border: 1px solid {_MOCHA["surface0"]};
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px;
|
||||||
|
}}
|
||||||
|
#SiloActivityFeed::item {{
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-bottom: 1px solid {_MOCHA["surface0"]};
|
||||||
|
color: {_MOCHA["subtext0"]};
|
||||||
|
font-size: 12px;
|
||||||
|
}}
|
||||||
|
#SiloActivityFeed::item:last {{
|
||||||
|
border-bottom: none;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Footer checkbox --- */
|
||||||
|
QCheckBox {{
|
||||||
|
color: {_MOCHA["subtext0"]};
|
||||||
|
font-size: 12px;
|
||||||
|
}}
|
||||||
|
QCheckBox::indicator {{
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Main start view
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class SiloStartView(QtWidgets.QWidget):
|
||||||
|
"""Native Qt start page with Silo database items, recent files, and
|
||||||
|
real-time activity feed."""
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setObjectName("SiloStartView")
|
||||||
|
|
||||||
|
self._silo_url = _get_silo_base_url()
|
||||||
|
self._connected = False
|
||||||
|
self._event_listener = None
|
||||||
|
self._activity_events = [] # list of (datetime, text) tuples
|
||||||
|
self._silo_imported = False
|
||||||
|
self._silo_cmds = None # lazy ref to silo_commands module
|
||||||
|
|
||||||
|
self._build_ui()
|
||||||
|
self.setStyleSheet(_STYLESHEET)
|
||||||
|
|
||||||
|
# Debounce timer for search
|
||||||
|
self._search_timer = QtCore.QTimer(self)
|
||||||
|
self._search_timer.setSingleShot(True)
|
||||||
|
self._search_timer.setInterval(300)
|
||||||
|
self._search_timer.timeout.connect(self._refresh_items)
|
||||||
|
|
||||||
|
# Periodic refresh
|
||||||
|
self._poll_timer = QtCore.QTimer(self)
|
||||||
|
self._poll_timer.setInterval(30000)
|
||||||
|
self._poll_timer.timeout.connect(self._periodic_refresh)
|
||||||
|
self._poll_timer.start()
|
||||||
|
|
||||||
|
# Initial load after event loop starts
|
||||||
|
QtCore.QTimer.singleShot(100, self._initial_load)
|
||||||
|
|
||||||
|
# -- lazy import --------------------------------------------------------
|
||||||
|
|
||||||
|
def _silo(self):
|
||||||
|
"""Lazy-import silo_commands to avoid circular import at module load."""
|
||||||
|
if not self._silo_imported:
|
||||||
|
try:
|
||||||
|
import silo_commands
|
||||||
|
|
||||||
|
self._silo_cmds = silo_commands
|
||||||
|
except Exception as e:
|
||||||
|
FreeCAD.Console.PrintWarning(f"Silo Start: cannot import silo_commands: {e}\n")
|
||||||
|
self._silo_cmds = None
|
||||||
|
self._silo_imported = True
|
||||||
|
return self._silo_cmds
|
||||||
|
|
||||||
|
# -- UI construction ----------------------------------------------------
|
||||||
|
|
||||||
|
def _build_ui(self):
|
||||||
|
root = QtWidgets.QVBoxLayout(self)
|
||||||
|
root.setContentsMargins(32, 24, 32, 16)
|
||||||
|
root.setSpacing(0)
|
||||||
|
|
||||||
|
# --- Status banner ---
|
||||||
|
banner = QtWidgets.QFrame()
|
||||||
|
banner.setObjectName("SiloStatusBanner")
|
||||||
|
banner_layout = QtWidgets.QHBoxLayout(banner)
|
||||||
|
banner_layout.setContentsMargins(16, 10, 16, 10)
|
||||||
|
|
||||||
|
self._status_icon = QtWidgets.QLabel()
|
||||||
|
self._status_icon.setFixedSize(12, 12)
|
||||||
|
banner_layout.addWidget(self._status_icon)
|
||||||
|
|
||||||
|
self._status_label = QtWidgets.QLabel("Checking Silo connection...")
|
||||||
|
self._status_label.setWordWrap(True)
|
||||||
|
banner_layout.addWidget(self._status_label, 1)
|
||||||
|
|
||||||
|
self._browser_btn = QtWidgets.QPushButton("Open in Browser")
|
||||||
|
self._browser_btn.setFixedWidth(130)
|
||||||
|
self._browser_btn.setCursor(QtCore.Qt.PointingHandCursor)
|
||||||
|
self._browser_btn.clicked.connect(self._open_in_browser)
|
||||||
|
banner_layout.addWidget(self._browser_btn)
|
||||||
|
|
||||||
|
self._retry_btn = QtWidgets.QPushButton("Retry")
|
||||||
|
self._retry_btn.setFixedWidth(70)
|
||||||
|
self._retry_btn.setCursor(QtCore.Qt.PointingHandCursor)
|
||||||
|
self._retry_btn.clicked.connect(self._initial_load)
|
||||||
|
self._retry_btn.hide()
|
||||||
|
banner_layout.addWidget(self._retry_btn)
|
||||||
|
|
||||||
|
root.addWidget(banner)
|
||||||
|
root.addSpacing(20)
|
||||||
|
|
||||||
|
# --- Main content: items (left) + recent files (right) ---
|
||||||
|
content_splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
|
||||||
|
content_splitter.setHandleWidth(12)
|
||||||
|
content_splitter.setStyleSheet(
|
||||||
|
f"QSplitter::handle {{ background-color: {_MOCHA['base']}; }}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Left: Database Items
|
||||||
|
left = QtWidgets.QWidget()
|
||||||
|
left_layout = QtWidgets.QVBoxLayout(left)
|
||||||
|
left_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
left_layout.setSpacing(8)
|
||||||
|
|
||||||
|
items_header = QtWidgets.QLabel("Database Items")
|
||||||
|
items_header.setProperty("class", "SiloSectionHeader")
|
||||||
|
left_layout.addWidget(items_header)
|
||||||
|
|
||||||
|
self._search_field = QtWidgets.QLineEdit()
|
||||||
|
self._search_field.setObjectName("SiloSearchField")
|
||||||
|
self._search_field.setPlaceholderText("Search items...")
|
||||||
|
self._search_field.textChanged.connect(self._on_search_changed)
|
||||||
|
left_layout.addWidget(self._search_field)
|
||||||
|
|
||||||
|
self._items_list = QtWidgets.QListWidget()
|
||||||
|
self._items_list.setProperty("class", "SiloList")
|
||||||
|
self._items_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
|
self._items_list.itemDoubleClicked.connect(self._on_item_double_clicked)
|
||||||
|
self._items_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||||
|
self._items_list.customContextMenuRequested.connect(self._on_item_context_menu)
|
||||||
|
left_layout.addWidget(self._items_list, 1)
|
||||||
|
|
||||||
|
content_splitter.addWidget(left)
|
||||||
|
|
||||||
|
# Right: Recent Files
|
||||||
|
right = QtWidgets.QWidget()
|
||||||
|
right_layout = QtWidgets.QVBoxLayout(right)
|
||||||
|
right_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
right_layout.setSpacing(8)
|
||||||
|
|
||||||
|
recent_header = QtWidgets.QLabel("Recent Files")
|
||||||
|
recent_header.setProperty("class", "SiloSectionHeader")
|
||||||
|
right_layout.addWidget(recent_header)
|
||||||
|
|
||||||
|
self._file_list = QtWidgets.QListWidget()
|
||||||
|
self._file_list.setProperty("class", "SiloList")
|
||||||
|
self._file_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
|
self._file_list.itemDoubleClicked.connect(self._on_file_clicked)
|
||||||
|
right_layout.addWidget(self._file_list, 1)
|
||||||
|
|
||||||
|
content_splitter.addWidget(right)
|
||||||
|
content_splitter.setStretchFactor(0, 3)
|
||||||
|
content_splitter.setStretchFactor(1, 2)
|
||||||
|
|
||||||
|
root.addWidget(content_splitter, 1)
|
||||||
|
root.addSpacing(12)
|
||||||
|
|
||||||
|
# --- Activity Feed (bottom) ---
|
||||||
|
activity_header = QtWidgets.QLabel("Activity")
|
||||||
|
activity_header.setProperty("class", "SiloSectionHeader")
|
||||||
|
root.addWidget(activity_header)
|
||||||
|
root.addSpacing(6)
|
||||||
|
|
||||||
|
self._activity_list = QtWidgets.QListWidget()
|
||||||
|
self._activity_list.setObjectName("SiloActivityFeed")
|
||||||
|
self._activity_list.setMaximumHeight(140)
|
||||||
|
self._activity_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
|
root.addWidget(self._activity_list)
|
||||||
|
root.addSpacing(12)
|
||||||
|
|
||||||
|
# --- Footer ---
|
||||||
|
footer = QtWidgets.QHBoxLayout()
|
||||||
|
footer.addStretch()
|
||||||
|
self._startup_cb = QtWidgets.QCheckBox("Don't show this page on startup")
|
||||||
|
start_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start")
|
||||||
|
show = start_prefs.GetBool("ShowOnStartup", True)
|
||||||
|
self._startup_cb.setChecked(not show)
|
||||||
|
self._startup_cb.toggled.connect(self._on_startup_toggled)
|
||||||
|
footer.addWidget(self._startup_cb)
|
||||||
|
root.addLayout(footer)
|
||||||
|
|
||||||
|
# -- data loading -------------------------------------------------------
|
||||||
|
|
||||||
|
def _initial_load(self):
|
||||||
|
"""First-time data load and SSE connection."""
|
||||||
|
self._refresh_status()
|
||||||
|
self._refresh_items()
|
||||||
|
self._refresh_recent_files()
|
||||||
|
self._start_sse()
|
||||||
|
|
||||||
|
def _periodic_refresh(self):
|
||||||
|
"""Periodic refresh of items and connection status."""
|
||||||
|
self._refresh_status()
|
||||||
|
self._refresh_items()
|
||||||
|
self._refresh_recent_files()
|
||||||
|
|
||||||
|
def _refresh_status(self):
|
||||||
|
"""Update the connection status banner."""
|
||||||
|
sc = self._silo()
|
||||||
|
if sc is None:
|
||||||
|
self._set_status(False, "Silo addon not available")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
reachable, _ = sc._client.check_connection()
|
||||||
|
except Exception:
|
||||||
|
reachable = False
|
||||||
|
|
||||||
|
self._silo_url = _get_silo_base_url()
|
||||||
|
if reachable:
|
||||||
|
self._set_status(True, f"Connected to {self._silo_url}")
|
||||||
|
else:
|
||||||
|
self._set_status(False, f"Cannot reach {self._silo_url}")
|
||||||
|
|
||||||
|
def _set_status(self, connected: bool, message: str):
|
||||||
|
self._connected = connected
|
||||||
|
if connected:
|
||||||
|
self._status_icon.setStyleSheet(
|
||||||
|
f"background-color: {_MOCHA['green']}; border-radius: 6px;"
|
||||||
|
)
|
||||||
|
self._retry_btn.hide()
|
||||||
|
self._browser_btn.show()
|
||||||
|
else:
|
||||||
|
self._status_icon.setStyleSheet(
|
||||||
|
f"background-color: {_MOCHA['red']}; border-radius: 6px;"
|
||||||
|
)
|
||||||
|
self._retry_btn.show()
|
||||||
|
self._browser_btn.hide()
|
||||||
|
self._status_label.setText(message)
|
||||||
|
|
||||||
|
def _refresh_items(self):
|
||||||
|
"""Fetch items from Silo API and populate the items list."""
|
||||||
|
sc = self._silo()
|
||||||
|
if sc is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._items_list.clear()
|
||||||
|
search = self._search_field.text().strip()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if search:
|
||||||
|
items = sc._client.list_items(search=search)
|
||||||
|
else:
|
||||||
|
items = sc._client.list_items()
|
||||||
|
except Exception:
|
||||||
|
item = QtWidgets.QListWidgetItem("(Unable to fetch items)")
|
||||||
|
item.setFlags(QtCore.Qt.NoItemFlags)
|
||||||
|
self._items_list.addItem(item)
|
||||||
|
return
|
||||||
|
|
||||||
|
if not isinstance(items, list) or not items:
|
||||||
|
item = QtWidgets.QListWidgetItem("(No items found)")
|
||||||
|
item.setFlags(QtCore.Qt.NoItemFlags)
|
||||||
|
self._items_list.addItem(item)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Collect local part numbers for badge
|
||||||
|
local_pns = set()
|
||||||
|
try:
|
||||||
|
for lf in sc.search_local_files():
|
||||||
|
local_pns.add(lf.get("part_number", ""))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for entry in items[:30]:
|
||||||
|
pn = entry.get("part_number", "")
|
||||||
|
desc = entry.get("description", "")
|
||||||
|
rev = entry.get("current_revision", "")
|
||||||
|
|
||||||
|
desc_display = desc
|
||||||
|
if len(desc_display) > 50:
|
||||||
|
desc_display = desc_display[:47] + "..."
|
||||||
|
|
||||||
|
local_badge = " [local]" if pn in local_pns else ""
|
||||||
|
rev_part = f" Rev {rev}" if rev else ""
|
||||||
|
label = f"{pn} \u2014 {desc_display}{rev_part}{local_badge}"
|
||||||
|
|
||||||
|
list_item = QtWidgets.QListWidgetItem(label)
|
||||||
|
list_item.setData(QtCore.Qt.UserRole, pn)
|
||||||
|
if desc and len(desc) > 50:
|
||||||
|
list_item.setToolTip(desc)
|
||||||
|
if pn in local_pns:
|
||||||
|
list_item.setForeground(QtGui.QColor(_MOCHA["green"]))
|
||||||
|
self._items_list.addItem(list_item)
|
||||||
|
|
||||||
|
def _refresh_recent_files(self):
|
||||||
|
"""Populate the recent files list."""
|
||||||
|
self._file_list.clear()
|
||||||
|
files = _get_recent_files()
|
||||||
|
if not files:
|
||||||
|
item = QtWidgets.QListWidgetItem("(No recent files)")
|
||||||
|
item.setFlags(QtCore.Qt.NoItemFlags)
|
||||||
|
self._file_list.addItem(item)
|
||||||
|
return
|
||||||
|
for f in files:
|
||||||
|
label = f"{f['name']}\n{_relative_time(f['modified'])}"
|
||||||
|
item = QtWidgets.QListWidgetItem(label)
|
||||||
|
item.setData(QtCore.Qt.UserRole, f["path"])
|
||||||
|
item.setToolTip(f["path"])
|
||||||
|
self._file_list.addItem(item)
|
||||||
|
|
||||||
|
# -- SSE ----------------------------------------------------------------
|
||||||
|
|
||||||
|
def _start_sse(self):
|
||||||
|
"""Connect to SSE for live activity updates."""
|
||||||
|
sc = self._silo()
|
||||||
|
if sc is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self._event_listener is not None:
|
||||||
|
return # already running
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._event_listener = sc.SiloEventListener()
|
||||||
|
self._event_listener.item_updated.connect(self._on_sse_item_updated)
|
||||||
|
self._event_listener.revision_created.connect(self._on_sse_revision_created)
|
||||||
|
self._event_listener.connection_status.connect(self._on_sse_status)
|
||||||
|
self._event_listener.start()
|
||||||
|
except Exception as e:
|
||||||
|
FreeCAD.Console.PrintLog(f"Silo Start: SSE listener failed to start: {e}\n")
|
||||||
|
|
||||||
|
def _stop_sse(self):
|
||||||
|
"""Stop SSE listener when the view is destroyed."""
|
||||||
|
if self._event_listener is not None:
|
||||||
|
self._event_listener.stop()
|
||||||
|
self._event_listener = None
|
||||||
|
|
||||||
|
def _on_sse_item_updated(self, part_number: str):
|
||||||
|
self._add_activity_event(f"{part_number} updated")
|
||||||
|
self._refresh_items()
|
||||||
|
|
||||||
|
def _on_sse_revision_created(self, part_number: str, revision: int):
|
||||||
|
self._add_activity_event(f"{part_number} Rev {revision} created")
|
||||||
|
self._refresh_items()
|
||||||
|
|
||||||
|
def _on_sse_status(self, status: str, retry: int, error: str):
|
||||||
|
if status == "connected":
|
||||||
|
FreeCAD.Console.PrintLog("Silo Start: SSE connected\n")
|
||||||
|
elif status == "disconnected":
|
||||||
|
FreeCAD.Console.PrintLog(f"Silo Start: SSE disconnected (retry {retry}): {error}\n")
|
||||||
|
|
||||||
|
def _add_activity_event(self, text: str):
|
||||||
|
"""Add an event to the activity feed."""
|
||||||
|
now = datetime.now()
|
||||||
|
self._activity_events.insert(0, (now, text))
|
||||||
|
self._activity_events = self._activity_events[:20]
|
||||||
|
self._rebuild_activity_feed()
|
||||||
|
|
||||||
|
def _rebuild_activity_feed(self):
|
||||||
|
"""Rebuild the activity list widget from stored events."""
|
||||||
|
self._activity_list.clear()
|
||||||
|
if not self._activity_events:
|
||||||
|
item = QtWidgets.QListWidgetItem("(No recent activity)")
|
||||||
|
item.setFlags(QtCore.Qt.NoItemFlags)
|
||||||
|
self._activity_list.addItem(item)
|
||||||
|
return
|
||||||
|
for ts, text in self._activity_events:
|
||||||
|
label = f"{text} \u00b7 {_relative_time(ts)}"
|
||||||
|
self._activity_list.addItem(label)
|
||||||
|
|
||||||
|
# -- interaction --------------------------------------------------------
|
||||||
|
|
||||||
|
def _on_search_changed(self, _text: str):
|
||||||
|
"""Debounce search input."""
|
||||||
|
self._search_timer.start()
|
||||||
|
|
||||||
|
def _on_item_double_clicked(self, item: QtWidgets.QListWidgetItem):
|
||||||
|
pn = item.data(QtCore.Qt.UserRole)
|
||||||
|
if not pn:
|
||||||
|
return
|
||||||
|
sc = self._silo()
|
||||||
|
if sc is None:
|
||||||
|
return
|
||||||
|
local_path = sc.find_file_by_part_number(pn)
|
||||||
|
if local_path and local_path.exists():
|
||||||
|
FreeCAD.openDocument(str(local_path))
|
||||||
|
else:
|
||||||
|
sc._sync.open_item(pn)
|
||||||
|
|
||||||
|
def _on_item_context_menu(self, pos):
|
||||||
|
item = self._items_list.itemAt(pos)
|
||||||
|
if item is None:
|
||||||
|
return
|
||||||
|
pn = item.data(QtCore.Qt.UserRole)
|
||||||
|
if not pn:
|
||||||
|
return
|
||||||
|
|
||||||
|
menu = QtWidgets.QMenu()
|
||||||
|
open_action = menu.addAction("Open in Create")
|
||||||
|
browser_action = menu.addAction("Open in Browser")
|
||||||
|
copy_action = menu.addAction("Copy Part Number")
|
||||||
|
|
||||||
|
action = menu.exec_(self._items_list.mapToGlobal(pos))
|
||||||
|
sc = self._silo()
|
||||||
|
if action == open_action:
|
||||||
|
if sc:
|
||||||
|
local_path = sc.find_file_by_part_number(pn)
|
||||||
|
if local_path and local_path.exists():
|
||||||
|
FreeCAD.openDocument(str(local_path))
|
||||||
|
else:
|
||||||
|
sc._sync.open_item(pn)
|
||||||
|
elif action == browser_action:
|
||||||
|
url = f"{_get_silo_base_url()}/items/{pn}"
|
||||||
|
QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
|
||||||
|
elif action == copy_action:
|
||||||
|
QtWidgets.QApplication.clipboard().setText(pn)
|
||||||
|
|
||||||
|
def _on_file_clicked(self, item: QtWidgets.QListWidgetItem):
|
||||||
|
path = item.data(QtCore.Qt.UserRole)
|
||||||
|
if path:
|
||||||
|
try:
|
||||||
|
FreeCADGui.open(path)
|
||||||
|
except Exception as e:
|
||||||
|
FreeCAD.Console.PrintError(f"Silo Start: failed to open {path}: {e}\n")
|
||||||
|
|
||||||
|
def _open_in_browser(self):
|
||||||
|
"""Open Silo web UI in the system browser."""
|
||||||
|
url = _get_silo_base_url()
|
||||||
|
QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _on_startup_toggled(checked: bool):
|
||||||
|
prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start")
|
||||||
|
prefs.SetBool("ShowOnStartup", not checked)
|
||||||
|
|
||||||
|
# -- cleanup ------------------------------------------------------------
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
self._stop_sse()
|
||||||
|
self._poll_timer.stop()
|
||||||
|
super().closeEvent(event)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Command override
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class _SiloStartCommand:
|
||||||
|
"""Replacement for the C++ Start_Start command."""
|
||||||
|
|
||||||
|
def Activated(self):
|
||||||
|
mw = FreeCADGui.getMainWindow()
|
||||||
|
mdi = mw.findChild(QtWidgets.QMdiArea)
|
||||||
|
if not mdi:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Reuse existing view if open
|
||||||
|
for sw in mdi.subWindowList():
|
||||||
|
if sw.widget() and sw.widget().objectName() == "SiloStartView":
|
||||||
|
mdi.setActiveSubWindow(sw)
|
||||||
|
sw.show()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create new view as MDI subwindow
|
||||||
|
view = SiloStartView()
|
||||||
|
sw = mdi.addSubWindow(view)
|
||||||
|
sw.setWindowTitle("Start")
|
||||||
|
sw.setWindowIcon(QtGui.QIcon(":/icons/StartCommandIcon.svg"))
|
||||||
|
sw.show()
|
||||||
|
mdi.setActiveSubWindow(sw)
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
return {
|
||||||
|
"MenuText": "&Start Page",
|
||||||
|
"ToolTip": "Displays the start page",
|
||||||
|
"Pixmap": "StartCommandIcon",
|
||||||
|
}
|
||||||
|
|
||||||
|
def IsActive(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
"""Override the Start_Start command with the Silo start page.
|
||||||
|
|
||||||
|
Call this from InitGui.py at module level so the override is in
|
||||||
|
place before the C++ StartLauncher fires (100ms after GUI init).
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
FreeCADGui.addCommand("Start_Start", _SiloStartCommand())
|
||||||
|
FreeCAD.Console.PrintMessage("Silo Start: registered start page override\n")
|
||||||
|
except Exception as e:
|
||||||
|
FreeCAD.Console.PrintWarning(f"Silo Start: failed to register override: {e}\n")
|
||||||
Submodule silo-client updated: a6ac3d4d06...68a4139251
Reference in New Issue
Block a user