Why not? (attached) It just adds a few things to the Tk* modules, as it seems
some of the useful things in them are private.
This is primarily used to have tcl configuration files for our Ruby-based CAD
tools. So it is not terribly complex.
I must make an obligatory disclaimer: I didn’t write any of this, coworkers
Craig Files and John Bratt did (hence the mix of styles). Perhaps if this is
useful to others it could be extended, cleaned up, and made even more useful.
A little example of one way we’d use this, rather neutered:
def ScanPlan.readCommandsFile(filename, scanplan)
create a class object so it can be reached outside the scope of an
individual object (how it has to be done with Tcl)
@@current_scanplan = scanplan
Next, set up tcl configuration commands
tcl_code = <<-EOC
proc set_constraint {scantype param_name param_value} {
ruby “ScanPlan.sp_set_param(‘$scantype’,‘$param_name’,‘$param_value’)”
return “$scantype”
}
# put in any other tcl code you want here… if long could certainly
# be read in from a file instead
EOC
TclUtils.eval(tcl_code)
TclUtils.load_file(filename)
error = TclUtils.fetchValue(“errorInfo”)
If load_file had errors, it will print to stderr the error, but nothing
will actually stop our current process.
raise “Reading tcl file #{filename} generated errors.” unless error.empty?
@@current_scanplan = nil
end
This is the ruby method that is called by the tcl procedure set_constraint
In such methods we may need to access the class variable which gives
us some context (this tools does things recursively, including reading
multiple tcl configuration file for a given level of hierarchy)
def ScanPlan.sp_set_param(scantype, param_name, param_value)
ScanPlan.checkNewParam(scantype,param_name,param_value)
ScanPlan[scantype,param_name] = param_value
return param_value
end
Note that the same restrictions in communication to and from Tcl apply as when
using the Tk modules–make sure each tcl proc and each Ruby method that cross
the Tcl/Ruby boundary returns a string and nothing but a string.
TclUtils.rb (3.02 KB)
···
On Apr 4, Jim Freeze wrote:
On Friday, 4 April 2003 at 2:03:50 +0900, Brett H. Williams wrote:
At this time, though, I don’t think I’m at liberty to share any of it. Hmmm…
we do have some simple utilities to parse and communicate with Tcl (so many CAD
tools use Tcl). I think that could be shared, and we’ve found it quite useful
despite its simplicity.
Please share
–
---------------------------------------------- | --------------------------
Brett Williams | (970) 288-0475