Replace hardcoded FreeCAD addon path searches with __file__-relative resolution for icons in both InitGui.py and silo_commands.py. Icons now load correctly regardless of install location. Add Silo_Settings command with URL and SSL verification fields. Settings persist via FreeCAD preferences and take priority over env vars. Wire SSL context into all SiloClient HTTP methods.
93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
"""Kindred Silo Workbench - Item database integration for Kindred Create."""
|
|
|
|
import os
|
|
|
|
import FreeCAD
|
|
import FreeCADGui
|
|
|
|
FreeCAD.Console.PrintMessage("Kindred Silo InitGui.py loading...\n")
|
|
|
|
|
|
class SiloWorkbench(FreeCADGui.Workbench):
|
|
"""Kindred Silo workbench for item database integration."""
|
|
|
|
MenuText = "Kindred Silo"
|
|
ToolTip = "Item database and part management for Kindred Create"
|
|
Icon = ""
|
|
|
|
def __init__(self):
|
|
# Resolve icon relative to this file so it works regardless of install location
|
|
icon_path = os.path.join(
|
|
os.path.dirname(os.path.abspath(__file__)), "resources", "icons", "silo.svg"
|
|
)
|
|
if os.path.exists(icon_path):
|
|
self.__class__.Icon = icon_path
|
|
|
|
def Initialize(self):
|
|
"""Called when workbench is first activated."""
|
|
import silo_commands
|
|
|
|
self.toolbar_commands = [
|
|
"Silo_Open",
|
|
"Silo_New",
|
|
"Silo_Save",
|
|
"Silo_Commit",
|
|
"Silo_Pull",
|
|
"Silo_Push",
|
|
"Silo_Info",
|
|
"Silo_Settings",
|
|
]
|
|
|
|
self.appendToolbar("Silo", self.toolbar_commands)
|
|
self.appendMenu("Silo", self.toolbar_commands)
|
|
|
|
def Activated(self):
|
|
"""Called when workbench is activated."""
|
|
FreeCAD.Console.PrintMessage("Kindred Silo workbench activated\n")
|
|
self._show_shortcut_recommendations()
|
|
|
|
def Deactivated(self):
|
|
pass
|
|
|
|
def GetClassName(self):
|
|
return "Gui::PythonWorkbench"
|
|
|
|
def _show_shortcut_recommendations(self):
|
|
"""Show keyboard shortcut recommendations dialog on first activation."""
|
|
try:
|
|
param_group = FreeCAD.ParamGet(
|
|
"User parameter:BaseApp/Preferences/Mod/KindredSilo"
|
|
)
|
|
if param_group.GetBool("ShortcutsShown", False):
|
|
return
|
|
param_group.SetBool("ShortcutsShown", True)
|
|
|
|
from PySide import QtGui
|
|
|
|
msg = """<h3>Welcome to Kindred Silo!</h3>
|
|
<p>For the best experience, set up these keyboard shortcuts:</p>
|
|
<table style="margin: 10px 0;">
|
|
<tr><td><b>Ctrl+O</b></td><td> - </td><td>Silo_Open (Search & Open)</td></tr>
|
|
<tr><td><b>Ctrl+N</b></td><td> - </td><td>Silo_New (Register new item)</td></tr>
|
|
<tr><td><b>Ctrl+S</b></td><td> - </td><td>Silo_Save (Save & upload)</td></tr>
|
|
<tr><td><b>Ctrl+Shift+S</b></td><td> - </td><td>Silo_Commit (Save with comment)</td></tr>
|
|
</table>
|
|
<p><b>To set shortcuts:</b> Tools > Customize > Keyboard</p>
|
|
<p style="color: #888;">This message appears once.</p>"""
|
|
|
|
dialog = QtGui.QMessageBox()
|
|
dialog.setWindowTitle("Silo Keyboard Shortcuts")
|
|
dialog.setTextFormat(QtGui.Qt.RichText)
|
|
dialog.setText(msg)
|
|
dialog.setIcon(QtGui.QMessageBox.Information)
|
|
dialog.addButton("Set Up Now", QtGui.QMessageBox.AcceptRole)
|
|
dialog.addButton("Later", QtGui.QMessageBox.RejectRole)
|
|
if dialog.exec_() == 0:
|
|
FreeCADGui.runCommand("Std_DlgCustomize", 0)
|
|
except Exception as e:
|
|
FreeCAD.Console.PrintWarning("Silo shortcuts dialog: " + str(e) + "\n")
|
|
|
|
|
|
FreeCADGui.addWorkbench(SiloWorkbench())
|
|
FreeCAD.Console.PrintMessage("Silo workbench registered\n")
|