So heres my functional UI:
import maya.cmds as cmds
import os
from functools import partial
fruits=['apples','oranges','bananas']
veggies=['carrots','onions','celery']
def populateTextScrollList(textScrollList,itemlist,*args):
cmds.textScrollList(textScrollList,edit=True,ra=True)
for item in itemlist:
cmds.textScrollList(textScrollList,edit=True,a=item)
def UI():
#check if window exists
if cmds.window('UI', exists=True):
cmds.deleteUI('UI')
window=cmds.window('UI', title='UI',minimizeButton=False , maximizeButton=False, sizeable=False)
layout=cmds.columnLayout('masterLayout',w=300)
#Produce frame
cmds.frameLayout(label='Produce',parent=layout)
produceList=cmds.textScrollList('produceList')
produceRadioBtnGrp=cmds.radioButtonGrp(labelArray2=['fruit','vegetable'], numberOfRadioButtons=2,select=1,on1=partial(populateTextScrollList,produceList,fruits),on2=partial(populateTextScrollList,produceList,veggies))
populateTextScrollList(produceList,fruits)
cmds.button(label='confirm list')
cmds.text(label='')
#launch UI
UI()
I fee like the radioButtonGroup() command, with those partial() commands is just too cumbersome.
I had tried to use a simpler function callback:
import maya.cmds as cmds
import os
from functools import partial
fruits=['apples','oranges','bananas']
veggies=['carrots','onions','celery']
def populateTextScrollList(textScrollList,itemlist,*args):
print 'populateTextScrollList(list)...'
cmds.textScrollList(textScrollList,edit=True,ra=True)
for item in itemlist:
cmds.textScrollList(textScrollList,edit=True,a=item)
def updateTheList(*args):
selectedRadioButton=cmds.radioButtonGrp(produceRadioBtnGrp,q=True,select=True)
populateTextScrollList(produceList,selectedRadioButton)
def UI():
if cmds.window('UI', exists=True):
cmds.deleteUI('UI')
window=cmds.window('UI', title='UI',minimizeButton=False , maximizeButton=False, sizeable=False)
layout=cmds.columnLayout('masterLayout',w=300)
#Produce frame
cmds.frameLayout(label='Produce',parent=layout)
produceList=cmds.textScrollList('produceList')
produceRadioBtnGrp=cmds.radioButtonGrp(labelArray2=['fruit','vegetable'], numberOfRadioButtons=2,select=1,cc=updateTheList)
populateTextScrollList(produceList,fruits)
cmds.button(label='confirm list')
cmds.text(label='')
#launch UI
cmds.showWindow(window)
UI()
and use an external function updateTheList() to repopulate the textScrollList
but the two functions ( UI() and updateTheList() ) are ignorant of each other, so the updateTheList() function can’t find any of the controls created in UI().
I can’t query the state of the radioButtonGrp or populate the textScrollList from an external function,
because the function updateTheList() throws an error that the controls are undefined.
how is this typically done?
how do I query and update UI controls from external functions?