File: ts_param.tcl

package info (click to toggle)
ts 9802-1
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,348 kB
  • ctags: 1,468
  • sloc: tcl: 4,567; ansic: 3,389; makefile: 88; sh: 1
file content (435 lines) | stat: -rw-r--r-- 12,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# ts_param.tcl

proc initparams {} {

  set s {
    { Edit  0 {
        {"Intern" "tedit" "%e"}
        {"vi &" "exbg" "xterm -geometry %g -e vi !i+%! %e"}
    } }
    { Compose 0 {
      {"LaTeX" "exwin" "latex %p"}
      {"TeX" "exwin" "tex %p"}
    } }
    { Reference 0 {
      {"Makeindex" "exwin" "makeindex %r.idx"}
    } }
    { View 0 {
      {"Xdvi" "exwin" "xdvi -geometry %g %r" }
      {"Xdvi &" "exbg" "xdvi -geometry %g %r"}
      {"Ghostview" "exwin" "ghostview %r.ps"}
    } }
    { Print 0 {
      {"DVIPS" exwin "dvips -t a4 !l-t landscape! !0-p %! !9-l %! !c-c %! !o-A! !e-B! !x%! %r"}
    } }
    { Graphic 0 {
      {"XFig &" "exbg" "xfig -geometry %g -but_ 3 -me %o.fig"}
    } }
    { Util 0 {
      {"View Logfile" exwin "less %r.log"}
      {"Delete Waste" exwin "rm *.aux *.log *.toc *.ind *.ilg *.bak"}
      {"Shell" exwin "/bin/sh"}
    } }
  }
  return $s
}

proc readparams {} {
  global params ted gparams

  if [catch {set fd [open $params(local_paramfile) r]}] {
    # Check for global options
    if [catch {set fd [open $params(global_paramfile) r]}] {
      # Default values
      set s [initparams]
    } else {
      set s [read $fd]
      close $fd
    }
  } else {
    set s [read $fd]
    close $fd
  }
  set ted(global_params) {}
  foreach l $s {
    set cmd [lindex $l 0]
    if {[lsearch {Edit Compose View Print Reference Graphic Util} $cmd] \
      >= 0} {
      set default [lindex $l 1]
      set params($cmd) [lindex $l 2]
      set params(${cmd}_name) [lindex [lindex $params($cmd) $default] 0]
      set params(${cmd}_default) $default
    } elseif {$cmd == "Options"} {
#     Set default values
      set gparams(hlplan) "eng"
      set gparams(showicons) 1
      set lopt [lindex $l 1]
      foreach par $lopt {
        set p0 [lindex $par 0]
	set p1 [lindex $par 1]
	set gparams($p0) $p1
      }
    }
  }
}

proc writeparams {} {
  global params ted gparams

  set fd [open $params(local_paramfile) w]
  foreach cmd {Edit Compose Reference View Print Util Graphic} {
    puts $fd "\{ $cmd $params(${cmd}_default) \{"
      foreach l $params($cmd) {
        puts $fd "\{$l\}"
      }
    puts $fd "\} \}"
  }
  puts $fd "\{ Options \{"
  foreach l [array names gparams] {
    puts $fd "\{[list $l $gparams($l)]\}"
  }
  puts $fd "\} \}"
  close $fd
}

proc selectparams {cmd} {
  global params pdlg

  proc PSetFields {i} {
    global pdlg

    set pdlg(sel) $i
    set l [lindex $pdlg(cmds) $i] 
    if {[llength $l] > 0} {set pdlg(name) [lindex $l 0]}
    if {[llength $l] > 1} {set pdlg(cmd) [lindex $l 1]}
    if {[llength $l] > 2} {set pdlg(opt) [lindex $l 2]}
  }

  proc PSelect {i} {
    global pdlg

    .pdlg.lb.b activate $i
    .pdlg.lb.b select anchor $i
    .pdlg.lb.b select set anchor $i
    .pdlg.lb.b see $i
    PSetFields $i
  }

  proc PNext {} {
    global pdlg

    incr pdlg(sel)
    if {$pdlg(sel) >= [.pdlg.lb.b size]} {
      set pdlg(sel) [expr [.pdlg.lb.b size] - 1]
    }
    PSelect $pdlg(sel)
  }
  proc PPrev {} {
    global pdlg

    incr pdlg(sel) -1
    if {$pdlg(sel) < 0} {set pdlg(sel) 0}
    PSelect $pdlg(sel)
  }
  
  proc PAdd {{app ins}} {
    global pdlg params

    foreach f [array names pdlg] {
      set p($f) ""
    }
    if {[InpDlg pdlg .idlg "Parameter" $params(dlg_geom) "Add Parameter" {
      {Name char 15 name}
      {"Exec Proc" char 15 cmd}
      {"Options" char 45 opt}
      } p]} {
      set l [list $pdlg(name) $pdlg(cmd) $pdlg(opt)]
      if {$app == "ins"} {
        set i $pdlg(sel)
      } else {
        set i [llength $pdlg(cmds)]
      }
      set pdlg(cmds) \
        [linsert $pdlg(cmds) $i $l]
      .pdlg.lb.b insert $i $pdlg(name)
      update idletasks
      PSelect $i
    }
  }

  proc PEdit {} {
    global pdlg

    debug "Dialog geometry: $pdlg(geom)"
    if {[InpDlg pdlg .idlg "Parameter" $pdlg(geom) "Edit Parameter" {
      {Name char 15 name}
      {"Exec Proc" char 15 cmd}
      {"Options" char 45 opt}
      } pdlg]} {
      set l [list $pdlg(name) $pdlg(cmd) $pdlg(opt)]
      set pdlg(cmds) \
        [lreplace $pdlg(cmds) $pdlg(sel) $pdlg(sel) $l]
        .pdlg.lb.b delete $pdlg(sel)
        .pdlg.lb.b insert $pdlg(sel) $pdlg(name)
      PSelect $pdlg(sel)
    }
  }
  proc PDel {} {
    global pdlg

    if {[Dialog .ddlg $pdlg(geom) "" "Delete entry $pdlg(name)" \
      question 0 1 {Yes <Any-y>} {No <Any-n>}] == 0} {
      debug "PDel"
      set pdlg(cmds) \
        [lreplace $pdlg(cmds) $pdlg(sel) $pdlg(sel)]
      .pdlg.lb.b delete $pdlg(sel)
      PSelect 0
    }
  }
  
  toplevel .pdlg
  wm transient .pdlg .
#  wm overrideredirect .pdlg 1
  wm geometry .pdlg $params(dlg_geom)
  wm title .pdlg "Select Parameter"

  frame .pdlg.b
  pack .pdlg.b -side right
  button .pdlg.b.ok -text "OK" -font 6x13bold -anchor w \
    -command {set pdlg(ok) 1}
  pack .pdlg.b.ok -side top -padx 5 -pady 5 -fill x
  button .pdlg.b.cancel -text "Cancel" -font 6x13bold -anchor w \
    -command {set pdlg(ok) 0}
  pack .pdlg.b.cancel -side top -padx 5 -pady 5 -fill x
  button .pdlg.b.edit -text "Edit" -underline 0 -font 6x13bold -anchor w \
  -command PEdit
  pack .pdlg.b.edit -side top -padx 5 -pady 5 -fill x
  button .pdlg.b.insert -text "Insert" -underline 0 -font 6x13bold \
    -anchor w -command {PAdd ins}
  pack .pdlg.b.insert -side top -padx 5 -pady 5 -fill x
  button .pdlg.b.append -text "Append" -underline 0 -font 6x13bold -anchor w \
    -command {PAdd app}
  pack .pdlg.b.append -side top -padx 5 -pady 5 -fill x
  button .pdlg.b.delete -text "Delete" -underline 0 -font 6x13bold -anchor w \
    -command {PDel}
  pack .pdlg.b.delete -side top -padx 5 -pady 5 -fill x

  label .pdlg.lsel -text "Select $cmd action" -font fixed
  pack .pdlg.lsel -anchor w
  frame .pdlg.lb 
  pack .pdlg.lb
  scrollbar .pdlg.lb.s -command ".pdlg.lb.b yview"
  listbox .pdlg.lb.b -yscroll ".pdlg.lb.s set" -relief sunken -bd 1
  pack .pdlg.lb.b -side left 
  pack .pdlg.lb.s -side right -fill y
  frame .pdlg.name
  pack .pdlg.name -side bottom -before .pdlg.b
  label .pdlg.name.l -text "Name" -width 10
  entry .pdlg.name.e -textvariable pdlg(name) -width 25 -state disabled
  pack .pdlg.name.l .pdlg.name.e -side left -anchor w
  frame .pdlg.cmd
  pack .pdlg.cmd -side bottom -before .pdlg.name
  label .pdlg.cmd.l -text "Exec proc" -width 10
  entry .pdlg.cmd.e -textvariable pdlg(cmd) -width 25 -state disabled
  pack .pdlg.cmd.l .pdlg.cmd.e -side left
  frame .pdlg.opt
  pack .pdlg.opt -side bottom -before .pdlg.cmd
  label .pdlg.opt.l -text "Call options" -width 10
  entry .pdlg.opt.e -textvariable pdlg(opt) -width 25 -state disabled
  pack .pdlg.opt.l .pdlg.opt.e -side left

  set pdlg(cmds) $params($cmd)
  foreach l $pdlg(cmds) {
    .pdlg.lb.b insert end [lindex $l 0]
  }
  set pdlg(sel) $params(${cmd}_default)
  set pdlg(name) $params(${cmd}_name)
  PSetFields $pdlg(sel)
  # Bindings
  bindtags .pdlg.lb.b [list Listbox .pdlg.lb.b]
  bind .pdlg.lb.b <Any-Return> {set pdlg(ok) 1}
  bind .pdlg.lb.b <Escape>  {set pdlg(ok) 0}
  bind .pdlg.lb.b <Any-a>   {PAdd app}
  bind .pdlg.lb.b <Any-i>   {PAdd ins}
  bind .pdlg.lb.b <Any-e>   {PEdit}
  bind .pdlg.lb.b <Any-d>   {PDel}
  bind .pdlg.lb.b <Delete>  {PDel}
  bind .pdlg.lb.b <Down>    {PSetFields [%W index active]}
  bind .pdlg.lb.b <Up>      {PSetFields [%W index active]}
  bind .pdlg.lb.b <1>	    {PSetFields [%W nearest %y]}
  update
  # Compute geometry
  set x [expr [winfo rootx .pdlg]]
  set y [expr [winfo rooty .pdlg] + [winfo height .pdlg] + 5]
  set pdlg(geom) +$x+$y
  debug "Dialog geometry: $pdlg(geom)"
  PSelect $pdlg(sel)
  set old_focus [focus]
  focus .pdlg.lb.b
  grab .pdlg
  tkwait var pdlg(ok)
  grab release .pdlg
  focus $old_focus
  destroy .pdlg
  if {$pdlg(ok)} {
    set params($cmd) $pdlg(cmds)
    set l [lindex $params($cmd) $pdlg(sel)]
    set params(${cmd}_name) [lindex $l 0]
    set params(${cmd}_default) $pdlg(sel)
    if {$cmd == "Util"} {
      utilmenu .menubar.mUtil
    }
  }
  return
}

proc SaCmd {} {
  global adlg params

  set params($adlg(cmd)_default) [.selact index active]
  set l [lindex $params($adlg(cmd)) $params($adlg(cmd)_default)]
  set params($adlg(cmd)_name) [lindex $l 0]

  grab release .selact
  focus $adlg(focus)
  .selact unpost
  destroy .selact
}

proc SelectAction {w cmd} {
  global adlg params

  #if [winfo exists .selact] {destroy .selact}
  set adlg(list) {}
  set adlg(cmd) $cmd
  catch {menu .selact -tearoff 0}
  .selact delete 0 end
  foreach e $params($cmd) {
    lappend adlg(list) [lindex $e 0]
    .selact add command -label [lindex $e 0] -command {SaCmd}
  }
  set x [winfo rootx $w]
  set y [expr [winfo rooty $w] + [winfo height $w]]
  .selact post $x $y
  .selact activate $params(${cmd}_default)
  set adlg(focus) [focus]
  focus .selact
  grab -global .selact
}

proc Options {} {
  global params odlg gparams

  # Set default values
  set odlg(font) fixed
  set odlg(background) #d9d9d9
  set odlg(foreground) #000000
  set odlg(hlplan) "eng"
  foreach l [array names gparams] {
    set odlg($l) $gparams($l)
  }
  set odlg(pos) "+[winfo rootx .]+[winfo rooty .]"
###  regexp {\+[0-9]+\+[0-9]+} [wm geometry .] odlg(pos)

  set hlplan {}
  foreach l [glob $params(hlpdir)/*] {
    lappend hlplan [file tail $l]
  }
  toplevel .odlg
  wm transient .odlg .
  wm geometry .odlg $params(dlg_geom)
  wm title .odlg "Options"
  
  frame .odlg.l -relief raised -bd 1
  pack .odlg.l -fill x -expand 1
  label .odlg.l.title -text "Global settings"
  pack .odlg.l.title

  frame .odlg.t -relief raised -bd 1
  pack .odlg.t -fill x
  label .odlg.t.l -text "TeXShell:" -anchor w
  frame .odlg.t.fpos
  label .odlg.t.lpos -text "Window Position:" -underline 7
  entry .odlg.t.epos -textvariable odlg(pos) -relief sunken -bd 2 \
    -width 10
  pack .odlg.t.lpos .odlg.t.epos -in .odlg.t.fpos -side left
#  checkbutton .odlg.t.out -text "Show Output Window" -underline 5 -anchor w \
#    -variable odlg(out)
  pack .odlg.t.l -padx 10 -pady 5 -fill x
  pack .odlg.t.fpos -fill x
#  pack .odlg.t.out -padx 10 -pady 5 -anchor w

  frame .odlg.h -relief raised -bd 1
  pack .odlg.h -fill x
  label .odlg.h.l -text "Help:" -anchor w
  label .odlg.h.lh -text "Language:" -underline 0 -anchor w
  listbox .odlg.h.lb -height 2
  set i 0
  set k 0
  foreach l $hlplan {
    .odlg.h.lb insert end $l
    if {$l == $odlg(hlplan)} {set k $i}
    incr i
  }
  .odlg.h.lb activate $k
  .odlg.h.lb select anchor $k
  .odlg.h.lb select set anchor $k
  pack .odlg.h.l -padx 10 -pady 5 -fill x -expand 1
  pack .odlg.h.lh -side left -fill x
  pack .odlg.h.lb -fill x
  
  frame .odlg.b -relief raised -bd 1
  pack .odlg.b -fill x -expand 1

  frame .odlg.b.fok -relief sunken -bd 1
  button .odlg.b.ok -text "OK" -command {set odlg(ok) 1}
  button .odlg.b.cancel -text "Cancel" -command {set odlg(ok) 0}
  pack .odlg.b.fok .odlg.b.cancel -side left -padx 10 -pady 5
  pack .odlg.b.ok -padx 5 -pady 5 -in .odlg.b.fok

  foreach w {.odlg.h.lb .odlg.t.epos} {
#    bind $w <Alt-Any-o> {set odlg(out) [expr ! $odlg(out)]}
    bind $w <Alt-Any-w> {set odlg(wrap) [expr ! $odlg(wrap)]}
    bind $w <Alt-Any-s> {set odlg(save) [expr ! $odlg(save)]}
    bind $w <Alt-Any-b> {set odlg(bak) [expr ! $odlg(bak)]}
    bind $w <Alt-Any-f> {OptionsSelFont}
    bind $w <Alt-Any-p> {focus .odlg.t.epos}
    bind $w <Alt-Any-l> {focus .odlg.h.lb}
    bind $w <Alt-Any-g> {OptionsSelColor background}
    bind $w <Alt-Any-r> {OptionsSelColor foreground}
    bind $w <Control-Return> {set odlg(ok) 1}
    bind $w <Escape>         {set odlg(ok) 0}
  }
#  bindtags .odlg.e.int {.odlg.e.int Entry}
#  bindtags .odlg.t.epos {.odlg.t.epos Entry}
  set old_focus [focus]
  focus .odlg
  grab .odlg
  tkwait variable odlg(ok)
  grab release .odlg
  if $odlg(ok) {
    foreach l [array names odlg] {
      set gparams($l) $odlg($l)
    }
    if {$odlg(pos) != ""} {
      set gparams(pos) $odlg(pos)
      wm geometry . $odlg(pos)
      SetPos   
    } else {
      set pos [winfo geometry .]
      if {[regexp {\+[0-9]+\+[0-9]+} $pos pos]} {
        set gparams(pos) $pos
      }
    }
    set gparams(hplan) [lindex $hlplan [.odlg.h.lb index active]]
    .term config -font $odlg(font)
    for {set i 0} {$i < 10} {incr i} {
      if [winfo exists .t$i] {
        .t$i.text config -bg $odlg(background) -fg $odlg(foreground) \
          -font $odlg(font)
      }
    }
  }
  focus $old_focus
  destroy .odlg
}