Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue translation support - tooltips #468

Open
wants to merge 10 commits into
base: development
Choose a base branch
from
11 changes: 6 additions & 5 deletions AnimationLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import FreeCAD as App

import Asm4_libs as Asm4
from Asm4_Translate import translate

# from AnimationProvider import animationProvider

Expand Down Expand Up @@ -121,11 +122,11 @@ def __init__(self):


def GetResources(self):
return {"MenuText": "Animate Assembly",
"ToolTip": "Animate Assembly",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_GearsAnimate.svg')
}

return {
"MenuText": "Animate Assembly",
"ToolTip": translate("Commands5", "Animate Assembly"),
"Pixmap": os.path.join(Asm4.iconPath, "Asm4_GearsAnimate.svg"),
}

def IsActive(self):
# is there an active document ?
Expand Down
19 changes: 9 additions & 10 deletions Asm4_Measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
# only needed for icons
import Asm4_libs as Asm4
import selectionFilter


from BaseCommand import BaseCommand
from Asm4_Translate import translate


"""
Expand Down Expand Up @@ -88,15 +88,14 @@ def getIcon(self):
| The menu and toolbar command |
+-----------------------------------------------+
"""
class MeasureCmd():
def __init__(self):
super(MeasureCmd,self).__init__()

def GetResources(self):
return {"MenuText": "Measure",
"ToolTip": "Measure Tool",
"Pixmap" : os.path.join( iconDir , 'Part_Measure.svg')
}

class MeasureCmd(BaseCommand):
def __init__(self):
super(MeasureCmd, self).__init__()
self.pixmap = os.path.join(iconDir, "Part_Measure.svg")
self.menutext = "Measure"
self.tooltip = translate("Commands5", "Measure Tool")

def IsActive(self):
if App.ActiveDocument:
Expand Down
14 changes: 11 additions & 3 deletions Asm4_Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
#
# Asm4_Translate.py


import os
import FreeCADGui as Gui
import FreeCAD as App

Gui.addLanguagePath(os.path.join(os.path.dirname(__file__), "Resources/translations"))


def _atr(context: str, text: str) -> str:
"""Wrap strings which should be translated in in this function."""
return App.Qt.translate(context, text)


# dummy function for the QT translator
def QT_TRANSLATE_NOOP(context, text):
def QT_TRANSLATE_NOOP(context: str, text: str) -> str:
"""NOP Marker Macro Alias for strings for which FreeCAD/Qt handles translations."""
return text


Expand Down
16 changes: 16 additions & 0 deletions BaseCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class BaseCommand():
"""Base class to prepare all the commands."""

def __init__(self):
pass

def Activated(self):
pass

def GetResources(self):
return {
"Pixmap": self.pixmap,
"MenuText": self.menutext,
"ToolTip": self.tooltip,
}

44 changes: 22 additions & 22 deletions FastenersDummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import FreeCADGui as Gui
import FreeCAD as App

from BaseCommand import BaseCommand
from Asm4_Translate import translate
#from FastenerBase import FSBaseObject

import Asm4_libs as Asm4
Expand All @@ -28,10 +31,14 @@
screwObj = sm.createFastener('ISO7046', 'M6', '20', 'simple', shapeOnly=False)
"""

class insertFastener:
class insertFastener(BaseCommand):
"My tool object"
def __init__(self, fastenerType):
self.fastenerType = fastenerType
self.tooltip = translate("Fasteners",
"FastenersWorkbench is not installed.\n \n"
"You can install it with the FreeCAD AddonsManager:\n"
"Menu Tools > Addon Manager > fasteners")
# Screw:
if self.fastenerType=='Screw':
self.menutext = translate("Fasteners", "Insert Screw")
Expand Down Expand Up @@ -72,17 +79,17 @@ def Activated(self):
| dummy placeFastener |
+-----------------------------------------------+
"""
class placeFastenerCmd():
class placeFastenerCmd(BaseCommand):
"My tool object"

def __init__(self):
super(placeFastenerCmd,self).__init__()

def GetResources(self):
return {"MenuText": "Edit Attachment of a Fastener",
"ToolTip": 'FastenersWorkbench is not installed.\n \nYou can install it with the FreeCAD AddonsManager:\nMenu Tools > Addon Manager > fasteners',
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_mvFastener.svg')
}
self.icon = os.path.join( Asm4.iconPath , 'Asm4_mvFastener.svg')
self.menutext = translate("Fasteners", "Edit Attachment of a Fastener")
self.tooltip = translate("Fasteners",
"FastenersWorkbench is not installed.\n \n"
"You can install it with the FreeCAD AddonsManager:\n"
"Menu Tools > Addon Manager > fasteners")

def IsActive(self):
# it's a dummy, always inactive
Expand All @@ -97,15 +104,13 @@ def Activated(self):
| dummy parameters |
+-----------------------------------------------+
"""
class changeFSparametersCmd():
class changeFSparametersCmd(BaseCommand):
def __init__(self):
super(changeFSparametersCmd,self).__init__()

def GetResources(self):
return {"MenuText": "Change Fastener parameters",
"ToolTip": "Change Fastener parameters",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_FSparams.svg')
}
self.icon = os.path.join( Asm4.iconPath , 'Asm4_FSparams.svg')
self.menutext = translate("Fasteners", "Change Fastener parameters")
self.tooltip = translate("Fasteners",
"Change Fastener parameters")

def IsActive(self):
# it's a dummy, always inactive
Expand All @@ -116,15 +121,10 @@ def Activated(self):



class cloneFastenersToAxesCmd():
class cloneFastenersToAxesCmd(BaseCommand):
def __init__(self):
super(cloneFastenersToAxesCmd,self).__init__()

def GetResources(self):
return {"MenuText": "Clone Fastener to Axes",
"ToolTip": 'FastenersWorkbench is not installed.\n \nYou can install it with the FreeCAD AddonsManager:\nMenu Tools > Addon Manager > fasteners',
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_cloneFasteners.svg')
}
self.pixmap

def IsActive(self):
# it's a dummy, always inactive
Expand Down
108 changes: 52 additions & 56 deletions FastenersLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
from Asm4_Translate import translate



# icon to show in the Menu, toolbar and widget window
iconFile = os.path.join( Asm4.iconPath , 'Asm4_mvFastener.svg')


iconFile = os.path.join(Asm4.iconPath, "Asm4_mvFastener.svg")


"""
Expand All @@ -49,7 +46,8 @@

"""

class insertFastener:

class insertFastener(BaseCommand):
"My tool object"
def __init__(self, fastenerType):
self.FSclass = fastenerType
Expand All @@ -59,40 +57,43 @@ def __init__(self, fastenerType):
'ThreadedRod':(0.3, 0.5, 0.75)
}
# Screw
if self.FSclass == 'Screw':
self.menutext = translate("Fasteners", "Insert Screw")
self.tooltip = "<p>Insert a Screw into the Assembly</p>"
self.tooltip += "<p>If another fastener is selected, a new fastener of the same type is created in the same assembly."
self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it."
self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.</p>"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Screw.svg')
if self.FSclass == "Screw":
self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Screw.svg")
self.menutext = translate("Fasteners", "Insert Screw")
self.tooltip = translate(
"Fasteners",
"<p>Insert a Screw into the Assembly</p>\n"
"<p>If another fastener is selected, a new fastener of the same type is created in the same assembly.\n"
"If an axis or LCS is selected, the new fastener will be attached to it.\n"
"If an assembly is selected, the new fastener will be inside that assembly.</p>",
)
# Nut
elif self.FSclass == 'Nut':
self.menutext = translate("Fasteners", "Insert Nut")
self.tooltip = "<p>Insert a Nut into the Assembly</p>"
self.tooltip += "<p>If another fastener is selected, a new fastener of the same type is created in the same assembly."
self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it."
self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.</p>"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Nut.svg')
elif self.FSclass == "Nut":
self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Nut.svg")
self.menutext = translate("Fasteners", "Insert Nut")
self.tooltip = translate(
"Fasteners",
"<p>Insert a Nut into the Assembly</p>\n"
"<p>If another fastener is selected, a new fastener of the same type is created in the same assembly.\n"
"If an axis or LCS is selected, the new fastener will be attached to it.\n"
"If an assembly is selected, the new fastener will be inside that assembly.</p>",
)
# Washer
elif self.FSclass == 'Washer':
self.menutext = translate("Fasteners", "Insert Washer")
self.tooltip = "<p>Insert a Washer into the Assembly</p>"
self.tooltip += "<p>If another fastener is selected, a new fastener of the same type is created in the same assembly."
self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it."
self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.</p>"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Washer.svg')
elif self.FSclass == "Washer":
self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Washer.svg")
self.menutext = translate("Fasteners", "Insert Washer")
self.tooltip = translate(
"Fasteners",
"<p>Insert a Washer into the Assembly</p>\n"
"<p>If another fastener is selected, a new fastener of the same type is created in the same assembly.\n"
"If an axis or LCS is selected, the new fastener will be attached to it.\n"
"If an assembly is selected, the new fastener will be inside that assembly.</p>",
)
# Threaded Rod (makes errors)
elif self.FSclass == 'ThreadedRod':
self.menutext = translate("Fasteners", "Insert threaded rod")
self.tooltip = "Insert threaded rod"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Rod.svg')


def GetResources(self):
return {"MenuText": self.menutext,
"ToolTip" : self.tooltip,
"Pixmap" : self.icon }
elif self.FSclass == "ThreadedRod":
self.pixmap = os.path.join(Asm4.iconPath, "Asm4_Rod.svg")
self.menutext = translate("Fasteners", "Insert threaded rod")
self.tooltip = translate("Fasteners", "Insert threaded rod")

def IsActive(self):
# if Asm4.getAssembly():
Expand Down Expand Up @@ -216,16 +217,14 @@ def Activated(self):
| wrapper for FSChangeParams |
+-----------------------------------------------+
"""
class changeFSparametersCmd():

def __init__(self):
super(changeFSparametersCmd,self).__init__()

def GetResources(self):
return {"MenuText": "Change Fastener parameters",
"ToolTip": "Change Fastener parameters",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_FSparams.svg')
}
class changeFSparametersCmd(BaseCommand):
def __init__(self):
super(changeFSparametersCmd, self).__init__()
self.pixmap = os.path.join(Asm4.iconPath, "Asm4_FSparams.svg")
self.menutext = translate("Fasteners", "Change Fastener parameters")
self.tooltip = translate("Fasteners", "Change Fastener parameters")

def IsActive(self):
if App.ActiveDocument and getSelectionFS():
Expand Down Expand Up @@ -278,21 +277,18 @@ def isFastener(obj):
+-----------------------------------------------+
| clone per App::Link fasteners |
+-----------------------------------------------+

Select a fastener and several datum axes and the fastener will
be cloned (as App::Link) and attached to those axes
"""
class cloneFastenersToAxesCmd():
class cloneFastenersToAxesCmd(BaseCommand):

def __init__(self):
super(cloneFastenersToAxesCmd,self).__init__()

def GetResources(self):
return {"MenuText": "Clone Fastener to Axes",
"ToolTip": "Clone Fastener to Axes",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_cloneFasteners.svg')
}

self.pixmap = os.path.join( Asm4.iconPath , 'Asm4_cloneFasteners.svg')
self.menutext = translate("Fasteners", "Clone Fastener to Axes")
self.tooltip = translate("Fasteners", "Clone Fastener to Axes")

def IsActive(self):
self.selection = self.getSelectedAxes()
if Asm4.getAssembly() and self.selection:
Expand All @@ -316,7 +312,7 @@ def Activated(self):
if axis and axis.Document:
newFstnr = Asm4.cloneObject(fstnr)
Asm4.placeObjectToLCS(newFstnr, axisData[2], axis.Document.Name, axisData[3])

Gui.Selection.clearSelection()
self.rootAssembly = Asm4.getAssembly()
if self.rootAssembly:
Expand All @@ -327,7 +323,7 @@ def getSelectedAxes(self):
holeAxes = []
fstnr = None
selection = Gui.Selection.getSelectionEx('', 0)

if selection:
for s in selection:
for seNames in s.SubElementNames:
Expand Down
7 changes: 3 additions & 4 deletions HelpCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
#
# HelpCmd.py

import os, webbrowser

import FreeCADGui as Gui

import os
import webbrowser
import Asm4_libs as Asm4
from Asm4_Translate import translate
import FreeCADGui as Gui


"""
Expand Down
Loading