• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

ChristianE
4-Jul-2012
[616x2]
view layout [
    radio-line of 'a "Check this out"
    radio-line of 'a "or this"
    pad 8
    radio-line of 'b "Or Check this out"
    radio-line of 'b "or this"
    radio-line of 'b "or that"
]
What' exactly is your problem with radio buttons, Arnold?
Arnold
4-Jul-2012
[618x2]
Well it was quite a problem to get the selected value. I ended up 
first initialising all /data fields to their respective values beforehand 
to true for the one on and false for the two unselected ones. After 
that the fields behaved like you would expect, being true in case 
the selection was on this button and false if not selected.
Radio-line is new to me.
Something like this cost me only a couple of hours trial and err 
(mostly err) for there was no proper example to copy and it didn't 
work out of the box without the initialisations. 
main: layout [
a: radio on 'things lbl-a: "A"
b: radio of 'things lbl-b: "B"
etc]
a/data: true
b/data: false
view main
Maxim
4-Jul-2012
[620x2]
by default all radio buttons in the same pane switch together, you 
can just wrap your radio buttons in a panel.
ex:

view layout [
	panel [across radio radio radio on]
	panel [across radio on radio radio]
]
Arnold
4-Jul-2012
[622x2]
Stil that was not the problem. I wanted to know what selection was 
made :)
In my previous example b/data had a value none in stead of false 
and I could have two radioselections selected at the same time.
Maxim
4-Jul-2012
[624x7]
yeah, well, all I can say is that whenever view or more specifically 
VID is frustrating, you should just mold the face which is aggravating 
you, save the code to a file and read it in your favorite syntax 
highlighted editor.


you will learn A LOT about how VID.view works and learn quite a few 
Reboling techniques too.
very few people use functions as extensively and as precisely as 
Carl.   many functions have supported types I never even realized... 
like 'PICK which supports   true/false
(Carl wrote VID, so its a good example of his Rebol coding)
(its coarse and dense though, so don't despair if you don't undersand 
it all, just go through it line by line ... and learn)
here is a simple way to get the code for a face within the layout 
function ( I found it the easiest to remember):

view layout [
	across
	text "1"
	my-radio: radio on 
	do [probe my-radio]
	text "2"
	radio
]


the advantage of this system is that you get the actual face with 
any facets setup as they really are in your gui.  this is often the 
easiest way to identify just where and how a specific facet affects 
a face... probe it without your change, and then run it again, with 
your change... comparing both probes in a diff or merge tool.
the other way is to use get-style.   the advantage here is that is 
preserves the init block, instead of clearing it after VID has done 
its work


a good look at the 'init block is often useful to understand why 
changing some of the face values is ineffective (like changing face/color 
is often useles... since that face is setup to use face/colors). 
 

this block is run after all the facets have been applied. 

note that you can set or append to this block in your own styles.
HTH  :-)
ChristianE
4-Jul-2012
[631x2]
get-radio-buttons: does [
    reduce [
        get-face option-1
        get-face option-2
        get-face option-3
    ]
]

reset-radio-buttons: does [
    clear-face option-1
    clear-face option-2
    clear-face option-3
]

view layout [

    option-1: radio-line "Option 1" of 'options [probe get-radio-buttons]

    option-2: radio-line "Option 2" of 'options [probe get-radio-buttons]

    option-3: radio-line "Option 3" of 'options [probe get-radio-buttons]

    btn "reset radios" [reset-radio-buttons]
]
Best to use the getter-/setter-methods wherever they are implemented.
Ladislav
4-Jul-2012
[633]
anyone know which one of these would be the correct one to use?
1. 
percentile: func[s p /local n][n: round/floor (p * (length? s) + 
0.5) return s/(n - 1)]
2. percentile: func[s p /local n][n: round/floor 
(p * (length? s) + 0.5) return s/(n)]

 - I cannot recommend any of them. (ROUND/FLOOR is not what is recommended 
 in Wikipedia, also the percentile calculated this way is not compatible 
 with the "standard median definition". I recommend to use interpolation 
 on Hazen ranks as mentioned in Wikipedia under "interpolation", or 
 on Mean ranks as recommended by NIST - also can be found in WP)
Arnold
4-Jul-2012
[634]
I have view.txt in my rebol/script folder a copy from system/view, 
it is 80000 lines mostly object definitions and images. quite different 
from the ancient one http://www.rebol.com/view/vid.rthat at least 
makes some sense to me ;-)
Arnold
5-Jul-2012
[635]
getter/setter is a nice theoretical concept, nice for OO purposes. 
Radio buttons of a group should function like this: always 1 selected, 
the default to begin with, each option should have a value that is 
copied to the radiogroup's /data field, so to know what was selected 
can be found just like that. Not more not less.
rg: radiogroup rg1
radio on 'rg1  "Text 1" "A" 
radio     'rg1 "Text 2" "B"
and in your program 
switch rg1/data [
A
 [do this]
B
 [do that]]
Henrik
5-Jul-2012
[636x2]
Arnold, take a look at the VID Extension Kit. It attempts to make 
VID more complete, although it's no longer directly compatible with 
VID.
One thing to note about VID: It was a demo toolkit that Carl wrote 
about 10 years ago in a couple of weeks. He expected someone to come 
up with something better.
Arnold
5-Jul-2012
[638x2]
It is hard to beat in its simplicity. But also hard to improve in 
its current state. More a modular way would have been nicer. So it 
would have been clear where to start if you want to improve (or first 
find out) the behaviour of radio buttons for example.
Same thing as he expected the community to come up with the new bindings 
of REBOL3 to about all other Open Source operating Systems (Rebolution!) 
whereas the REBOL kernel source stays closed source. Not much animo 
since. Au contraire. Could have been the final nail...
Chris
7-Jul-2012
[640x2]
Arnold, I came up with one solution to the radio question here:

http://stackoverflow.com/questions/6401469/how-do-i-get-the-radio-button-value-in-rebol
It may be overkill, but it iterates through all faces looking for 
the 'of relationship, returning the selected face.
Arnold
7-Jul-2012
[642]
Hi Chris! Thank you. I consulted this site also. But there is better 
news to this! In stead of the words on and of you have to use the 
words true and false and the problems are solved! Didn't even have 
to initialize the /data fields between creating the layout and calling 
it in action with view.

Not documented but stil possible. (Like it is also undocumented on 
the REBOL site that you can have a checkbox followed by an action 
block.And this is also possible on text-labels making them clickable 
and have an mouse-over effect.)
Arnold
11-Jul-2012
[643]
Today I experimented with calling a REBOL script from my php script. 
Thanks to previous contributions of a.o. Ralph Roberts of abooks.com 
from 1999(!) and an entry on the PHP site I found out how to do this 
on my apache driven site.

It was not quite as straightforward as Robert said like: include 
("rebolnow.r");
Nor was it as simple as: system("rebolnow.r 2>&1", $myout);
echo $myout;

But it worked when I called out for the REBOL program first. Both 
two of the next examples worked for me:
system("/path/to/cgi-bin/rebol -c %rebolnow.r 2>&1", $myout);
echo $myout;
AND secondly
echo system("/path/to/cgi-bin/rebol -c %rebolnow.r");
Work!

The REBOL script must be in the same dir as your PHP script (Not 
in your cgi-bin directory)(I didn't test sub dirs and other dirs 
but I suppose they work like usual)
The script does not need the #!/path/to/rebol line at the top.
The script should not print http-headers and

When printing stuff the last line should read print "" because the 
last printed line will be repeated.

Hope this helps more people to switch from php scripting to REBOL 
scripting for their websites.
Izkata
11-Jul-2012
[644]
If you want to just echo the REBOL output, I would suggest using 
PHP's passthru() instead - it was designed for that:  http://php.net/manual/en/function.passthru.php
Arnold
12-Jul-2012
[645x2]
This says it is for binary data like images. In the first lines of 
this post http://www.mail-archive.com/[list-:-rebol-:-com]/msg01452.html 
it is mentioned as bringing not the solution to this wish. I passed 
this by, I'll stil have a second look, things in php could have 'suffered' 
improvements..
Does anybody have any experience in controlling servo motors using 
REBOL through USB devices/ports?
Henrik
12-Jul-2012
[647]
isn't that sort of time-critical?
Arnold
12-Jul-2012
[648]
I'm not in a hurry?! :)
Kaj
12-Jul-2012
[649]
I think Henrik means that you can get bitten by REBOL hanging for 
short periods of time in the garbage collector
Arnold
12-Jul-2012
[650x2]
It is interacting with the real world, robotica, control engineering..
Then the garbage should be separatedly collected. The paper, the 
glass, the compostable material, heavy metal's and rest-garbage. 
:)
Henrik
12-Jul-2012
[652]
You can turn off garbage collecting and do it in the "coffee breaks", 
with this.

recycle/off
Arnold
12-Jul-2012
[653x4]
With the 'large' programs I have in mind there will never be lots 
of garbage to collect. I don't know much/anything about robitics 
and control engineering by the way, I am interested in this because 
I realized using REBOL to do things like this could have large potential. 
And I want to move a little car with a photocamera and taking photo's 
from centain positions. The car may also be guided by a rail of some 
sort.
centain=certain
Domotica could also be a nice DSL.
PHP: I tried the passthru function. It worked, but I do not see any 
benefit from the exec function. I prefer exec over passthru. Saves 
typing, not that I do any. I always cut and paste code offcourse.
Arnold
13-Jul-2012
[657]
I meant system. exec didn't work. I still prefer system above passthru. 
I have integrated my first REBOL module within my website. I needed 
to add a cookie section to obey the new cookie law anyway. I even 
used a REBOL script to generate all cookie pictures to the same size 
and png format.
Endo
23-Jul-2012
[658]
How can I get the error text when I use TRY, I want to show the original 
error text to the user: 
if error? set/any 'err try [1 / 0] [probe disarm err]


I think I saw something similar in UniServe sources but couldn't 
find it.
DocKimbel
23-Jul-2012
[659]
This function should help you:

form-error: func [err [object!]][
	foreach w [arg1 arg2 arg3][
		set w either unset? get/any in err w [none][
			get/any in err w
		]
	]
	reform [
		"***" system/error/(err/type)/type #":"
		reduce system/error/(err/type)/(err/id) newline
		"*** Where:" mold/flat get in err 'where newline
		"*** Near: " mold/flat get in err 'near newline
	]
]
Endo
23-Jul-2012
[660]
Great! Thanks a lot Doc.
Gabriele
24-Jul-2012
[661]
this is my version: http://www.rebol.it/power-mezz/mezz/form-error.html

note that it does not make arg1, arg2 and arg3 global.
Endo
24-Jul-2012
[662]
Thanks Gabriele.
Arnold
26-Jul-2012
[663x2]
I am busy with a little chess program. Just the board and the pieces 
to be moved on the board. (I have seen the examples on rebol.org). 
It is meant to be for a chess learning/training program and possibly 
demonstration/game review and maybe have a coupling with an open 
source chess engine like Stockfish.. I am going to write a little 
script to determine all possible legal moves.  

 I want some information for what is an appropriate way to represent 
 the board and moves in REBOL, for example the 8-bit white/black init-position 
 king queen rook bisschop kNight pawn and board could be a1-h8 or 
 an array of 64 elements or a block (of blocks)
Suggestions welcome please. Tia.
In the script display-chess-board.r on rebol.org there is this part
   ;;  counter is now an image -  note the 'key effect 
    ;;  user to make the black in the image transparent.
    ;;  ------------------------------------------------
    counter: box 30x30 effect [key 0.0.0 oval]
 

This does not work, when keyword merge is added the middle part is 
transparent when the tuple is replaced with an integer, but only 
the other way around or the oval is limiting the working of merge 
to the inside of the circle?
Maxim
26-Jul-2012
[665]
you must add merge to the begining of effects, when you want images 
to pass thru faces.