<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    GUI支持

    ProgDlg

    創建和管理模式進度條。它旨在與協程一起使用 ,在協程中,主UI線程控制進度條對話框,而后臺協程(工作線程)在步驟之間屈服于主線??程。主線程檢查“ 取消”按鈕的狀態,如果未設置,則將控制權返回給協程。

    GUI支持
    舊版(GTK +)用戶界面將其顯示為單獨的對話框,因此后綴為“ Dlg”。Qt用戶界面在主狀態欄中顯示一個進度條。

    ProgDlg.new([title], [task])

    創建并顯示ProgDlg帶有“ 取消”按鈕和可選標題的新進度條。強烈建議您包裝使用ProgDlg實例的代碼,因為它在遇到錯誤時不會自動關閉。需要GUI。

    Example

        if not gui_enabled() then return end
    
        local p = ProgDlg.new("Constructing", "tacos")
    
        -- We have to wrap the ProgDlg code in a pcall in case some unexpected
        -- error occurs.
        local ok, errmsg = pcall(function()
                local co = coroutine.create(
                        function()
                                local limit = 100000
                                for i=1,limit do
                                        print("co", i)
                                        coroutine.yield(i/limit, "step "..i.." of "..limit)
                                end
                        end
                )
    
                -- Whenever coroutine yields, check the status of the cancel button to determine
                -- when to break. Wait up to 20 sec for coroutine to finish.
                local start_time = os.time()
                while coroutine.status(co) ~= 'dead' do
                        local elapsed = os.time() - start_time
    
                        -- Quit if cancel button pressed or 20 seconds elapsed
                        if p:stopped() or elapsed > 20 then
                                break
                        end
    
                        local res, val, val2 = coroutine.resume(co)
                        if not res or res == false then
                                if val then
                                        debug(val)
                                end
                                print('coroutine error')
                                break
                        end
    
                        -- show progress in progress dialog
                        p:update(val, val2)
                end
        end)
    
        p:close()
    
        if not ok and errmsg then
                report_failure(errmsg)
        end
    
    Arguments

    title (optional)

    進度條的標題。默認為“Progress”。
    task (optional)

    可選的任務名稱,將添加到標題之后。默認為空字符串(“”)。

    Returns

    新創建的ProgDlg對象。

    progdlg:update(progress, [task])

    根據完成百分比設置進度對話框的進度欄位置。

    Arguments

    progress
    進度值,例如0.75。值必須介于0.0和1.0之間(含0.0和1.0)。
    task (optional)

    Task name. Currently ignored. Defaults to empty string (“”).

    Errors
    • GUI not available
    • Cannot be called for something not a ProgDlg
    • Progress value out of range (must be between 0.0 and 1.0)

    progdlg:stopped()

    檢查用戶是否按下了“ 取消”按鈕。

    Returns

    Ture or false

    progdlg:close()

    Hides the progress bar.

    Returns

    A string specifying whether the Progress Dialog has stopped or not.

    Errors
    • GUI not available

    TextWindow

    創建和管理一個文本窗口。文本可以是只讀的或可編輯的,并且可以在文本下面添加按鈕。

    GUI支持

    TextWindow.new([title])

    創建一個新的TextWindow文本窗口并顯示它。需要一個GUI。

    例:

    如果不是gui_enable(),則返回END。

    –創建新的文本窗口并初始化其文本。
    local win = TextWindow.new(“Log”)
    win:set(“Hello world!”)
    –添加按鈕以清除文本窗口并啟用編輯。
    win:add_button(“Clear”, function() win:clear() end)
    win:add_button(“Enable edit”, function() win:set_editable(true) end)

    –添加按鈕將文本更改為大寫。
    win:add_button(“Uppercase”, function()
    local text = win:get_text()
    if text ~= “” then
    win:set(string.upper(text))
    end
    end)

    –當用戶關閉文本winw時,將“Closing”打印到stdout。
    win:set_atclose(function() print(“closing”) end)

    參數:
    title (optional)

    Title of the new window. Optional. Defaults to “Untitled Window”.

    Returns

    The newly created TextWindow object.

    Errors
    • GUI not available

    textwindow:set_atclose(action)

    設置文本窗口關閉時將調用的函數。
    參數:
    action

    A Lua function to be executed when the user closes the text window.

    Returns

    The TextWindow object.

    Errors
    • GUI not available

    textwindow:set(text)

    • 設置要顯示的文本。
    Arguments

    text

    The text to be displayed.

    Returns

    The TextWindow object.

    Errors
    • GUI not available

    textwindow:append(text)

    • 將文本附加到當前窗口內容。

    參數:

    Arguments

    text

    The text to be appended.

    Returns

    The TextWindow object.

    Errors
    • GUI not available

    textwindow:prepend(text)

    在當前窗口內容前添加文本。

    Arguments

    text

    The text to be prepended.

    Returns

    The TextWindow object.

    Errors
    • GUI not available

    textwindow:clear()

    • 擦除窗口中的所有文本。
    Returns

    The TextWindow object.

    Errors
    • GUI not available

    textwindow:get_text()

    Get the text of the window.

    Returns

    The `TextWindow’s text.

    Errors
    • GUI not available

    textwindow:close()

    Close the window.

    Errors
    • GUI not available

    Close the window.

    Errors
    • GUI not available

    textwindow:set_editable([editable])

    Make this text window editable.

    Arguments

    editable (optional)

    true to make the text editable, false otherwise. Defaults to true.

    Returns

    The TextWindow object.

    Errors
    • GUI not available

    textwindow:add_button(label, function)

    Adds a button with an action handler to the text window.

    Arguments

    label

    The button label.

    function

    The Lua function to be called when the button is pressed.

    Returns

    The TextWindow object.

    Errors
    • GUI not available

    本文章首發在 網安wangan.com 網站上。

    上一篇 下一篇
    討論數量: 0
    只看當前版本


    暫無話題~
    亚洲 欧美 自拍 唯美 另类