Modal progress dialog
[1/6] from: adl::absentis::com at: 13-Apr-2006 16:57
Hello everyone
I need to pop up a modal progress dialog, a customised one that contains more than just
a progress bar. As far as I can see there is no way to do this as it would require that
there was a event on the dialog's first appearance after the 'inform' from where I could
run the code that would update and at termination, close the dialog. Has anyone solved
this problem before me?
thanks
Andrew
[2/6] from: gabriele:colellachiara at: 14-Apr-2006 12:39
Hi Andrew,
On Thursday, April 13, 2006, 6:57:38 PM, you wrote:
AL> I need to pop up a modal progress dialog, a
AL> customised one that contains more than just a progress bar. As
AL> far as I can see there is no way to do this as it would
AL> require that there was a event on the dialog's first
AL> appearance after the 'inform' from where I could run the code
AL> that would update and at termination, close the dialog. Has
AL> anyone solved this problem before me?
You can use SHOW-POPUP directly.
>> source inform
inform: func [
{Display an exclusive focus panel for alerts, dialogs, and requestors.}
panel [object!]
/offset where [pair!] "Offset of panel"
/title ttl [string!] "Dialog window title"
/timeout time
][
panel/text: copy any [ttl "Dialog"]
panel/offset: either offset [where] [system/view/screen-face/size - panel/size / 2]
panel/feel: system/view/window-feel
show-popup panel
either time [if none? wait time [hide-popup/timeout]] [do-events]
]
Basically you don't want the WAIT (DO-EVENTS is WAIT []) in the
last line.
Regards,
Gabriele.
--
Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/
Colella Chiara software division --- http://www.colellachiara.com/
[3/6] from: adl:absentis at: 14-Apr-2006 16:52
On Fri, Apr 14, 2006 at 12:39:59PM +0200, Gabriele Santilli wrote:
> You can use SHOW-POPUP directly.
> Basically you don't want the WAIT (DO-EVENTS is WAIT []) in the
> last line.
That more or less solves the main problem, thanks, I just have a
couple of details to clean up, here is some example code;
REBOL []
inform-and-process: func [
dlg [object!]
fun [function!] "Function to be run, passed the progress dialog wrapper"
/offset where [pair!] "Offset of panel"
/title ttl [string!] "Dialog window title"
][
dlg/lay/text: copy any [ttl "Dialog"]
dlg/lay/offset: either offset [where] [system/view/screen-face/size - dlg/lay/size /
2]
dlg/lay/feel: system/view/window-feel
dlg/show
fun dlg
dlg/hide
]
my-progress-dialog: make object! [
progress-bar: none
lay: layout [
txt "Process in process, please wait"
progress-bar: progress 200 black red]
set-progress: func ["This doesn't appear to work" val][
progress-bar/data: val
show progress-bar]
show: does [show-popup lay]
hide: does [hide-popup]
]
my-func: func [dlg][
wait 1
for x 1 100 1 [
dlg/progress-bar/data: (x / 100)
show dlg/progress-bar
;dlg/set-progress (x / 100)
wait 0.05
]
]
inform-and-process my-progress-dialog :my-func
You'll see that I prefer to wrap the layout in an object to keep
everything nicely wrapped. It does require that I agree a protocol
with myself but I'll manage. What I do wonder though is why the
commented out line in my-func does not update the progress bar in the
way that the two preceding lines do? Secondly, how would I set up an
event handler to make the dialog un-closeable?
cheers
Andrew
[4/6] from: anton:wilddsl:au at: 15-Apr-2006 2:50
Hi Andrew, the reason is that the set-progress function body
code is bound to the my-progress-dialog object when it is
made (by MAKE).
So you are unintentionally doing [show-popup lay] instead of
just show.
You can refer to the global SHOW function like this:
set-progress: func [val][
progress-bar/data: val
system/words/show progress-bar
]
but I would advise against redefining the globals SHOW and HIDE
as it will probably just lead to confusion. Up to you, though :)
Anton.
[5/6] from: adl:absentis at: 14-Apr-2006 17:39
On Sat, Apr 15, 2006 at 02:50:05AM +1000, Anton Rolls wrote:
> Hi Andrew, the reason is that the set-progress function body
> code is bound to the my-progress-dialog object when it is
<<quoted lines omitted: 8>>
> but I would advise against redefining the globals SHOW and HIDE
> as it will probably just lead to confusion. Up to you, though :)
I deserved that one :) My only remaining doubt is how to make the
dialog unkillable by the user, I thought that adding an
'insert-event-func with a function that simply did nothing on a 'close
event would work but nothing changed, is there another way?
thanks
Andrew
[6/6] from: gabriele:colellachiara at: 15-Apr-2006 11:12
Hi Andrew,
On Friday, April 14, 2006, 7:39:42 PM, you wrote:
AL> I deserved that one :) My only remaining doubt is how to make the
AL> dialog unkillable by the user, I thought that adding an
AL> 'insert-event-func with a function that simply did nothing on a 'close
AL> event would work but nothing changed, is there another way?
You actually need a custom handler for the popup (popups are
handled a bit specially).
The default one (notice there are many, based on the refinements
of SHOW-POPUP and so on) is:
>> probe system/view/popface-feel
make object! [
redraw: none
detect: func [face event][
either all [
event/type = 'key
face: find-key-face face event/key
] [
if get in face 'action [do-face face event/key]
none
] [
event
]
]
over: none
engage: none
close-events: [close]
inside?: func [face event][face = event/face]
process-outside-event: func [event][
either event/type = 'resize [event] [none]
]
pop-detect: func [face event][
either inside? face event [
either find close-events event/type [hide-popup none] [event]
] [
process-outside-event event
]
]
]
So you should be able to do what you want by removing 'close from
your popup's feel/close-events.
Regards,
Gabriele.
--
Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/
Colella Chiara software division --- http://www.colellachiara.com/
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted