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

World: r4wp

[Rebol School] REBOL School

Henrik
29-Jun-2012
[495x3]
try this interactive test:

view layout [p: panel [button]]

escape to console and type:

p/pane: get in layout/tight [field 100] 'pane

show p
This replaces the pane in the panel P.
Then you will of course need to resize the panel and the window.
Arnold
29-Jun-2012
[498]
Within a panel sure would be smoother. Some larger layouts would 
require resizing as well. 

The example did what was to be expected. And I learned how to return 
to the running REBOL script after escaping in the terminal window!
Henrik
29-Jun-2012
[499x2]
it's a great way to interactively test and workout techniques for 
updating layouts.
when escaping to the console, events are no longer processed in the 
window. to continue getting events in the window, type:

do-events
Arnold
30-Jun-2012
[501]
I changed 1 label the font/color by setting panel1/pane/:n/text/font/color: 
white  and now all text fields including ones not on the panel are 
written in white. :-(
Henrik
30-Jun-2012
[502x3]
That is another attribute of VID, which is that many faces share 
the same font object. Update one, updates all font objects. The purpose 
of this is to save memory, but it comes off more as inconvenient, 
when doing things like this.
Update one, updates all font objects.
 => "Update one, updates all faces."
You can copy the font object with something like this:

label "boo" with [font: make font []]


There are other ways to trigger copying the font object during the 
layout process, but I can't exactly remember how, right now.
Arnold
30-Jun-2012
[505]
If I could switch it from a text to a label it would be nice. As 
yet I have this puzzling experience:
REBOL []
high-on: high-on-odd: false
swap-even: func [/local n] [

    either high-on [for n 2 8 2 [ panel-rechts/pane/:n/font/color: 'white] 
    high-on: false

    ][              for n 1 7 2 [ panel-rechts/pane/:n/font/color: 'black] 
    high-on: true ]
    show panel-rechts]

swap-odd: func [/local n] [

    either high-on-odd [for n 1 7 2 [panel-rechts/pane/:n/font/color: 
    'white

                                     panel-rechts/pane/:n/style: 'lbl-h-la-white] high-on-odd: false
    ][for n 1 7 2 [panel-rechts/pane/:n/font/color: 'black

                   panel-rechts/pane/:n/style: 'lbl-h-la-normal] high-on-odd: true]
    show panel-rechts]

spiegel-styles: stylize [
    lbl-h-la-normal: text left middle 40x100
    lbl-h-la-white: label left middle 40x100]
    
view layout [styles spiegel-styles
	across
	panel-rechts: panel [below space 0x0

    lbl-h-la-white "_" lbl-h-la-white "_" lbl-h-la-normal "_" lbl-h-la-normal 
    "_"

    lbl-h-la-normal "_" lbl-h-la-normal "_" lbl-h-la-normal "_" lbl-h-la-normal 
    "_"]
    return
    button "Even" [swap-even] button "Odd" [swap-odd]
    button "Debug" [print dump-face panel-rechts
    print panel-rechts/pane/1/font/color
    print panel-rechts/pane/1/color
    print panel-rechts/pane/1/style]
]

Where the first two labels change when button Odd is clicked. and 
then stay unchanged and the debug button shows the changes as expected 
(by me)
Henrik
30-Jun-2012
[506x3]
You can't simply switch the style by putting a new word in the STYLE 
facet. Each style is a prototype object with very different code 
to manage its internals. Generating a style using layout therefore 
involves getting a face from the style library, performing a set 
of operations on it for correct size and offset and run its initialization 
procedure. Only then is it inserted at the right localtion in the 
pane of the parent panel.
(But otherwise, it would be handy, if you could just do that :-))
You can study different styles using GET-STYLE.

For example:

probe get-style 'field


It's a bit misleading, though, as many styles share the same code. 
To really see how styles are built, you need to read the sourcecode 
for VID.
Arnold
30-Jun-2012
[509x2]
That is now on the wish-list!
When I name the labels lr1 thru lr8 and use the trick I found on 
www.pat665.free.fr/gtk/rebol-view.html which is w: to-word rejoin 
["lr" n] (for n is 1, 2, 3 or    8 you get the picture.) and f: get 
:w 

f/font/color: white and directly show the label: show f I can set 
them seperately. But it is a bit ugly to do it like this if I may 
say so.
Sujoy
3-Jul-2012
[511x3]
Hi! Have a quick question:
Hi! Have a quick question:
i have a block of objects:
each object is constructed like...
  c: #object! [
    name: "wonderwoman"
    attribs: [
      Y1991: #object! [ a: 1 n: 2]
      Y1992: #object! [ a: 1 n: 2]
    ]
  ]

i need to sort the series based on fields of the attribs inner object
i dont want to create a new series...any ideas?
Maxim
3-Jul-2012
[514x2]
use the /compare refinement of sort (which can be a function).
>> help sort
USAGE:

    SORT series /case /skip size /compare comparator /part length /all 
    /reverse


DESCRIPTION:
     Sorts a series.
     SORT is an action value.

ARGUMENTS:
     series -- (Type: series port)

REFINEMENTS:
     /case -- Case sensitive sort.
     /skip -- Treat the series as records of fixed size.
         size -- Size of each record. (Type: integer)
     /compare -- Comparator offset, block or function.
         comparator -- (Type: integer block function)
     /part -- Sort only part of a series.
         length -- Length of series to sort. (Type: integer)
     /all -- Compare all fields
     /reverse -- Reverse sort order
Sujoy
3-Jul-2012
[516]
hi maxim!

thanks - saw that in the docs, and also saw brett;s sort-object-series 
function on the mailing list
not quite sure how it works with an inner object though
Maxim
3-Jul-2012
[517]
the compare function should return true of false based on order of 
the two input arguments.
Sujoy
3-Jul-2012
[518x2]
this works great for fields in a simple object series:
sort-object-series: func [
  series
  field
] [

  sort/compare series func[a b][lesser? get in a field get in b field]
]
am fumbling with the get in bit...
Maxim
3-Jul-2012
[520x2]
sf: func [a b][   a/attribs/Y1991/n > b/attribs/Y1991/n  ]
sort/compare series :sf
Sujoy
3-Jul-2012
[522]
that was stupid of me to miss!
thanks!
Maxim
3-Jul-2012
[523]
no, its so simple we often think that there is more to it :-)
Sujoy
3-Jul-2012
[524x3]
:)
can i introduce an additional complexity?
what if i need to sort a hash?
m: #hash! [key-a obj-a key-b obj-b]
sort/compare/skip series :sf 2
??
Maxim
3-Jul-2012
[527]
yep
Sujoy
3-Jul-2012
[528]
cool! love rebol :)
Maxim
3-Jul-2012
[529x2]
but if you need to sort with sf above (which uses obj data) then 
you also need to add the index within the skip. (because the obj 
is not the first item of the fields marked with /skip
so it would be:
sort/compare/skip/index series :sf 2 2
Sujoy
3-Jul-2012
[531]
testing it now...
Maxim
3-Jul-2012
[532x3]
doh... that's my old modified sort func...
compare is used for the index and the func... hum.
I think you get blocks of fields when you use /compare with /skip
Sujoy
3-Jul-2012
[535x6]
>> blk: [1 [2  3] 0 [4 8] 5 [4 3]]
>> sort/skip blk 1
== [0 [4 8] 1 [2 3] 5 [4 3]]
sorry - that should read 
>> sort/skip blk 2
ok - am failing with the test, probably because i specified the problem 
wrongly
h: #hash! [k-a object! [
    name: "wonderwoman"
    attribs: make hash! ["1993-1994" #object! [
            rebal-year: 1993
            m: 160.018245
        ] "1992-1993" #object! [
            rebal-year: 1992
            m: 104.293
        ] "1991-1992" #object! [
            rebal-year: 1991
            m: 26.628
        ]]
...and so on...
my keys - for both the main hash and the inner hash are strings
i need to sort the hash h by the m attribute of the attribs hash
any ideas? would the same :sf work?
Maxim
3-Jul-2012
[541x3]
ok, so to get complete records, you need the /all refinement...
>> sort/skip/compare/all [1 [2  "a"] 0 [4 "z"] 5 [4 "m"]] 2 func 
[a b][a/2/2 < b/2/2 ]
== [1 [2 "a"] 5 [4 "m"] 0 [4 "z"]]
a, m, z are sorted.
Sujoy
3-Jul-2012
[544]
yup - that works...
but would it work for the structure i posted?