/[ascend]/trunk/tcltk/TK/script.tcl
ViewVC logotype

Contents of /trunk/tcltk/TK/script.tcl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 659 - (show annotations) (download) (as text)
Sun Jun 4 20:01:04 2006 UTC (16 years, 7 months ago) by ben.allan
File MIME type: text/x-tcl
File size: 14982 byte(s)
added File->Open everywhere equivalent to File->Read ...  to resolve pye request.
At a 1.0 release of tcltk, we should consider getting rid of
the file reads, but not before. existing users have muscle memories
that are not to be toyed with.
1 # script.tcl
2 # by Benjamin A. Allan and Kirk A. Abbott
3 # Created: January 1994
4 # Part of ASCEND
5 # Revision: $Revision: 1.37 $
6 # Last modified on: $Date: 1998/06/18 15:55:38 $
7 # Last modified by: $Author: mthomas $
8 # Revision control file: $RCSfile: script.tcl,v $
9 #
10 # This file is part of the ASCEND Tcl/Tk Interface.
11 #
12 # Copyright (C) 1994-1998 Carnegie Mellon University
13 #
14 # The ASCEND Tcl/Tk Interface is free software; you can redistribute
15 # it and/or modify it under the terms of the GNU General Public
16 # License as published by the Free Software Foundation; either
17 # version 2 of the License, or (at your option) any later version.
18 #
19 # The ASCEND Tcl/Tk Interface is distributed in hope that it will be
20 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with the program; if not, write to the Free Software
26 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the
27 # file named COPYING. COPYING is found in ../compiler.
28
29 # Module: script.tcl
30 # Tcl version: 7.1 (Tcl/Tk/XF)
31 # Tk version: 3.4
32 # XF version: 2.2
33 #
34
35 # module contents
36 global moduleList
37 global autoLoadList
38 set moduleList(script.tcl) { .script}
39 set autoLoadList(script.tcl) {0}
40
41 # procedures to show toplevel windows
42
43 #----------------------------
44 # procedure to show window ShowWindow.script
45 # proc ShowWindow.script { args}
46 proc ShowWindow.script { args} {
47 # xf ignore me 7
48 global ascScripVect ascGlobalVect env
49
50 StartupSrc.script
51
52 # build widget .script
53 if {"[info procs XFEdit]" != ""} {
54 catch "XFDestroy .script"
55 } {
56 catch "destroy .script"
57 }
58 toplevel .script
59
60 #
61 # Window manager configurations
62 #
63 wm positionfrom .script user
64 wm sizefrom .script user
65 wm iconname .script {Script}
66 wm minsize .script 100 100
67 wm title .script {A4 Script}
68 wm protocol .script WM_DELETE_WINDOW {Script_do_Exit}
69
70 #
71 # Build frame along bottom of script to hold
72 # record button and file name
73 #
74 frame .script.check_frm \
75 -borderwidth {2} \
76 -relief {raised}
77
78 entry .script.check_frm.file_entry \
79 -relief {raised} \
80 -width {24} \
81 -textvariable ascScripVect(filename) \
82 -font $ascScripVect(font) \
83 -state disabled \
84 -exportselection 0
85
86 label .script.check_frm.record_btn \
87 -text { } \
88 -font $ascGlobalVect(font)
89
90 pack append .script.check_frm \
91 .script.check_frm.record_btn {left frame center padx 10 pady 6} \
92 .script.check_frm.file_entry {left frame w pady 5 expand fill}
93
94 #
95 # Build the main frame of the script. This holds the text boxes.
96 #
97 frame .script.main_frm \
98 -borderwidth {0}
99
100 # Build the first script-text-box (script_box_0)
101 build_scriptbox .script.main_frm 0 $ascScripVect(font)
102 pack append .script.main_frm \
103 .script.main_frm.script_box_0 {top frame center expand fill}
104
105 #
106 # Build the menu bar and submenus
107 #
108 menu .script.menubar \
109 -tearoffcommand .SCRIPT.MENUBAR \
110 -tearoff 0
111
112 # The Edit menu.
113 menu .script.menubar.edit \
114 -tearoffcommand .SCRIPT.MENUBAR.EDIT \
115 -tearoff 0
116 .script.menubar.edit add checkbutton \
117 -variable ascScripVect(Record) \
118 -offvalue {0} \
119 -onvalue {1} \
120 -label {Record actions} \
121 -accelerator {Alt-e r} \
122 -underline 0
123 .script.menubar.edit add command \
124 -command {Script_do_SelectAll} \
125 -label {Select all} \
126 -accelerator {Alt-e s} \
127 -underline 0
128 .script.menubar.edit add separator
129 .script.menubar.edit add command \
130 -command {Script_do_RemoveStats} \
131 -accelerator {Alt-e d} \
132 -label {Delete statements} \
133 -underline 0
134 .script.menubar.edit add command \
135 -command Script_do_Cut \
136 -label Cut \
137 -accelerator F2 \
138 -underline -1
139 .script.menubar.edit add command \
140 -command Script_do_Copy \
141 -label Copy \
142 -accelerator F3 \
143 -underline -1
144 .script.menubar.edit add command \
145 -command Script_do_Paste \
146 -label Paste \
147 -accelerator F4 \
148 -underline -1
149
150
151 # The Execute menu.
152 menu .script.menubar.execute \
153 -tearoffcommand .SCRIPT.MENUBAR.EXECUTE \
154 -tearoff 0
155 .script.menubar.execute add command \
156 -command {Script_do_ExecuteStats} \
157 -label {Run statements selected} \
158 -accelerator {F5} \
159 -underline 0
160 .script.menubar.execute add command \
161 -command {Script_do_ExecuteStats 0} \
162 -label {Step through statements selected} \
163 -accelerator {F6} \
164 -underline 0
165
166
167 # The File menu
168 menu .script.menubar.file \
169 -tearoffcommand .SCRIPT.MENUBAR.FILE \
170 -tearoff 0
171 .script.menubar.file add command \
172 -command {Script_do_NewFile} \
173 -accelerator {Alt-f n} \
174 -label {New file} \
175 -underline 0
176 .script.menubar.file add command \
177 -command {Script_do_ReadFile} \
178 -label {Read file...} \
179 -accelerator {Alt-f r} \
180 -underline 0
181 .script.menubar.file add command \
182 -command {Script_do_ReadFile} \
183 -label {Open script file...} \
184 -accelerator {Alt-f o} \
185 -underline 0
186 .script.menubar.file add command \
187 -command {Script_do_Import_File} \
188 -label {Import file...} \
189 -accelerator {Alt-f i} \
190 -underline 0
191 .script.menubar.file add separator
192 .script.menubar.file add command \
193 -command {Script_do_Exit} \
194 -accelerator {Alt-f e} \
195 -underline 0 \
196 -label {Exit ASCEND...}
197 .script.menubar.file add separator
198 .script.menubar.file add command \
199 -command {Script_do_WriteBuf} \
200 -label {Save} \
201 -accelerator {Alt-f s} \
202 -underline 0
203 .script.menubar.file add command \
204 -command {Script_do_WriteBufAs} \
205 -label {Save As...} \
206 -accelerator {Alt-f a} \
207 -underline 5
208 .script.menubar.file add separator
209
210
211 # The Help menu.
212 menu .script.menubar.help \
213 -tearoffcommand .SCRIPT.MENUBAR.HELP \
214 -tearoff 0
215 .script.menubar.help add command \
216 -command {Script_do_Help} \
217 -label {On Script} \
218 -underline 3
219 .script.menubar.help add command \
220 -command {Script_getting_started} \
221 -label {On getting started with ASCEND} \
222 -underline 3
223 .script.menubar.help add command \
224 -command {ascShowInfo 1} \
225 -label {About ASCEND IV} \
226 -underline 3
227
228
229 # The Tools menu.
230 menu .script.menubar.tools \
231 -tearoffcommand .SCRIPT.MENUBAR.TOOLS \
232 -tearoff 0
233 .script.menubar.tools add checkbutton \
234 -variable ascLibrVect(window.open) \
235 -onvalue 1 \
236 -offvalue 0 \
237 -label {Type class library ...} \
238 -accelerator {Alt-t l} \
239 -underline 11
240 .script.menubar.tools add checkbutton \
241 -variable ascBrowVect(window.open) \
242 -onvalue 1 \
243 -offvalue 0 \
244 -accelerator {Alt-t b} \
245 -label {Instance browser ...} \
246 -underline 9
247 .script.menubar.tools add checkbutton \
248 -variable ascProbVect(window.open) \
249 -onvalue 1 \
250 -offvalue 0 \
251 -label {Data probe ...} \
252 -accelerator {Alt-t p} \
253 -underline 5
254 .script.menubar.tools add checkbutton \
255 -variable ascSolvVect(window.open) \
256 -onvalue 1 \
257 -offvalue 0 \
258 -label {Solvers ...} \
259 -accelerator {Alt-t s} \
260 -underline 0
261 .script.menubar.tools add checkbutton \
262 -variable ascDispVect(window.open) \
263 -onvalue 1 \
264 -offvalue 0 \
265 -label {Display slave ...} \
266 -accelerator {Alt-t d} \
267 -underline 0
268 .script.menubar.tools add checkbutton \
269 -variable ascUnitVect(window.open) \
270 -onvalue 1 \
271 -offvalue 0 \
272 -accelerator {Alt-t m} \
273 -label {Measuring units ...} \
274 -underline 0
275 .script.menubar.tools add checkbutton \
276 -variable ascToolVect(window.open) \
277 -onvalue 1 \
278 -offvalue 0 \
279 -label {Toolbox ...} \
280 -accelerator {Alt-t t} \
281 -underline 0
282 .script.menubar.tools add separator
283 .script.menubar.tools add command \
284 -command {NoteBrowse} \
285 -label {Notes on models ...} \
286 -accelerator {Alt-t n} \
287 -underline 0
288 .script.menubar.tools add command \
289 -command {ascconsole_open} \
290 -label {Open console} \
291 -accelerator {Alt-t c} \
292 -underline 5
293 .script.menubar.tools add command \
294 -command {ascplot_open} \
295 -accelerator {Alt-t a} \
296 -label {ASCPLOT ...} \
297 -underline 0
298 .script.menubar.tools add command \
299 -command {Tool_do_UtilBox} \
300 -accelerator {Alt-t u} \
301 -label {System utilities ...} \
302 -underline 7
303 .script.menubar.tools add command \
304 -command {Tool_do_Callbacks} \
305 -accelerator {Alt-t i} \
306 -label {Internal functions ...} \
307 -underline 0
308 .script.menubar.tools add command \
309 -command {Tool_do_Bugs} \
310 -accelerator {Alt-t g} \
311 -label {Report bug ...} \
312 -underline 9
313
314
315 # The options menu.
316 menu .script.menubar.options \
317 -tearoffcommand .SCRIPT.MENUBAR.OPTIONS \
318 -tearoff 0
319 .script.menubar.options add command \
320 -command {View_Save_Values} \
321 -label {Save all options and appearances for all windows} \
322 -accelerator {Alt-o s} \
323 -underline 0
324
325 # The View menu.
326 menu .script.menubar.view \
327 -tearoffcommand .SCRIPT.MENUBAR.VIEW \
328 -tearoff 0
329 .script.menubar.view add command \
330 -command {Script_do_Font} \
331 -label {Font ...} \
332 -accelerator {Alt-v f} \
333 -underline 0
334 .script.menubar.view add command \
335 -command {View_Set_Save_Options script} \
336 -label {Save Script appearance} \
337 -accelerator {Alt-v s} \
338 -underline 0
339 .script.menubar.view add command \
340 -command {Script_do_SaveOptions} \
341 -label {Save all appearances} \
342 -accelerator {Alt-v a} \
343 -underline 5
344
345
346 #
347 # Add the menus as cascades of the toplevel's menu;
348 # add the toplevel's menu to the toplevel
349 #
350 .script.menubar add cascade \
351 -menu .script.menubar.file \
352 -label {File} \
353 -underline 0
354 .script.menubar add cascade \
355 -menu .script.menubar.edit \
356 -label {Edit} \
357 -underline 0
358 .script.menubar add cascade \
359 -menu .script.menubar.execute \
360 -label {Execute} \
361 -underline 1
362 .script.menubar add cascade \
363 -menu .script.menubar.options \
364 -label {Options} \
365 -underline 0
366 .script.menubar add cascade \
367 -menu .script.menubar.view \
368 -label {View} \
369 -underline 0
370 .script.menubar add cascade \
371 -menu .script.menubar.tools \
372 -label {Tools} \
373 -underline 0
374 .script.menubar add cascade \
375 -menu .script.menubar.help \
376 -label {Help} \
377 -underline 0
378 .script configure \
379 -menu .script.menubar
380
381 #
382 # Add the main frame and the bottom frame to the toplevel .script
383 #
384 pack append .script \
385 .script.main_frm {top frame center expand fill} \
386 .script.check_frm {top frame center fillx}
387
388 EndSrc.script
389
390 if {"[info procs XFEdit]" != ""} {
391 catch "XFMiscBindWidgetTree .script"
392 after 2 "catch {XFEditSetShowWindows}"
393 }
394 }
395
396 # proc StartupSrc.script {args}
397 proc StartupSrc.script {args} {
398 # script startup entrance
399 # as much of the C/global dependencies managed here as possible
400 global ascScripVect ascGlobalVect env
401 if {[catch {set ascScripVect(windowname)} ]} {
402 set ascScripVect(minsize) 10x10
403 set ascScripVect(geometry) 37x21+10+10
404 set ascScripVect(iconname) Script
405 set ascScripVect(initialstate) normal
406 set ascScripVect(font) "-*-*"
407 }
408 if {[catch {set ascGlobalVect(font)} ]} {
409 set ascGlobalVect(font) "-*-*"
410 set ascGlobalVect(labelfont) "-*-*"
411 set ascGlobalVect(tbg) "white"
412 set ascGlobalVect(tfg) "black"
413 set ascGlobalVect(bg) "white"
414 set ascGlobalVect(fg) "black"
415 set ascGlobalVect(afg) "white"
416 set ascGlobalVect(abg) "black"
417 set ascGlobalVect(sfg) "white"
418 set ascGlobalVect(sbg) "black"
419 set ascGlobalVect(visibility) 1
420 set ascGlobalVect(c_loaded) "0"
421 set ascGlobalVect(toolbitmap) \
422 "@$env(ASCENDBITMAPS)/toolAttributes.xbm"
423 }
424 }
425
426 # proc EndSrc.script {}
427 proc EndSrc.script {} {
428 # script startup exit
429 global ascScripVect
430 set ascScripVect(geometry) [sanegeometry $ascScripVect(geometry)]
431 set minw [lindex [split $ascScripVect(minsize) x] 0]
432 set minh [lindex [split $ascScripVect(minsize) x] 1]
433 set gw [lindex [split [lindex [split $ascScripVect(geometry) +-] 0] x] 0]
434 set gh [lindex [split [lindex [split $ascScripVect(geometry) +-] 0] x] 1]
435 set gpx [lindex [split [split $ascScripVect(geometry) x] +-] 1]
436 set gpy [lindex [split [split $ascScripVect(geometry) x] +-] 2]
437 if {[expr $gw < $minw]} {set gw $minw}
438 if {[expr $gh < $minh]} {set gh $minh}
439 set gwh "${gw}x${gh}"
440 wm minsize .script $minw $minh
441 wm geometry .script "${gwh}+${gpx}+$gpy"
442 # wm geometry .script [gospos .script $gpx $gpy]
443 wm iconname .script $ascScripVect(iconname)
444
445 if {$ascScripVect(initialstate)!="iconic" && \
446 $ascScripVect(initialstate)!="iconified" && \
447 $ascScripVect(initialstate) !="withdrawn"} {
448 wm deiconify .script
449 }
450 if {"$ascScripVect(initialstate)"=="withdrawn"} {
451 wm withdraw .script
452 }
453
454 }
455
456
457 #
458 # proc build_scriptbox {parentname winnum font}
459 #---------------------------------------------------------------------------
460 # creates a text widget with scrollbars in the context
461 # of parentname, if same does not already exist.
462 # the name of the text widget is
463 # $parentname.script_box_$winnum
464 # returns the name $parentname.script_box_$winnum
465 # The widget with this name has a child named text2.
466 # scrollbars are done with bg/fg colors
467 # text is done with tbg/tfg, sbg/sfg for plain and selected text,
468 # respectively.
469 # if the widget already exists, recolors it from the given input.
470 #---------------------------------------------------------------------------
471 #
472 proc build_scriptbox {parentname winnum font} {
473
474 if {[winfo exists $parentname.script_box_$winnum]} {
475 return $parentname.script_box_$winnum
476 }
477
478 # build widget $parentname.script_box_$winnum
479 frame $parentname.script_box_$winnum \
480 -relief {raised}
481
482 # build widget $parentname.script_box_$winnum.scrollbar1
483 scrollbar $parentname.script_box_$winnum.scrollbar1 \
484 -command "$parentname.script_box_$winnum.text2 yview"
485
486 # build widget $parentname.script_box_$winnum.text2
487 text $parentname.script_box_$winnum.text2 \
488 -exportselection 0 \
489 -borderwidth {2} \
490 -height {2} \
491 -relief {raised} \
492 -setgrid {1} \
493 -width {10} \
494 -wrap {word} \
495 -yscrollcommand "$parentname.script_box_$winnum.scrollbar1 set" \
496 -font $font
497
498 # pack widget $parentname.script_box_$winnum
499 pack append $parentname.script_box_$winnum \
500 $parentname.script_box_$winnum.scrollbar1 {right frame center filly} \
501 $parentname.script_box_$winnum.text2 {top frame center expand fill}
502 catch {emacs-bind $parentname.script_box_$winnum.text2}
503 set w $parentname.script_box_$winnum.text2
504 bind $w <F2> Script_do_Cut
505 bind $w <F3> Script_do_Copy
506 bind $w <F4> Script_do_Paste
507 bind $w <F5> {
508 Script_do_ExecuteStats
509 }
510 bind $w <F6> {
511 Script_do_ExecuteStats 0
512 }
513 $w mark set insert end
514 }
515
516
517 # Internal procedures
518
519 # eof
520 #

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22