I inspired from http://www.codeconscious.com/rebol/view-notes.html
I don't understand: why is close sent immediately: that's not what I want and I would expect it to be sent when I click on Window close
query-on-close: func[face event][
print "query-on-close"
remove-event-func :query-on-close
RETURN event
]
view layout [
do [ insert-event-func :query-on-close ]
]
rebol []
query-on-close: func [face event][
prin event/type prin " "
either 'close = event/type [
print "^/query-on-close handler now removed. Next close will now close this window"
remove-event-func :f
return none
][
RETURN event
]
]
f: insert-event-func :query-on-close
view layout [
title "Test screen"
]
As written the first event you receive will print the message, and then remove the handler. You need to test specifically for the CLOSE event.
Related
I am trying following code where user enters 2 numbers and on clicking calculate button, answer should be shown. There are also buttons for clearing fields and for exiting.
REBOL[]
fields: [f-ht f-wt ans]
reset-fields: does [
unfocus
f-ht/text: " " ; Changing this to "ENTER NUMBER HERE" does not help
f-wt/text: " "
focus f-ht
]
oncalc: does [
ans/text: (to integer! f-wt/text) / ((100 * to integer! f-ht/text) * (100 * to integer! f-ht/text))
show fields
]
lo: layout [
style tx label 200x24 center
style fld field 200x24 center
style btn button 200x24 center
tx "First Number:"
f-ht: fld
tx "Second Number:"
f-wt: fld
btn "Calculate" [oncalc]
ans: tx "Answer"
btn "Clear" [reset-fields show fields] ; NOT WORKING- NOTHING HAPPENS
btn "Exit" escape [unview/only lo]
]
reset-fields
view center-face lo
The GUI is showing all right. However, there are following problems:
On clear button clicking, nothing is happening.
There are no changes on GUI and no errors are being reported. Where is the problem and how can this be solved? Thanks for your help.
Clear the fields instead of setting to new strings
reset-fields: does [
unfocus
clear f-ht/text
clear f-wt/text
focus f-ht
]
When Elm has a lot of DOM manipulation to do, there is some lag before the results show up. I'm trying to figure out how to show a placeholder div that says "Loading..." while Elm is doing its thing.
To demonstrate the lag, I've modified one of the Elm examples to render an increasingly huge number of text elements upon a button click:
import Html exposing (beginnerProgram, div, button, text)
import Html.Events exposing (onClick)
main =
beginnerProgram { model = 0, view = view, update = update }
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
, div [] (List.repeat (2 ^ model) (text ". ")) -- this is my addition
]
type Msg = Increment | Decrement
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
When running the example, clicking the '+' button will show a '.' characters in powers of 2. When the number is sufficiently high (around 16 on my machine), there is a multi-second delay after clicking before the '.' characters are shown.
What is a good way to show a 'loading...' element (in a 'div', say) before rendering the '.' elements?
You'll need to use a regular Html.program and return a Cmd from the Increment/Decrement update handlers that will pause to let the DOM render the "Loading" and then reenter the update:
import Html exposing (program, div, button, text)
import Html.Events exposing (onClick)
import Process
import Task
main =
program { init = (Model 0 False, Cmd.none), view = view, update = update, subscriptions = \_ -> Sub.none }
type alias Model =
{ count: Int
, loading: Bool
}
view model =
let
dotsDisplay =
if model.loading then
div [] [text "Loading..."]
else
div [] (List.repeat (2 ^ model.count) (text ". "))
in
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (toString model.count) ]
, button [ onClick Increment ] [ text "+" ]
, dotsDisplay
]
type Msg = Increment | Decrement | FinishLoading
finishLoadingCmd =
Task.map2 (\_ b -> b) (Process.sleep 10) (Task.succeed FinishLoading)
|> Task.perform identity
update msg model =
case msg of
Increment ->
{model | count = model.count + 1, loading = True} ! [finishLoadingCmd]
Decrement ->
{model | count = model.count - 1, loading = True} ! [finishLoadingCmd]
FinishLoading ->
{model | loading = False} ! []
It's still going to lock up the browser while it renders all those nodes though, so you probably still want to look for a way to not be rendering 100k+ DOM elements...
REBOL
I currently trying to redo a small app I made in Delphi.
This application displays a background image among n and a text among n, but I cannot change the image or the text, the change of image and text is done by the button >>.
This is the simplified code without the random part because I found out about it:
Rebol[
Title: "You have a message !"
Version: 1.0.0
Needs: [1.2.115]
]
the-imag1: load %"/C/MyFile/Cours CD/Affiche/Images/Vague9.jpg"
the-imag2: load %"/C/MyFile/Cours CD/Affiche/Images/Vague3.jpg"
the-image: the-imag1
text1: "Your banner text here"
view xx1: layout [
size the-image/size
b1: backdrop the-image
at b1/offset + 110x120
box 350x150 font-size 20 font-color black [align: 'center] text1
at b1/offset + 530x370
btn ">>" [the-image: the-imag2 ; new image
text1: "Hello" ; new text
show xx1] effect [multiply 90]
]
You are redefining the face, not just the content. Just redefine the field you need. Try this:
Rebol[
Title: "You have a message !"
Version: 1.0.0
Needs: [1.2.115]
]
the-imag1: load %"/C/MyFile/Cours CD/Affiche/Images/Vague9.jpg"
the-imag2: load %"/C/MyFile/Cours CD/Affiche/Images/Vague3.jpg"
the-image: the-imag1
text1: "Your banner text here"
view xx1: layout [
size the-image/size
b1: backdrop the-image
at b1/offset + 110x120
t1: text text1
at b1/offset + 530x370
btn ">>" [
b1/image: the-imag2 ; new image
t1/text: "Hello" ; new text
show xx1
] effect [multiply 90]
]
I tried to implement a save-as-ftp button in Rebol embedded editor. Implementation of the save-as-button is this:
save-as-ftp: has [file-content][
file-content: t1/text
prefs-file: rejoin [_self-path %ftp.preferences.txt]
either exists? prefs-file [
prefs-ftp: construct load prefs-file; see article application configuration file
user: prefs-ftp/user
password: prefs-ftp/password
server-path: prefs-ftp/server-path
][
user: ask "User: "
password: ask/hide "Password: "
server-path: ask "Server-Path: "
]
view ftp-view: layout [
origin 10x10 space 8x4
style btn btn 140
ftp-field: text bold "" 140 center
pad 0x4
btn-enter 140 "Save" #"s" [hide-popup result: ftp-field/text]
btn red + 50 "Quit - No Save" [hide-popup quit-now]
]
file-target: result
ftp-target: rejoin [ftp:// user ":" password "#" server-path file-target]
write ftp-target file-content
print ["uploaded" file-target "to" rejoin [ftp:// "XXXXXXX" ":" "XXXXXXX" "#" server-path]]
true
]
My problem is with view ftp-view : I cannot even type in ftp-field text box as the popup window loses focus.
hide-popup is used to close a modal window.
A modal window is opened by using 'inform
I don't see any modal windows here.
Oh .. this is a button or something that you are attaching to the rebol editor?
I modified mine some years ago to edit ftp files ... I'll have to see if I can find what I did.
download-dir: request-dir
Print ["downloading " "VStudio2008Express.iso" "..." ]
url: http://go.microsoft.com/fwlink/?LinkId=104679
file-save: to-rebol-file rejoin [download-dir "VStudio2008Express.iso"]
request-download/to url file-save
In the end whereas the progress bar has shown the download has finished:
** Script Error: Not enough memory
** Where: append
** Near: insert tail series :value
>>
So how to correct request-download as it is a mezzanine function:
func [
{Request a file download from the net. Show progress. Return none on error.}
url [url!]
/to "Specify local file target." local-file [file! none!]
/local prog lo stop data stat event-port event
][
view/new center-face lo: layout [
backeffect [gradient 1x1 water gray]
space 10x8
vh2 300 gold "Downloading File:"
vtext bold center 300 to-string url
prog: progress 300
across
btn 90 "Cancel" [stop: true]
stat: text 160x24 middle
]
stop: false
data: read-thru/to/progress/update url local-file func [total bytes] [
prog/data: bytes / (max 1 total)
stat/text: reform [bytes "bytes"]
show [prog stat]
not stop
]
unview/only lo
if not stop [data]
]
Rebol's read functions read all the input data into memory at once and cannot be used on large datasets. You have to open a port and copy the data from it in chunks to handle large datasets.
I would think that the request-download function could be modified to use ports for both the input and output data. This thread from the Rebol Mailing List may help you:
http://www.rebol.org/ml-display-thread.r?m=rmlFQXC
You can find a fuller example on Carl's blog at http://www.rebol.com/cgi-bin/blog.r?view=0281#comments
Even using this technique there is a limit of approximately 2Gb to the size of files that can be handled in Rebol 2.
Try this
http://anton.wildit.net.au/rebol/util/batch-download.r