tioga 1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/Tioga_README +372 -0
  2. data/lgpl.txt +504 -0
  3. data/split/Dtable/defs.h +33 -0
  4. data/split/Dtable/dtable.c +1928 -0
  5. data/split/Dtable/dtable_intern.h +144 -0
  6. data/split/Dtable/dvector.h +61 -0
  7. data/split/Dtable/extconf.rb +4 -0
  8. data/split/Dtable/include/dtable.h +35 -0
  9. data/split/Dtable/lib/Dtable_extras.rb +90 -0
  10. data/split/Dtable/namespace.h +47 -0
  11. data/split/Dtable/safe_double.h +104 -0
  12. data/split/Dtable/symbols.c +92 -0
  13. data/split/Dtable/symbols.h +52 -0
  14. data/split/Dvector/defs.h +33 -0
  15. data/split/Dvector/dvector.c +5486 -0
  16. data/split/Dvector/dvector_intern.h +142 -0
  17. data/split/Dvector/extconf.rb +4 -0
  18. data/split/Dvector/include/dvector.h +61 -0
  19. data/split/Dvector/lib/Dvector_extras.rb +328 -0
  20. data/split/Dvector/lib/Numeric_extras.rb +134 -0
  21. data/split/Dvector/namespace.h +47 -0
  22. data/split/Dvector/safe_double.h +104 -0
  23. data/split/Dvector/symbols.c +92 -0
  24. data/split/Dvector/symbols.h +52 -0
  25. data/split/Flate/defs.h +33 -0
  26. data/split/Flate/extconf.rb +19 -0
  27. data/split/Flate/flate.c +156 -0
  28. data/split/Flate/flate_intern.h +97 -0
  29. data/split/Flate/include/flate.h +98 -0
  30. data/split/Flate/namespace.h +47 -0
  31. data/split/Flate/safe_double.h +104 -0
  32. data/split/Flate/symbols.c +92 -0
  33. data/split/Flate/symbols.h +52 -0
  34. data/split/Function/defs.h +33 -0
  35. data/split/Function/dvector.h +61 -0
  36. data/split/Function/extconf.rb +4 -0
  37. data/split/Function/function.c +988 -0
  38. data/split/Function/joint_qsort.c +258 -0
  39. data/split/Function/lib/Function_extras.rb +44 -0
  40. data/split/Function/namespace.h +47 -0
  41. data/split/Function/safe_double.h +104 -0
  42. data/split/Function/symbols.c +92 -0
  43. data/split/Function/symbols.h +52 -0
  44. data/split/Tioga/axes.c +774 -0
  45. data/split/Tioga/defs.h +33 -0
  46. data/split/Tioga/dtable.h +35 -0
  47. data/split/Tioga/dvector.h +61 -0
  48. data/split/Tioga/extconf.rb +4 -0
  49. data/split/Tioga/figures.c +672 -0
  50. data/split/Tioga/figures.h +855 -0
  51. data/split/Tioga/flate.h +98 -0
  52. data/split/Tioga/init.c +524 -0
  53. data/split/Tioga/lib/Arcs_and_Circles.rb +64 -0
  54. data/split/Tioga/lib/ColorConstants.rb +274 -0
  55. data/split/Tioga/lib/Colorbars.rb +10 -0
  56. data/split/Tioga/lib/Colormaps.rb +105 -0
  57. data/split/Tioga/lib/Coordinate_Conversions.rb +194 -0
  58. data/split/Tioga/lib/Creating_Paths.rb +94 -0
  59. data/split/Tioga/lib/Doc.rb +91 -0
  60. data/split/Tioga/lib/Executive.rb +515 -0
  61. data/split/Tioga/lib/FigMkr.rb +2224 -0
  62. data/split/Tioga/lib/FigureConstants.rb +125 -0
  63. data/split/Tioga/lib/Figures_and_Plots.rb +268 -0
  64. data/split/Tioga/lib/Images.rb +278 -0
  65. data/split/Tioga/lib/Legends.rb +190 -0
  66. data/split/Tioga/lib/MarkerConstants.rb +122 -0
  67. data/split/Tioga/lib/Markers.rb +129 -0
  68. data/split/Tioga/lib/Page_Frame_Bounds.rb +567 -0
  69. data/split/Tioga/lib/Rectangles.rb +94 -0
  70. data/split/Tioga/lib/Shading.rb +100 -0
  71. data/split/Tioga/lib/Special_Paths.rb +307 -0
  72. data/split/Tioga/lib/Strokes.rb +129 -0
  73. data/split/Tioga/lib/TeX_Text.rb +454 -0
  74. data/split/Tioga/lib/TexPreamble.rb +358 -0
  75. data/split/Tioga/lib/Titles_and_Labels.rb +306 -0
  76. data/split/Tioga/lib/Transparency.rb +89 -0
  77. data/split/Tioga/lib/Using_Paths.rb +164 -0
  78. data/split/Tioga/lib/Utils.rb +74 -0
  79. data/split/Tioga/lib/X_and_Y_Axes.rb +749 -0
  80. data/split/Tioga/lib/irb_tioga.rb +122 -0
  81. data/split/Tioga/lib/tioga.rb +1 -0
  82. data/split/Tioga/lib/tioga_ui.rb +5 -0
  83. data/split/Tioga/lib/tioga_ui_cmds.rb +793 -0
  84. data/split/Tioga/makers.c +989 -0
  85. data/split/Tioga/mk_tioga_sty.rb +53 -0
  86. data/split/Tioga/namespace.h +47 -0
  87. data/split/Tioga/pdf_font_dicts.c +18253 -0
  88. data/split/Tioga/pdfcolor.c +486 -0
  89. data/split/Tioga/pdfcoords.c +505 -0
  90. data/split/Tioga/pdffile.c +342 -0
  91. data/split/Tioga/pdfimage.c +536 -0
  92. data/split/Tioga/pdfpath.c +914 -0
  93. data/split/Tioga/pdfs.h +229 -0
  94. data/split/Tioga/pdftext.c +443 -0
  95. data/split/Tioga/safe_double.h +104 -0
  96. data/split/Tioga/symbols.c +92 -0
  97. data/split/Tioga/symbols.h +52 -0
  98. data/split/Tioga/texout.c +380 -0
  99. data/split/defs.h +33 -0
  100. data/split/extconf.rb +107 -0
  101. data/split/mkmf2.rb +1612 -0
  102. data/split/namespace.h +47 -0
  103. data/split/safe_double.h +104 -0
  104. data/split/scripts/tioga +4 -0
  105. data/split/symbols.c +92 -0
  106. data/split/symbols.h +52 -0
  107. data/tests/dtable_test.data +6 -0
  108. data/tests/dvector_read_test.data +1 -0
  109. data/tests/dvector_test.data +101 -0
  110. data/tests/tc_Dtable.rb +221 -0
  111. data/tests/tc_Dvector.rb +791 -0
  112. data/tests/tc_FMkr.rb +162 -0
  113. data/tests/tc_Flate.rb +45 -0
  114. data/tests/tc_Function.rb +111 -0
  115. data/tests/ts_Tioga.rb +38 -0
  116. metadata +163 -0
@@ -0,0 +1,122 @@
1
+ require "Tioga/tioga_ui_cmds.rb"
2
+
3
+ module Tioga
4
+ module IRB_Tioga
5
+
6
+ $tioga_figure_filename = nil
7
+ $tioga_figure_num = nil
8
+
9
+ def o(filename=nil)
10
+ filename = $tioga_figure_filename if filename == nil
11
+ filename = $tioga_ui.fix_filename(filename)
12
+ result = $tioga_ui.setdir_and_load(filename)
13
+ return false if result == nil
14
+ $tioga_figure_filename = result
15
+ $tioga_figure_num = 0
16
+ return true
17
+ end
18
+
19
+ def do_figs(fignums,view)
20
+ if fignums.kind_of?String
21
+ fignums = $tioga_ui.parse_figs(fignums)
22
+ end
23
+ if fignums == nil
24
+ $tioga_ui.make_all_pdfs(view)
25
+ elsif fignums.kind_of?Integer
26
+ fignums += FigureMaker.default.num_figures if fignums < 0
27
+ $tioga_ui.do_fignums([fignums],view)
28
+ else
29
+ $tioga_ui.do_fignums(fignums,view)
30
+ end
31
+ set_figure_num(fignums[-1]) unless fignums == nil
32
+ return true
33
+ end
34
+
35
+ def s(fignums=nil)
36
+ do_figs(fignums,true)
37
+ return true
38
+ end
39
+
40
+ def m(fignums=nil)
41
+ do_figs(fignums,false)
42
+ return true
43
+ end
44
+
45
+ def set_figure_num(num)
46
+ num = FigureMaker.default.figure_names.index(num) unless num == nil || num.kind_of?(Integer)
47
+ $tioga_figure_num = num
48
+ end
49
+
50
+ def p(fignums=nil)
51
+ if fignums.kind_of?String
52
+ fignums = $tioga_ui.parse_figs(fignums)
53
+ end
54
+ if fignums == nil
55
+ $tioga_ui.make_portfolio(true)
56
+ elsif fignums.kind_of?Integer
57
+ fignums += FigureMaker.default.num_figures if fignums < 0
58
+ $tioga_ui.make_portfolio(true,[fignums])
59
+ else
60
+ $tioga_ui.make_portfolio(true,fignums)
61
+ end
62
+ set_figure_num(fignums[-1]) unless fignums == nil
63
+ return true
64
+ end
65
+
66
+ def r
67
+ if $tioga_figure_num != nil
68
+ figname = FigureMaker.default.figure_names[$tioga_figure_num]
69
+ else
70
+ figname = nil
71
+ end
72
+ o(nil)
73
+ if figname != nil
74
+ num = FigureMaker.default.figure_names.index(figname)
75
+ if num != nil
76
+ s(num)
77
+ end
78
+ end
79
+ end
80
+
81
+
82
+ def l
83
+ $tioga_ui.list_figures
84
+ return true
85
+ end
86
+
87
+ def h
88
+ puts ''
89
+ puts " Command description"
90
+ puts " o 'filename' open tioga file (with extension .rb)."
91
+ puts " l output a list of the defined figures by number and name."
92
+ puts " m <figs> make PDFs without showing them in the viewer."
93
+ puts " s <figs> make and show PDFs, each in a separate viewer window."
94
+ puts " p <figs> make PDFs and show the portfolio as a multi-page document."
95
+ puts " r reloads the current tioga file and reshows the current figure."
96
+ puts " h helpfully print this list of commands."
97
+ puts "\n Since the filename extension is known, you can skip typing it if you like."
98
+ puts "\n If <figs> is omitted, then tioga does all the figures defined in the file"
99
+ puts " ordered by their definition index numbers."
100
+ puts "\n Otherwise, <figs> must be either"
101
+ puts " a valid ruby array index number for a figure (can be negative), or"
102
+ puts " an array of index numbers for a set of figures, or"
103
+ puts " a string with a space-less, comma-separated list of figure indices and ranges, or"
104
+ puts " a string giving a defined figure name (as supplied to def_figure in the tioga file)."
105
+ puts ''
106
+ puts " For example, s 'Plot1' makes and shows the pdf for the figure named Plot1,"
107
+ puts " and p '5,0..3,-1' makes a portfolio with the figure having index 5 on page 1,"
108
+ puts " followed by pages showing the figures with indices 0, 1, 2, 3, and -1."
109
+ puts "\n The viewer for showing PDFs is specified by the $pdf_viewer variable."
110
+ puts " The default value can be set by creating a .tiogainit file in your home directory."
111
+ puts " Your current setting for $pdf_viewer is " + $pdf_viewer + '.'
112
+ puts " To change it, edit ~/.tiogainit to add the line $pdf_viewer = 'my viewer command'."
113
+ puts " The command tioga uses to show a pdf is $pdf_viewer + ' ' + full_PDF_filename."
114
+ puts ''
115
+
116
+ return true
117
+ end
118
+
119
+ end # module IRB_Tioga
120
+ end # module Tioga
121
+
122
+ $tioga_ui = TiogaUI.new([],true)
@@ -0,0 +1 @@
1
+ require 'Tioga/FigureMaker'
@@ -0,0 +1,5 @@
1
+
2
+ require 'Tioga/tioga_ui_cmds.rb'
3
+
4
+ TiogaUI.new(ARGV)
5
+
@@ -0,0 +1,793 @@
1
+
2
+ =begin
3
+ Copyright (C) 2007 Bill Paxton
4
+
5
+ This file is part of Tioga.
6
+
7
+ Tioga is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Library Public License as published
9
+ by the Free Software Foundation; either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Tioga is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU Library General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Library General Public License
18
+ along with Tioga; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ =end
21
+
22
+ require 'Tioga/tioga.rb'
23
+ require "rbconfig.rb"
24
+ include Config
25
+
26
+ include Tioga
27
+ include FigureConstants
28
+
29
+ class TiogaUI
30
+
31
+ def fm
32
+ FigureMaker.default
33
+ end
34
+
35
+
36
+ def append_to_log(str)
37
+ if @no_Tk
38
+ puts str
39
+ return
40
+ end
41
+ return if @logText == nil
42
+ return unless str.kind_of?String
43
+ @logText.insert('end', str + "\n")
44
+ @logText.see('end')
45
+ end
46
+
47
+
48
+ def check_have_loaded
49
+ return true if @have_loaded
50
+ append_to_log "Must open a file first!"
51
+ return false
52
+ end
53
+
54
+
55
+ def report_number_and_name(num,name)
56
+ if num < 10
57
+ puts ' ' + num.to_s + ' ' + name
58
+ elsif num < 100
59
+ puts ' ' + num.to_s + ' ' + name
60
+ else
61
+ puts num.to_s + ' ' + name
62
+ end
63
+ end
64
+
65
+
66
+ def make_all_pdfs(view = true, fignums = nil)
67
+ return unless check_have_loaded
68
+ fm.make_all(fignums,false)
69
+ if view == false
70
+ if fignums == nil
71
+ fm.figure_pdfs.each_with_index { |name,num| report_number_and_name(num,name) }
72
+ else
73
+ fignums.each { |num| report_number_and_name(num,fm.figure_pdfs[num]) }
74
+ end
75
+ return
76
+ end
77
+ if fignums == nil
78
+ fm.num_figures.times { |i| view_pdf(fm.figure_pdfs[i]) }
79
+ else
80
+ fignums.each { |i| view_pdf(fm.figure_pdfs[i]) }
81
+ end
82
+ end
83
+
84
+
85
+ def make_portfolio(view = true, fignums = nil)
86
+ return unless check_have_loaded
87
+ name = @title_name + '_portfolio'
88
+ make_all_pdfs(false,fignums)
89
+ portfolio_name = fm.make_portfolio(name,fignums)
90
+ return unless view
91
+ view_pdf(portfolio_name)
92
+ return if @no_Tk
93
+ return unless $mac_command_key
94
+ append_to_log "\nNote: Preview fails to make updated thumbnails after a Revert for a portfolio,"
95
+ append_to_log "so for now you'll have to Close and redo Open as a workaround.\n"
96
+ end
97
+
98
+
99
+ def require_pdf(arg) # num is either figure number or name
100
+ begin
101
+ num = arg
102
+ num = fm.figure_names.index(num) unless num == nil || num.kind_of?(Integer)
103
+ if fm.num_figures == 0
104
+ puts "\nCan't build pdf because failed to define any figures."
105
+ puts ''
106
+ raise
107
+ end
108
+ if num == nil || num < 0 || num >= fm.num_figures
109
+ puts "\n" + arg.to_s + ' is an invalid figure specification.'
110
+ puts ''
111
+ raise
112
+ end
113
+ result = fm.require_pdf(num)
114
+ if result == nil
115
+ puts "\nFailed during attempt to create pdf file."
116
+ puts ''
117
+ raise
118
+ end
119
+ #append_to_log result + "\n"
120
+ return result
121
+ end
122
+ end
123
+
124
+
125
+ def view_pdf(pdf_file)
126
+ if pdf_file == nil || pdf_file == false
127
+ puts "\nERROR: invalid pdf file."
128
+ puts ''
129
+ raise
130
+ end
131
+ system($pdf_viewer + ' ' + pdf_file + ' > /dev/null')
132
+ append_to_log pdf_file
133
+ end
134
+
135
+
136
+ def loadfile(fname,reselect=true)
137
+ @have_loaded = false
138
+ fm.reset_state
139
+ begin
140
+
141
+ append_to_log "loading #{fname}\n"
142
+ load(fname) # this should define the TiogaFigures class
143
+ num_fig = fm.num_figures
144
+ if num_fig == 0
145
+ raise "Failed to define any figures. ' +
146
+ 'Remember to invoke 'new' for the class containing the figure definitions"
147
+ end
148
+
149
+ @title_name = fname.split('/')[-1]
150
+ @title_name = @title_name[0..-4] if @title_name[-3..-1] == ".rb"
151
+ fname = fname[0..-4] if fname[-3..-1] == ".rb"
152
+ @pdf_name = fname + ".pdf"
153
+ @have_loaded = true
154
+
155
+ return if @no_Tk
156
+
157
+ @root.title('Tioga:' + @title_name)
158
+ @listBox.delete(0, 'end')
159
+ fm.figure_names.each { |name| @listBox.insert('end', name) }
160
+ set_selection(0) if reselect
161
+
162
+ rescue Exception => er
163
+ report_error(er, "ERROR: load failed for #{fname}\n")
164
+ end
165
+ end
166
+
167
+
168
+ def set_working_dir(filename)
169
+
170
+ return filename unless $change_working_directory
171
+
172
+ # if necessary, add the current directory to the front of the filename
173
+ filename = Dir.getwd + '/' + filename if filename[0..0] != '/'
174
+
175
+ parts = filename.split('/')
176
+ if parts[-1].length < 2 || parts[-1][-2..-1] != "rb"
177
+ append_to_log "ERROR: filename must have extension 'rb' instead has <" + parts[-1][-2..-1] + ">"
178
+ return nil
179
+ end
180
+ dir = ""
181
+ parts[0..-2].each {|part| dir << '/' + part unless part.length == 0 }
182
+
183
+ if dir != Dir.getwd
184
+ append_to_log "changing working directory to " + dir
185
+ Dir.chdir(dir) # change current working directory
186
+ end
187
+
188
+ return filename
189
+
190
+ end
191
+
192
+
193
+ def show_help(filename,opt1)
194
+ unless opt1 == '-help' || filename == '-help' || filename == nil
195
+ puts 'Sorry: ' + opt1 + ' is not a recognized option.'
196
+ end
197
+ puts "\nThis program is a command line interface for the open-source tioga kernel."
198
+ puts "The tioga kernel is for creating figures and plots using Ruby, PDF, and TeX."
199
+ puts "Following is a brief description of the tioga command line options."
200
+ puts "For more information, visit http://theory.kitp.ucsb.edu/~paxton/tioga.html."
201
+ puts "\nBefore any command line information is processed, tioga runs ~/.tiogainit if it exists."
202
+ puts " The primary use of this file is to set your default pdf viewer command (see below)."
203
+ puts "\nIf there are no command line arguments, or the argument is -h, this help info is output."
204
+ puts "\nOtherwise, the command line should start with a tioga file name (with extension .rb)."
205
+ puts " Since the extension is known, you can skip typing it if you like."
206
+ puts "\nThe remainder of the command line should consist of an optional series of control commands"
207
+ puts " followed by a figure command."
208
+ puts "\nAny control commands are done after ~/.tiogainit and before the figure file is loaded."
209
+ puts " -r file runs the file (using Ruby's require method)."
210
+ puts ' -C dir changes the working directory.'
211
+ puts ' If there is no -C command, tioga changes the working directory to the'
212
+ puts ' location of the figure file .'
213
+ puts ' -v prints version information.'
214
+ puts "\nThe figure command comes last and should be one of these:"
215
+ puts " -l output a list of the defined figures by number and name."
216
+ puts " -<num> make and show figure with index equal <num> (0 <= num < num_figures)."
217
+ puts " -m <figs> make PDFs without showing them in the viewer."
218
+ puts " -s <figs> make and show PDFs, each in a separate viewer window."
219
+ puts " -p <figs> make PDFs and show the portfolio as a multi-page document."
220
+ puts "\nIf the figure command is omitted, then it defaults to -0."
221
+ puts "\nIf <figs> is omitted, then tioga does all the figures defined in the file"
222
+ puts " ordered by their definition index numbers."
223
+ puts "\nOtherwise, <figs> must be either"
224
+ puts " a defined figure name (as supplied to def_figure in the tioga file), or"
225
+ puts " a valid ruby array index number for a figure (can be negative), or"
226
+ puts " a valid ruby range specification selecting a sequence of figures, or"
227
+ puts " a space-less, comma-separated list of figure indices and ranges."
228
+ puts ''
229
+ puts " For example, -s Plot1 makes and shows the pdf for the figure named Plot1,"
230
+ puts " and -p 5,0..3,-1 makes a portfolio with the figure having index 5 on page 1,"
231
+ puts " followed by pages showing the figures with indices 0, 1, 2, 3, and -1."
232
+ puts "\nThe viewer for showing PDFs is specified by the $pdf_viewer variable in tioga."
233
+ puts " The default value can be set by creating a .tiogainit file in your home directory."
234
+ puts " The .tiogainit file is run before any command line options are processed."
235
+ puts " Your current setting for $pdf_viewer is " + $pdf_viewer + '.'
236
+ puts " To change it, edit ~/.tiogainit to add the line $pdf_viewer = 'my viewer command'."
237
+ puts " The command tioga uses to show a pdf is $pdf_viewer + ' ' + full_PDF_filename."
238
+ puts " You can use the -e control command to try a different viewer setting"
239
+ puts " by doing the $pdf_viewer assignment from the command line."
240
+ puts ''
241
+ end
242
+
243
+
244
+ def report_error(er, msg)
245
+ if msg != nil
246
+ append_to_log msg
247
+ append_to_log ""
248
+ end
249
+ append_to_log " " + "#{er.message}" + " [version: " + FigureMaker.version + "]"
250
+ line_count = 0
251
+ show_count = 0
252
+ past_callers_routines = false
253
+ in_callers_routines = false
254
+ er.backtrace.each do |line|
255
+ if (line.include?('Tioga/FigMkr.rb')) || (line.include?('Tioga/tioga_ui.rb'))
256
+ if in_callers_routines
257
+ past_callers_routines = true
258
+ in_callers_routines = false
259
+ end
260
+ else
261
+ in_callers_routines = true
262
+ end
263
+ if (show_count < fm.num_error_lines) and in_callers_routines
264
+ append_to_log " " + line
265
+ show_count = show_count + 1
266
+ end
267
+ line_count = line_count + 1
268
+ end
269
+ end
270
+
271
+
272
+ def setdir_and_load(filename)
273
+ filename = set_working_dir(filename)
274
+ return nil if filename == nil
275
+ loadfile(filename)
276
+ return filename
277
+ end
278
+
279
+
280
+ def parse_figs(figs)
281
+ return [0] if (figs == nil) || (figs.length == 0)
282
+ return figs unless (/^\d/ === figs) || (/^-\d/ === figs)
283
+ ranges = figs.split(',')
284
+ fignums = Array.new(fm.num_figures) {|i| i}
285
+ result = []
286
+ ranges.each do |r|
287
+ nums = eval('fignums[' + r + ']') # do it this way in case r is negative
288
+ if nums.kind_of?Integer
289
+ result << nums
290
+ else
291
+ nums.each {|n| result << n}
292
+ end
293
+ end
294
+ return result
295
+ end
296
+
297
+
298
+ def show_version
299
+ puts FigureMaker.version
300
+ end
301
+
302
+
303
+ def setup(args)
304
+
305
+ # set the standard defaults
306
+ $tioga_args = Array.new(args.length) {|i| args[i]} # copy the args
307
+ $change_working_directory = true
308
+ if Config::CONFIG["target"] =~ /darwin/i
309
+ $pdf_viewer = "repreview"
310
+ #$mac_command_key = true
311
+ else
312
+ $pdf_viewer = "xpdf"
313
+ #$mac_command_key = false
314
+ end
315
+
316
+ =begin
317
+ # Ruby/Tk defaults
318
+ $geometry = '600x250+700+50'
319
+ $background = 'WhiteSmoke'
320
+ $mac_command_key = false
321
+ $log_font = 'system 12'
322
+ $figures_font = 'system 12'
323
+ =end
324
+
325
+ tiogainit_name = ENV['HOME'] + '/.tiogainit'
326
+ if File.exist?(tiogainit_name)
327
+ load(tiogainit_name)
328
+ end
329
+
330
+ @pdf_name = nil
331
+ @have_loaded = false
332
+ @no_Tk = true
333
+
334
+ end
335
+
336
+
337
+ def fix_filename(filename)
338
+ if filename != nil && filename[-3..-1] != '.rb' &&
339
+ filename[-3..-1] != '.RB' && filename != '-help' && filename != '-v'
340
+ filename += '.rb'
341
+ end
342
+ return filename
343
+ end
344
+
345
+
346
+ def do_fignums(fignums,view)
347
+ fignums.each do |n|
348
+ pdf_name = require_pdf(n)
349
+ if view
350
+ view_pdf(pdf_name)
351
+ else
352
+ report_number_and_name(n,pdf_name)
353
+ end
354
+ end
355
+ end
356
+
357
+
358
+ def list_figures
359
+ fm.figure_names.each_with_index do |name,i|
360
+ puts sprintf("%3i %s\n",i,name)
361
+ end
362
+ end
363
+
364
+
365
+ def initialize(args, just_setup=false)
366
+
367
+ setup(args)
368
+
369
+ return if just_setup
370
+
371
+ if ($tioga_args.length == 0) || ($tioga_args[0] == '-h') || ($tioga_args[0] == '-help')
372
+ show_help(nil,nil)
373
+ return
374
+ end
375
+
376
+ if ($tioga_args[0] == '-v') || ($tioga_args[0] == '-version') || ($tioga_args[0] == '-V')
377
+ show_version
378
+ return
379
+ end
380
+
381
+ if $tioga_args.length > 0
382
+ filename = fix_filename($tioga_args[0])
383
+ end
384
+
385
+ begin
386
+ # currently, we are only supporting command line interface.
387
+ # the code for making a Ruby/Tk interface can be enabled if you want to play with it.
388
+
389
+ argnum = 1 # the filename is in $tioga_args[0]
390
+
391
+ # do control commands
392
+ while argnum < $tioga_args.length
393
+ cmd = $tioga_args[argnum]
394
+ argnum = argnum + 1
395
+ if cmd == '-r'
396
+ puts 'require ' + $tioga_args[argnum]
397
+ require $tioga_args[argnum]
398
+ argnum = argnum + 1
399
+ elsif cmd == '-C'
400
+ puts 'chdir to ' + $tioga_args[argnum]
401
+ Dir.chdir($tioga_args[argnum])
402
+ $change_working_directory = false
403
+ argnum = argnum + 1
404
+ elsif cmd == '-v'
405
+ show_version
406
+ else
407
+ argnum = argnum - 1 # backup
408
+ break
409
+ end
410
+ end
411
+
412
+ setdir_and_load(filename)
413
+
414
+ # do the figure command
415
+
416
+ if argnum == $tioga_args.length
417
+ view_pdf(require_pdf(0))
418
+ return
419
+ end
420
+
421
+ cmd = $tioga_args[argnum]
422
+ argnum = argnum + 1
423
+
424
+ if /^-\d+$/ === cmd
425
+ view_pdf(require_pdf(cmd[1..-1].to_i))
426
+ elsif cmd == '-l'
427
+ list_figures
428
+ elsif cmd == '-h' || cmd == '-help'
429
+ show_help(nil,nil)
430
+ elsif (cmd == '-s' || cmd == '-m')
431
+ if argnum == $tioga_args.length
432
+ make_all_pdfs(cmd != '-m')
433
+ return
434
+ end
435
+ do_fignums(parse_figs($tioga_args[argnum]),cmd == '-s')
436
+ elsif cmd == '-p'
437
+ if argnum == $tioga_args.length
438
+ make_portfolio(true)
439
+ return
440
+ end
441
+ make_portfolio(true, parse_figs($tioga_args[argnum]))
442
+ else # unrecognized command
443
+ show_help(filename,cmd)
444
+ end
445
+ rescue
446
+ end
447
+
448
+ end
449
+
450
+ =begin
451
+
452
+ def start_Tk
453
+ # Ruby/Tk
454
+
455
+ @no_Tk = false
456
+
457
+ @history = [ ]
458
+ resetHistory
459
+
460
+ @accel_key = ($mac_command_key)? 'Cmd' : 'Ctrl'
461
+ @bind_key = ($mac_command_key)? 'Command' : 'Control'
462
+
463
+ require 'tk'
464
+
465
+ @root = TkRoot.new {
466
+ geometry $geometry
467
+ background $background
468
+ pady 2
469
+ }
470
+
471
+ createMenubar(@root)
472
+ contentFrame = TkFrame.new(@root) { background 'WhiteSmoke' }
473
+ createFigureList(contentFrame)
474
+ createLogText(contentFrame)
475
+ contentFrame.pack('side' => 'top', 'fill' => 'both', 'expand' => true)
476
+ createEvalField(@root)
477
+ @root.bind('Key-Up', proc { prev_in_list })
478
+ @root.bind('Key-Down', proc { next_in_list })
479
+ @root.bind('Key-Left', proc { back })
480
+ @root.bind('Key-Right', proc { forward })
481
+
482
+ loadfile unless filename == nil
483
+ Tk.mainloop(false)
484
+ end
485
+
486
+
487
+ def figureSelected
488
+ preview(@listBox.curselection[0])
489
+ end
490
+
491
+
492
+ def preview(num)
493
+ result = require_pdf(num)
494
+ return result if $pdf_viewer == nil
495
+ syscmd = "cp " + result + " " + @pdf_name
496
+ system(syscmd)
497
+ saveInHistory(num)
498
+ return view_pdf(@pdf_name)
499
+ end
500
+
501
+
502
+ def show_in_own_window
503
+ view_pdf(fm.figure_pdfs[@listBox.curselection[0]])
504
+ end
505
+
506
+
507
+ def set_selection(num)
508
+ @listBox.see(num)
509
+ @listBox.selection_clear(0,'end')
510
+ @listBox.selection_set(num)
511
+ figureSelected
512
+ end
513
+
514
+
515
+ def reload
516
+ return unless check_have_loaded
517
+ selection = @listBox.curselection[0]
518
+ name = (selection.kind_of?(Integer))? fm.figure_names[selection] : nil
519
+ loadfile(false)
520
+ num = fm.figure_names.index(name)
521
+ unless num.kind_of?(Integer)
522
+ reset_history
523
+ num = 0
524
+ end
525
+ set_selection(num)
526
+ end
527
+
528
+
529
+ def next_in_list
530
+ return unless check_have_loaded
531
+ num = @listBox.curselection[0] + 1
532
+ num = 0 if num >= @listBox.size
533
+ set_selection(num)
534
+ end
535
+
536
+
537
+ def prev_in_list
538
+ return unless check_have_loaded
539
+ num = @listBox.curselection[0] - 1
540
+ num = @listBox.size - 1 if num < 0
541
+ set_selection(num)
542
+ end
543
+
544
+
545
+ def resetHistory
546
+ @history_loc = -1
547
+ @history_len = 0
548
+ @forward_back = false
549
+ end
550
+
551
+
552
+ def saveInHistory(num)
553
+ if @forward_back
554
+ forward_back = false
555
+ return
556
+ end
557
+ return if (@history_len > 0 && @history_loc >= 0 && @history[@history_loc] == num)
558
+ @history_len = @history_loc + 2
559
+ @history_loc = @history_len - 1
560
+ @history[@history_loc] = num
561
+ end
562
+
563
+
564
+ def back
565
+ return if (@history_loc <= 0 || @history_len == 0)
566
+ @history_loc = @history_loc - 1
567
+ @forward_back = true
568
+ set_selection(@history[@history_loc])
569
+ end
570
+
571
+
572
+ def forward
573
+ return if (@history_loc + 1 >= @history_len)
574
+ @history_loc = @history_loc + 1
575
+ @forward_back = true
576
+ set_selection(@history[@history_loc])
577
+ end
578
+
579
+
580
+ def eval
581
+ begin
582
+ str = @evalEntry.get
583
+ append_to_log "eval " + str
584
+ result = fm.eval_function(str)
585
+ append_to_log result.to_s + "\n"
586
+ rescue Exception => er
587
+ report_error(er, "ERROR: eval failed for #{str}\n")
588
+ end
589
+ end
590
+
591
+
592
+ def openDocument
593
+ filetypes = [["Ruby Files", "*.rb"]]
594
+ filename = Tk.getOpenFile('filetypes' => filetypes,
595
+ 'parent' => @root)
596
+ return unless (filename.kind_of?String) && (filename.length > 0)
597
+ set_working_dir(filename)
598
+ loadfile
599
+ end
600
+
601
+
602
+ def addFileMenu(menubar)
603
+ fileMenuButton = TkMenubutton.new(menubar,
604
+ 'text' => 'File',
605
+ 'background' => 'WhiteSmoke',
606
+ 'underline' => 0)
607
+ fileMenu = TkMenu.new(fileMenuButton, 'tearoff' => false)
608
+
609
+ fileMenu.add('command',
610
+ 'label' => 'Open',
611
+ 'command' => proc { openDocument },
612
+ 'underline' => 0,
613
+ 'accel' => @accel_key + '+O')
614
+ @root.bind(@bind_key + '-o', proc { openDocument })
615
+
616
+
617
+ fileMenu.add('command',
618
+ 'label' => 'Reload',
619
+ 'command' => proc { reload },
620
+ 'underline' => 0,
621
+ 'accel' => @accel_key + '+R')
622
+ @root.bind(@bind_key + '-r', proc { reload })
623
+
624
+ fileMenuButton.menu(fileMenu)
625
+ fileMenuButton.pack('side' => 'left')
626
+ end
627
+
628
+
629
+ def addToolsMenu(menubar)
630
+ toolsMenuButton = TkMenubutton.new(menubar,
631
+ 'text' => 'Tools',
632
+ 'background' => 'WhiteSmoke',
633
+ 'underline' => 0)
634
+ toolsMenu = TkMenu.new(toolsMenuButton, 'tearoff' => false)
635
+
636
+ acc = ($mac_osx)
637
+
638
+ toolsMenu.add('command',
639
+ 'label' => 'Portfolio PDF',
640
+ 'command' => proc { make_portfolio },
641
+ 'underline' => 0,
642
+ 'accel' => @accel_key + '+P')
643
+ @root.bind(@bind_key + '-p', proc { make_portfolio })
644
+
645
+ toolsMenu.add('command',
646
+ 'label' => 'Make All PDFs',
647
+ 'command' => proc { make_all_pdfs },
648
+ 'underline' => 0,
649
+ 'accel' => @accel_key + '+M')
650
+ @root.bind(@bind_key + '-m', proc { make_all_pdfs })
651
+
652
+ toolsMenu.add('command',
653
+ 'label' => 'Show in Own Window',
654
+ 'command' => proc { show_in_own_window },
655
+ 'underline' => 0,
656
+ 'accel' => @accel_key + '+S')
657
+ @root.bind(@bind_key + '-s', proc { show_in_own_window })
658
+
659
+ toolsMenuButton.menu(toolsMenu)
660
+ toolsMenuButton.pack('side' => 'left')
661
+ end
662
+
663
+
664
+ def addTiogaMenu(menubar)
665
+ tiogaMenuButton = TkMenubutton.new(menubar,
666
+ 'text' => 'Tioga',
667
+ 'background' => 'WhiteSmoke',
668
+ 'underline' => 0)
669
+ tiogaMenu = TkMenu.new(tiogaMenuButton, 'tearoff' => false)
670
+
671
+ tiogaMenu.add('command',
672
+ 'label' => 'About Tioga',
673
+ 'command' => proc { showAboutBox },
674
+ 'underline' => 0)
675
+
676
+ tiogaMenu.add('separator')
677
+
678
+ tiogaMenu.add('command',
679
+ 'label' => 'Quit',
680
+ 'command' => proc { exit },
681
+ 'underline' => 0,
682
+ 'accel' => @accel_key + '+Q')
683
+ @root.bind(@bind_key + '-q', proc { exit })
684
+
685
+ tiogaMenuButton.menu(tiogaMenu)
686
+ tiogaMenuButton.pack('side' => 'left')
687
+ end
688
+
689
+
690
+ def showAboutBox
691
+ Tk.messageBox('icon' => 'info', 'type' => 'ok',
692
+ 'title' => 'About Tioga-Point-and-Click',
693
+ 'parent' => @root,
694
+ 'message' => "Tioga-Point-and-Click is a Ruby/Tk Application.\n" +
695
+ "It uses the Tioga kernel to create PDFs and then calls your favorite viewer to show them.\n\n" +
696
+ "Version 0.1 -- January, 2007\n\n" +
697
+ "Visit http://theory.kitp.ucsb.edu/~paxton/tioga.html")
698
+ end
699
+
700
+
701
+ def createMenubar(parent)
702
+ menubar = TkFrame.new(parent) { background 'WhiteSmoke' }
703
+
704
+ addTiogaMenu(menubar)
705
+ addFileMenu(menubar)
706
+ addToolsMenu(menubar)
707
+
708
+ menubar.pack('side' => 'top', 'fill' => 'x', 'padx' => 8, 'pady' => 8)
709
+ end
710
+
711
+
712
+ def createLogText(parent)
713
+
714
+ logFrame = TkFrame.new(parent) { background 'WhiteSmoke' }
715
+
716
+ logText = TkText.new(logFrame) {
717
+ borderwidth 0
718
+ selectborderwidth 0
719
+ height 6
720
+ font $log_font
721
+ }
722
+
723
+ scrollBar = TkScrollbar.new(logFrame) { command proc { |*args| logText.yview(*args) } }
724
+ logText.yscrollcommand(proc { |first, last| scrollBar.set(first, last) })
725
+
726
+ scrollBar.pack('side' => 'right', 'fill' => 'y', 'pady' => 3)
727
+ logText.pack('side' => 'right', 'fill' => 'both', 'expand' => true, 'pady' => 2)
728
+
729
+ logFrame.pack('side' => 'right', 'fill' => 'both', 'expand' => true)
730
+
731
+ @logText = logText
732
+ end
733
+
734
+
735
+ def createFigureList(parent)
736
+
737
+ listFrame = TkFrame.new(parent) { background 'WhiteSmoke' }
738
+ listBox = TkListbox.new(listFrame) {
739
+ selectmode 'single'
740
+ background 'white'
741
+ borderwidth 0
742
+ height 6
743
+ font $figures_font
744
+ }
745
+ scrollBar = TkScrollbar.new(listFrame) { command proc { |*args| listBox.yview(*args) } }
746
+ listBox.yscrollcommand(proc { |first, last| scrollBar.set(first, last) })
747
+
748
+ listBox.bind('ButtonRelease-1') { figureSelected }
749
+
750
+ spacer = TkFrame.new(listFrame) { background 'WhiteSmoke' }
751
+ spacer.pack('side' => 'left', 'padx' => 4)
752
+
753
+ listBox.pack('side' => 'left', 'fill' => 'both', 'expand' => true, 'pady' => 2)
754
+ scrollBar.pack('side' => 'right', 'fill' => 'y', 'pady' => 3)
755
+
756
+ listFrame.pack('side' => 'left', 'fill' => 'both', 'expand' => true)
757
+
758
+ @listBox = listBox
759
+ end
760
+
761
+
762
+ def createEvalField(parent)
763
+
764
+ evalFrame = TkFrame.new(parent, 'background' => 'WhiteSmoke') do
765
+ pack('side' => 'bottom', 'fill' => 'x', 'pady' => 4)
766
+ end
767
+
768
+ evalLabel = TkLabel.new(evalFrame, 'background' => 'WhiteSmoke') do
769
+ text ' eval'
770
+ font 'courier 12'
771
+ pack('side' => 'left')
772
+ end
773
+
774
+ evalEntry = TkEntry.new(evalFrame) do
775
+ borderwidth 0
776
+ pack('side' => 'left', 'fill' => 'x', 'expand' => true)
777
+ end
778
+
779
+ TkLabel.new(evalFrame, 'background' => 'WhiteSmoke') do
780
+ text ' '
781
+ font 'courier 12'
782
+ pack('side' => 'right')
783
+ end
784
+
785
+ evalEntry.bind('Key-Return', proc { eval })
786
+
787
+ @evalEntry = evalEntry
788
+
789
+ end
790
+
791
+ =end
792
+
793
+ end