listen to events only for a specific window?
[1/15] from: arolls::bigpond::net::au at: 11-Jul-2001 17:25
How can I have two windows open, but
listen for events on only one of them?
eg. If you click on the button, an
error is generated and the error
window pops open. But! You can still
click on the button! The first window
is still receiving events. I want
to stop/pause that until user makes a
decision in the error window.
lay: layout [
button [lafd] ; generate error
]
; If an error happens in the VID code, I am going to catch it.
first-time?: yes
while [
error? err: try [
either first-time? [view center-face lay][wait none]
]
][
if error? err [err: disarm err]
first-time?: no
view/new layout [
origin 5x5
h3 "Program Error"
across
button "continue" [unview]
button "quit" [unview/all halt]
return
area mold err
]
; this effectively continues from here - it shouldn't.
; I want to listen only to the error window
; until "continue" is pressed.
;probe wait/all []
]
[2/15] from: agem:crosswinds at: 11-Jul-2001 15:04
RE: [REBOL] listen to events only for a specific window?
AFAIK like this.
but there is a bug (at linux?):
if dialog contains text (title)
and base-window not, text stays
editable?! (second example).
[rebol []
dialog: [
title "type in old window.."
button "ok" [
hide-popup
]
]
cf: :center-face
view cf layout [
title "test the buttons"
button "inform" [unfocus
inform layout dialog
]
button "show-popup" [
show-popup cf layout dialog
do-events ;don't forget!
]
area "type here when dialog open.."
]
]
[rebol []
context [
dialog: [
title "type in old window.."
button "ok" [
hide-popup
]
]
cf: :center-face
view/new/offset cf layout [
title "test the buttons"
button "inform" [unfocus
inform layout dialog
]
button "show-popup" [
show-popup cf layout dialog
do-events ;don't forget!
]
area "type here when dialog open.."
] 50x20
]
context [
dialog: [
title "type in old window.."
button "ok" [
hide-popup
]
]
cf: :center-face
view/new/offset cf layout [
;;;text "test the buttons"
button "inform" [unfocus
inform layout dialog
]
button "show-popup" [
show-popup cf layout dialog
do-events ;don't forget!
]
area "type here when dialog open.."
]400x20
]
do-events
]
[arolls--bigpond--net--au] wrote:
[3/15] from: arolls:bigpond:au at: 14-Jul-2001 2:13
I'm sorry, but in both these examples
the original window still receives
events.
The reason I wanted to do this is to
catch unforseen situations in VID
code that produce an error and halt
rebol.
See my anim/VR4.r "Dilbert" demo.
You can uncomment a bit of code
which reveals a button, which, when
pressed, gets angry and produces an
error.
This usually has the effect of
stopping the fun completely. You
have to restart the program in this
case.
But I have put in a mechanism for
catching the error and showing a
window, just as in the example
at the very bottom of this email,
with details of the error and some
buttons to let the user decide what
to do. Unfortunately, after showing
the error window to the user, the
first window keeps going.
If there is a situation in some
code in the future where an error
occurs at each "tick" of an
animation, I can imagine my
error-trapping code opening new
error message windows 30 times per
second. Not very friendly.
I need to stop the animation!
The first window needs to stop until
the user has decided what to do
about it. (Could be, auto-email author.)
I hope you understand me now. :)
Anton.
[4/15] from: cyphre:volny:cz at: 13-Jul-2001 18:32
Hi Anton,
I hope you can solve the problem by filtering events using feel's detect
function.
Sorry for the short advice but I'm really busy to wirte little example for
now. If you cannot solve it I would post it something during this weekend.
Regards
Cyphre
[5/15] from: arolls:bigpond:au at: 14-Jul-2001 3:23
Yes, I just tried that, but it doesn't work.
Thanks anyway.
This is the essential:
block-window: does [
old-feel: make lay/feel [] ; remember original feel
lay/feel: make lay/feel [
redraw: over: detect: engage: none ; don't do anything with events
]
]
unblock-window: does [
lay/feel: old-feel
]
...
; oh my gosh! an error!
block-window
; show error window here
view/new layout [title "program error" ...]
wait none
unblock-window
I think I need some deeper way to disable
the window. It's interesting; when you
click on a window title bar (win2k), the
animation stops. That's what I want to
do here, I think.
[6/15] from: g:santilli:tiscalinet:it at: 13-Jul-2001 19:43
Hello Anton!
On 13-Lug-01, you wrote:
A> I'm sorry, but in both these examples
A> the original window still receives
A> events.
[...]
You really want to block the window out? I used a nice trick
lately to do that (I wasn't using INFORM for other reasons). I did
something like:
layout [at 0x0 blocker: box effect [grayscale]]
busy-win: func [win] [
append win/pane make blocker [size: win/size]
]
free-win: func [win] [
; WIN must have been blocked first!
remove back tail win/pane
]
This as the nice visual effect of turning blocked windows into
grayscale. :-)
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[7/15] from: max:ordigraphe at: 13-Jul-2001 14:18
Hi Gabrielle,
...This kind of thing just makes you think...
Why didn't -I- Think of that... damn, sometimes we forget the simplest
of tricks ;-)
I've also been trying to figure out a way around the inform trashing bug
I'm having...
-Max
PS: Ahem - A little personal question... "Gabriele" (italian I guess) is
that He or She?
-------------
<< Don't rush me Sonny - you rush a miracle man, you get lousy miracles
>>
Miracle Max (Princess Bride)
-------------
Maxim Olivier-Adlhoch
[8/15] from: arolls:bigpond:au at: 14-Jul-2001 4:57
How useful!
But see below...
> You really want to block the window out? I used a nice trick
> lately to do that (I wasn't using INFORM for other reasons). I did
<<quoted lines omitted: 9>>
> This as the nice visual effect of turning blocked windows into
> grayscale. :-)
In this first example I tried,
only the button turns grey... interesting.
It doesn't stop the first window
animations etc.
You put a screen on top to stop
mouse input but that doesn't stop
background stuff as in this demo:
; needs your functions defined above
view lay: layout [
l: image white rate 1 feel [
engage: func [f a e][if a = 'time [
l/color: white - l/color show l]
]
]
button "block" [busy-win lay view/new layout [
button "unblock" [free-win lay unview]]
]
]
Anton.
[9/15] from: agem:crosswinds at: 13-Jul-2001 23:44
RE: [REBOL] Re: listen to events only for a specific window?
maybe
The Detect Feel http://www.rebol.com/how-to/feel.html#sect6.6.
could help?
or hide the windows temporary:
[rebol []
windows: system/view/screen-face/pane
cf: :center-face
;to show we doesnt count in background
counter: 1
;here you would put the "anim crashed!"
lay-frozen: [
freezer: info mold counter rate 1
feel [engage: func [face act evt] [
face/text: counter show face]]
button "flatsch" [
insert clear windows old-windows
show system/view/screen-face
]]
;two windows to have something to hide
; one "anims" a counter
view/new lay1: cf layout [title "win 1"
ticker: info mold counter rate 1
feel [engage: func [face act evt] [
face/text: counter counter: counter + 1 show face]]
]
view/new/offset lay2: layout [button "flutsch" [
old-windows: copy windows
clear windows
show system/view/screen-face
view/new cf layout lay-frozen
]]
lay1/offset + 100x20
; and now:
do-events
]
;-) Volker
[arolls--bigpond--net--au] wrote:
[10/15] from: cyphre:volny:cz at: 14-Jul-2001 1:20
Hi Anton and all again,
here is the working test example (WATCH OUT LINE BREAKS!):
-----snip-----
REBOL [
title: "simple example of freezing/redirecting event flow in multiple
lauoyts/windows"
author: [cyphre--volny--cz]
]
insert-event-func func [f e][ ;this little function does all the magic,
using 'frozen flag you can freeze any window when this function is inserted
either e/face/options = 'frozen [
return none
][
return e
]
]
view win1: layout [
banner "Window 1"
box 100x24 with [; just simple clock for testing time evets ;-)
rate: 1
feel: make feel [
engage: func [f a e][
if e/type = 'time [
f/text: to-string now/time
show f
]
]
]
]
field "type anything here" ; just for testing key events
button 150x24 "Freeze win1 now!" [
win1/options: 'frozen ;you can set this flag to any of your windows but
you have to insert the global event-func above
view/new win2: layout/offset [
banner "Window 1 is frozen"
vtext "it doesnot receive any kind of event..."
button 150x24 "Unfreeze win1 now!" [
win1/options: none ;unfreezing the window
unview win2
]
] 300x20
]
]
-----snip----
Just one little detail: I didn't checked the 'close event so when you close
the second window using native window close buton you cannot unfreeze the
window1 again and have to kill the reboil process...but solution of this
simple and its up to you ;-)
regards
Cyphre
[11/15] from: arolls::bigpond::net::au at: 14-Jul-2001 16:24
Re: listen to events only for a specific window? Thanks
Cyphre with the goods.:)
Volker too, but for my application,
I will go with Cyphre's solution.
Volker hides the window completely
in his demo. Useful for another
situation.
By the way, Volker, what is the meaning
of "flatsch" and "flutsch" ?
I tried BabelFish already.
By the way, for those interested, it's
useful to have an icon straight to
AllenK's BabelFish Translator on the
desktop, for these matters... :)
In Win2k, I made an icon, with properties (watch wrap):
Target: D:\path\to\View\rebol.exe -cs
D:\path\to\view\public\www.rebolforces.com\reb\babel.r
(and I changed the icon to a little book).
Just make sure that you have the necessary %babel.r
in your public cache:
load-thru http://www.rebolforces.com/reb/babel.r
That's all.
[12/15] from: g:santilli:tiscalinet:it at: 14-Jul-2001 14:25
Re: listen to events only for a specific window?
Hello Maxim!
On 13-Lug-01, you wrote:
MO> PS: Ahem - A little personal question... "Gabriele" (italian
MO> I guess) is that He or She?
He. :) (Yes, italian. Quite a common name here.)
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[13/15] from: g:santilli:tiscalinet:it at: 14-Jul-2001 14:39
Hello Anton!
On 13-Lug-01, you wrote:
A> You put a screen on top to stop
A> mouse input but that doesn't stop
A> background stuff as in this demo:
Of course. :-) Blocking away any event is not always needed, but
in that case you could add a DETECT function blocking everything
or patch the event port's awake function to only handle the events
you want to be handled (it already should do this...).
DETECT example:
view/new win: layout [...]
; this should be done AFTER viewing the window because
; the function VIEW may change win/feel.
win/feel: make win/feel [
; this will block ALL events
detect: func [face event] [none]
]
The default awake function is system/view/wake-event.
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[14/15] from: arolls:bigpond:au at: 14-Jul-2001 23:52
I got the VID catching code working.
Great. You can see the result in
Rebol.com/Sites/Anton/Animations/VR 4
http://users.bigpond.net.au/datababies/anton/rebol/anim/vr4.r
You will need to uncomment the button
near the bottom of the main layout
that creates errors so we can see
the error catching code at work.
During "inlining" the star plotting
code, there was an error which was
caught successfully, so that's a good
sign.
That's one less place that errors can
hide.
The way is open to add facilities
like emailing the author with a
bug report.
Thanks all for ideas.
Anton.
[15/15] from: arolls:bigpond:au at: 15-Jul-2001 2:02
Ah good! Another way, even simpler.
Here's how I see it:
view/new lay: layout [
t: h3 300 form now/time rate 1 feel [
engage: func [f a e][
if e/type = 'time [
t/text: form now/time show t
]
]
]
]
view/new layout [
button "disable" [
lay/feel: make lay/feel [
detect: func [f e][none]
]
]
button "enable" [
lay/feel: make lay/feel [
detect: func [f e][e]
]
]
]
do-events
Of course, I am obliterating the
lay window's feel, but that's ok,
we can make a copy and restore later.
A mistake that held me up in all
this was forgetting that viewing
a window sets the window's feel.
Anton.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted