Add progress bar to AlertWindow() #720
Replies: 4 comments 3 replies
|
Here is an example of |
|
Here is another way using |
|
I am using the Progress bar example in an Alert dialog. So far, it's working well. (My 2 buttons are Start and Cancel) When the Alert window is up, what is runModalLoop() actually doing? Just waiting for a user to press a button? How can I in the middle of the timer loops look for a key press and decide what to do? There are different ways to display the progress bar, but my core question is - in the middle of a long process is there any general key handling capabilities that we can access? |
|
I keep forgetting ... Even though I probably haven't created any new cool uses of CtrlrX, here's a couple quick videos showing what I've been working on. If you do see anything of interest, I'll try to create a @dnaldoog worthy demo of it. https://www.youtube.com/watch?v=oRm7ZE67ghc |



Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Here is a way of creating a progress bar within an AlertWindow using an embedded
uiComponentThe secret seems to be you have to declare the
uiComponentas in 1 or 2 below, but not 3 otherwise crashes on both Ctrlr and CtrlX1
PBAR=panel:getModulatorByName("pbar"):getComponent()-- declared in init2
panel:getModulatorByName("pbar"):getComponent()3
mw:addCustomComponent(panel:getComponent("pbar"))I haven't yet been able to get the AlertWindow method addProgressBarComponent working.
init = function(--[[ CtrlrInstance --]] type) progPerc=0 PBAR=panel:getModulatorByName("pbar"):getComponent() end -- -- Called when a component needs repainting -- @comp -- @g http://ctrlr.org/api/class_ctrlr_lua_graphics.html -- see also http://www.rawmaterialsoftware.com/juce/api/classGraphics.html -- paintPbar = function(--[[ CtrlrComponent --]] comp --[[ CtrlrComponent --]], g) g:fillAll(Colour(0xffffcc00)) -- background colour local w, h = comp:getWidth(), comp:getHeight() g:setColour(Colour(0xff99ccff)) -- progress bar colour local r = Rectangle(0, 0, w * progress, h) g:fillRect(r) g:setColour(Colour(0xff000000)) -- font colour g:setFont(13) r = Rectangle(comp:getLocalBounds()) -- centre text in component g:drawText(string.format("%s%%", progPerc), r, Justification(Justification.centred), true) end -- -- Called when a mouse is down on this component -- alert = function(--[[ CtrlrComponent --]] comp --[[ MouseEvent --]], event) mw = AlertWindow("BULK DATA DUMP SAVE", "Save INTERNAL or CARD data to file?", AlertWindow.QuestionIcon) mw:addButton("INTERNAL ", 1, KeyPress(KeyPress.returnKey), KeyPress()) mw:addButton("CARD", 2, KeyPress(), KeyPress()) mw:addButton("Cancel", 0, KeyPress(KeyPress.escapeKey), KeyPress()) -- mw:addProgressBarComponent(bar) not working if PBAR ~= nil then mw:addCustomComponent(PBAR) end mw:setEscapeKeyCancels(true) local ret = mw:runModalLoop() if ret == 1 then -- mw:setVisible(false) progress=0 timercounter = 0 timer:setCallback(1, TimerCallback) timer:startTimer(1, 600) elseif ret == 2 then utils.warnWindow("OPTION2", "Not set to do anything") mw:setVisible(false) else mw:setVisible(false) end --mw:setVisible(false) end TimerCallback = function(timerId) if timerId == 1 then timercounter = timercounter + 1 progress = round(timercounter / #t, 3) console(string.format("%f %d %d", progress, timercounter, #t)) progPerc=progress*100 PBAR:repaint() mw:repaint() if timercounter >= #t then timer:stopTimer(timerId) progPerc=0 mw:setVisible(false) end end end function round(num, numDecimalPlaces) -- rounding function local mult = 10 ^ (numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end --functionaddProgressBar_4.zip
All reactions