|
| 1 | +""" |
| 2 | +Extension classes enhance TouchDesigner components with python. An |
| 3 | +extension is accessed via ext.ExtensionClassName from any operator |
| 4 | +within the extended component. If the extension is promoted via its |
| 5 | +Promote Extension parameter, all its attributes with capitalized names |
| 6 | +can be accessed externally, e.g. op('yourComp').PromotedFunction(). |
| 7 | +
|
| 8 | +Help: search "Extensions" in wiki |
| 9 | +""" |
| 10 | + |
| 11 | +from TDStoreTools import StorageManager |
| 12 | +import TDFunctions as TDF |
| 13 | + |
| 14 | +class ExtQuickExt: |
| 15 | + """ |
| 16 | + ExtExtensionCreate description |
| 17 | + """ |
| 18 | + def __init__(self, ownerComp): |
| 19 | + # The component to which this extension is attached |
| 20 | + self.ownerComp = ownerComp |
| 21 | + self.dialog = op('popDialog') |
| 22 | + self.ConfigComp = None |
| 23 | + self.extType = 'empty' |
| 24 | + |
| 25 | + |
| 26 | + def CreateExtension(self, _target): |
| 27 | + if not _target: |
| 28 | + return |
| 29 | + self.ConfigComp = _target |
| 30 | + self.dialog.Open(textEntry='Ext') |
| 31 | + pass |
| 32 | + |
| 33 | + def getExtIndex(self): |
| 34 | + idx = self.ConfigComp.par.ext.sequence.numBlocks+1 |
| 35 | + for _seqBlock in self.ConfigComp.par.ext.sequence: |
| 36 | + if not _seqBlock.par.object.eval(): |
| 37 | + idx = _seqBlock.index+1 |
| 38 | + break |
| 39 | + return idx |
| 40 | + |
| 41 | + def OnSelect(self, info): |
| 42 | + sel = True if info['buttonNum'] == 1 else False |
| 43 | + if sel and self.ConfigComp: |
| 44 | + extIndex = self.getExtIndex() |
| 45 | + extName = info['enteredText'] |
| 46 | + extModuleName = extName |
| 47 | + extPar = getattr(self.ConfigComp.par, 'extension' + str(extIndex)) |
| 48 | + extPromotePar = getattr(self.ConfigComp.par, |
| 49 | + 'promoteextension' + str(extIndex)) |
| 50 | + extNamePar = getattr(self.ConfigComp.par, |
| 51 | + 'extname' + str(extIndex)) |
| 52 | + edges =TDF.findNetworkEdges(self.ConfigComp) |
| 53 | + edgeX = edges['positions']['left'] |
| 54 | + edgeY = edges['positions']['top'] |
| 55 | + xPos = edgeX - 500 - (extIndex - 1) * 200 |
| 56 | + yPos = edgeY |
| 57 | + #extDat = self.ConfigComp.create(textDAT, extModuleName) |
| 58 | + |
| 59 | + masterExt = self.ownerComp.op(self.extType.lower() + |
| 60 | + 'ExtensionText') |
| 61 | + masterUtils = self.ownerComp.op('extUtils') |
| 62 | + extDat = self.ConfigComp.copy(masterExt, name=extModuleName) |
| 63 | + extUtils = self.ConfigComp.copy(masterUtils, includeDocked=True) |
| 64 | + extUtils.dock = extDat |
| 65 | + |
| 66 | + extensionText = self.ownerComp.op(self.extType.lower() + |
| 67 | + 'ExtensionText').text |
| 68 | + extensionText = extensionText.replace('DefaultExt', |
| 69 | + extModuleName) |
| 70 | + extDat.par.file.mode = ParMode.CONSTANT |
| 71 | + extDat.par.file.expr = '' |
| 72 | + extDat.par.file = '' |
| 73 | + extDat.text = extensionText |
| 74 | + extDat.par.language = 'python' |
| 75 | + extDat.nodeX = xPos |
| 76 | + extDat.nodeY = yPos |
| 77 | + extDat.viewer = True |
| 78 | + extDat.tags.add('TDExtension') |
| 79 | + extPar.val = "op('./" + extModuleName + "').module." \ |
| 80 | + + extModuleName + '(me)' |
| 81 | + extPromotePar.val = True |
| 82 | + extNamePar.val = '' |
| 83 | + extDat.docked[0].nodeX = extDat.nodeX + 150 |
| 84 | + extDat.docked[0].nodeY = extDat.nodeY - 120 |
| 85 | + extDat.docked[0].showDocked = True |
| 86 | + extDat.current = True |
| 87 | + |
| 88 | + for idx, _dock in enumerate(extUtils.docked): |
| 89 | + _dock.nodeX = extUtils.nodeX |
| 90 | + _dock.nodeY = extUtils.nodeY - 120 * (idx + 1) |
| 91 | + _dock.showDocked = False |
| 92 | + if hasattr(_dock.par, 'file'): |
| 93 | + _dock.par.file.mode = ParMode.CONSTANT |
| 94 | + _dock.par.file.expr = '' |
| 95 | + _dock.par.file = '' |
| 96 | + |
| 97 | + self.ConfigComp.par.reinitextensions.pulse() |
| 98 | + # fin |
| 99 | + |
| 100 | + def OnOpen(self, info): |
| 101 | + pass |
| 102 | + |
| 103 | + def OnClose(self, info): |
| 104 | + pass |
0 commit comments