update databasing system with minimum API, schema parsing and FreeCAD
integration
This commit is contained in:
109
pkg/freecad/InitGui.py
Normal file
109
pkg/freecad/InitGui.py
Normal file
@@ -0,0 +1,109 @@
|
||||
"""Silo FreeCAD Workbench - Item database integration."""
|
||||
|
||||
import os
|
||||
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
FreeCAD.Console.PrintMessage("Silo InitGui.py loading...\n")
|
||||
|
||||
|
||||
class SiloWorkbench(FreeCADGui.Workbench):
|
||||
"""Silo workbench for item database integration."""
|
||||
|
||||
MenuText = "Silo"
|
||||
ToolTip = "Item database and part management"
|
||||
Icon = ""
|
||||
|
||||
def __init__(self):
|
||||
# Find icon path
|
||||
try:
|
||||
locations = [
|
||||
os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "Silo"),
|
||||
os.path.join(FreeCAD.getResourceDir(), "Mod", "Silo"),
|
||||
os.path.expanduser(
|
||||
"~/.var/app/org.freecad.FreeCAD/data/FreeCAD/Mod/Silo"
|
||||
),
|
||||
os.path.expanduser("~/.FreeCAD/Mod/Silo"),
|
||||
]
|
||||
for silo_dir in locations:
|
||||
icon_path = os.path.join(silo_dir, "resources", "icons", "silo.svg")
|
||||
if os.path.exists(icon_path):
|
||||
self.__class__.Icon = icon_path
|
||||
FreeCAD.Console.PrintMessage("Silo icon: " + icon_path + "\n")
|
||||
break
|
||||
except Exception as e:
|
||||
FreeCAD.Console.PrintWarning("Silo icon error: " + str(e) + "\n")
|
||||
|
||||
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",
|
||||
]
|
||||
|
||||
self.appendToolbar("Silo", self.toolbar_commands)
|
||||
self.appendMenu("Silo", self.toolbar_commands)
|
||||
|
||||
def Activated(self):
|
||||
"""Called when workbench is activated."""
|
||||
FreeCAD.Console.PrintMessage("Silo workbench activated\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
" API: SILO_API_URL (default: http://localhost:8080/api)\n"
|
||||
)
|
||||
FreeCAD.Console.PrintMessage(
|
||||
" Projects: SILO_PROJECTS_DIR (default: ~/projects)\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/Silo"
|
||||
)
|
||||
if param_group.GetBool("ShortcutsShown", False):
|
||||
return
|
||||
param_group.SetBool("ShortcutsShown", True)
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
msg = """<h3>Welcome to Silo Workbench!</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")
|
||||
Reference in New Issue
Block a user