我正在检查进度条的值,如果它是100,我想退出,以便完成的上传不会被打印两次。如果我查询进度条,我不知道为什么100会出现两次。
def callback(self,*args):
cmds.progressBar('progbar', edit=True, step=1)
if cmds.progressBar('progbar',q=True, progress=True)==100:
print "Finished Uploading."
break
我找到了a similar thread,但我的情况略有不同......
答案 0 :(得分:0)
您尚未提供足够的代码示例,以便能够为您提供帮助。首先,你的callback()函数包含一个break语句,即使这个函数实际上没有循环。
在任何情况下,我都会编写以下示例进行检查,实际上只会在达到100时打印“完成上传”一次。
import maya.cmds as cmds
cmds.progressBar('progressBar') # initialise the progress bar
def callback():
# Begin loop from 0 to 100 - remember range(n) returns numbers from 0 (inclusive) to n (exclusive)
for i in range(101):
cmds.progressBar('progressBar', edit=True, step=1) # increase step by 1
if (cmds.progressBar('progressBar',q=True, progress=True)==100):
print "Finished Uploading."
break
# Theoretically, breaking is simply here so that you stop wasting iterations in some cases,
# but it's not necessary for the printout, since we have only specified that the print will
# happen when the progress value is equal to exactly 100.
# Finally, if there is NO loop (like the code you pasted originally), then you shouldn't have
# a break.
callback()
问题的一个可能原因是您的进度条超过了100步进度,并且进度条的最大值为100.在这种情况下,随着您不断增加步数,值将保持为100(这是最大值),因此每次查询它是否等于100时,它将返回True。
不幸的是,如果没有您提供的更具体的信息,我无法回答任何更具体的问题。