When you hit the save button of this applet it will append what is displayed to the persistent storage area, shared with the right tclet. | When you hit the load of this tclet it will read the local persistent storage and display it when you hit load (and it also tries to display the current content at startup) |
Notes: The first time you should get an error in the right tclet as the persistent file does not yet exist, but as soon as you will have saved something on the left, the right Load should work. You can also delete the file on the left and then observe the loading error on the right. |
Important note: by default the persistence storage area allocated for a tclet is private, to allow sharing, you must specify a common prefix for the tclets, either in the embed statement or by changing embed_args(prefix) in the tclet as in this example. The prefix expected a path relative to the origin server root and which must include the origin path where the tclet is coming from (see persist man page).
Source of the left Tclet | Source of the right Tclet |
set embed_args(prefix)\ [file dirname [getattr originPath]] frame .f text .f.t -yscrollcommand {.f.s set}\ -wrap word scrollbar .f.s -command {.f.t yview}\ -width 12 pack .f.s -side right -fill y pack .f.t -side left -fill both -expand 1 frame .fb button .fb.b1 -text Save\ -command {save .f.t} button .fb.b2 -text Delete\ -command {delete .f.t} pack .fb.b1 .fb.b2 -side left -padx 10 pack .fb -side bottom pack .f -fill both -expand 1 .f.t tag configure error -foreground red proc bgerror {msg} { .f.t insert end "\nError: $msg\n" error } proc save {w} { policy home set f [open "share1.txt" a+] puts -nonewline $f [$w get 1.0 end] close $f } proc delete {w} { policy home $w delete 1.0 end file delete "share1.txt" } |
set embed_args(prefix)\ [file dirname [getattr originPath]] frame .f text .f.t -yscrollcommand {.f.s set}\ -wrap word scrollbar .f.s -command {.f.t yview}\ -width 12 pack .f.s -side right -fill y pack .f.t -side left -fill both -expand 1 button .b -text Load -command load pack .b -side bottom pack .f -fill both -expand 1 .f.t tag configure error -foreground red .f.t tag configure input -foreground green4 proc insert {txt {tags ""} {clear 0}} { .f.t configure -state normal if {$clear} { .f.t delete 1.0 end } .f.t insert end $txt $tags .f.t configure -state disabled } proc bgerror {msg} { insert "\nError: $msg\n" error } proc load {} { policy home set f [open "share1.txt" r] insert [read $f] input 1 close $f } after idle load |