Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Rebol View, function behaving differently when called diectly or from other funtion

 [1/4] from: yvan_iigs::gmx::net at: 25-Aug-2006 17:37


Hello, I have problems with the following REBOL code (I inserted the code at the end of this e-mail). Basically I have the following functions: video-menu: func ["Stripped down GUI for test"] ; GUI with a menu 'create new video' (starts 'create-new-video') create-new-video: func [..see below..] ;some debugging code, should create a video record, starts a function 'Videoform' to ask for video data Videoform: func ["Creates Input form for new video record"] ;opens a window for the user to enter the video data ;and some debugging code to see what happens Now 'create-new-video' works, starting 'create-new-video' from shell: - Windows with fields to enter new video data opens - no output in shell Entering fields in Window and clicking OK button - Window closes - in shell I see the following output
>> create-new-video
true Form ready
>>
This is how I want it, 'create-new-video' executes the following lines: Formfilled: False video-record: Videoform ; here it waits until the OK button of the window in VideoForm is pressed print Formfilled ; Pressing the OK button of VideoForm changed the value of Formfilled to true if Formfilled [print "Form ready"] ; and the form is ready But when I start 'create-new-video' from 'video-menu' the strange things happen: - First a window with a menu opens, when I click on the button 'Create new Video' the now well known function 'create-new-video' is called. - the Form window opens - in the shell you see the output 'false' Now entering values in the form and clicking the OK produces no further output, so 'formfilled' doesn't seem to have changed:
>> video-menu
false
>>
This is not how I want it, 'create-new-video' should still execute the following lines:: Formfilled: False ;just for debugging video-record: Videoform ; but now it doesn't seem to wait. Why???? print Formfilled ; This line is printed with the value false, why? if Formfilled [print "Form ready"] ; this line is not printed It seems that the 4 lines of code are not executed sequencially????? What the hell is wrong? Here is the complete code: REBOL [] video-menu: func ["Stripped down GUI for test"] [ view layout [text "Video DB Main Menu" text "Click on of the following selections" button 400x20 "Create new Video" [create-new-video] button 400x20 "Quit Video DB" [quit] ] ] create-new-video: func [ "Asks user for data and creates new Video Record. Last part missing for test purpose" /local video-record [block!] ] [ Formfilled: False ;just for debugging video-record: Videoform print Formfilled if Formfilled [print "Form ready"] ] Videoform: func ["Creates Input form for new video record"] [ Formular: view layout [ text "Title" FTitel: field text "Producer" FProduzent: field button #"^M""OK" [OK: TRUE ;Title has to be entered if (empty? FTitel/text) [ OK: FALSE FTitel/edge: make FTitel/edge [color: red] focus FTitel ] if OK [ Formfilled: true unview ] ] ] ; Missing return code ]

 [2/4] from: anton:wilddsl:au at: 26-Aug-2006 13:54


Hi Yvan, The quick solution is to put UNVIEW just before Formular: view layout ... eg: Videoform: func ["Creates Input form for new video record"][ unview Formular: view layout [ ... Another solution uses a modal window using INFORM (probably better solution): Videoform: func ["Creates Input form for new video record"][ inform Formular: center-face layout [ text "Title" FTitel: field text "Producer" FProduzent: field button #"^M""OK" [ OK: TRUE ;Title has to be entered if (empty? FTitel/text) [ OK: FALSE FTitel/edge: make FTitel/edge [color: red] focus FTitel ] if OK [ Formfilled: true hide-popup Formular ; <---- ] ] ] Formular ; return value ] INFORM windows should be closed properly using HIDE-POPUP. ---- Some extra notes, maybe not relevant in your final code: - Note: in the following line, [block!] does not force video-record to be a block: /local video-record [block!] Just making sure you understand it's only useful as a comment. Only arguments to a function are type-checked. - The following comment in videoform makes me wonder if you realise that there *is* a return value: ; Missing return code (?) The returned value is the value evaluated last in the function. In the case of videoform, it is the window face returned by: Formular: view layout ... - So it seems you are expecting video-record to be a block, but in create-new-video you do this: video-record: Videoform which sets video-record to the returned window face object, which is perhaps not what you want. (I understand that's maybe not the final code, though.) - Debugging tips: - Use PROBE. You can usually insert it anywhere without side-effects, eg: if (empty? probe FTitel/text) [ ... - Use ?? which prints nicely molded output, eg: ?? Formfilled prints: Formfilled: true Regards, Anton.

 [3/4] from: anton::wilddsl::net::au at: 26-Aug-2006 14:40


Hi Yvan, I forgot to explain why "VIEW in a VIEW" doesn't work. It's not simple to explain, however... Consider the following code: view layout [button "open" [print 1 view layout [field] print 2]] This is what happens: 1) VIEW - opens the main window - DO-EVENTS (WAITs for events) 2) User presses "open" button - print 1 - VIEW - opens window-2 - VIEW does not call DO-EVENTS again, because there was an existing window. - VIEW returns immediately - print 2 3) Events are still being WAITed on. This will stop only when the window is closed. This "VIEW inside a VIEW" confuses lots of beginners. Maybe we can redesign it? Regards, Anton.

 [4/4] from: yvan_iigs::gmx::net at: 29-Aug-2006 18:31


Hello Anton, thanks for your hints and explanations I will have to try it and to understand it (I just red your e-mail). My code is a stripped down code for this mailing list. I wanted to show only the code where I have a problem, not to confuse the readers. I even translated my function and variable names from german to english to make it easier. It was funny to see your example re-translated to german. The missing return code has been removed for the mailing list. What it does is to build a video-record from the form input fields. Okay, thanks and I will now launch my rebol interpreter and see what I can do. Cheers Yvan On 26.08.2006, you wrote: