I am trying to implement a Drop Window using the MASH api
You can see in the example (copied below) that it works as a python generator, which I’m quite new to. I am really confused about the seemingly cyclical reference to “smartPreset” - it’s defined outside the function but referenced inside the function.
It all seems to work fine when run directly, but I want to import my script as a module and call the function to build the window. That’s where it all falls apart and I get a NameError. How can I create this generator window after I import it as a module? I hope that makes sense, I’m fumbling my way through this.
import flux.core as fx def runPreset(): ''' ... Some cool code ... ''' fx.DropWindow.getDrop(label='Put a window title here:', callback=lambda data: smartPreset.send(data)) node = yield ''' 'node' will be a string of all the nodes you dropped onto the Drop Window Multiple nodes will be newline seperated. One way to split the string is like so: ''' nodeList = node.split('\n') print nodeList # print it out so that this example actually does something ''' Finish the Generator with a Yield so that it knows where to stop. ''' yield ''' Now run your Smart Preset like so ''' smartPreset = runPreset() smartPreset.next()