gpt4 book ai didi

lua - 如何使用 Lua 和 IUP 显示进度条

转载 作者:行者123 更新时间:2023-12-02 02:31:28 30 4
gpt4 key购买 nike

我构建了一个长时间运行的脚本,并在其中添加了一个带有以下代码的进度条:

function StartProgressBar()
gaugeProgress = iup.gaugeProgress{}
gaugeProgress.show_text = "YES"
gaugeProgress.expand = "HORIZONTAL"
dlgProgress = iup.dialog{gaugeProgress; title = "Note Replacement in Progress"}
dlgProgress.size = "QUARTERxEIGHTH"
dlgProgress.menubox = "NO" -- Remove Windows close button and menu.
dlgProgress:showxy(iup.CENTER, iup.CENTER) -- Put up Progress Display
return dlgProgress
end

这是在循环之前调用的,并且在循环期间更新进度条(我没有调用 MainLoop)。在流程结束时,我调用 dlgProgress.destroy 来清除它。

只要我不从进度条上获取焦点,它就可以正常工作,但如果失去焦点,程序就会崩溃,所以我确信我做错了。谁能告诉我正确的方法。详细google了一下,没有找到我的iup,lua进度条的例子。

提前谢谢你。

最佳答案

这是一个工作示例。

require "iuplua"local cancelflaglocal gaugeProgresslocal function StartProgressBar()    cancelbutton = iup.button {        title = "Cancel",        action=function()            cancelflag = true            return iup.CLOSE        end    }    gaugeProgress = iup.progressbar{ expand="HORIZONTAL" }    dlgProgress = iup.dialog{        title = "Note Replacement in Progress",        dialogframe = "YES", border = "YES",        iup.vbox {            gaugeProgress,            cancelbutton,    }    }    dlgProgress.size = "QUARTERxEIGHTH"    dlgProgress.menubox = "NO"  --  Remove Windows close button and menu.    dlgProgress.close_cb = cancelbutton.action    dlgProgress:showxy(iup.CENTER, iup.CENTER)  --  Put up Progress Display    return dlgProgressenddlg = StartProgressBar()gaugeProgress.value = 0.0for i=0,10000 do    -- take one step in a long calculation    -- update progress in some meaningful way    gaugeProgress.value = i / 10000    -- allow the dialog to process any messages    iup.LoopStep()    -- notice the user wanting to cancel and do something meaningful    if cancelflag then break endend-- distinguish canceled from finished by inspecting the flagprint("cancled:",cancelflag)

我在这里使用了 IUP 3.0 和它的标准 Lua 绑定(bind)。仪表控件在 IUP 3.0 中被命名为 iup.progressbar,在早期版本中被命名为 iup.gauge。在早期版本中,它可能也在扩展控件库中。

我已经在 Windows 上测试过了。人们假设它在其他平台上有类似的行为,但你的里程可能会有所不同。

关于lua - 如何使用 Lua 和 IUP 显示进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3641616/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com