1

我正在为一个 CFD 可视化程序编写一个脚本,它有一个与 python 的接口。我创建了一个通用对话框,用户可以在其中输入一些值。现在,如果输入为假,我想重复该对话框(这仅意味着一个变量大于另一个变量):

items = []
items.append(['text',ITEM_TEXT,"Automatically save the evaluation in data file(s)\n",""])
items.append(['text',ITEM_TEXT,"Determine the range of timesteps that you want to save:",""])
items.append(['step_begin',ITEM_INT,"Start timestep:","Start timestep",first_step,first_step,timesteps])
items.append(['step_end',ITEM_INT,"End timestep:","End timestep",timesteps,first_step,timesteps])
a = CeiQtGenericDialog(items,None,"Save evaluation","Ok","Cancel")
ret = a.doit()

if (ret > 0):
    for i in a.getValues():
        if (i=='step_begin'):
            begin = a.getValue(i)
        if (i=='step_end'):
            end = a.getValue(i)

    if (begin > end):
        items2 = []
        items2.append(['text',ITEM_TEXT,"Start timestep must be smaller than end timestep!!",""])
        a = CeiQtGenericDialog(items2,None,"Error","Ok","Cancel")
        ret = a.doit()

        if (ret > 0):
            ????

a.getValues()之前存储了通用对话框的值。如果我想跳回之前的通用对话框,现在最后。换句话说,我想从某一行开始重复代码,以便用户可以在之前的通用对话框中重复输入“step_begin”和“step_end”,这怎么可能?

编辑/如果用户在通用对话框中单击确定,则 ret 获得值 1 如果用户单击取消,则 ret 获得值 0

4

2 回答 2

0

我会使用如下的while循环:

begin = 0
end = -1
ret = 1
while (begin > end and ret > 0):
    items = []
    items.append(['text',ITEM_TEXT,"Automatically save the evaluation in data file(s)\n",""])
    items.append(['text',ITEM_TEXT,"Determine the range of timesteps that you want to save:",""])
    items.append(['step_begin',ITEM_INT,"Start timestep:","Start timestep",first_step,first_step,timesteps])
    items.append(['step_end',ITEM_INT,"End timestep:","End timestep",timesteps,first_step,timesteps])
    a = CeiQtGenericDialog(items,None,"Save evaluation","Ok","Cancel")
    ret = a.doit()

    if (ret > 0):
        for i in a.getValues():
            if (i=='step_begin'):
                begin = a.getValue(i)
            if (i=='step_end'):
                end = a.getValue(i)

        if (begin > end):
            items2 = []
            items2.append(['text',ITEM_TEXT,"Start timestep must be smaller than end timestep!!",""])
            a = CeiQtGenericDialog(items2,None,"Error","Ok","Cancel")
            ret = a.doit()
于 2013-11-06T08:02:38.393 回答
0

我认为您应该在没有得到结果的情况下重复整个这一部分

while True:
    a = CeiQtGenericDialog(items,None,"Save evaluation","Ok","Cancel")
    ret = a.doit()

    if (ret < 0): 
        break # if cancel dialog will not proceed data analysis
    for i in a.getValues():
        if (i=='step_begin'):
            begin = a.getValue(i)
        if (i=='step_end'):
            end = a.getValue(i)

    if (begin < end):
        break # if everything is ok move out 
    items2 = []
    items2.append(['text',ITEM_TEXT,"Start timestep must be smaller than end timestep!!",""])
    a = CeiQtGenericDialog(items2,None,"Error","Ok","Cancel")
    ret = a.doit()
        if ret < 0:
           break # if cancel dialog will not proceed data analysis
于 2013-11-06T07:51:26.587 回答