Q&D button maker
[1/3] from: swhite::ci::bloomington::mn::us at: 3-Mar-2006 17:22
I suppose everybody but me knew this, but I just figured it out, and I didn't find anything
like in the library while I was figuring it out, so I thought I would mention it.
The application is a web-browser-based CGI program I am writing in COBOL. I wanted some
buttons to put on a web page just because it would look better than just a highlighted
text link. I don't have access to anything like Photoshop to make buttons. The application
is on a unix computer on our internal network. I work at a Windows workstation on which
I have installed REBOL.
This script works because in REBOL everything, code, data, graphical things on the screen,
are referred to by words. I see now the beauty of that idea.
I wrote a script that displays some buttons. I assigned a word to each button (identified
each button by a variable name, or however you want to say it). The word that identifies
a button "contains" all the information about the button.
The function assigned to a button can identify its own button by the button's word (its
name). It passes that button (converted to an image) to another function that saves
the button to a "png" file and ftp's the graphic over to the server where I am writing
the CGI program.
I modify my "button library" script so the buttons look like I want them to look, then
I run the script. I click on each button and a graphic for each button magically appears
over on the unix computer.
This is so cool.
The script follows, with the user name, password, and directory nodes replaced with generic
place-holder values.
*---------------
REBOL [
]
;; [----------------------------------------------------------------]
;; [ These are the buttons for the temporary reservation program ]
;; [ for Park and Rec. ]
;; [----------------------------------------------------------------]
SAVE-SITE: "ftp://user:password-99.99.99.99//x/y/z/graphics/"
SAVE-BUTTON: func [
BUTTON-FILENAME [file!]
BUTTON-IMAGE [image!]
/local SAVE-FTP-LOC
] [
save/png BUTTON-FILENAME BUTTON-IMAGE
SAVE-FTP-LOC: copy ""
SAVE-FTP-LOC: to-url join SAVE-SITE [to-string BUTTON-FILENAME]
write/binary SAVE-FTP-LOC read/binary BUTTON-FILENAME
delete BUTTON-FILENAME
]
view layout [
B01: button 260x55
"Add a new reservation/invoice"
font [size: 14]
[SAVE-BUTTON %btnresadd.png to-image B01]
B02: button 260x55
"Modify/print an invoice"
font [size: 14]
[SAVE-BUTTON %btnresmod.png to-image B02]
B03: button 260x55
"Display one day at a facility"
font [size: 14]
[SAVE-BUTTON %btnresprt.png to-image B03]
B04: button 260x55
"Display one month at a facility"
font [size: 14]
[SAVE-BUTTON %btnresmth.png to-image B04]
]
Steven White
City of Bloomington
1800 W Old Shakopee Rd
Bloomington MN 55431-3096
USA
952-563-4882 (voice)
952-563-4672 (fax)
steven.white-ci.bloomington.mn.us
[2/3] from: anton::wilddsl::net::au at: 7-Mar-2006 0:16
Hi Steven, yes it's cool ! :)
But I had a look and found that you probably do not
need to set words to your button faces at all, as
the faces are available in each button action.
So you can have the same functionality with even less
code ! :)
Have at look at this console session:
>> layout [b: button [print "hi"]]
>> print mold get in b 'action
func [face value][print "hi"]
As you can see, the action facet of the button face
is a function which takes two arguments FACE and VALUE.
When the action function is called, the View system passes the
face whose action is being done in the FACE argument.
This means the action code can refer to FACE if it wants to find
out anything about the button.
An example will make things clearer. Your code can be simplified
like this:
layout [
style button button 260x55 font-size 14
button "Add a new reservation/invoice" [
save-button %btnresadd.png to-image face
]
button "etc"
]
So you can see the reference to face removes the need for
setting a word to each button. :)
I've thrown in another optimization with the LAYOUT dialect keyword,
STYLE. It just restyles the BUTTON style with some default facet values,
which saves specifying them for every button.
(Mmm.. and you could move TO-IMAGE inside SAVE-BUTTON... but I'll leave
that to you.)
Regards,
Anton.
[3/3] from: greggirwin::mindspring::com at: 6-Mar-2006 9:56
Hi Steven,
Cool app! I use REBOL to generate graphics as well, because I'm not
skilled in that area. It's very easy to make box diagrams and such
this way.
Volker did a cool thing when some of us built a slashdot reader. He
wrote a tool that ran each UI script and grabbed a screenshot, then
built an installer that showed you a preview of each UI available.
-- Gregg