Home   Archive   Permalink



Blinking a field

Hi, I was wondering if you can blink a specific field or text area. I haven't found anything specific on it but I noticed there is a blinker field in the face object.

posted by:   John       16-Apr-2014/20:27:35-7:00



I've never used the 'blinker property, but I have done it like this:
    
R E B O L []
    
b: "blinking on and off"
    
view layout [button 200 b rate 2]
    
view layout [
     field b rate 2 feel [
         engage: func [f a e] [
             if a = 'time [
                 f/text: either f/text = b [""] [b]
                 show f
             ]
         ]
     ]
]
    
view/new g: layout [f: field]
forever [
     f/text: either f/text = b [""] [b]
     show f wait .5
     if not viewed? g [quit] ; [unview]
]

posted by:   Nick       17-Apr-2014/11:52:56-7:00



Thanks. I will use this. I have a collection of all the techniques that I will show you later today.


posted by:   John O'Rourke       17-Apr-2014/12:01:03-7:00



One question about this is: the entry field is blinking an external message. What I want to have is a generic routine that I can call for each field that is in error and when I reenter the field I want the blinking to turn off.

posted by:   John       17-Apr-2014/21:34:23-7:00



I'm pressed for time to play with this at the moment, but I've used colors instead of blinking before. Maybe this will help:
        
R E B O L []
test: func [val fc] [
     typs: reduce [date! integer! money!]
     either error? try [
         either not find typs (type? txt: load val) [
             fc/colors: [250.0.0 255.240.120]
             show fc
             return
         ] [
             fc/colors: [240.240.240 255.240.120]
             show fc
         ]
     ] [
         fc/colors: [250.0.0 255.240.120]
         show fc
     ] [
         fc/colors: [240.240.240 255.240.120]
     ]
]
view g: layout [
     text "Enter a date:"
     f: field "3-xx-2014"
     text "Enter a money value:"
     a: area "asdf"
     btn "val" [
         txts: copy []
             foreach face g/pane [
             if face/var [append txts reduce [get-face face face]]
         ]
         foreach [txt fc] reduce txts [test txt fc]
     ]
]

posted by:   Nick       18-Apr-2014/9:01:56-7:00



This version may be closer to what you want:
    
R E B O L []
test: func [fc typs] [
     typs: reduce typs ; [date! integer! money!]
     either error? try [
         either not find typs (type? load fc/text) [
             fc/colors: [250.0.0 255.240.120]
             show fc
             return
         ] [
             fc/colors: [240.240.240 255.240.120]
             show fc
         ]
     ] [
         fc/colors: [250.0.0 255.240.120]
         show fc
     ] [
         fc/colors: [240.240.240 255.240.120]
     ]
]
view g: layout [
     text "Enter a date:"
     f: field "3-xx-2014"
     text "Enter a money or integer value:"
     a: field "asdf"
     btn "val" [
         test f [date!]
         test a [money! integer!]
     ]
]

posted by:   Nick       18-Apr-2014/11:44:03-7:00



I appreciate the effort Nick. I really want it to blink and I WANT it to call the feel business in a function but I don't know what to pass to the function. I will show you what I have but it obviously doesn't work. Just need to know how to pass perhaps the whole screen and have it blink a specific incorrect field.
R E B O L []
blink: func [ fc][
    fc rate 2 feel
         engage: func [f a e] [
             if a = 'time [
                 f/text: either f/text = b [""] [b]
                 show f
             ]
         ]
]
    
view gui: layout [
     f1: field
button "val" [
    if f1/text == "blink" [blink f1]
    ]
        
     ]

posted by:   John       18-Apr-2014/15:33:58-7:00



A little clunky, but you could do this:
    
R E B O L []
flag: false
view layout [
     t: field
     btn rate 2 feel [
         engage: func [f a e] [
             if a = 'down [flag: true]
             if all [flag = true a = 'time] [
                 t/font/color: either t/font/color = t/color [black] [t/color]
                 show t
             ]
         ]
     ]
     btn [flag: false]
]
    
You can use a timer on the validation button to run through any number of faces. And instead of changing the text color, you could also potentially repeatedly move and hide an empty field widget over the coordinates of any field widgets which hold text meant to blink. That's definitely a kludge, be it would probably make for simpler code.

posted by:   Nick       20-Apr-2014/23:43:17-7:00



You could hide the btn:
    
view layout [
     t: field
     at -100x-100 btn rate 2 feel [
         engage: func [f a e] [
             either all [t/text = "blink" a = 'time] [
                 t/font/color: either t/font/color = t/color [black] [t/color]
                 show t
             ] [
                 t/font/color: black
                 show t
             ]
         ]
     ]
]

posted by:   Nick       20-Apr-2014/23:49:52-7:00



Hi, I appreciate all the help you have given me here. This works well for a single field. I will try to turn it into a generic function so that I can call it blink func view xxx layout [etc] then I would just say blink t. I don't know if I can do this yet from within another view layout block. we'll see.


posted by:   John       21-Apr-2014/0:39:14-7:00



Is anything like the following possible? When I attempt to run it is says that gui has no value near blink gui t
    
R E B O L []
    
    
blink: func [scr fld] [
view scr [
    
     at -100x-100 btn rate 2 feel [
         engage: func [f a e] [
             either all [fld/text = "blink" a = 'time] [
                 fld/font/color: either t/font/color = fld/color [black] [fld/color]
                 show fld
             ] [
                 fld/font/color: black
                 show fld
             ]
         ]
     ]
]
]
view gui: layout [
     t: field
        
     blink gui t
     ]

posted by:   John       21-Apr-2014/2:02:19-7:00



Even if I put blink gui inside a button it doesn't blow up but it doesn't blink either.


posted by:   John       21-Apr-2014/3:23:18-7:00



You can do a little 'eval sort of metaprogramming thing to refer to each item in a block:
    
R E B O L []
clrs: reduce [black white]
view layout [
     x: field
     y: field
     at -100x-100 btn rate 2 feel [
         engage: func [f a e] [
             foreach fc [x y] [
                 either all ["blink" = do rejoin [fc "/text"] a = 'time] [
                     do rejoin [fc "/font/color: first reverse clrs show " fc]
                 ] [
                     do rejoin [fc "/font/color: black show " fc]
                 ]
             ]
         ]
     ]
]

posted by:   Nick       21-Apr-2014/22:58:59-7:00



That is clever. I suppose that there is no way to make it an external function to remove the code from the layout. I'm just trying to keep the layout code as clean as possible.
    


posted by:   John       22-Apr-2014/2:07:16-7:00



Take a look at this. I created a gobal block of faces, and stored the blinking colors in the 'user-data field of each face. Still a clunky solution, but I think it answers each of your questions:
    
R E B O L []
fcs: copy []
test: func [fc typs] [
     typs: reduce typs
     either error? try [
         either not find typs (type? load fc/text) [
             unless find fcs fc/var [append fcs fc/var]
             return
         ] [
             remove find fcs fc/var
             do rejoin [fc/var "/font/color: black show " fc/var]
         ]
     ] [
         unless find fcs fc/var [append fcs fc/var]
     ] [
         remove find fcs fc/var
         do rejoin [fc/var "/font/color: black show " fc/var]
     ]
]
view g: layout [
     text "Enter a date:"
     x: field "3-xx-2014" with [user-data: reduce [black white]]
     text "Enter a money or integer value:"
     y: field "asdf" with [user-data: reduce [black white]]
     btn "val" [
         test x [date!]
         test y [money! integer!]
     ]
     at -100x-100 btn rate 2 feel [
         engage: func [f a e] [
             if a = 'time [
                 foreach fac copy fcs [
                     do rejoin [fac "/font/color: first reverse " fac "/user-data show " fac]
                 ]
             ]
         ]
     ]
]

posted by:   Nick       22-Apr-2014/6:46:11-7:00



Hi,
I'm beginning to feel a tad guilty that you are doing so much work to implement something I want. I do appreciate it in that each rendition gives me a tad more insight into rebol and the capabilities of vid. I feel it is really vid that needs to be given more power - to hold a converted value so I don't need to reconvert the /text field from a string multiple times. to make the blinker bit work and to turn it off WHEN I ENTER THE FIELD AGAIN. to have a validation block that allows me to put validation code into the field and to have an error block to display next to the field when there is an error. This way i can fill in the validation code outside the layout and ideally the validation code can do anything a regular rebol program can do but do it for fields that need it . In addition the field should have a data type and an appropriate error message . All of this could be handled by a vid routine but we are having to reinvent one to handle things that should be routine. Anyways thank you for this current solution. It does provide me an answer to how to handle some of the problems I was talking about in my last post.

posted by:   John       22-Apr-2014/19:25:57-7:00



John,
    
I've only given a small bit of free time when I've had the moments, and I enjoy it, so no worries. The point of this forum is to encourage communication and to provide some support for issues which may be of practical benefit to others, to encourage community (that's my selfish goal), etc.    
    
To get the blinker to shut off when you enter the field again, create a new style field widget with a 'key event which removes the face from the 'fcs block.

posted by:   Nick       23-Apr-2014/10:27:05-7:00



... or maybe even simpler, just add the current face/text to the /user-data data block, and compare with the current text (in the blink loop). If it's changed, stop the blinking.

posted by:   Nick       23-Apr-2014/10:30:28-7:00