Version 23 of Writing to Your Starkit

Updated 2004-03-11 22:16:43

By default starkits are read-only. You must give the -writeable flag to sdx when doing the wrap for your starkit to be writeable.

You make your starkit writeable by doing it at wrap time:

  sdx wrap app.kit -writeable

"-writeable" starkits automatically commit changes every 5 seconds.


TR Here is an example of a program that modifies its own contents using a writeable starkit. It is like 'tar'. Just download this file and do

 sdx qwrap TarKit.tcl
 sdx unwrap TarKit.kit
 sdx wrap TarKit -writable

This produces the starkit named 'TarKit'.

  package require Tk 8.4

 # this is the list of files in the archive:
 set myFiles [list]

 # this is the directory where we store the files:
 if {! [file exists [file join $starkit::topdir data]]} {
         file mkdir [file join $starkit::topdir data]
 }

 # copy a file into the starkit vfs:
 proc FileStore {} {
         global myFiles
         set data {}
         set file [tk_getOpenFile]
         if {[string length $file]} {
                 file copy $file [file join $starkit::topdir data]
                 # update the listbox contents:
                 lappend myFiles [file tail $file]
                 set myFiles [lsort $myFiles]
         }
 }

 # copy a file from the starkit vfs back into the real world:
 proc FileExtract {} {
         set index [.archive.lst curselection]
         if {[llength $index] == 0} {
                 tk_messageBox -title "Ups" \
                 -message "You must select a file for this action." \
                 -type ok -icon info
                 return
         }
         set file [.archive.lst get $index]
         if {[string length $file]} {
                 set destination [tk_getSaveFile -initialfile $file]
                 if {[string length $destination]} {
                         file copy [file join $starkit::topdir data $file] $destination
                 }
         }
 }

 wm title . "TarKit"

 # list the conents of the archive here:
 labelframe .archive -text "File archive"
 pack .archive -side right -padx 5 -pady 5 -fill both -expand 1
 listbox .archive.lst -listvar myFiles
 pack .archive.lst -padx 2 -pady 2 -fill both -expand 1

 # these are the possible actions:
 labelframe .actions -text "Actions"
 pack .actions -side left -padx 5 -pady 5 -fill both -expand 1
 foreach {btn cmd text} {
         store FileStore "Add a file"
         extract FileExtract "Extract selected file"
         quit exit "Quit"
 } {
         button .actions.$btn -command $cmd -text $text -width 20
         pack .actions.$btn -padx 5 -pady 2
 }

 # initialize the listbox with the currently stores files:
 foreach file [lsort [glob -nocomplain [file join $starkit::topdir data *]]] {
         lappend myFiles [file tail $file]
 }

Hmm, after having used that a bit, I thought it was time for something more useful --> TarKit.


 #! tclkit
 package require mk4vfs
 mk4vfs::mount mykit mykit.kit
 cd mykit
 glob *
 cd lib/app-mykit
 # Can I just update the file here?

05Feb03 Jeff Smith - "HeadsUp" [L1 ] is an example of single-file website - i.e. tclhttpd wrapped up as starkit, with user data inside.


Sexy Starkits

Category Tclkit