-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathExtQuickExt.py
More file actions
191 lines (161 loc) · 6.25 KB
/
ExtQuickExt.py
File metadata and controls
191 lines (161 loc) · 6.25 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from TDStoreTools import StorageManager
import TDFunctions as TDF
import copy
class ExtQuickExt:
def __init__(self, ownerComp):
self.ownerComp = ownerComp
self.dialog = self.ownerComp.op('popDialog')
self.ConfigComp = None
self.extTemplate = self.ownerComp.op('extTemplate')
self.stubser = self.ownerComp.op('stubser')
self.my_ext_type = 'QuickExt'
# < - DO NOT REMOVE THIS VERY IMPORTANT LINE!!! used by QuickExt to inject extension - >
self.MY_FORCED_TAG = f'# < - DO NOT REMOVE THIS VERY IMPORTANT LINE!!! used by {self.my_ext_type} to inject extension - >'
self.__modifyCompEditor()
def __modifyCompEditor(self):
compEditor = op.TDDialogs.op('CompEditor')
# copy self.extTemplate to compEditor as lower case self.my_ext_type+ExtensionText
if not compEditor.op(self.my_ext_type.lower()+"ExtensionText"):
new_ext = compEditor.copy(self.extTemplate, name=self.my_ext_type.lower()+"ExtensionText")
new_ext.nodeY = compEditor.op('emptyExtensionText').nodeY - new_ext.nodeHeight - 20
new_ext.nodeX = compEditor.op('emptyExtensionText').nodeX
# erase file par value
if hasattr(new_ext.par, 'file'):
new_ext.par.file.mode = ParMode.CONSTANT
new_ext.par.file.expr = ''
new_ext.par.file = ''
compEditor_ext = compEditor.op('CompEditorExt')
# Look for the line that contains "if extType in ['Standard', 'Empty']:" and modify it
lines = compEditor_ext.text.split('\n')
modified = False
for i, line in enumerate(lines):
if "if extType in ['Standard', 'Empty']:" in line:
lines[i] = line.replace("['Standard', 'Empty']", f"['Standard', 'Empty', '{self.my_ext_type}']")
modified = True
break
if modified:
compEditor_ext.text = '\n'.join(lines)
addMenuExec = compEditor.op('extensions/ext1/addMenuExec')
# Look for line that contains "menu.Open(['Standard', 'Empty'" and modify it
lines = addMenuExec.text.split('\n')
modified = False
for i, line in enumerate(lines):
if "menu.Open(['Standard', 'Empty']" in line:
lines[i] = line.replace("['Standard', 'Empty']", f"['Standard', 'Empty', '{self.my_ext_type}']")
modified = True
break
if modified:
addMenuExec.text = '\n'.join(lines)
def CreateExtension(self, _target):
if not _target:
return
self.ConfigComp = _target
self.dialog.Open(textEntry='Ext')
pass
def getExtIndex(self):
idx = self.ConfigComp.par.ext.sequence.numBlocks+1
for _seqBlock in self.ConfigComp.par.ext.sequence:
if not _seqBlock.par.object.eval():
idx = _seqBlock.index+1
break
return idx
def OnSelect(self, info, inject_ext = None):
if inject_ext is not None and self.MY_FORCED_TAG not in inject_ext.text:
# so: in kindergaertner we can only react to the tag `TDExtension`
# and for some reason when injecting an extTemplate through the comp editor, the tags are removed
# so when not injecting we also have the tag `TDExtension` and we've already done the work
return
sel = True if inject_ext is not None or info['buttonNum'] == 1 else False
if sel and self.ConfigComp:
masterUtils = self.ownerComp.op('ExtUtils')
masterExt = self.extTemplate
extIndex = self.getExtIndex()
extIndex = extIndex if inject_ext is None else extIndex-1
extModuleName = info['enteredText'] if info is not None else op.TDDialogs.op('CompEditor').ExtClassNames.get(extIndex)
edges = TDF.findNetworkEdges(self.ConfigComp)
if edges:
edgeX = edges['positions']['left']
edgeY = edges['positions']['top'] - 220
else:
edgeX = 0
edgeY = 0
xPos = edgeX - 400
yPos = edgeY
extPar = getattr(self.ConfigComp.par, 'extension' + str(extIndex))
extPromotePar = getattr(self.ConfigComp.par,
'promoteextension' + str(extIndex))
extNamePar = getattr(self.ConfigComp.par,
'extname' + str(extIndex))
if inject_ext is None:
extDat = self.ConfigComp.copy(masterExt, name=extModuleName)
else:
extDat = inject_ext
extDat.color = masterExt.color
extDat.tags = masterExt.tags
extDat.nodeWidth = masterExt.nodeWidth
extDat.nodeHeight = masterExt.nodeHeight
extDat.par.file.mode = ParMode.CONSTANT
extDat.par.file.expr = ''
extDat.par.file = ''
extDat.par.language = 'python'
extUtils = self.ConfigComp.copy(masterUtils, includeDocked=True)
extUtils.dock = extDat
#extUtils.par.file = ''
extensionText = copy.deepcopy(masterExt.text)
if self.MY_FORCED_TAG in extensionText:
# remove the manual tag from the text
new_text = extensionText.replace(self.MY_FORCED_TAG, '')
extensionText = new_text
extensionText = extensionText.replace('QuickExtTemplate',
extModuleName)
extDat.nodeX = xPos
extDat.nodeY = yPos
extDat.viewer = True
extDat.tags.add('TDExtension')
extPromotePar.val = True
extNamePar.val = ''
extDat.docked[0].nodeX = extDat.nodeX
extDat.docked[0].nodeY = extDat.nodeY - 200
extDat.docked[0].showDocked = True
extDat.current = True
self.__purgeTags(extDat)
self.__purgeTags(extUtils)
for _dock in extUtils.ops('*'):
#_dock.showDocked = False
self.__purgeTags(_dock)
if hasattr(_dock.par, 'file'):
_dock.par.file.mode = ParMode.CONSTANT
_dock.par.file.expr = ''
_dock.par.file = ''
extPar.val = "op('./" + extModuleName + "').module." \
+ extModuleName + '(me)'
extDat.text = extensionText
self.ConfigComp.initializeExtensions(extIndex-1)
self.__updateCompEditor(extIndex)
# TODO: stubify packages
#if self.ownerComp.par.Deploystubs.eval():
for _op in extUtils.findChildren(type=DAT):
if 'extPackage' in _op.tags:
self.stubser.StubifyDat(_op)
def __updateCompEditor(self, index):
compEditor = op.TDDialogs.op('CompEditor')
entry = compEditor.op('extensions/ext'+str(int(index)))
if entry is None:
return
bg = entry.op('extClassStatus1/bg')
bg.cook(force=True)
def __purgeTags(self, _op):
TAGS_TO_REMOVE = ['FNS_externalized', 'pi_suspect']
for _tag in TAGS_TO_REMOVE:
if _tag in _op.tags:
_op.tags.remove(_tag)
def OnCompEditor(self, new_ops):
# get the ops (probably only one) from new ops with the tags 'CompEditor' and 'extTemplate'
self.ConfigComp = op.TDDialogs.op('CompEditor').ConfigComp
for _op in new_ops:
self.OnSelect(None, inject_ext=_op)
pass
def OnClose(self, info):
pass
def OnOpen(self, info):
pass