Home   Archive   Permalink



Changing and image's image (R2)

Is this the happening place for REBOL support questions? It's too bad that REBOL 2 got replaced before it got thoroughly documented.
    
I want to put some "indicator lights" on a window, as shown below:
    
R E B O L [
]
    
view center-face layout [
     IND-1: image 50x50 %GreenCheck.png
     IND-2: image 50x50 %OrangeQuestion.png
     IND-3: image 50x50 %RedX.png
]
    
But, what I REALLY want to do is have each of those indicators be a DIFFERENT image depending on some condition that exists when I show the window. In other words, IND-1 might be the GreenCheck.png file if some condition is true, otherwise it might be the RedX.png file.    
    
In addition, I might want the image for each indicator to change while the window is displayed (on a timer perhaps, or in response to a button). In other words, IND-3 might start as RedX.png, but then I might do something and click a "recheck" button, and then the image for IND-3 would change to GreenCheck.png.
    
Can anyone point down the right path to accomplish that, if it indeed can be done?
    
Thank you.


posted by:   Steven White       19-Sep-2013/9:57:36-7:00



Hi Steven,
    
You can set the /image property of an image style, to change the displayed image:
    
R E B O L []
GreenCheck: to-image layout/tight [check green]
RedCheck: to-image layout/tight [check red]
green: true
view center-face layout [
     IND-1: image GreenCheck
     btn "Change" [
         either green [
             IND-1/image: RedCheck
             green: false
         ] [
             IND-1/image: GreenCheck
             green: true
         ]
         show IND-1
     ]
]

posted by:   Nick       19-Sep-2013/10:07:01-7:00



For some simple cases, you may just want to use the toggle widget (or some stylized variation for your needs):
    
R E B O L []
GreenCheck: to-image layout/tight [check green]
RedCheck: to-image layout/tight [check red]
    
view layout [
     toggle 50x50 GreenCheck RedCheck
]

posted by:   Nick       19-Sep-2013/10:23:49-7:00



Thank you, that got me going. Here is my final test script, for reference.
    
R E B O L []
     Title: "Indicator light demo"
    
;; Create images for our indicator lights
GREEN-CHECK: load %GreenCheck.png
RED-X: load %RedX.png
    
;; For testing, make lights come up red, for "bad"
IND-1-OK: false
IND-2-OK: false
IND-3-OK: false
    
;; These procedures set the indicators depending on conditions
CHECK-IND-1: does [
     either IND-1-OK [
         IND-1/image: GREEN-CHECK
     ] [
         IND-1/image: RED-X
     ]
     show IND-1
]
CHECK-IND-2: does [
     either IND-2-OK [
         IND-2/image: GREEN-CHECK
     ] [
         IND-2/image: RED-X
     ]
     show IND-2
]
CHECK-IND-3: does [
     either IND-3-OK [
         IND-3/image: GREEN-CHECK
     ] [
         IND-3/image: RED-X
     ]
     show IND-3
]
    
;; Main window, default indicators are green for OK
MAIN-WINDOW: layout [
     across
     IND-1: image 50x50 GREEN-CHECK
     button "Recheck" [IND-1-OK: true CHECK-IND-1]
     return
     IND-2: image 50x50 GREEN-CHECK
     button "Recheck" [IND-2-OK: true CHECK-IND-2]
     return
     IND-3: image 50x50 GREEN-CHECK
     button "Recheck" [IND-3-OK: true CHECK-IND-3]
]
    
;; Before we view window, check for initial states of indicators
CHECK-IND-1
CHECK-IND-2
CHECK-IND-3
    
;; Now show the main window
view center-face MAIN-WINDOW
    


posted by:   Steven White       19-Sep-2013/11:19:23-7:00



I have to point out something interesting about this situation. There are situations of paid software support where one has a question, posts it to the appropriate support place, and then maybe waits on hold on the phone or gets an email response some time later. Here, I am using a programming language used by a few dozen people in the whole world, and I asked a question and got an answer in TEN MINUTES. This seems like something that should be on some list of "best-kept secrets of computer programming" or something like that.

posted by:   Steven White       19-Sep-2013/11:25:11-7:00



Glad to see you got it working. I think one of the reasons you see so much support among Rebolers is that the answers are usually really simple and quick to provide ;)

posted by:   Nick       19-Sep-2013/20:56:10-7:00