How to display the progress bar using Lua and IUP

I built a long script to which I added a progress bar with the following code:

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

This is called before the loop, and the progress bar is updated during the loop (I am not calling MainLoop). At the end of the process, I call dlgProgress.destroy to clear it.

Until I focus on the progress bar, it works fine, but if the focus is lost, the program will work, so I'm sure I'm doing it wrong. Can someone tell me the right way. Detailed google did not find me examples for iup, lua progress bars.

Thanks in advance.

+3
source share
1 answer

Here is a working example.

require "iuplua"

local cancelflag
local gaugeProgress

local 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 dlgProgress
end


dlg = StartProgressBar()
gaugeProgress.value = 0.0

for 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 end
end

-- distinguish canceled from finished by inspecting the flag
print("cancled:",cancelflag)

IUP 3.0 Lua. iup.progressbar IUP 3.0 iup.gauge. .

Windows. , , .

+2
source

Source: https://habr.com/ru/post/1763210/


All Articles