Closed raganmd closed 5 years ago
This is good - but IMO a little clunky. You've got an examine DAT pulling data from your Cue_Lab
component, and then you're selecting to another dat, that you then have to sort. Blarg.
This can be come fragile - if the examine DAT or the sort DAT change you could have something broken. Instead, this is a great use for the script DAT.
Here's a sample approach for how you'd get there:
def onCook(scriptOp):
scriptOp.clear()
# set-up header for dat
header = ['menuName', 'menulabels']
# fetch Cues dict, and sort items
cues = sorted(op('Cue_Lab').fetch('Cues'))
# list comprehension to create a set of lists
# you can loop through
script_DAT_rows = [[cue, ''] for cue in cues]
# insert header at the top of the list of cues:
script_DAT_rows.insert(0, header)
# loop through all cues and fx
for each_cue in script_DAT_rows:
scriptOp.appendRow(each_cue)
return
I'd also consider a regular menu instead of a string menu here - again just to help ensure you're avoiding invalid entries. That one is your call for sure - it'd be a great thing to user test, watch someone else use your widget and then see where it helps or hinders.
Also - list comprehensions are amazing, and something you should learn more about and practice if you're not familiar:
https://www.pythonforbeginners.com/basics/list-comprehensions-in-python
Related to issue #4, entering strings can be a real bummer - all sorts of things can go wrong. Another way to think about this is to use a drop down menu instead.
Challenge - Find a way to use a DAT as a menu source for your component.
Hint - there's a thread on the forum about how to tackle this challenge. See if you can pull apart the example and make it work in your project.
https://www.derivative.ca/Forum/viewtopic.php?f=17&t=8502&p=32243&hilit=menu+from+table#p32243