source: trunk/lang/tcl/scripts/types/language.tcl @ 2157

Last change on this file since 2157 was 2157, checked in by mmc, 13 years ago

Added support for -tooltip options on all attributes, and added descriptions
of attributes to all objects. This gives the user pop-up help inside the
builder.

File size: 4.3 KB
Line 
1# ----------------------------------------------------------------------
2#  EDITOR: programming language
3#
4#  Used within the Instant Rappture builder to edit the "language"
5#  which is an attribute of the tool.  This control offers any of
6#  the built-in template languages, or the "custom" option (which
7#  allows the user to specify the tool invocation command).
8#
9# ======================================================================
10#  AUTHOR:  Michael McLennan, Purdue University
11#  Copyright (c) 2004-2011  Purdue Research Foundation
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16itcl::class AttrLanguage {
17    constructor {win args} {
18        Rappture::getopts args params {
19            value -tooltip ""
20        }
21
22        Rappture::Combobox $win.val -width 12 -editable no
23        pack $win.val -side left
24        foreach name [lsort [RapptureBuilder::templates::languages]] {
25            $win.val choices insert end $name $name
26        }
27        $win.val choices insert end "--" "Other"
28
29        bind $win.val <<Value>> [itcl::code $this _react]
30
31        Rappture::Tooltip::for $win.val $params(-tooltip)
32
33        frame $win.custom
34        label $win.custom.l -text "Command:"
35        pack $win.custom.l -side left
36        entry $win.custom.val
37        pack $win.custom.val -side left -expand yes -fill x
38        Rappture::Tooltip::for $win.custom.val "Enter the command line that Rappture should invoke to run your simulation program.  Include @driver somewhere on this line; it will be replaced with the name of the Rappture driver file (usually passed in as the first argument on the command line).  If you include @tool, it will be replaced with the name of the directory where the tool.xml file is installed.  Instead of hard-coding your program path, you can express it as a relative path from @tool."
39
40        set _win $win
41    }
42
43    public method check {} {
44        if {[$_win.val translate [$_win.val value]] eq "--"} {
45            if {[string trim [$_win.custom.val get]] eq ""} {
46                return [list error "Must specify a custom invocation command for this tool"]
47            }
48        }
49        return ""
50    }
51
52    public method load {val} {
53        # If the value is !language, then it may have been saved earlier
54        if {[string index $val 0] eq "!"} {
55            $_win.val value [string range $val 1 end]
56            $_win.custom.val delete 0 end
57            return
58        }
59
60        # It's hard to reload a real command from a tool.xml file.
61        # Scan through all languages and treat @@FILENAME@@ as a wildcard.
62        # See if any of the languages match.
63        foreach lang [RapptureBuilder::templates::languages] {
64            set cmd [RapptureBuilder::templates::generate command \
65                -language $lang -macros {@@FILENAME@@ * @@FILEROOT@@ *}]
66
67            if {[string match $cmd $val]} {
68                $_win.val value $lang
69                $_win.custom.val delete 0 end
70                return
71            }
72        }
73        # must be a custom command
74        $_win.val value "Other"
75        $_win.custom.val delete 0 end
76        $_win.custom.val insert end $val
77    }
78
79    public method save {var} {
80        upvar $var value
81        set str [$_win.val translate [$_win.val value]]
82        if {$str eq "--"} {
83            # save custom command
84            set value [string trim [$_win.custom.val get]]
85        } else {
86            # save !language and substitute proper command later
87            set value "!$str"
88        }
89        return 1
90    }
91
92    public method edit {} {
93        focus -force $_win.val
94    }
95
96    public proc import {xmlobj path} {
97        return [$xmlobj get $path]
98    }
99
100    public proc export {xmlobj path value} {
101        set value [string trim $value]
102        if {$value ne ""} {
103            $xmlobj put $path $value
104        }
105    }
106
107    # invoked whenever the user changes the language choice
108    private method _react {} {
109        if {[$_win.val translate [$_win.val value]] eq "--"} {
110            # custom option -- put up extra controls
111            pack $_win.custom -side left -expand yes -fill x
112        } else {
113            pack forget $_win.custom
114        }
115    }
116
117    private variable _win ""       ;# containing frame
118}
Note: See TracBrowser for help on using the repository browser.