File: print.tk

package info (click to toggle)
dstooltk 2.0-3
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 2,500 kB
  • ctags: 3,169
  • sloc: ansic: 27,185; tcl: 4,770; makefile: 587; sh: 70; csh: 7
file content (333 lines) | stat: -rw-r--r-- 9,292 bytes parent folder | download | duplicates (2)
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
#
# print.tk
#

proc print(build) {name} {
    global Model
    global Print
    global File

    build_Title $name "Print"

    #
    # Button bar for Print Go command and Dismiss panel.
    #
    build_DismissButtonbar $name dbbar "window(dismiss) print" \
        {"Go..." print(go) } \
	{"Preview..." print(preview) } 

    set cmd [build_CmdFrame $name cmd]

    #
    # Label and Entry widgets for Title, Hor Label and Ver Label.
    # Pop-up selection menu for Hor and Ver Vars.
    # Entry widgets for Hor and Ver max and min range.
    #
    build_LabelEntryColumns $cmd le0 \
        {text   {} {"Title:"} } \
        {lentry {} {Print(Title)}}
    bind_LabelEntryColumns $cmd.le0 1 <Return> print(update)

    set cmdvar [build_StdFrame $cmd cmdvar]

    set cmdvarpop [build_StdFrame $cmdvar popups]

    set varblist [array_to_listvalues Model Varb_Names]
    set parmlist [array_to_listvalues Model Param_Names]
    set funclist [array_to_listvalues Model Funct_Names]

    set Print(Varb_Length) [llength $varblist]
    set Print(Parm_Length) [llength $parmlist]
    set Print(Func_Length) [llength $funclist]

    build_PopupMenu $cmdvarpop hor "Hor:" \
        Print(HorIndex) \
        print(hor) \
        [concat [array_to_listvalues Model Varb_Names] \
                [array_to_listvalues Model Param_Names] \
                [array_to_listvalues Model Funct_Names] ]
    build_PopupMenu $cmdvarpop ver "Ver:" \
        Print(VerIndex) \
        print(ver) \
        [concat [array_to_listvalues Model Varb_Names] \
                [array_to_listvalues Model Param_Names] \
                [array_to_listvalues Model Funct_Names] ]
    pack $cmdvarpop -side left

    print(hor)
    print(ver)

    set cmdvarlab [build_StdFrame $cmdvar labels]
    build_LabelEntryColumns $cmdvarlab le1 \
        {text   {} {"Hor label:"}} \
        {dentry {} {Print(Hor_Label)}} 
    bind_LabelEntryColumns $cmdvarlab.le1 1 <Return> print(update)
    build_LabelEntryColumns $cmdvarlab le2 \
        {text   {} {"Ver label:"}} \
        {dentry {} {Print(Ver_Label)}}
    bind_LabelEntryColumns $cmdvarlab.le2 1 <Return> print(update)
    pack $cmdvarlab -side left
    pack $cmdvar -anchor w

    build_LabelEntryColumns $cmd le3 \
             [list text {} [list "Hor range:" "Ver range:"]] \
             [list dentry {} [list Print(HorMin) Print(VerMin)]] \
             [list dentry {} [list Print(HorMax) Print(VerMax)]]
    bind_LabelEntryColumns $cmd.le3 1 <Return> print(update)
    bind_LabelEntryColumns $cmd.le3 2 <Return> print(update)
  
    #
    # Radio and Entry widgets for Printer, File, Directory.
    #
    set radio [build_StdFrame $cmd radio]

    set choices [build_StdFrame $radio choices]
    build_Choicecols $choices cf1 "" Print(File_Flag) \
	{ "Printer:" \
          "File:"  }
    build_Label $choices dir "Directory:"
    pack $choices -fill x -pady 3 -side left -anchor n

    build_LabelEntryColumns $radio le4 \
        {lentry {} {Print(Printer_Name) \
                    Print(Filename) \
                    Print(Directory)}}
    bind_LabelEntryColumns $radio.le4 1 <Return> print(update)
    pack $radio.le4 -fill x -side left -anchor n

    pack $radio -fill x -side top



    # 
    # Pop-up selection menu for Fonts. 
    # Entry widgets for other font variables. 
    # 
    build_PopupMenu $cmd p1 "Font:" \
            Print(Font) \
            print(noop) \
            { "Times-Roman" \
              "Times-Italic" \
              "Times-Bold" \
              "Times-BoldItalic" \
              "Helvetica" \
              "Helvetica-Oblique" \
              "Helvetica-Bold" \
              "Helvetica-BoldOblique" \
              "Courier" \
              "Courier-Oblique" \
              "Courier-Bold" \
              "Courier-BoldOblique" }

    build_LabelEntryColumns $cmd le1 \
        {text   {} {"Title size (pts):" "Hor tick marks:" \
			"Hor length (pts):" "Hor offset (pts):"} } \
        {ientry {} {Print(Title_Pt) Print(Num_Hor_Ticks) \
			Print(BBox_Hor_Length) Print(BBox_Hor_Offset)} } \
        {text   {} {"Label size (pts):" "Ver tick marks:" \
			"Ver height (pts):" "Ver offset (pts):"} } \
        {ientry {} {Print(Label_Pt) Print(Num_Ver_Ticks) \
		    Print(BBox_Ver_Length) Print(BBox_Ver_Offset)}}

    set Print(DefaultBBoxHorOffset) $Print(BBox_Hor_Offset)


    # 
    # Option buttons for other Page parameters. 
    #
    set opts [build_StdFrame $cmd opts]
    build_Optionscol $opts ol3 print(landscape) \
        {"Landscape mode" Print(Landscape)}
    pack $opts.ol3 -side left

    build_Optionscol $opts ol1 print(noop) \
	{"Use color PostScript" Print(Color_Flag)} \
	{"Use picked colors" Print(Pick_Color)} \
        {"Connect the dots" Print(Connect)} 
    pack $opts.ol1 -side left
     
    build_Optionscol $opts ol2 print(noop) \
        {"Show bounding box" Print(Show_BBox)}  \
        {"Show system info" Print(Show_Info) }
    pack $opts.ol2 -side left
    pack $opts -fill x

    #
    # finish it off!
    #
    pack $cmd -fill both -expand 1
}

proc print(update) {} {
    tcl_to_pm Print
    pm_to_tcl Print
}

proc print(upfile) {} {
    global Print
    global File

    set Print(Filename)  $File(Filename)
    set Print(Directory) $File(Directory)

    tcl_to_pm Print
    pm_to_tcl Print
}

proc print(go) {} {
    global Print

    print(update)
    if {$Print(File_Flag)} {
	begin_wait "Writing postscript file..."
	window(open) filesl
        filesl(init) "Save" \
		     "*" \
                      $Print(Directory)    \
                      $Print(Filename)     \
                     "print(upfile)"       \
                     "pm EXEC Print.Go"  

        #pm EXEC Print.Go
        end_wait
    } else {
	begin_wait "Sending to printer..."
        pm EXEC Print.Go
        end_wait
    }

    #pm EXEC Print.Go
    #end_wait
}

proc print(landscape) {} {
    global Print

    if {$Print(Landscape) == 1} {
      set Print(BBox_Hor_Offset) \
                [expr $Print(BBox_Hor_Offset)+$Print(BBox_Hor_Length)+45]
    } else {
      set Print(BBox_Hor_Offset) $Print(DefaultBBoxHorOffset)
    }
    print(update)
}

proc print(noop) {} {
    global Print
}

proc print(sethtype) {t} {
    global Print

    switch $t {
	Varb  {set Print(HorType) 103}
	Param {set Print(HorType) 104
               set Print(HorIndex) \
                   [ expr $Print(HorIndex)-$Print(Varb_Length)]}
	Funct {set Print(HorType) 105
               set Print(HorIndex) \
                   [ expr $Print(HorIndex)-$Print(Varb_Length) \
                                          -$Print(Parm_Length)]}
    } 
}

proc print(hor) {} {
    global Print
    global Defaults

    
    set nm(hor) [index_to_type $Print(HorIndex) Varb Param Funct]
    set ht [lindex $nm(hor) 0]
    set hn [lindex $nm(hor) 1]

    print(sethtype) $ht

#    set Print(HorMin) $Defaults($ht\_Min,$hn)
#    set Print(HorMax) $Defaults($ht\_Max,$hn)

    set vals [concat [array_to_listvalues Model Varb_Names] \
             [array_to_listvalues Model Param_Names] \
             [array_to_listvalues Model Funct_Names] ]

    set Print(Hor_Label) [lindex $vals $Print(HorIndex)]

    print(update)
}

proc print(setvtype) {t} {
    global Print

    switch $t {
	Varb  {set Print(VerType) 103} 
	Param {set Print(VerType) 104
               set Print(VerIndex) \
                   [ expr $Print(VerIndex)-$Print(Varb_Length)]}
	Funct {set Print(VerType) 105
               set Print(VerIndex) \
                   [ expr $Print(VerIndex)-$Print(Varb_Length) \
                                          -$Print(Parm_Length)]}
    } 
}

proc print(ver) {} {
    global Print
    global Defaults

    set nm(ver) [index_to_type $Print(VerIndex) Varb Param Funct]
    set vt [lindex $nm(ver) 0]
    set vn [lindex $nm(ver) 1]

    print(setvtype) $vt

#    set Print(VerMin) $Defaults($vt\_Min,$vn)
#    set Print(VerMax) $Defaults($vt\_Max,$vn)

    set vals [concat [array_to_listvalues Model Varb_Names] \
             [array_to_listvalues Model Param_Names] \
             [array_to_listvalues Model Funct_Names] ]

    set Print(Ver_Label) [lindex $vals $Print(VerIndex)]

    print(update)
}

proc print(preview) {} {
    global Print EXT
    
    print(update)

    set fpath $Print(Directory)/$Print(Filename)
    set fstat [file isfile $fpath]

    switch $fstat {
        0 { message_show "File $Print(Filename) not found."
            build_Dialog printfail "Print Preview" \
                         "File $Print(Filename) not found." \
                         0 Ok }
        1 { set pid 0
            set pid [eval $EXT(psview)]
#           set pid [exec gs $fpath &] 

            switch $pid {
              default { message_show "File sent to ghostscript." }
              0       { build_Dialog printfail "Print Preview" \
                        "Preview app `gs' not found." \
                        0 Ok 
                        message_show "Print preview failed." }
            } }
    }
}

proc print(updatevars) {n} {
    global Print
    upvar #0 twoD$n nm
 
    set Print(HorIndex) $nm(horindex)
    set Print(VerIndex) $nm(verindex)

    set Print(HorMin) $nm(hormin)
    set Print(HorMax) $nm(hormax)

    set Print(VerMin) $nm(vermin)
    set Print(VerMax) $nm(vermax)
}