Skip to content

Commit

Permalink
Merge pull request #73 from APEbbers/Develop
Browse files Browse the repository at this point in the history
Preparation for translations
  • Loading branch information
APEbbers authored Sep 27, 2024
2 parents 9b075a7 + f75c63b commit c3f7366
Show file tree
Hide file tree
Showing 13 changed files with 1,074 additions and 244 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ __pycache__
.pre-commit-search-and-replace.yaml
.pttx
*.pptx
/CreateTranslations.bat
229 changes: 160 additions & 69 deletions FCBinding.py

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@
import FreeCADGui as Gui
import FCBinding


def QT_TRANSLATE_NOOP(context, text):
return text


translate = App.Qt.translate

try:
print("Activating Ribbon Bar...")
print(translate("FreeCAD Ribbon", "Activating Ribbon Bar..."))
mw = Gui.getMainWindow()
mw.workbenchActivated.connect(FCBinding.run)
except Exception as e:
print(e)

Gui.addLanguagePath(os.path.join(os.path.dirname(__file__), "translations"))
Gui.updateLocale()
516 changes: 384 additions & 132 deletions LoadDesign_Ribbon.py

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions LoadSettings_Ribbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def __init__(self):
self.form.EnableBackup.clicked.connect(self.on_EnableBackup_clicked)
self.form.BackUpLocation.clicked.connect(self.on_BackUpLocation_clicked)
self.form.IconSize_Small.textChanged.connect(self.on_IconSize_Small_TextChanged)
self.form.IconSize_Medium.textChanged.connect(self.on_IconSize_Medium_TextChanged)
self.form.IconSize_Medium.textChanged.connect(
self.on_IconSize_Medium_TextChanged
)
self.form.StyleSheetLocation.clicked.connect(self.on_StyleSheetLocation_clicked)

self.form.ShowText_Small.clicked.connect(self.on_ShowTextSmall_clicked)
Expand All @@ -115,7 +117,9 @@ def Cancel():
def GenerateJsonExit():
self.on_Close_clicked(self)

self.form.GenerateJsonExit.connect(self.form.GenerateJsonExit, SIGNAL("clicked()"), GenerateJsonExit)
self.form.GenerateJsonExit.connect(
self.form.GenerateJsonExit, SIGNAL("clicked()"), GenerateJsonExit
)
# endregion

return
Expand All @@ -135,7 +139,9 @@ def on_EnableBackup_clicked(self):

def on_BackUpLocation_clicked(self):
BackupFolder = ""
BackupFolder = StandardFunctions.GetFolder(parent=None, DefaultPath=Parameters_Ribbon.BACKUP_LOCATION)
BackupFolder = StandardFunctions.GetFolder(
parent=None, DefaultPath=Parameters_Ribbon.BACKUP_LOCATION
)
if BackupFolder != "":
self.pathBackup = BackupFolder
self.form.label_4.setText(BackupFolder)
Expand Down Expand Up @@ -209,12 +215,22 @@ def on_Cancel_clicked(self):
def on_Close_clicked(self):
Parameters_Ribbon.Settings.SetBoolSetting("BackupEnabled", self.Backup)
Parameters_Ribbon.Settings.SetStringSetting("BackupFolder", self.BackupLocation)
Parameters_Ribbon.Settings.SetIntSetting("IconSize_Small", int(self.form.IconSize_Small.text()))
Parameters_Ribbon.Settings.SetIntSetting("IconSize_Medium", int(self.form.IconSize_Medium.text()))
Parameters_Ribbon.Settings.SetIntSetting(
"IconSize_Small", int(self.form.IconSize_Small.text())
)
Parameters_Ribbon.Settings.SetIntSetting(
"IconSize_Medium", int(self.form.IconSize_Medium.text())
)
Parameters_Ribbon.Settings.SetStringSetting("Stylesheet", self.StyleSheet)
Parameters_Ribbon.Settings.SetBoolSetting("ShowIconText_Small", self.ShowText_Small)
Parameters_Ribbon.Settings.SetBoolSetting("ShowIconText_Medium", self.ShowText_Medium)
Parameters_Ribbon.Settings.SetBoolSetting("ShowIconText_Large", self.ShowText_Large)
Parameters_Ribbon.Settings.SetBoolSetting(
"ShowIconText_Small", self.ShowText_Small
)
Parameters_Ribbon.Settings.SetBoolSetting(
"ShowIconText_Medium", self.ShowText_Medium
)
Parameters_Ribbon.Settings.SetBoolSetting(
"ShowIconText_Large", self.ShowText_Large
)

# Close the form
self.form.close()
Expand Down
19 changes: 15 additions & 4 deletions Parameters_Ribbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,34 @@ def SetIntSetting(settingName: str, value: int):

# Define the resources
ICON_LOCATION = os.path.join(os.path.dirname(__file__), "Resources", "icons")
STYLESHEET_LOCATION = os.path.join(os.path.dirname(__file__), "Resources", "stylesheets")
STYLESHEET_LOCATION = os.path.join(
os.path.dirname(__file__), "Resources", "stylesheets"
)
UI_LOCATION = os.path.join(os.path.dirname(__file__), "Resources", "ui")

# Define the icon sizes
if Settings.GetIntSetting("IconSize_Small") is not None or Settings.GetIntSetting("IconSize_Small") > 0:
if (
Settings.GetIntSetting("IconSize_Small") is not None
or Settings.GetIntSetting("IconSize_Small") > 0
):
ICON_SIZE_SMALL = Settings.GetIntSetting("IconSize_Small")
else:
ICON_SIZE_SMALL = int(30)
Settings.SetIntSetting("IconSize_Small", 30)

if Settings.GetIntSetting("IconSize_Medium") is not None or Settings.GetIntSetting("IconSize_Medium") > 0:
if (
Settings.GetIntSetting("IconSize_Medium") is not None
or Settings.GetIntSetting("IconSize_Medium") > 0
):
ICON_SIZE_MEDIUM = Settings.GetIntSetting("IconSize_Medium")
else:
ICON_SIZE_MEDIUM = int(40)
Settings.SetIntSetting("IconSize_Medium", 40)

if Settings.GetIntSetting("IconSize_Large") is not None or Settings.GetIntSetting("IconSize_Large") > 0:
if (
Settings.GetIntSetting("IconSize_Large") is not None
or Settings.GetIntSetting("IconSize_Large") > 0
):
ICON_SIZE_LARGE = Settings.GetIntSetting("IconSize_Large")
else:
ICON_SIZE_LARGE = int(50)
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## FreeCAD Ribbon UI

An Ribbon UI for FreeCAD, based on the PyQtRibbon library (https://github.com/haiiliin/pyqtribbon).
This ribbon is based the work of Geolta (https://github.com/geolta/FreeCAD-Ribbon) and HakanSeven (https://github.com/HakanSeven12/Modern-UI) for the Modern-UI workbench.
An Ribbon UI for FreeCAD, based on the PyQtRibbon library (https://github.com/haiiliin/pyqtribbon).
This ribbon is based the work of Geolta (https://github.com/geolta/FreeCAD-Ribbon) and HakanSeven (https://github.com/HakanSeven12/Modern-UI) for the Modern-UI workbench.

![](https://github.com/APEbbers/FreeCAD-Ribbon/blob/main/Resources/Images/Screenshot.png)

Expand Down Expand Up @@ -51,12 +51,11 @@ Download this repository, extract the folder and copy it to the `Mod` folder of
1. Restart FreeCAD.

## Discussion
Feel free to discuss this addon on the [FreeCAD Forum](https://forum.freecad.org/viewtopic.php?t=79235).
Feel free to discuss this addon on the [FreeCAD Forum](https://forum.freecad.org/viewtopic.php?t=79235).

## Known Issues
- To retrieve all toolbars and command per workbench, all workbenches must be activated. Unfortunally, this results in a longer loading time for the Ribbon Design menu. (up to a few minutes)
- When the Assembly4 Workbench is installed, make sure that the internal assembly workbench is placed before the Assembly4 workbench. If not, the ribbon for the internal assembly will show the wrong panel named "Assembly".

## License
GPL v3.0 (see [LICENSE](LICENSE))

5 changes: 2 additions & 3 deletions Resources/stylesheets/default.qss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RibbonStackedWidget {
QToolButton, RibbonApplicationButton{
margin: 1px 3px 1px 3px;
padding: 0px;
border-radius: 4px;
border-radius: 4px;
text-align:left;
}
QToolButton:hover{
Expand All @@ -32,7 +32,7 @@ QToolButton, RibbonApplicationButton{
subcontrol-origin: content;
subcontrol-position: center center;
}
QToolButton::menu-button {
QToolButton::menu-button {
border-radius: 2px;
padding: 1px;
border-radius: 2px;
Expand All @@ -58,4 +58,3 @@ QToolBar {
padding: 2px;
/*background-color: transparent;*/
}

42 changes: 30 additions & 12 deletions Scripts/CreateDefaultRibbonStructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,9 @@
"Post Process",
"Check the CAM job for common errors",
],
"commands": {"CAM_Job": {"size": "large", "text": "Job", "icon": "CAM_Job"}},
"commands": {
"CAM_Job": {"size": "large", "text": "Job", "icon": "CAM_Job"}
},
},
"Tool Commands": {
"order": [
Expand Down Expand Up @@ -2879,7 +2881,9 @@ def CreateJson():
"order",
],
)
Dict_RibbonCommandPanel["workbenches"][WorkBenchName]["toolbars"]["order"] = ToolbarOrder
Dict_RibbonCommandPanel["workbenches"][WorkBenchName]["toolbars"][
"order"
] = ToolbarOrder

# Go through the toolbars
for key, value in wbToolbars.items():
Expand Down Expand Up @@ -2914,7 +2918,9 @@ def CreateJson():
for i3 in range(len(value)):
CommandOrder = Gui.Command.get(value[i3])
if CommandOrder is not None:
MenuNameOrder = CommandOrder.getInfo()["menuText"].replace("&", "")
MenuNameOrder = CommandOrder.getInfo()[
"menuText"
].replace("&", "")
Order.append(MenuNameOrder)

# Set the first command to large
Expand Down Expand Up @@ -2943,12 +2949,12 @@ def CreateJson():
],
)

Dict_RibbonCommandPanel["workbenches"][WorkBenchName]["toolbars"][Toolbar][
"order"
] = Order
Dict_RibbonCommandPanel["workbenches"][WorkBenchName]["toolbars"][Toolbar]["commands"][
CommandName
] = {
Dict_RibbonCommandPanel["workbenches"][WorkBenchName][
"toolbars"
][Toolbar]["order"] = Order
Dict_RibbonCommandPanel["workbenches"][WorkBenchName][
"toolbars"
][Toolbar]["commands"][CommandName] = {
"size": Size,
"text": MenuName,
"icon": IconName,
Expand Down Expand Up @@ -3104,7 +3110,12 @@ def List_ReturnCustomToolbars():
).GetGroups()

for Group in CustomToolbars:
Parameter = App.ParamGet("User parameter:BaseApp/Workbench/" + WorkBenchName + "/Toolbar/" + Group)
Parameter = App.ParamGet(
"User parameter:BaseApp/Workbench/"
+ WorkBenchName
+ "/Toolbar/"
+ Group
)
Name = Parameter.GetString("Name")

ListCommands = []
Expand Down Expand Up @@ -3137,7 +3148,12 @@ def Dict_ReturnCustomToolbars(WorkBenchName):
).GetGroups()

for Group in CustomToolbars:
Parameter = App.ParamGet("User parameter:BaseApp/Workbench/" + WorkBenchName + "/Toolbar/" + Group)
Parameter = App.ParamGet(
"User parameter:BaseApp/Workbench/"
+ WorkBenchName
+ "/Toolbar/"
+ Group
)
Name = Parameter.GetString("Name")

if Name != "":
Expand All @@ -3163,7 +3179,9 @@ def Dict_AddCustomToolbarsToWorkbench(WorkBenchName):
try:
for CustomToolbar in Dict_CustomPanels["customToolbars"][WorkBenchName]:
ListCommands = []
Commands = Dict_CustomPanels["customToolbars"][WorkBenchName][CustomToolbar]["commands"]
Commands = Dict_CustomPanels["customToolbars"][WorkBenchName][
CustomToolbar
]["commands"]

for key, value in Commands.items():
for i in range(len(List_Commands)):
Expand Down
4 changes: 3 additions & 1 deletion Scripts/GenerateCommandsList.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def CreateLists():
# get the command with this name
command = Gui.Command.get(CommandName[0])
WorkBenchName = CommandName[1]
if command is not None and not List_QuickAccessCommands.__contains__(CommandName[0]):
if command is not None and not List_QuickAccessCommands.__contains__(
CommandName[0]
):
# get the icon for this command
if command.getInfo()["pixmap"] != "":
Icon = Gui.getIcon(command.getInfo()["pixmap"])
Expand Down
10 changes: 6 additions & 4 deletions Scripts/UpdateCommandNames.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,19 @@ def UpdateCommands():
# Continue if the "Toolbar" is not named order. This is the orderlist for the toolbars
if ToolBar != "order":
# Go through the commands in the toolbar
for Command in Dict_RibbonCommandPanel["workbenches"][WorkBench]["toolbars"][ToolBar]["commands"]:
for Command in Dict_RibbonCommandPanel["workbenches"][WorkBench][
"toolbars"
][ToolBar]["commands"]:
# Get the command (key) and its custom name (value) from the commandlist
# And compare them with the command in the Dict_RibbonCommandPanel
for key, value in Dict_Commands.items():
# If the command and key are equal and value is not empty or three dots,
# Get the custom name and change the text in the Dict_RibbonCommandPanel
if Command == key:
if value[2] != "" and value[2] != "...":
Dict_RibbonCommandPanel["workbenches"][WorkBench]["toolbars"][ToolBar]["commands"][
Command
]["text"] = value[2]
Dict_RibbonCommandPanel["workbenches"][WorkBench][
"toolbars"
][ToolBar]["commands"][Command]["text"] = value[2]


def WriteJson():
Expand Down
24 changes: 18 additions & 6 deletions Standard_Functions_RIbbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ def restart_freecad():

args = QtWidgets.QApplication.arguments()[1:]
if Gui.getMainWindow().close():
QtCore.QProcess.startDetached(QtWidgets.QApplication.applicationFilePath(), args)
QtCore.QProcess.startDetached(
QtWidgets.QApplication.applicationFilePath(), args
)

return

Expand Down Expand Up @@ -331,17 +333,23 @@ def GetFileDialog(Filter="", parent=None, DefaultPath="", SaveAs: bool = True) -

file = ""
if SaveAs is False:
file = QFileDialog.getOpenFileName(parent=parent, caption="Select a file", dir=DefaultPath, filter=Filter)[0]
file = QFileDialog.getOpenFileName(
parent=parent, caption="Select a file", dir=DefaultPath, filter=Filter
)[0]
if SaveAs is True:
file = QFileDialog.getSaveFileName(parent=parent, caption="Select a file", dir=DefaultPath, filter=Filter)[0]
file = QFileDialog.getSaveFileName(
parent=parent, caption="Select a file", dir=DefaultPath, filter=Filter
)[0]
return file


def GetFolder(parent=None, DefaultPath="") -> str:
from PySide.QtWidgets import QFileDialog

Directory = ""
Directory = QFileDialog.getExistingDirectory(parent=parent, caption="Select Folder", dir=DefaultPath)
Directory = QFileDialog.getExistingDirectory(
parent=parent, caption="Select Folder", dir=DefaultPath
)

return Directory

Expand All @@ -366,7 +374,9 @@ def CreateToolbar(Name: str, WorkBenchName: str = "Global", ButtonList: list = [
# Define the name for the toolbar
ToolBarName = Name
# define the parameter path for the toolbar
WorkbenchToolBarsParamPath = "User parameter:BaseApp/Workbench/" + ToolbarGroupName + "/Toolbar/"
WorkbenchToolBarsParamPath = (
"User parameter:BaseApp/Workbench/" + ToolbarGroupName + "/Toolbar/"
)

# add the ToolbarGroup in the FreeCAD Parameters
WorkbenchToolbar = App.ParamGet(WorkbenchToolBarsParamPath + ToolBarName)
Expand All @@ -392,7 +402,9 @@ def RemoveWorkBenchToolbars(Name: str, WorkBenchName: str = "Global") -> None:
# Define the name for the toolbar
ToolBarName = Name
# define the parameter path for the toolbar
ToolBarsParamPath = "User parameter:BaseApp/Workbench/" + ToolbarGroupName + "/Toolbar/"
ToolBarsParamPath = (
"User parameter:BaseApp/Workbench/" + ToolbarGroupName + "/Toolbar/"
)

custom_toolbars = App.ParamGet(ToolBarsParamPath)
custom_toolbars.RemGroup(ToolBarName)
Expand Down
Loading

0 comments on commit c3f7366

Please sign in to comment.