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

Field color change on error.

 [1/18] from: louisaturk:coxinet at: 16-Oct-2002 23:55


Hi rebols, I want the background of the field to turn red when an invalid email is entered....and also the font's color and style (yellow and bold). How do I do it? view layout [ lab "email:" email: field [ if not find value "@" [ replace value value "<<<<< INVALID EMAIL >>>>>" ; <====<<< WORKS face/color: red ; <=====<<< DOESN'T WORK. backdrop red : <=====<<< DOESN'T WORK show face ] ] return ] This is my first serious try at gui proramming with rebol/view, so if you see anything else wrong with the above, please point it out. Thanks, Louis

 [2/18] from: anton:lexicon at: 17-Oct-2002 15:54


Hi Louis, Try look at this: view center-face layout [ backdrop [unfocus f] f: field "I will change" field "I'll stay the same" button "change" [ ; using make to make a new copy of the font object, ; which is used by other fields and other styles as well f/font: make f/font [style: 'bold color: yellow] f/colors: reduce [red pink] ; normal & selected field background colors show f ] ] Anton.

 [3/18] from: greggirwin:mindspring at: 17-Oct-2002 1:07


Hi Louis, Anton tackled the GUI part, so I'll just add a little note on another way to validate the data. Instead of just looking for "@" in the text, you could see if REBOL understands it as an email (i.e. let it do the hard work for you). view layout [ field [ print either email! = type? attempt [load value]["YES"]["NO"] ] ] --Gregg

 [4/18] from: carl:cybercraft at: 17-Oct-2002 21:22


On 17-Oct-02, Gregg Irwin wrote:
> Hi Louis, > Anton tackled the GUI part, so I'll just add a little note on
<<quoted lines omitted: 7>>
> ] > ]
Attempt? ...
>> ? attempt
No information on attempt (word has no value) Only in the beta REBOLs perhaps? -- Carl Read

 [5/18] from: al:bri:xtra at: 17-Oct-2002 22:25


Carl Read wrote:
> >> ? attempt > No information on attempt (word has no value) > > Only in the beta REBOLs perhaps? >> source attempt
attempt: func [ {Tries to evaluate and returns result or NONE on error.} value ][ if not error? set/any 'value try :value [get/any 'value] ] Perhaps my %Patches.r script may be of use? It's attached and available from my site. Andrew Martin Beta Rebol-er... ICQ: 26227169 http://valley.150m.com/ -><- -- Attached file included as plaintext by Listar -- -- File: Patches.r Rebol [ Name: 'Patches Title: "Patches" File: %Patches.r Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Web: http://valley.150m.com Date: 12/October/2002 Version: 1.1.5 Purpose: {Various patches to Rebol.} Category: [util 5] ] ; Replaces 'days with 'weekdays, to match /weekday refinement for date! values. if none? in rebol/locale 'weekdays [ rebol/Locale: make object! [ Months: rebol/locale/months Weekdays: rebol/locale/days ] ] ; Replacement 'Extract to work with series!, and better initial length. Extract: function [ "Extracts every n-th value from a series." Series [series!] Width [integer!] "Size of each entry (the skip)." /Index "Position to extract from." N [number! logic!] ] [New] [ if not Index [N: 1] New: make Series (length? Series) / Width forskip Series Width [ insert/only tail New pick Series N ] New ] ; Replacement 'Alter. Alter: function [ {If a value is not found in a series, append it; otherwise, remove it.} Series [series! port!] Value [any-type!] ] [Temp] [ either Temp: find/only Series :Value [ remove Temp ] [ insert/only tail Series :Value ] :Series ] ; Replacement 'Append. Append: func [ {Appends a value to the tail of a series and returns the series.} Series [series! port!] Value [any-type!] /Only "Appends a block value as a block." ][ either only [ insert/only tail Series :Value ] [ insert tail Series :Value ] :Series ] ; Replacement 'Repend. Repend: func [ {Appends a reduced value to a series and returns the series.} Series [series! port!] Value [any-type!] /Only "Appends a block value as a block." ][ either only [ insert/only tail :Series reduce :Value ] [ insert tail :Series reduce :Value ] :Series ] ; Needed until very latest versions of Rebol are released. if not value? 'as-pair [ as-pair: func [ "Combine X and Y values into a pair." x [number!] y [number!] ][ to-pair reduce [to-integer x to-integer y] ] ] ; Needed until very latest versions of Rebol are released. decode-cgi: func [ {Converts CGI argument string to a block of set-words and value strings.} args [any-string!] "Starts at first argument word." /local block name value here tmp ][ block: make block! 7 parse/all args [ any [ copy name [to #"=" | to #"&" | to end] skip here: ( if tmp: find name #"&" [ here: skip here (offset? tmp name) - 2 clear tmp ] append block to-set-word name ) :here [ [copy value to #"&" skip | copy value to end] ( append block either none? value [copy ""] [ replace/all dehex replace/all value #"+" #" " crlf newline ] ) ] ] end ] block ] ; Needed until very latest versions of Rebol are released. array: func [ "Makes and initializes a series of a given size." size [integer! block!] "Size or block of sizes for each dimension" /initial "Specify an initial value for all elements" value "Initial value" /local block rest ][ if not initial [value: none] if block? size [ rest: next size if tail? rest [rest: none] size: first size if not integer? size [make error! "Integer size required"] ] block: make block! size either not rest [ either series? value [ loop size [insert/only block copy/deep value] ] [ insert/dup block value size ] ] [ loop size [ if series? value [value: copy/deep value] block: insert/only block array/initial rest value ] ] head block ] ; Needed until very latest versions of Rebol are released. sign?: func [ {Returns sign of number as 1, 0, or -1 (to use as multiplier).} number [number! money! time!] ][ either positive? number [1] [either negative? number [-1] [0]] ] ; Needed until very latest versions of Rebol are released. attempt: func [ {Tries to evaluate and returns result or NONE on error.} value ][ if not error? set/any 'value try :value [get/any 'value] ] ; Needed until very latest versions of Rebol are released. build-markup: func [ {Return markup text replacing <%tags%> with their evaluated results.} content [string! file! url!] /quiet "Do not show errors in the output." /local out eval value ][ content: either string? content [copy content] [read content] out: make string! 126 eval: func [val /local tmp] [ either error? set/any 'tmp try [do val] [ if not quiet [ tmp: disarm :tmp append out reform ["***ERROR" tmp/id "in:" val] ] ] [ if not unset? get/any 'tmp [append out :tmp] ] ] parse/all content [ any [ end break | "<%" [copy value to "%>" 2 skip | copy value to end] (eval value) | copy value [to "<%" | to end] (append out value) ] ] out ] ; Needed until very latest versions of Rebol are released. component?: func [ "Returns specific REBOL component info if enabled." name [word!] ][ find system/components name ]

 [6/18] from: g:santilli:tiscalinet:it at: 17-Oct-2002 11:34


Hi Louis, On Thursday, October 17, 2002, 6:55:23 AM, you wrote: LAT> I want the background of the field to turn red when an invalid email is LAT> entered....and also the font's color and style (yellow and bold). How do I LAT> do it? view layout [ email: field [ if not find value "@" [ face/colors: reduce [red red] set-font face color yellow set-font face style 'bold show face ] ] ] Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [7/18] from: greggirwin:mindspring at: 17-Oct-2002 10:54


<< Attempt? ... >> Thanks for catching me Carl! That's what I get for posting late at night. :) Andrew beat me to a response though. Gotta love those mezzanines. --Gregg

 [8/18] from: louisaturk:coxinet at: 17-Oct-2002 11:22


Hi Gabriele, Andrew, Anton, and Carl, Many thanks for all the help. I now have almost everything I want. Compositing everything all of you said I came up with this: lab "email:" email: field [ either email? attempt [load value] [ face/colors: reduce [white white] set-font face color black set-font face style 'normal ; <====<< DOESN'T WORK ][ replace value value "<<<<< INVALID EMAIL >>>>>" face/colors: reduce [red red] set-font face color yellow set-font face style 'bold show face ] ] return When an invalid email is entered, this sets the background color to red, and the font to bold yellow, and prints "<<<<< INVALID EMAIL >>>>>" exactly as I want. Then when a valid email is entered the colors are set back as they were. However, the font style remains bold. How do I set it back to normal? Also, why does this result in an error message instead of false?
>> email? kkkkk
** Script Error: kkkkk has no value ** Near: email? kkkkk
>>
That just doesn't seem right to me in this particular context. I know that kkkkk is an unset word, but all you want to know with email? is the validity of the entry. It seems to me that email? value by itself should do what email? attempt [load value] does. Anton, your example is very interesting, and I am still studying it. Thanks again to all of you. Louis At 11:34 AM 10/17/2002 +0200, you wrote:

 [9/18] from: sunandadh::aol::com at: 17-Oct-2002 15:18


Louis:
> either email? attempt [load value]
I'd caution against this use of 'load -- -- At the best of times it'll eat up space in system/words -- At the worse, it lets the user type in code that will be executed -- try this in your entry field: Rebol [quit] I think this line solves most of the problems: either email? try [first to-block value] Sunanda.

 [10/18] from: g:santilli:tiscalinet:it at: 17-Oct-2002 21:04


Hi Louis, On Thursday, October 17, 2002, 6:22:02 PM, you wrote: LAT> set-font face style 'normal ; <====<< DOESN'T WORK set-font face style none Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [11/18] from: greggirwin:mindspring at: 17-Oct-2002 13:25


Hi Louis, << Also, why does this result in an error message instead of false?
>> email? kkkkk
** Script Error: kkkkk has no value ** Near: email? kkkkk
>> >>
kkkkk is a word, and REBOL is evaluating it to find the value it references, to see if it is an email! value. If you give it an email value, the scanner will recognize it as such.
>> e: [gregg--pointy--com]
== [gregg--pointy--com]
>> email? e
== true
>> email? [gregg--pointy--com]
== true HTH! --Gregg

 [12/18] from: carl:cybercraft at: 18-Oct-2002 9:51


Hi Louis, On 18-Oct-02, Louis A. Turk wrote:
> Hi Gabriele, Andrew, Anton, and Carl, > Many thanks for all the help. I now have almost everything I
<<quoted lines omitted: 20>>
> However, the font style remains bold. How do I set it back to > normal?
A font's style can be either none, 'bold, 'italic, 'underline or a block with the styles in. (Or an empty block). However, neither of these seem to work... set-font face style none set-font face style 'none so you'll have to use a method other than set-font. ie... face/font/style: none which is probably faster anyway, not to mention shorter.
> Also, why does this result in an error message instead of false? >>> email? kkkkk
<<quoted lines omitted: 5>>
> email? is the validity of the entry. It seems to me that email? > value by itself should do what email? attempt [load value] does.
'kkkkk is evaluated before its result are returned to email?, so the error occurs before email? gets 'kkkkk. You could perhaps use something like...
>> email? first [kkkkk]
== false
>> email? first [[k--kkk]]
== true or if the word's a, err, word's value...
>> w: 'kkkkk
== kkkkk
>> email? w
== false
>> w: ['k--kkk]
== ['k--kkk]
>> email? w
== true PS. Oh, you've had some replies already. (: Gabriele suggested this... set-font face style none yet it doesn't work for me...
>> view layout [field "aaa" [set-font face style none show face]]
** Script Error: Invalid argument: none ** Where: action ** Near: show face Another beta enhancemant I assume? -- Carl Read

 [13/18] from: g:santilli:tiscalinet:it at: 18-Oct-2002 0:59


Hi Carl, On Thursday, October 17, 2002, 11:51:24 PM, you wrote: CR> block with the styles in. (Or an empty block). However, neither of CR> these seem to work... CR> set-font face style none CR> set-font face style 'none CR> so you'll have to use a method other than set-font. ie... Hmm, indeed looking at the source:
>> source set-font
set-font: func [aface 'word val][ if none? aface/font [aface/font: vid-face/font] if not flag-face? aface font [aface/font: make aface/font [] flag-face aface font] either word = 'style [ if none? aface/font/style [aface/font/style: copy []] if word? aface/font/style [aface/font/style: reduce [aface/font/style]] aface/font/style: union aface/font/style reduce [val] ] [set in aface/font word val] ] seems like they forgot the case when one sets the style to none. CR> face/font/style: none CR> which is probably faster anyway, not to mention shorter. Of course, that's the way to go if you have already cloned the font object. However I'd suggest to flag the face in that case, so that it is not cloned again and again. In the case when you don't know if the object has been cloned or not, of course the safest way is to clone it always; the most efficient is probably doing something like SET-FONT, however. CR> PS. Oh, you've had some replies already. (: Gabriele suggested CR> this... CR> set-font face style none CR> yet it doesn't work for me... I didn't test it, sorry. CR> Another beta enhancemant I assume? Doesn't like so, by looking at the source above. BTW, is [feedback--rebol--com] working? I miss the times when you got back a ticket number immediately, and a message from Bo the day after... Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [14/18] from: g:santilli:tiscalinet:it at: 18-Oct-2002 0:48


Hi SunandaDH, On Thursday, October 17, 2002, 9:18:24 PM, you wrote: Sac> -- At the best of times it'll eat up space in system/words That's true. Sac> -- At the worse, it lets the user type in code that will be executed -- try Sac> this in your entry field: People should use LOAD/ALL on the old REBOLs. LOAD is safe in the new versions (the header is no more evaluated). Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [15/18] from: rotenca:telvia:it at: 18-Oct-2002 2:11


Hi all,
> A font's style can be either none, 'bold, 'italic, 'underline or a > block with the styles in. (Or an empty block). However, neither of > these seem to work... > > set-font face style none > set-font face style 'none
Set-font does not support none. It would be useful to do a little change to the funtion: set-font: func [aface 'word val][ if none? aface/font [aface/font: vid-face/font] if not flag-face? aface font [aface/font: make aface/font [] flag-face aface font] either word = 'style [ either none? val [aface/font/style: none][ if none? aface/font/style [aface/font/style: copy []] if word? aface/font/style [aface/font/style: reduce [aface/font/style]] aface/font/style: union aface/font/style reduce [val] ] ] [set in aface/font word val] ] --- Ciao Romano

 [16/18] from: louisaturk:coxinet at: 23-Oct-2002 4:58


Hi Greg, Gabriele, Sunanda, Carl, and Romano, Many thanks for your help. I am happy to report that with your help I was able to rapidly develop two gui data input windows with extensive error detection and correction that are saving a lot of time. For a long time I hesitated to get involved with View as I figured it would be very hard and time consuming to learn and use. Instead it turned out to be very fast and easy (especially with your help), and I was able to use it to overcome some problems that have prevented me from achieving some goals for a long time. Thanks again, Louis At 02:11 AM 10/18/2002 +0200, you wrote:

 [17/18] from: greggirwin:mindspring at: 23-Oct-2002 11:44


Thank you Louis! It's always great to hear that people are pleasantly surprised, and that we could be of help here. --Gregg

 [18/18] from: louisaturk:coxinet at: 23-Oct-2002 17:25


Gregg and list, You are welcome. As you can probably tell, I like the Rebol programming language, and I like the people on this list. You are very reasonable, knowledgeable and helpful people. Both Rebol and the people on this list amaze me. Thanks again, Louis At 11:44 AM 10/23/2002 -0600, you wrote:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted