Compare commits
6 Commits
feature/si
...
feature/ac
| Author | SHA1 | Date | |
|---|---|---|---|
| 373f3aaa79 | |||
| 66b2baf510 | |||
| 35f33f2079 | |||
|
|
d26bb6da2d | ||
|
|
e5126c913d | ||
| 76973aaae0 |
@@ -2366,13 +2366,13 @@ class SiloEventListener(QtCore.QThread):
|
||||
item_updated = QtCore.Signal(str) # part_number
|
||||
revision_created = QtCore.Signal(str, int) # part_number, revision
|
||||
connection_status = QtCore.Signal(
|
||||
str
|
||||
) # "connected" / "disconnected" / "unsupported"
|
||||
str, int, str
|
||||
) # (status, retry_count, error_message)
|
||||
server_mode_changed = QtCore.Signal(str) # "normal" / "read-only" / "degraded"
|
||||
|
||||
_MAX_FAST_RETRIES = 3
|
||||
_FAST_RETRY_SECS = 5
|
||||
_SLOW_RETRY_SECS = 30
|
||||
_MAX_RETRIES = 10
|
||||
_BASE_DELAY = 1 # seconds, doubles each retry
|
||||
_MAX_DELAY = 60 # seconds, backoff cap
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
@@ -2395,6 +2395,7 @@ class SiloEventListener(QtCore.QThread):
|
||||
|
||||
def run(self):
|
||||
retries = 0
|
||||
last_error = ""
|
||||
while not self._stop_flag:
|
||||
try:
|
||||
self._listen()
|
||||
@@ -2402,21 +2403,24 @@ class SiloEventListener(QtCore.QThread):
|
||||
if self._stop_flag:
|
||||
return
|
||||
retries += 1
|
||||
last_error = "connection closed"
|
||||
except _SSEUnsupported:
|
||||
self.connection_status.emit("unsupported")
|
||||
self.connection_status.emit("unsupported", 0, "")
|
||||
return
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
retries += 1
|
||||
last_error = str(exc) or "unknown error"
|
||||
|
||||
self.connection_status.emit("disconnected")
|
||||
if retries > self._MAX_RETRIES:
|
||||
self.connection_status.emit("gave_up", retries - 1, last_error)
|
||||
return
|
||||
|
||||
if retries <= self._MAX_FAST_RETRIES:
|
||||
delay = self._FAST_RETRY_SECS
|
||||
else:
|
||||
delay = self._SLOW_RETRY_SECS
|
||||
self.connection_status.emit("disconnected", retries, last_error)
|
||||
|
||||
delay = min(self._BASE_DELAY * (2 ** (retries - 1)), self._MAX_DELAY)
|
||||
|
||||
# Interruptible sleep
|
||||
for _ in range(delay):
|
||||
for _ in range(int(delay)):
|
||||
if self._stop_flag:
|
||||
return
|
||||
self.msleep(1000)
|
||||
@@ -2440,7 +2444,7 @@ class SiloEventListener(QtCore.QThread):
|
||||
except urllib.error.URLError:
|
||||
raise
|
||||
|
||||
self.connection_status.emit("connected")
|
||||
self.connection_status.emit("connected", 0, "")
|
||||
|
||||
event_type = ""
|
||||
data_buf = ""
|
||||
@@ -2706,13 +2710,28 @@ class SiloAuthDockWidget:
|
||||
self._event_listener.stop()
|
||||
self._sse_label.setText("")
|
||||
|
||||
def _on_sse_status(self, status):
|
||||
def _on_sse_status(self, status, retry, error):
|
||||
if status == "connected":
|
||||
self._sse_label.setText("Listening")
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #4CAF50;")
|
||||
self._sse_label.setToolTip("")
|
||||
FreeCAD.Console.PrintMessage("Silo: SSE connected\n")
|
||||
elif status == "disconnected":
|
||||
self._sse_label.setText("Reconnecting...")
|
||||
self._sse_label.setText(
|
||||
f"Reconnecting ({retry}/{SiloEventListener._MAX_RETRIES})..."
|
||||
)
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #FF9800;")
|
||||
self._sse_label.setToolTip(error or "Connection lost")
|
||||
FreeCAD.Console.PrintWarning(
|
||||
f"Silo: SSE reconnecting ({retry}/{SiloEventListener._MAX_RETRIES}): {error}\n"
|
||||
)
|
||||
elif status == "gave_up":
|
||||
self._sse_label.setText("Disconnected")
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #F44336;")
|
||||
self._sse_label.setToolTip(error or "Max retries reached")
|
||||
FreeCAD.Console.PrintError(
|
||||
f"Silo: SSE gave up after {retry} retries: {error}\n"
|
||||
)
|
||||
elif status == "unsupported":
|
||||
self._sse_label.setText("Not available")
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #888;")
|
||||
@@ -2766,7 +2785,7 @@ class SiloAuthDockWidget:
|
||||
|
||||
def _refresh_activity_panel(self):
|
||||
"""Refresh the Database Activity panel if it exists."""
|
||||
from PySide import QtWidgets
|
||||
from PySide import QtCore, QtGui, QtWidgets
|
||||
|
||||
mw = FreeCADGui.getMainWindow()
|
||||
if mw is None:
|
||||
@@ -2778,6 +2797,24 @@ class SiloAuthDockWidget:
|
||||
if activity_list is None:
|
||||
return
|
||||
activity_list.clear()
|
||||
|
||||
# Connect interaction signals (once)
|
||||
if not getattr(activity_list, "_silo_connected", False):
|
||||
activity_list.itemDoubleClicked.connect(self._on_activity_double_click)
|
||||
activity_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||
activity_list.customContextMenuRequested.connect(
|
||||
lambda pos: self._on_activity_context_menu(activity_list, pos)
|
||||
)
|
||||
activity_list._silo_connected = True
|
||||
|
||||
# Collect local part numbers for badge
|
||||
local_pns = set()
|
||||
try:
|
||||
for lf in search_local_files():
|
||||
local_pns.add(lf.get("part_number", ""))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
items = _client.list_items()
|
||||
if isinstance(items, list):
|
||||
@@ -2787,12 +2824,96 @@ class SiloAuthDockWidget:
|
||||
updated = item.get("updated_at", "")
|
||||
if updated:
|
||||
updated = updated[:10]
|
||||
activity_list.addItem(f"{pn} - {desc} - {updated}")
|
||||
|
||||
# Fetch latest revision info
|
||||
rev_num = ""
|
||||
comment = ""
|
||||
try:
|
||||
revs = _client.get_revisions(pn)
|
||||
if revs:
|
||||
latest = revs[0] if isinstance(revs, list) else revs
|
||||
rev_num = str(latest.get("revision_number", ""))
|
||||
comment = latest.get("comment", "") or ""
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Truncate long descriptions
|
||||
desc_display = desc
|
||||
if len(desc_display) > 40:
|
||||
desc_display = desc_display[:37] + "..."
|
||||
|
||||
# Build display text
|
||||
rev_part = f" \u2013 Rev {rev_num}" if rev_num else ""
|
||||
date_part = f" \u2013 {updated}" if updated else ""
|
||||
local_badge = " \u25cf local" if pn in local_pns else ""
|
||||
line1 = (
|
||||
f"{pn} \u2013 {desc_display}{rev_part}{date_part}{local_badge}"
|
||||
)
|
||||
|
||||
if comment:
|
||||
line1 += f'\n "{comment}"'
|
||||
else:
|
||||
line1 += "\n (no comment)"
|
||||
|
||||
list_item = QtWidgets.QListWidgetItem(line1)
|
||||
list_item.setData(QtCore.Qt.UserRole, pn)
|
||||
if desc and len(desc) > 40:
|
||||
list_item.setToolTip(desc)
|
||||
if pn in local_pns:
|
||||
list_item.setForeground(QtGui.QColor("#4CAF50"))
|
||||
activity_list.addItem(list_item)
|
||||
|
||||
if activity_list.count() == 0:
|
||||
activity_list.addItem("(No items in database)")
|
||||
except Exception:
|
||||
activity_list.addItem("(Unable to refresh activity)")
|
||||
|
||||
def _on_activity_double_click(self, item):
|
||||
"""Open/checkout item from activity pane."""
|
||||
pn = item.data(256) # Qt.UserRole
|
||||
if not pn:
|
||||
return
|
||||
local_path = find_file_by_part_number(pn)
|
||||
if local_path and local_path.exists():
|
||||
FreeCAD.openDocument(str(local_path))
|
||||
else:
|
||||
_sync.open_item(pn)
|
||||
|
||||
def _on_activity_context_menu(self, activity_list, pos):
|
||||
"""Show context menu for activity pane items."""
|
||||
from PySide import QtCore, QtGui
|
||||
|
||||
item = activity_list.itemAt(pos)
|
||||
if item is None:
|
||||
return
|
||||
pn = item.data(QtCore.Qt.UserRole)
|
||||
if not pn:
|
||||
return
|
||||
|
||||
menu = QtGui.QMenu()
|
||||
open_action = menu.addAction("Open in Create")
|
||||
browser_action = menu.addAction("Open in Browser")
|
||||
copy_action = menu.addAction("Copy Part Number")
|
||||
revisions_action = menu.addAction("View Revisions")
|
||||
|
||||
action = menu.exec_(activity_list.mapToGlobal(pos))
|
||||
if action == open_action:
|
||||
local_path = find_file_by_part_number(pn)
|
||||
if local_path and local_path.exists():
|
||||
FreeCAD.openDocument(str(local_path))
|
||||
else:
|
||||
_sync.open_item(pn)
|
||||
elif action == browser_action:
|
||||
import webbrowser
|
||||
|
||||
api_url = _get_api_url().rstrip("/")
|
||||
base_url = api_url[:-4] if api_url.endswith("/api") else api_url
|
||||
webbrowser.open(f"{base_url}/items/{pn}")
|
||||
elif action == copy_action:
|
||||
QtGui.QApplication.clipboard().setText(pn)
|
||||
elif action == revisions_action:
|
||||
FreeCADGui.runCommand("Silo_Info", 0)
|
||||
|
||||
# -- Actions ------------------------------------------------------------
|
||||
|
||||
def _on_login_clicked(self):
|
||||
|
||||
Reference in New Issue
Block a user