Hello
I would like to create a ubiquitous gui class called "UserQueryUI". The idea is that this will be a go-to user prompt for any script with a question or announcement to the user and their choice of an affirmative, negative or "cancel op" reply . What I am currently trying to work out is how I can call this class in any script and ‘wait’ for an answer.
My snag is that when I call the class and it's .create method, the script doesn't stop and wait for the user to reply before moving on resulting in the script/tool completing before the user even replies..
This approach was a shot in the dark so let me know if what I ask is not possible or if there is a better approach, but if there is a solution, I would love to learn about it.
Cheers
#example script and user query class
import maya.cmds as cmds
#External Script
def testFunction():
q=UserQueryUI('Replace with query text' ,'affirmativeButtonTxt','negativeButtonTxt')
q.create()
#Script needs to wait for a reply before calling the reply from the class.
print 'Users reply', q.reply
#UserQueryUI Class
class UserQueryUI:
reply = None
def __init__(self, query ,affirmativeReply,negativeReply):
self.title = 'userQueryUI'
self.query = query
self.affirmativeReply = affirmativeReply
self.negativeReply = negativeReply
def create(self):
def affirmative(x):
print 'Positive reply'
reply=True
cmds.deleteUI('userQueryUI',window=True )
def negative(x):
print 'Negative reply'
reply=False
cmds.deleteUI('userQueryUI',window=True )
def cancelTool(x):
print 'Cancel reply'
reply=None
cmds.deleteUI('userQueryUI',window=True )
print '--Creating userQueryUI with query',self.query
self.window = cmds.window(
self.name, title=self.title)
self.form = cmds.formLayout()
self.queryText = cmds.text(self.query, w=400, align='left' )
height = 1
cmds.formLayout(self.form, edit=True, attachForm=[(self.queryText, 'top', 5),(self.queryText,'left',5)])
self.affirmativeButton = cmds.button(l=self.affirmativeReply, al='center', w=100,h=25, c = affirmative)
self.negativeButton = cmds.button(l=self.negativeReply, al='center', w=100,h=25, c = negative)
self.cancelButton = cmds.button(l='Cancel Tool', al='center', w=100,h=25, c = cancelTool)
cmds.formLayout(self.form, edit=True, attachForm=[
(self.affirmativeButton, 'top', height+50),
(self.affirmativeButton,'left',50),
(self.negativeButton, 'top', height+50),
(self.negativeButton,'left',150),
(self.cancelButton, 'top', height+50),
(self.cancelButton,'left',250)
])
cmds.showWindow(self.window)
cmds.window(self.window, edit=True, s=True, wh=(400,height+80))
testFunction()
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe