Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Data: request-file i cant get it to work
Pages: [1] Print
Author Topic: Data: request-file i cant get it to work  (Read 426 times)
riacg
Newbie
*
Offline Offline

Posts: 1


View Profile
Data: request-file i cant get it to work
« on: October 19, 2006, 12:00:54 PM »

I just started using rebol today and its been going pretty well, i decided to try to make a program that would ask the user to choose a picture then the program would grayscale it.

This is the code i used:
data: request-file view layout [image load data effect [grayscale]]

anyways i have tried many variations of this code and i always get "image has no value" so i guess im somehow using the data: request-file command wrong.

anyone wanan tell me what im doing wrong?

Edit: sorry i put the wrong error, the program works but all i see is a gray background (not a grayscaled picture but a lack of one lol)
« Last Edit: October 19, 2006, 12:03:07 PM by riacg » Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: Data: request-file i cant get it to work
« Reply #1 on: October 19, 2006, 03:45:32 PM »

This is a common error by newbies.

The words between the layout [ .. ] are not rebol, but a rebol dialect.  So, the word "load" is not understood.

Futhermore the 'request-file returns a block of files.  You need to pick the first one in that block.

Code:
data: first load request-file view layout [image data effect [grayscale]]
Logged

Anton
Jr. Member
**
Offline Offline

Posts: 66

Rebol veteran


View Profile WWW
Re: Data: request-file i cant get it to work
« Reply #2 on: October 20, 2006, 02:25:47 AM »

I usually use the /ONLY refinement of REQUEST-FILE to cause it to return only a single file.
Here are some examples, which you can test by pasting straight into the rebol console:

   if file: request-file/keep/only/save/title "Save Layout:" "Save Layout" [
      alert "save-layout"
      ;save-layout file
   ]
   
   ; Save PNG
   if file: request-file/keep/only/save/title "Save a PNG image:" "Save PNG" [
      alert "create-layout and save/png"
      ;save/png file to-image layout create-layout
      ;view/new layout [image (load file)]
   ]
   
and your code I would probably rewrite like:

   if file: request-file/keep/only/title "Load an image:" "Load image" [
      my-image: load file
      either image? my-image [
         view layout [image (my-image)]
      ][
         alert "not an image file!"
         my-image: none
      ]
   ]

or this:

   view center-face layout [
      btn "Load Image" [
         if file: request-file/keep/only/title "Load an image:" "Load image" [
            my-image: load file
            either image? my-image [
               pic/image: my-image
               show pic
            ][
               alert reform ["The selected file did not load as an image:" file]
               my-image: none
            ]
         ]
      ]
      pic: image effect [fit grayscale]
   ]
Logged
Brock
Newbie
*
Offline Offline

Posts: 14


View Profile
Re: Data: request-file i cant get it to work
« Reply #3 on: October 21, 2006, 08:42:28 PM »

Yes, the /only refinement will only show the file you selected and not the block returned by the request-file command - as Anton stated.  Graham's response shows you the first item in the block, so the same net effect.  Here's the simple change to your script;
data: request-file/only view layout [image load data effect [grayscale]]

The 'load' of data is not required, but as you can see from Anton's script, using load you will be able to use the image? command to determine if it's an image or not.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Data: request-file i cant get it to work
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 07:51:10 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2311 Posts in 595 Topics by 4142 Members
Latest Member: FoxxxTrott

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc