by
Theo VerelstThe
Bwise package can save items on a (the main bwise) canvas to a tcl/tk
source-able file, but thus far only graphical items, no widgets.
This upgrade proc saves the Entry and Mon blocks, too. More will follow, this is not heavily tested. In fact I just found out that -bg -fg and -bd cases aren't filtered out yet, they need to be treated as special cases since reading back the conf values in a command generates an error ! (I'll update soon)
The above blocks are all saved, the red marked bottom ones aren'tFor those interested, simply start bwise, and load this procedure to replace the old one.
proc save_canvas { } {
global mc
set o ""
set sv {bcount scopeindex wireindex shellindex drumindex entrycount moncount proccount seqcount stackcount termindex textcount}
eval global $sv
eval {append o global " " $sv \n}
foreach i $sv {
catch { eval set j $$i ;
append o set " " $i " " $j \n
}
}
# save images on canvas
foreach in [image names] {
if {[$in cget -file] != ""} {
append o "image create photo " $in " -file " [$in cget -file] \n
}
}
# save all canvas items except menus and (for now) sub-windows
foreach i [$mc find all] {
if {[$mc type $i] != "window" && [$mc type $i] != "menu"} {
append o $mc " " create " " [$mc type $i] " " [$mc coords $i]
foreach k [ $mc itemco $i] {
append o " " [lindex $k 0] " " [list [lindex $k end]]
}
append o \n }
}
# save all widgets under the Bwise canvas, with all reloadable options
set oo {};
foreach w [ilist $mc] {
if {[winfo class $w] != "Menu"} {
set p {};
foreach i [$w conf] {
# filter out options of which the value starts with -
if {[string index [lindex $i end] 0] != "-"} {
lappend p [list [lindex $i 0] [lindex $i end]]
}
};
append o "[string tolower [winfo class $w]] $w " ;
foreach i $p {append o $i " "} ; append o "\n"
}
}
# save all canvas window items, which match tops of sub widget hierarchies
foreach i [$mc find all] {
if {[$mc type $i] == "window" } {
append o $mc " " create " " [$mc type $i] " " [$mc coords $i]
foreach k [ $mc itemco $i] {
append o " " [lindex $k 0] " " [list [lindex $k end]]
}
append o \n }
}
uplevel #0 {
set ooo {}
foreach bi [tag_and {block}] {
set b [block_name_fromid $bi]
foreach i [lsort -dict [info vars $b.*]] {
if {[string index $i 0] != "\$" &&
[array exists $i] == 0} {
eval set ttt $\{$i\}
#set uuu "set \{$i\} \{$ttt\} \n"
#eval set uuu $\{$i\}
append ooo "set " $i " " \{ $ttt \} \n
}
}
}
}
global ooo
set fn [tk_getSaveFile];
if {$fn != ""} {
set fd [open $fn w];
puts $fd $o; puts $fd {# now the block related variables\n}
puts $fd $ooo; close $fd
}
}
More work is in progress to save all widget hierarchies, maybe to upgrade the code here and there, and possibly I'll look into the defaults and their proper use, maybe even a global default.def or so, to save against either average or dedicated default option values, and mention only abberations in the saved canvas file.
TV (jume 4 '04) Some time in sunny france (well most of the time) hasn't brought an extensive Save routine yet, but I though I'd write some stuff about the things already there, which can at least be used for proofs of reasonable concept. The above does work in the sense that one can start
bwise, create some blocks, also containing single widgets, like entry, monitor, and image, which can be connected somehow and 'run', and then save the whole thing, and it will come back up when reloaded, that actually works.
Not the whole state is saved, but most of it, though not of the widget contents, AFAIR, Bwise blocks have state variables for the contents of the pin-corresponding variables, so often re-activating the network is enough to restore certain widgets.
I'll make a page on
example simple bwise widget block use .
TV (14 jun '04) I just rechecked this page, it appears the above example doesn't always work, so beware some options like -bd borderWidth are still a problem, donno why exactly, I'll look into it.