如何在web2py中制作进度条/进度计?

0 投票
1 回答
1448 浏览
提问于 2025-04-16 11:51

我在web2py里做了一个进度条,但是它只在终端窗口里显示。请问我该怎么做才能让这个进度条在web2py的网页上显示出来呢?

下面是代码的一部分:

k = 1 # This is the loop variable for subplots.
for counter in nus:
    fig = plt.figure()
    D = E*(h**3)/(12*(1-counter**2)) # Cylindrical rigidity.
    T0 = (L**2)/(D*np.pi**2)*T0_orig # Nondimensional tension.
    amax = T0/kappa # Maximum allowed alpha (to keep tension nonnegative everywhere).
    alphas = [0, (10**-6)*amax, (10**-4)*amax, (10**-2)*amax] # Nondimensional alphas to use for plot.
    workdone = 0.0 # How much of the Figure has been calculated? 0.0 = none, 1.0 = Figure is ready to show.
    workstep = 100.0/len(alphas) # How much work is done during one step in the loop? If there are 4 steps in the loop, then then step will be 100.0/4 = 25.0.
    for alpha in alphas:
        lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx)
        V0 = np.sqrt( T0_orig/m + np.pi**2 * D/(m*L**2)*lambda_ )
        if (k == 1):
            V0_ref = V0

        # Figure 1
        fig_a = fig.add_subplot(2,2,k)
        fig.subplots_adjust(hspace=0.4)
        if (k == 1):
            fig_a.set_title(r'$\alpha / \alpha_{max} = %.2g, V_{0}^{ref} = %.6g$ m/s' % (alpha/amax, V0))
        else:
            fig_a.set_title(r'$\alpha / \alpha_{max} = %.2g, V_{0}/V_{0}^{ref} = %.6g$' % (alpha/amax, V0/V0_ref))
        fig_a.plot(xx,f)
        plt.xlim(-kappa,kappa)
        plt.xlabel(r'$\eta$')
        plt.ylim(-0.1,1.1)
        if ((k == 1) or (k == 3)):
            plt.ylabel(r'$f(\eta)$')
        workdone = workdone + workstep
        print "Figure 1:", workdone, "%/100.0% done."

        # Let's get ready for the next subfigure.
        k = k + 1

1 个回答

2

你可以考虑去问一下这个邮件列表

你的代码是在控制器函数里面吗?注意,打印语句并不会把任何输出发送到网页上(也就是说,它们不会影响HTTP响应)——要做到这一点,你的控制器需要返回一个字典给视图(或者返回一个字符串)。如果你想做一个进度条,可能需要用到Ajax(另外,你可以看看这里)。

这个客户端工具模块里面有一个进度条的例子(可以滚动到“更多例子”那一节)。我没有用过这个模块,不确定它是否适合你的需求,但可能会给你一些灵感。

撰写回答