-
Notifications
You must be signed in to change notification settings - Fork 22
/
loadToolsAuto.py
86 lines (57 loc) · 2.27 KB
/
loadToolsAuto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# This tool gets "Tools" array from file loadToolsSettings.py and
# generate loadTools.py file.
# This should be run only once if you added new macro.
# There is no need to run it ad each workbench startup.
import loadToolsSettings
arr = loadToolsSettings.Tools
output = '''# This file has been automatically generated by the loadToolsAuto.py script. Don't change it here.
import FreeCAD, FreeCADGui
translate = FreeCAD.Qt.translate
def QT_TRANSLATE_NOOP(context, text):
return text
import os, sys
import fakemodule
path = os.path.dirname(fakemodule.__file__)
iconPath = os.path.join(path, "Icons")
'''
# ######################################################################################################################
# Create Classes
# ######################################################################################################################
i = 0
while i < len(arr):
output += '''
# ######################################################################################################################
class '''+arr[i+1]+'''():
def GetResources(self):
return {"Pixmap" : os.path.join(iconPath, "'''+arr[i+1]+'''.'''+arr[i+2]+'''"),
"MenuText": QT_TRANSLATE_NOOP("'''+arr[i+1]+'''", "'''+arr[i+3]+'''"),
"ToolTip" : QT_TRANSLATE_NOOP("'''+arr[i+1]+'''", "'''+arr[i+4]+'''"),
"Accel" : "" }
def Activated(self):
import os, sys
import fakemodule
modulePath = sys.path
module = "'''+arr[i+1]+'''"
path = os.path.dirname(fakemodule.__file__)
path = os.path.join(path, "Tools")
'''
if arr[i] != "":
output += '''path = os.path.join(path, "'''+arr[i]+'''")'''
output += '''
sys.path.append(path)
if module in sys.modules:
del sys.modules[module]
__import__(module, globals(), locals(), [], 0)
sys.path = modulePath
return
def IsActive(self):
# not needed now, maybe in the future
return True
FreeCADGui.addCommand("'''+arr[i+1]+'''", '''+arr[i+1]+'''())
'''
i += 5
# ######################################################################################################################
# Overwrite the file loadTools.py
# ######################################################################################################################
with open("loadTools.py", 'w') as file:
file.write("%s" % output)