r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[View] discuss view related issues

Louis
14-Oct-2006
[5766x5]
Is there anything wrong with this:


style dater txt bold right [trans-date/text: copy (to-string now/date)] 
48x24
or this:


        dater "T-Date:" trans-date: field 80x24 (to-string now/date) feel 
        [
            engage: func [face action event][
                if action = 'up [

                    lv-dat: request-date/date/offset (now/date) 315x30
                    if lv-dat <> none [
                        trans-date/text: copy to string! lv-dat
                        show trans-date
                    ]
                ]
            ]
            ;trans-date/text: copy (to-string now/date)
            show trans-date
        ]
I really have trouble debugging view scripts, especially long complicated 
ones.  Usually, I make only one of two changes, then run the script. 
That way I know what part of the code is actually causing the error. 
This time, however, after making some changes I had to take care 
of an unrelated problem before I had opportunity to test the script. 
Now several months later, I finally have time to test, but ... I 
can't remember what the last changes were.
Has anyone written a "How to debug REBOL/View" doc?
Are there any debug tools?
Graham
14-Oct-2006
[5771x3]
Your error says 'trans-date is not defined.
trans-date is defined in your layout .. so therefore must be reference 
before the layout is created if you have that error.
without seeing the relevant part it may be that the problem is that 
your style references a field which has not been defined yet.
Louis
14-Oct-2006
[5774x2]
Thank, Graham. I'm looking.
I was using the wrong version of the SDK.
Anton
14-Oct-2006
[5776]
Louis,  you're doing something strange there with the SHOW in the 
feel.
Louis
14-Oct-2006
[5777x2]
I couldn't find the error because it didn't exist in the code. :>)
Anton, you mean because there are two shows?
Anton
14-Oct-2006
[5779x2]
No, when you specify a feel spec block, you're actually doing something 
like this:

	feel: make feel [
1)		engage: func ...
2)		show trans-date
	]
You are making an object.

On line 1) you are replacing the value of the 'engage word with a 
new function value of your own.

On line 2) you are simply doing some code. So this code executes 
at the time of the object creation.
Louis
14-Oct-2006
[5781]
OK, how do I do it right?
Anton
14-Oct-2006
[5782x5]
Looking at the code I assume what you want to do is initialise the 
text facet and make sure it's shown the first time the display is 
shown.
Well, you shouldn't have to SHOW the first time - that should be 
taken care of by VIEW or the SHOW that shows your whole layouted 
face in which you have your dater and trans-date field.
So that just leaves setting the text correctly the first time. And 
you are already doing that.
So just remove those two final lines from the feel spec.
By the way, to-string already makes a copy.
>> same? (to string! str: "example") str
== false
Louis
14-Oct-2006
[5787]
I'm learning a lot tonight. Thanks.
Anton
14-Oct-2006
[5788]
Welcome.
Robert
15-Oct-2006
[5789]
I have a question WRT changing the text of a shown label. I use a 
way where the layout of my GUI is done at startup-time once. Now 
I need to change the text of some labels at run-time and I don't 
want to do the following:
	- name each label that needs to be updated.

 - write a function that changes the TEXT word and shows the widget


I would like to use a word in the initial context that keeps a reference 
to the text (or function returning the text) which gets reevaluated 
if a SHOW is used.


Do I have to write an own style that supports this or is there a 
simpler way?
Henrik
15-Oct-2006
[5790x2]
an easy way is to keep all labels in a panel and then traverse the 
pane and set the label texts on a label.
if your panel consists of multiple different types of faces, you 
can filter on 'style
Anton
15-Oct-2006
[5792x4]
How about this:
data: ["hello" "there" "robert"]

spec: copy []
foreach string data [
	append spec compose [label 100 (string)]
]

view window: layout append spec [
	btn "change original strings" [
		insert clear data/1 "happy"
		insert clear data/2 "to be"
		insert clear data/3 "changed"
		show window
	]
]
You have to make sure the initial labels are large enough for your 
longest strings. Of course we can stylize label so that it resizes 
automatically, but maybe you don't need that.
Henrik's way can be helped using SET-FACE, I think. (I haven't used 
this feature yet.)
Have a look in svv/vid-styles/panel/access 'set-face*
Robert
15-Oct-2006
[5796x3]
Anton, ah the insert clear method... I missed this one. I think that's 
the way to go. I'll check this out. Thanks.
Hmm... one more. Let's I have:
	label-text: "The current value is ?"

and I know want to change the ? dynamically. After first replacement 
the ? is gone. So I need some way to keep the source version. Or 
first insert the source version, than replace and show.
Oh man... to many typos (I cut my right finger):
- Let's say I have
- know = now
Gregg
15-Oct-2006
[5799]
; Something like this maybe?

REBOL []

texts: [
    EN [
       lbl-1 "Hello"
       lbl-2 "Goodbye"
    ]
    DE [
       lbl-1 "Hallo"
       lbl-2 "Aufwiedersehen"
    ]
]

lang: 'EN
res: func [id] [texts/:lang/:id]

good-ID?: func [id] [find texts/:lang id]

has-res-ID?: func [face] [
    all [
        find first face 'res-ID
        word? face/res-ID
        good-ID? face/res-ID
    ]
]

re-show: func [face] [
    foreach f face/pane [
        if has-res-ID? f [
            set-face f res f/res-ID
        ]    
    ]
    show face
] 


lay: layout [
    text 100 with [res-ID: 'lbl-1]
    text 100 with [res-ID: 'lbl-2]
    btn "English" [lang: 'EN  re-show lay]
    btn "Deutsch" [lang: 'DE  re-show lay]
]

re-show lay
view lay
Louis
15-Oct-2006
[5800]
tr "Rp/US$:" exchange-rate: field 270x24 feel [
            exchange-rate/text: exchange-rat
            show exchange-rate
        ]


The above code loads exchange-rat into exchange-rate/text when the 
script loads.  But after saving data it appears to be empty. How 
can exchange-rate/text be forced to persistently show its contents?
Louis
16-Oct-2006
[5801x3]
I changed it to this:

        tr "Rp/US$:" exchange-rate: field 270x24 

        feel [exchange-rate/text: exchange-rat: (read %exchange-rate.txt)
            show exchange-rate 
            (write %exchange-rate.txt exchange-rat) 
        ]

But it still doesn't work.
What I want is:


1. The exchange rate to be saved in a file, so that it will always 
be loaded upon start the script.

2. The exchange rate to remain in the field through each loop of 
view.

3. And, of course, I want to be able to change the exchange rate 
if needed.


Seems like it should be a common easy thing to do, but it eludes 
me.
Perhaps it would be clearer to say that I don't want to have to manually 
enter the exchange rate for each record.
MikeL
16-Oct-2006
[5804x2]
Louis, I haven't been following this problem but if you want to just 
load a rate from a text file you could do something like this which 
handles loading before showing the face and allows saving an updated 
rate 

REBOL []

these-styles: stylize [
	lab: label  60x20 right bold middle font-size 11
    fld: field  60x20 font-size 11 middle edge [size: 1x1]
]

    rate-file: %/c/rate-file.txt
    if not exists? rate-file [write rate-file 1.000]    
    rate: load rate-file

view layout [
    across
    styles these-styles
    lab "Rate"    rate-field: fld bold (form rate) return
    btn "Save" #"^s" [save rate-file form rate-field/text]
]
If you want to keep the update function out of this script, it is 
simple to just use the REBOL editor to update the rate via 

btn "Editor" #"^e" [editor rate-file]

But make the rate field read only.
Louis
16-Oct-2006
[5806]
MikeL, thanks! I'm testing to see if this does what I need. I'll 
report back.
Anton
16-Oct-2006
[5807x2]
Robert, try this:
data: [
	"name: ?" "name: Robert" 
	"age: ?" "age: unknown" 
	"occupation: ?" "occupation: programmer"
]

spec: copy []
foreach [format string] data [
	append spec compose [label 100 (string)]
]

view window: layout append spec [
	btn "change original strings" [
		insert clear data/2 replace copy data/1 "?" "Anton"
		insert clear data/4 replace copy data/3 "?" "31"
		insert clear data/6 replace copy data/5 "?" "rebol surgeon"
		show window
	]
]
Louis
16-Oct-2006
[5809x7]
rebol []
either exists? %exchange-rate.txt [
    exchange-rat: load %exchange-rate.txt
][
    save %exchange-rate.txt 1
    exchange-rat: load %exchange-rate.txt
]
exchange-rate-style: stylize [
    exchange-rate-label: label  60x20 right bold middle
    exchange-rate-field: field  270x24 middle
]
view layout [
    styles exchange-rate-style

    exchange-rate-label "Rp/US$:" exchange-rate: exchange-rate-field 
    bold (form exchange-rat)
    button "Save" [
        save %exchange-rate.txt exchange-rate/text
    ]
]


The above code works in the above test script (mimics MikeL's script); 
but in my accounting script it yields and error message: 

** Script Error: val needs a value
** Where: forskip
** Near: forall args [
    val: first args
    switch/default type?/word val [
        pair! [append pairs val]
        integer...
>>
and = an
I just cut and pasted the code from my accounting script into the 
test script above.
In my accounting script, however, some of the code is separated by 
other code. Could that be the problem?
By the way, thanks MikeL. This is what I am wanting.
Ok, I've traced the problem to 'clear-fields. How can I protect this 
particular field so that it is not cleared by 'clear-fields with 
all the rest of the fields upon save?
rebol []

either all [exists? %exchange-rate.txt "" <> read %exchange-rate.txt][
    exchange-rat: read %exchange-rate.txt
][
    write %exchange-rate.txt 1
    exchange-rat: read %exchange-rate.txt
]
exchange-rate-style: stylize [
    exchange-rate-label: label  60x20 
    exchange-rate-field: field  50x24
    note-label: label 55x20
    Note-field: field 55x55
]
test: layout [
    styles exchange-rate-style
    note-label "Notes:" notes: note-field bold 

    exchange-rate-label "Rp/US$:" exchange-rate: exchange-rate-field 
    bold (form exchange-rat)
    button "Save" [
        exchange-rat: exchange-rate/text
        write %exchange-rate.txt exchange-rate/text

        ;clear-fields test show test ;<=========<< UNCOMMENT THIS LINE TO 
        SEE THE PROBLEM.

        ;Needed: for the Notes field to clear on each save, but the exchange-rate 
        field to persist.
    ]
]
view/options  test [resize]