|
1 # |
|
2 # user interface code (tcl visuals) for OCR |
|
3 # started 9/95, Archie Russell |
|
4 wm withdraw . |
|
5 append OCRCHIE_ROOT [pwd] "/" |
|
6 append face_image $OCRCHIE_ROOT face_happy.xbm |
|
7 append eye_image $OCRCHIE_ROOT eye.xbm |
|
8 append write_image $OCRCHIE_ROOT edit2.xbm |
|
9 |
|
10 set xvprocess "0" |
|
11 set main_window_width 800 |
|
12 set main_window_height 800 |
|
13 set dummy 0 |
|
14 # I'd like to be able to use the above parameters in here, |
|
15 # but I think tcl might get a little angry if I try |
|
16 # the size of the window, and the position of its upper left |
|
17 set main_window_geometry 800x800+200+100 |
|
18 |
|
19 set menu_bar_width $main_window_width |
|
20 set menu_bar_height 50 |
|
21 set button_bar_width $main_window_width |
|
22 set button_bar_height 50 |
|
23 set display_height 400 |
|
24 set edit_window_height 300 |
|
25 set quit_dialog_geometry 300x135+500+500 |
|
26 set save_ascii_geometry 275x140+500+500 |
|
27 # save a little room for scrollbars, etc. |
|
28 |
|
29 set BACKGROUND #CCCCCC |
|
30 set FOREGROUND #000000 |
|
31 set SELECT white |
|
32 # set FONT -bitstream-*-medium-r-normal--26-171-110-110-p-150-iso8859-1 |
|
33 #set FONT -bitstream-*-medium-r-normal--19-140-85-85-p-110-hp-roman8 |
|
34 #set SMALLFONT -bitstream-*-medium-r-normal--19-140-85-85-p-110-hp-roman8 |
|
35 #2 lines above changed to 2 lines below 5/17/96 RJF |
|
36 set FONT -bitstream-*-medium-r-normal-*-19-*-75-75-p-110-iso8859-1 |
|
37 set SMALLFONT -bitstream-*-medium-r-normal-*-19-*-75-75-p-110-iso8859-1 |
|
38 |
|
39 |
|
40 |
|
41 set EDIT_BACKGROUND #000000 |
|
42 set LOW_PRECISION_BACKGROUND blue |
|
43 set MISPELLED_BACKGROUND SeaGreen |
|
44 set UNKNOWN_CHAR_BACKGROUND red |
|
45 |
|
46 set scroll_inc 30 |
|
47 |
|
48 |
|
49 |
|
50 set canvas_width [expr $main_window_width - 30] |
|
51 set canvas_hight [expr $main_window_height -30] |
|
52 global variables for equation marking |
|
53 set curx 0 |
|
54 set cury 0 |
|
55 set curline 0 |
|
56 set curline_startrow 0 |
|
57 set curline_endrow 0 |
|
58 set in_equation 0 |
|
59 set WbxEquationsOnly 0 |
|
60 #Was the component selected valid in component_select |
|
61 set validComponent 0 |
|
62 |
|
63 #comp_menu.tcl holds all of the component options, join, split, and learn |
|
64 source "comp_menu.tcl" |
|
65 |
|
66 #multi_zone.tcl holds the code for displaying a document for zoning |
|
67 set multiZone_display_open 0 |
|
68 source "multi_zone.tcl" |
|
69 |
|
70 proc init_user_interface {} { |
|
71 |
|
72 # tcl requires declaration of global variables used in a fxn |
|
73 |
|
74 global main_window_geometry main_window_width main_window_height menu_bar_width menu_bar_height button_bar_width button_bar_height display_height BACKGROUND FOREGROUND EDIT_BACKGROUND edit_window_height validComponent |
|
75 |
|
76 # toplevel windows are at the same level as 'xterms' |
|
77 toplevel .main_window |
|
78 |
|
79 # $ sign means 'get the value' (otherwise uses the string) |
|
80 wm geometry .main_window $main_window_geometry |
|
81 wm title .main_window "OCR user interface" |
|
82 wm minsize . 400 300 |
|
83 .main_window configure -background $BACKGROUND |
|
84 # frames are subwindows that are there mostly to 'hold' other windows |
|
85 frame .main_window.menu_bar -width $menu_bar_width -height $menu_bar_height -relief raised -bd 2 -background $BACKGROUND |
|
86 init_menu_bar |
|
87 |
|
88 frame .main_window.button_bar -width $button_bar_width -height $button_bar_height -background $BACKGROUND |
|
89 init_button_bar |
|
90 |
|
91 |
|
92 init_display |
|
93 |
|
94 frame .main_window.edit_window -width $main_window_width -height $edit_window_height -relief ridge -bd 5 -bg $EDIT_BACKGROUND |
|
95 init_edit_window |
|
96 |
|
97 # pack puts things together: this will put the menu_bar window just above the button_bar_window above the display |
|
98 |
|
99 pack .main_window.menu_bar -side top -fill x |
|
100 pack .main_window.button_bar .main_window.display .main_window.edit_window -side top -anchor w -fill x |
|
101 focus .main_window |
|
102 |
|
103 bind .main_window.display <Enter> { |
|
104 SWITCH_TO_ACTIVE_PAGE |
|
105 } |
|
106 |
|
107 #Mark an equation |
|
108 bind .main_window.display.work_space <ButtonPress-3> { |
|
109 equation_mark %W %x %y } |
|
110 #Delete an equation |
|
111 bind .main_window.display.work_space <Double-2> { |
|
112 equation_delete %W %x %y } |
|
113 #Bind <Control-l> to learn |
|
114 bind .main_window.display.work_space <Control-l> { |
|
115 set curx [%W canvasx %x] |
|
116 set cury [%W canvasy %y] |
|
117 component_select %W $curx $cury |
|
118 component_learn |
|
119 } |
|
120 |
|
121 #Select a component |
|
122 |
|
123 bind .main_window.display.work_space <Double-1> { |
|
124 if { [component_select %W [%W canvasx %x] [%W canvasy %y] ] } { |
|
125 init_component_menu %W [%W canvasx %x] [%W canvasy %y] |
|
126 } |
|
127 } |
|
128 |
|
129 } |
|
130 |
|
131 |
|
132 proc init_menu_bar { } { |
|
133 # this command initializes the main menu bar (stuff like file, etc) |
|
134 # shortcuts not working! why? |
|
135 global BACKGROUND FOREGROUND FONT |
|
136 |
|
137 menubutton .main_window.menu_bar.file -text "File " -menu .main_window.menu_bar.file.menu -borderwidth 2 -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
138 init_file_menu |
|
139 |
|
140 menubutton .main_window.menu_bar.tools -text "Tools " -menu .main_window.menu_bar.tools.menu -borderwidth 2 -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
141 init_tools_menu |
|
142 |
|
143 menubutton .main_window.menu_bar.options -text "Options " -menu .main_window.menu_bar.options.menu -borderwidth 2 -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
144 init_options_menu |
|
145 |
|
146 menubutton .main_window.menu_bar.windows -text "Windows " -menu .main_window.menu_bar.windows.menu -borderwidth 2 -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
147 init_windows_menu |
|
148 |
|
149 pack .main_window.menu_bar.file .main_window.menu_bar.tools .main_window.menu_bar.options .main_window.menu_bar.windows -side left -padx 1m -pady 1m |
|
150 |
|
151 |
|
152 button .main_window.menu_bar.help -text "Help" -borderwidth 2 -background $BACKGROUND -foreground $FOREGROUND -font $FONT -relief flat \ |
|
153 -command { init_help .main_window.menu_bar.help } |
|
154 |
|
155 pack .main_window.menu_bar.help -side right |
|
156 } |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 proc init_file_menu { } { |
|
162 # this creates the menu associated with the file menubutton |
|
163 global FOREGROUND BACKGROUND FONT |
|
164 menu .main_window.menu_bar.file.menu -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
165 # and these initialize the entries in the menu (open is linked to the command popup_open_menu) |
|
166 .main_window.menu_bar.file.menu add command -label "Open..." -command popup_open_menu |
|
167 .main_window.menu_bar.file.menu add command -label "Close" -command close_document |
|
168 .main_window.menu_bar.file.menu add separator |
|
169 # .main_window.menu_bar.file.menu add command -label "Save TIFF" -command popup_save_tiff_menu |
|
170 .main_window.menu_bar.file.menu add command -label "Save ASCII" -command popup_save_ascii_menu |
|
171 # .main_window.menu_bar.file.menu add command -label "Save WORD/POS" -command popup_save_word_pos_menu |
|
172 .main_window.menu_bar.file.menu add command -label "Save WORDBOX" -command popup_save_wordbox_menu |
|
173 .main_window.menu_bar.file.menu add command -label "Save EQUATION BOUNDS" -command popup_save_equations_menu |
|
174 |
|
175 .main_window.menu_bar.file.menu add command -label "Save Learned Characters" -command popup_save_learned_chars_menu |
|
176 .main_window.menu_bar.file.menu add command -label "Read Learned Characters" -command popup_read_learned_chars_menu |
|
177 |
|
178 # .main_window.menu_bar.file.menu add command -label "Save Setup" -command popup_save_setup_menu |
|
179 # a separator is just a horizontal line for show |
|
180 .main_window.menu_bar.file.menu add separator |
|
181 .main_window.menu_bar.file.menu add command -label "Quit" -command popup_quit_dialog_box |
|
182 } |
|
183 |
|
184 proc close_document { } { |
|
185 .main_window.edit_window.text_part delete 1.0 end |
|
186 .main_window.display.work_space delete all |
|
187 |
|
188 set COLORED_WORDS {} |
|
189 if { [winfo exist .zoning_window] } { |
|
190 focus .zoning_window |
|
191 zone_message "No active zone" |
|
192 } else { |
|
193 DEALLOCATE_PAGE |
|
194 |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 proc init_tools_menu { } { |
|
200 # this creates the menu associated with the tools menubutton |
|
201 global BACKGROUND FOREGROUND FONT |
|
202 menu .main_window.menu_bar.tools.menu -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
203 # and these initialize the entries in the menu (open is linked to the command popup_open_menu) |
|
204 |
|
205 # supposed to just find the angle and tell you what it is... |
|
206 # .main_window.menu_bar.tools.menu add command -label "Skew Angle" -command popup_skew_angle_menu |
|
207 |
|
208 # supposed to let the user arbitrarily rotate the image |
|
209 # .main_window.menu_bar.tools.menu add command -label "Rotate" -command popup_rotate_menu |
|
210 |
|
211 .main_window.menu_bar.tools.menu add command -label "Extract Components" -command EXTRACT_COMP |
|
212 .main_window.menu_bar.tools.menu add command -label "Recognize" -command popup_recognize_menu |
|
213 .main_window.menu_bar.tools.menu add command -label "Learn" -command popup_learn_menu |
|
214 .main_window.menu_bar.tools.menu add separator |
|
215 .main_window.menu_bar.tools.menu add command -label "Zoom in" -command ZOOM_IN |
|
216 .main_window.menu_bar.tools.menu add command -label "Zoom out" -command ZOOM_OUT |
|
217 .main_window.menu_bar.tools.menu add separator |
|
218 .main_window.menu_bar.tools.menu add command -label "Refresh" -command DISPLAY_INTERVALS |
|
219 .main_window.menu_bar.tools.menu add command -label "Deskew" -command popup_deskew_menu |
|
220 |
|
221 # automated spell correction |
|
222 # .main_window.menu_bar.tools.menu add command -label "SpellCorrect" -command popup_correct_menu |
|
223 |
|
224 # interactive learning |
|
225 # .main_window.menu_bar.tools.menu add command -label "Learn Mode" -command popup_learn_mode |
|
226 } |
|
227 |
|
228 set CURRENT_DEFAULT_FONT Helvetica |
|
229 set CURRENT_DEFAULT_SIZE 9 |
|
230 proc popup_learn_mode { } { |
|
231 global BACKGROUND FOREGROUND SMALLFONT FONT |
|
232 toplevel .learn |
|
233 frame .learn.c -width 100 -height 100 |
|
234 canvas .learn.c.c -background $BACKGROUND -width 100 -height 100 |
|
235 pack .learn.c.c |
|
236 frame .learn.s |
|
237 entry .learn.s.learned_string -width 5 -bg $BACKGROUND -fg $FOREGROUND -font $SMALLFONT -selectbackground $SELECT |
|
238 .learn.s.learned_string icursor 0 |
|
239 .learn.s.learned_string select range 0 10 |
|
240 label .learn.s.string_message -text "Ascii" -bg $BACKGROUND -fg $FOREGROUND -font $SMALLFONT |
|
241 pack .learn.s.learned_string .learn.s.string_message -side left -expand 1 |
|
242 |
|
243 tk_optionMenu .learn.font CURRENT_DEFAULT_FONT Helvetica Courier Times |
|
244 .learn.font configure -bg $BACKGROUND -fg $FOREGROUND -font $SMALLFONT |
|
245 .learn.font.menu configure -bg $BACKGROUND -fg $FOREGROUND |
|
246 tk_optionMenu .learn.size CURRENT_DEFAULT_SIZE 9 10 12 18 |
|
247 .learn.size configure -bg $BACKGROUND -fg $FOREGROUND -font $SMALLFONT |
|
248 .learn.size.menu configure -bg $BACKGROUND -fg $FOREGROUND |
|
249 frame .learn.buttons |
|
250 button .learn.buttons.ok -text Learn -command learn_ok -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
251 button .learn.buttons.cancel -text Skip -command learn_skip -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
252 pack .learn.buttons.ok .learn.buttons.cancel -side left -expand 1 -fill x |
|
253 pack .learn.c .learn.s .learn.font .learn.size .learn.buttons -side top -fill x |
|
254 } |
|
255 |
|
256 |
|
257 proc init_windows_menu { } { |
|
258 # this creates the menu associated with the windows menubutton. Just |
|
259 #focuses the window |
|
260 |
|
261 global FOREGROUND BACKGROUND FONT |
|
262 menu .main_window.menu_bar.windows.menu -background $BACKGROUND -foreground $FOREGROUND -font $FONT |
|
263 # and these initialize the entries in the menu (open is linked to the command popup_open_menu) |
|
264 .main_window.menu_bar.windows.menu add command -label "Zoning Window" -command { if { [winfo exists .zoning_window] } {focus .zoning_window} } |
|
265 .main_window.menu_bar.windows.menu add command -label "Active Window" -command {focus .main_window} |
|
266 |
|
267 } |
|
268 |
|
269 proc init_help { path } { |
|
270 global FOREGROUND BACKGROUND FONT |
|
271 |
|
272 |
|
273 if { [winfo exists $help] } { |
|
274 focus $help |
|
275 return |
|
276 } |
|
277 |
|
278 set help [toplevel .main_help ] |
|
279 wm title $help "Active Window Help" |
|
280 # wm geometry $help 400x500+600+150 |
|
281 message $help.msg -background white -foreground $FOREGROUND -font $FONT\ |
|
282 -width 600 -text "\n\ |
|
283 Mark Equation - <Button3> at start and end of Equation \n\ |
|
284 Delete Equation- <Double-2> within the equation \n\n\ |
|
285 Component Menu - <Double-1> within the component boundaries \n\ |
|
286 \t Join - Select \[Join\] and <Double-1> on component to join\n\ |
|
287 \t Split - Select \[Horizontal Split\] or \[Vertical Split\]\n\ |
|
288 \t Learn - Select \[Learn\] and enter value. \n" |
|
289 |
|
290 |
|
291 |
|
292 pack $help.msg -fill x -fill y -expand true |
|
293 |
|
294 } |
|
295 |
|
296 proc popup_deskew_menu { } { |
|
297 puts stdout "Calling get_skew" |
|
298 DESKEW |
|
299 } |
|
300 |
|
301 proc popup_recognize_menu { } { |
|
302 puts stdout "Calling recognize from Tcl" |
|
303 RECOGNIZE |
|
304 } |
|
305 proc popup_learn_menu { } { |
|
306 puts stdout "Calling interactive learn from Tcl" |
|
307 |
|
308 set fileid [open recog.tmp w] |
|
309 puts $fileid [.main_window.edit_window.text_part get 1.0 end] |
|
310 close $fileid |
|
311 |
|
312 # last argument synchronizes words |
|
313 LEARN_PAGE recog.tmp 1 |
|
314 |
|
315 } |
|
316 |
|
317 set XV 2 |
|
318 proc init_options_menu { } { |
|
319 global dummy word_certainty_value screen_view_style FOREGROUND BACKGROUND FONT XV |
|
320 menu .main_window.menu_bar.options.menu -foreground $FOREGROUND -background $BACKGROUND -font $FONT |
|
321 .main_window.menu_bar.options.menu add command -label "Warning Levels..." -command popup_confidence_menu |
|
322 |
|
323 # .main_window.menu_bar.options.menu add command -label "Zoom Ratio" -command popup_zoom_ratio_menu |
|
324 .main_window.menu_bar.options.menu add checkbutton -label "Display Line Boundaries" -variable DISPLAY_LINE_BOUNDARIES |
|
325 .main_window.menu_bar.options.menu add checkbutton -label "Display Bounding Boxes" -variable DISPLAY_BOUNDING_BOXES |
|
326 .main_window.menu_bar.options.menu add checkbutton -label "Spellcheck" -variable SPELLCHECK |
|
327 .main_window.menu_bar.options.menu add separator |
|
328 .main_window.menu_bar.options.menu add radiobutton -label "No Display" -variable DISPLAY_IMAGE -value 0 |
|
329 .main_window.menu_bar.options.menu add radiobutton -label "OCRchie Display" -variable DISPLAY_IMAGE -value 1 |
|
330 .main_window.menu_bar.options.menu add radiobutton -label "xv" -variable DISPLAY_IMAGE -value $XV |
|
331 .main_window.menu_bar.options.menu add separator |
|
332 .main_window.menu_bar.options.menu add radiobutton -label "No deskew" -variable DESKEW_METHOD -value -1 |
|
333 .main_window.menu_bar.options.menu add radiobutton -label "RLE rotate" -variable DESKEW_METHOD -value 1 |
|
334 .main_window.menu_bar.options.menu add radiobutton -label "Bitmap rotate" -variable DESKEW_METHOD -value 0 |
|
335 .main_window.menu_bar.options.menu add cascade -label "Global Vars" \ |
|
336 -menu .main_window.menu_bar.options.menu.globals |
|
337 init_global_menu { NoiseTolerance MinLineSize MinVertSeparation \ |
|
338 MinHorizSeparation ConfidenceThreshold JoinTolerance } |
|
339 |
|
340 |
|
341 |
|
342 } |
|
343 |
|
344 set GLOBAL_MESSAGE "<none>" |
|
345 proc init_button_bar { } { |
|
346 global FONT BACKGROUND FOREGROUND GLOBAL_MESSAGE |
|
347 message .main_window.button_bar.msg -font $FONT -background $BACKGROUND -foreground $FOREGROUND -width 400 |
|
348 pack .main_window.button_bar.msg |
|
349 } |
|
350 |
|
351 proc init_display { } { |
|
352 global display_height canvas_width canvas_height FOREGROUND BACKGROUND IMAGE_DISPLAY_WIN main_window_width display_height scroll_inc |
|
353 frame .main_window.display -width $main_window_width -height $display_height -relief ridge -bd 5 -bg $BACKGROUND |
|
354 canvas .main_window.display.work_space -bg white -xscrollcommand ".main_window.display.xscroller set" -yscrollcommand ".main_window.display.yscroller set" -xscrollincrement $scroll_inc -cursor {crosshair black gray} -width $canvas_width -height $display_height |
|
355 # two scrollbars |
|
356 scrollbar .main_window.display.xscroller -command ".main_window.display.work_space xview" -orient horizontal -background $BACKGROUND |
|
357 scrollbar .main_window.display.yscroller -command ".main_window.display.work_space yview" -background $BACKGROUND |
|
358 |
|
359 pack .main_window.display.xscroller -side bottom -fill x |
|
360 |
|
361 pack .main_window.display.yscroller -side right -fill y |
|
362 pack .main_window.display.work_space -side top -fill x |
|
363 set IMAGE_DISPLAY_WIN .main_window.display.work_space |
|
364 .main_window.display.work_space configure -scrollregion { 0 0 5000 5000 } |
|
365 |
|
366 # box_init |
|
367 } |
|
368 |
|
369 proc init_edit_window { } { |
|
370 global edit_window_height canvas_width EDIT_BACKGROUND COLORED_WORDS LOW_PRECISION_BACKGROUND MISPELLED_BACKGROUND UNKNOWN_CHAR_BACKGROUND SMALLFONT SCALE_FACTOR scroll_inc |
|
371 text .main_window.edit_window.text_part -bg $EDIT_BACKGROUND -height $edit_window_height -width $canvas_width -insertbackground yellow -insertwidth 8 -font $SMALLFONT -fg white -wrap word |
|
372 pack .main_window.edit_window.text_part -side bottom |
|
373 .main_window.edit_window.text_part tag configure LOW_PRECISION -background $LOW_PRECISION_BACKGROUND |
|
374 .main_window.edit_window.text_part tag configure MISPELLED -background $MISPELLED_BACKGROUND |
|
375 .main_window.edit_window.text_part tag configure UNKNOWN_CHAR -background $UNKNOWN_CHAR_BACKGROUND |
|
376 # Tab binding for the window is supposed to advance the cursor to the |
|
377 # next uncertain word and scroll the image display to show the image |
|
378 # of that word |
|
379 bind .main_window.edit_window.text_part <Tab> { |
|
380 if {[llength $COLORED_WORDS] == 0} { |
|
381 puts stdout "No more words" |
|
382 } else { |
|
383 .main_window.edit_window.text_part mark set insert [pop_colored_words] |
|
384 set xpos [pop_colored_words] |
|
385 set ypos [pop_colored_words] |
|
386 # puts "xpos and ypos for this word" |
|
387 set ulx [expr $SCALE_FACTOR * ($xpos - 300)] |
|
388 set uly [expr $SCALE_FACTOR * ($ypos - 100)] |
|
389 set lrx [expr $SCALE_FACTOR * ($xpos + 300)] |
|
390 set lry [expr $SCALE_FACTOR * ($ypos + 100)] |
|
391 # I could never get this scrolling to work quite right, maybe |
|
392 # someone will figure it out someday |
|
393 .main_window.display.work_space configure -scrollregion [list $ulx $uly $lrx $lry] |
|
394 .main_window.display.work_space configure -scrollregion {0 0 5000 5000} |
|
395 # .main_window.display.work_space xview moveto [expr (($SCALE_FACTOR * $xpos) / $scroll_inc)] |
|
396 # .main_window.display.work_space yview moveto [expr (($SCALE_FACTOR * $ypos) / $scroll_inc)] |
|
397 |
|
398 set x [.main_window.edit_window.text_part index insert] |
|
399 # puts "New index is $x" |
|
400 .main_window.edit_window.text_part see insert |
|
401 set local_tags [.main_window.edit_window.text_part tag names insert] |
|
402 # puts "Tags at this place: $local_tags" |
|
403 } |
|
404 break |
|
405 } |
|
406 } |
|
407 |
|
408 proc addword { w {xpos 0} {ypos 0} {status OK}} { |
|
409 global COLORED_WORDS LOW_PRECISION_BACKGROUND MISPELLED_BACKGROUND UNKNOWN_CHAR_BACKGROUND |
|
410 # puts stdout "Adding $w with status $status" |
|
411 |
|
412 if { ![string compare $status OK] } { |
|
413 .main_window.edit_window.text_part insert end "$w " |
|
414 .main_window.edit_window.text_part mark set insert end |
|
415 } elseif { ![string compare $status LOW_PRECISION] || ![string compare $status MISPELLED] || ![string compare $status UNKNOWN_CHAR] } { |
|
416 .main_window.edit_window.text_part insert end "$w" $status |
|
417 .main_window.edit_window.text_part insert end " " |
|
418 # xpos and ypos can be tags too, but they really slow things down |
|
419 # .main_window.edit_window.text_part mark set insert end |
|
420 # .main_window.edit_window.text_part mark set insert "end -3 char" |
|
421 # .main_window.edit_window.text_part tag add $status "insert wordstart" "insert wordend" |
|
422 # .main_window.edit_window.text_part tag add x$xpos "insert wordstart" "insert wordend" |
|
423 # .main_window.edit_window.text_part tag add y$ypos "insert wordstart" "insert wordend" |
|
424 .main_window.edit_window.text_part mark set insert "end -3 char" |
|
425 .main_window.edit_window.text_part mark set insert "insert wordstart" |
|
426 lappend COLORED_WORDS [.main_window.edit_window.text_part index insert] |
|
427 lappend COLORED_WORDS $xpos |
|
428 lappend COLORED_WORDS $ypos |
|
429 .main_window.edit_window.text_part mark set insert end |
|
430 } else { |
|
431 puts stdout "Unknown word status for $w: $status" |
|
432 .main_window.edit_window.text_part insert end "$w UNKNOWNSTATUS? " |
|
433 } |
|
434 } |
|
435 |
|
436 proc pop_colored_words { } { |
|
437 global COLORED_WORDS |
|
438 set x [lindex $COLORED_WORDS 0] |
|
439 if {[llength $COLORED_WORDS] == 1} { |
|
440 set COLORED_WORDS {} |
|
441 } elseif {[llength $COLORED_WORDS] == 0} { |
|
442 set COLORED_WORDS $COLORED_WORDS |
|
443 } else { |
|
444 set COLORED_WORDS [lrange $COLORED_WORDS 1 [llength $COLORED_WORDS]] |
|
445 } |
|
446 return $x |
|
447 } |
|
448 |
|
449 |
|
450 set open_menu_geometry 250x300+400+400 |
|
451 set current_directory [pwd] |
|
452 set box_entry $current_directory |
|
453 set open_menu_pattern *.tif |
|
454 |
|
455 set singleZone "Single Zone" |
|
456 set multiZone "Multi Zone" |
|
457 set zoning "Single Zone" |
|
458 |
|
459 proc popup_open_menu { } { |
|
460 # |
|
461 # this procedure pops up an interactive box which can be used to open files |
|
462 # what a horrible mess. Writing it took forever |
|
463 # |
|
464 global open_menu_geometry open_menu_pattern current_directory FONT FOREGROUND BACKGROUND SMALLFONT box_entry singleZone multiZone zoning SELECT |
|
465 |
|
466 if { [winfo exists .open_menu] } { |
|
467 focus .open_menu |
|
468 return |
|
469 } |
|
470 toplevel .open_menu |
|
471 wm geometry .open_menu $open_menu_geometry |
|
472 wm title .open_menu Open |
|
473 .open_menu configure -background $BACKGROUND |
|
474 # force the user to interact with this box |
|
475 # grab set .open_menu |
|
476 |
|
477 # directory listing and scrollbar |
|
478 frame .open_menu.dirstuff |
|
479 |
|
480 frame .open_menu.cur_dir |
|
481 label .open_menu.cur_dir.l -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -text "Dir: " |
|
482 entry .open_menu.cur_dir.e -relief sunken -bd 2 -textvariable box_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT -selectbackground $SELECT |
|
483 .open_menu.cur_dir.e icursor 0 |
|
484 |
|
485 |
|
486 frame .open_menu.zone |
|
487 |
|
488 radiobutton .open_menu.zone.single -variable zoning -value $singleZone \ |
|
489 -text $singleZone -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
490 |
|
491 radiobutton .open_menu.zone.multi -variable zoning -value $multiZone \ |
|
492 -text $multiZone -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
493 |
|
494 pack .open_menu.zone.single -side left |
|
495 pack .open_menu.zone.multi -side left |
|
496 pack .open_menu.zone -side top -fill x |
|
497 |
|
498 .open_menu.cur_dir.e icursor end |
|
499 bind .open_menu.cur_dir.e <Return> { |
|
500 set file_to_open $box_entry |
|
501 if [file isdirectory $file_to_open] { |
|
502 cd $file_to_open |
|
503 set current_directory [pwd] |
|
504 clear_directory_box |
|
505 puts stdout "Changing to $current_directory" |
|
506 fill_in_directory_box $current_directory $open_menu_pattern |
|
507 } elseif [file exists $file_to_open] { |
|
508 puts stdout "Opening file $file_to_open" |
|
509 if { $zoning == $singleZone } { |
|
510 singleZone_open $file_to_open |
|
511 } else |
|
512 { multiZone_open $file_to_open } |
|
513 destroy .open_menu |
|
514 } else { |
|
515 puts stdout "Cannot acccess that file" |
|
516 } |
|
517 } |
|
518 pack .open_menu.cur_dir.l .open_menu.cur_dir.e -side left |
|
519 |
|
520 scrollbar .open_menu.dirstuff.yscroll -command ".open_menu.dirstuff.directory yview" -background $BACKGROUND |
|
521 listbox .open_menu.dirstuff.directory -yscrollcommand ".open_menu.dirstuff.yscroll set" -width 22 -height 11 -relief raised -font $SMALLFONT -background $BACKGROUND -foreground $FOREGROUND |
|
522 |
|
523 fill_in_directory_box $current_directory $open_menu_pattern |
|
524 bind .open_menu.dirstuff.directory <Double-Button-1> { |
|
525 set file_to_open [selection get] |
|
526 # puts stdout "Bound button" |
|
527 if [file isdirectory $file_to_open] { |
|
528 cd $file_to_open |
|
529 set current_directory [pwd] |
|
530 clear_directory_box |
|
531 # puts stdout "Changing to $current_directory" |
|
532 fill_in_directory_box $current_directory $open_menu_pattern |
|
533 } elseif [file exists $file_to_open] { |
|
534 # puts stdout "Opening file $file_to_open" |
|
535 if { $zoning == $singleZone } { |
|
536 singleZone_open $file_to_open |
|
537 } else { multiZone_open $file_to_open } |
|
538 destroy .open_menu.dirstuff.directory |
|
539 destroy .open_menu |
|
540 } else { |
|
541 puts stdout "Cannot access that file" |
|
542 } |
|
543 } |
|
544 # pattern for listings to match |
|
545 |
|
546 |
|
547 frame .open_menu.pattern_match -background $BACKGROUND |
|
548 label .open_menu.pattern_match.label -text "Match files of type:" -font $SMALLFONT -background $BACKGROUND -fg $FOREGROUND |
|
549 entry .open_menu.pattern_match.entry -width 5 -relief sunken -bd 2 -textvariable open_menu_pattern -font $SMALLFONT -background $BACKGROUND -fg $FOREGROUND |
|
550 # refresh the directory listing after user presses return |
|
551 bind .open_menu.pattern_match.entry <Return> { |
|
552 set current_directory [pwd] |
|
553 clear_directory_box |
|
554 fill_in_directory_box $current_directory $open_menu_pattern |
|
555 } |
|
556 |
|
557 pack .open_menu.pattern_match.label .open_menu.pattern_match.entry -side left |
|
558 pack .open_menu.dirstuff.directory .open_menu.dirstuff.yscroll -side left -fill y |
|
559 |
|
560 |
|
561 pack .open_menu.pattern_match .open_menu.cur_dir .open_menu.dirstuff -side top -anchor w |
|
562 focus .open_menu.pattern_match.entry |
|
563 } |
|
564 |
|
565 |
|
566 proc popup_confidence_menu { } { |
|
567 # a little box for the user to change the confidence |
|
568 # warning levels (words that get highlighted) |
|
569 global BACKGROUND FOREGROUND SMALLFONT FONT |
|
570 toplevel .confidence -background $BACKGROUND |
|
571 wm geometry .confidence 250x225+500+500 |
|
572 message .confidence.m -text "Warning thresholds for the output display\n (255 = warn unless perfect)" -background $BACKGROUND -foreground $FOREGROUND -font $SMALLFONT -justify center -width 250 |
|
573 scale .confidence.very_low -from 0 -to 255 -variable VERY_LOW_CONFIDENCE -orient horizontal -label "Poor (displayed in red)" -background $BACKGROUND -foreground $FOREGROUND -font $SMALLFONT |
|
574 scale .confidence.low -from 0 -to 255 -variable LOW_CONFIDENCE -orient horizontal -label "Fair (displayed in blue)" -background $BACKGROUND -foreground $FOREGROUND -font $SMALLFONT |
|
575 pack .confidence.m .confidence.very_low .confidence.low -side top -fill x |
|
576 } |
|
577 |
|
578 proc singleZone_open { filename } { |
|
579 # 1 means success |
|
580 global IMAGE_DISPLAY_WIN SCALE_FACTOR DISPLAY_IMAGE XV xvprocess |
|
581 # puts stdout "Opening $filename" |
|
582 page_open $filename |
|
583 # puts stdout "Done putting into page structure" |
|
584 if { 1 } { |
|
585 set display_height [expr $SCALE_FACTOR * [get_page_height]] |
|
586 set display_width [expr $SCALE_FACTOR * [get_page_width]] |
|
587 append geometry [expr int($display_width)] x [expr int($display_height)] |
|
588 # puts stdout "Displaying Image" |
|
589 if { $DISPLAY_IMAGE == $XV } { |
|
590 set xvprocess [exec xv $filename &] |
|
591 puts stdout "xvprocess $xvprocess" |
|
592 } else { |
|
593 # use the canvas... |
|
594 DISPLAY_INTERVALS .main_window.display.work_space $SCALE_FACTOR |
|
595 FIND_LINES |
|
596 } |
|
597 } else { |
|
598 popup_image_failure_win |
|
599 } |
|
600 puts stdout "Determining Line boundaries" |
|
601 |
|
602 } |
|
603 |
|
604 set save_entry "recog.txt" |
|
605 proc popup_save_ascii_menu { } { |
|
606 # |
|
607 # Pops up a little window for saving the ascii recognized text |
|
608 # Should have a general function for all the saves, but now |
|
609 # they are just cuts and pastes |
|
610 # |
|
611 # |
|
612 global save_ascii_geometry BACKGROUND FOREGROUND FONT SMALLFONT save_entry OCRCHIE_ROOT write_image SELECT |
|
613 |
|
614 set save_entry recog.txt |
|
615 toplevel .save_ascii -background $BACKGROUND |
|
616 wm geometry .save_ascii $save_ascii_geometry |
|
617 wm title .save_ascii "Save ASCII Text" |
|
618 grab set .save_ascii |
|
619 |
|
620 |
|
621 label .save_ascii.image -bitmap @$write_image -foreground $FOREGROUND -background $BACKGROUND |
|
622 frame .save_ascii.s -background $BACKGROUND |
|
623 label .save_ascii.s.txt -text "Save ascii text as:" -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
624 entry .save_ascii.s.ent -relief sunken -bd 2 -textvariable save_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT -selectbackground $SELECT |
|
625 |
|
626 .save_ascii.s.ent icursor 0 |
|
627 .save_ascii.s.ent select range 0 12 |
|
628 |
|
629 pack .save_ascii.s.txt .save_ascii.s.ent -side top |
|
630 frame .save_ascii.buttons |
|
631 button .save_ascii.buttons.ok -text OK -command save_ascii -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
632 button .save_ascii.buttons.cancel -text Cancel -command save_ascii_cancel -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
633 pack .save_ascii.buttons.ok .save_ascii.buttons.cancel -side left -expand 1 -fill x |
|
634 pack .save_ascii.image .save_ascii.s .save_ascii.buttons -side top |
|
635 |
|
636 bind .save_ascii.s.ent <Return> { |
|
637 save_ascii |
|
638 } |
|
639 } |
|
640 |
|
641 proc save_ascii_cancel { } { |
|
642 destroy .save_ascii |
|
643 } |
|
644 |
|
645 proc save_ascii { } { |
|
646 # need to put some error checking in here |
|
647 global save_entry |
|
648 set fileid [open $save_entry w] |
|
649 puts $fileid [.main_window.edit_window.text_part get 1.0 end] |
|
650 close $fileid |
|
651 destroy .save_ascii |
|
652 } |
|
653 |
|
654 proc popup_save_word_pos_menu { } { |
|
655 global save_ascii_geometry BACKGROUND FOREGROUND FONT SMALLFONT save_entry OCRCHIE_ROOT face_image |
|
656 |
|
657 set save_entry recog.wps |
|
658 toplevel .save_word_pos -background $BACKGROUND |
|
659 wm geometry .save_word_pos $save_ascii_geometry |
|
660 wm title .save_word_pos "Save in word/pos format" |
|
661 grab set .save_word_pos |
|
662 |
|
663 label .save_word_pos.image -bitmap @$face_image -foreground $FOREGROUND -background $BACKGROUND |
|
664 frame .save_word_pos.s -background $BACKGROUND |
|
665 label .save_word_pos.s.txt -text "Save word_pos text as:" -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
666 entry .save_word_pos.s.ent -relief sunken -bd 2 -textvariable save_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
667 pack .save_word_pos.s.txt .save_word_pos.s.ent -side top |
|
668 frame .save_word_pos.buttons |
|
669 button .save_word_pos.buttons.ok -text OK -command save_word_pos -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
670 button .save_word_pos.buttons.cancel -text Cancel -command save_word_pos_cancel -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
671 pack .save_word_pos.buttons.ok .save_word_pos.buttons.cancel -side left -expand 1 -fill x |
|
672 pack .save_word_pos.image .save_word_pos.s .save_word_pos.buttons -side top |
|
673 |
|
674 bind .save_word_pos.s.ent <Return> { |
|
675 save_word_pos |
|
676 } |
|
677 } |
|
678 |
|
679 proc save_word_pos_cancel { } { |
|
680 destroy .save_word_pos |
|
681 } |
|
682 |
|
683 proc save_word_pos { } { |
|
684 # need to put some error checking in here |
|
685 global save_entry |
|
686 WRITE_WORD_POS $save_entry |
|
687 destroy .save_word_pos |
|
688 } |
|
689 |
|
690 proc popup_save_wordbox_menu { } { |
|
691 global save_ascii_geometry BACKGROUND FOREGROUND FONT SMALLFONT save_entry OCRCHIE_ROOT face_image WbxEquationsOnly |
|
692 |
|
693 set save_entry recog.wbx |
|
694 toplevel .save_wordbox -background $BACKGROUND |
|
695 wm geometry .save_wordbox 275x200+500+500 |
|
696 wm title .save_wordbox "Save in word/pos format" |
|
697 grab set .save_wordbox |
|
698 |
|
699 label .save_wordbox.image -bitmap @$face_image -foreground $FOREGROUND -background $BACKGROUND |
|
700 frame .save_wordbox.s -background $BACKGROUND |
|
701 label .save_wordbox.s.txt -text "Save wordbox text as:" -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
702 entry .save_wordbox.s.ent -relief sunken -bd 2 -textvariable save_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
703 pack .save_wordbox.s.txt .save_wordbox.s.ent -side top |
|
704 frame .save_wordbox.buttons |
|
705 checkbutton .save_wordbox.buttons.eqn \ |
|
706 -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT \ |
|
707 -text "Equations only" -variable WbxEquationsOnly |
|
708 |
|
709 button .save_wordbox.buttons.ok -text OK -command save_wordbox -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
710 button .save_wordbox.buttons.cancel -text Cancel -command save_wordbox_cancel -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
711 pack .save_wordbox.buttons.eqn -side top -expand 1 -fill x |
|
712 pack .save_wordbox.buttons.ok .save_wordbox.buttons.cancel -side left \ |
|
713 -expand 1 -fill x |
|
714 |
|
715 pack .save_wordbox.image .save_wordbox.s .save_wordbox.buttons -side top |
|
716 |
|
717 bind .save_wordbox.s.ent <Return> { |
|
718 save_wordbox |
|
719 } |
|
720 } |
|
721 |
|
722 proc save_wordbox_cancel { } { |
|
723 destroy .save_wordbox |
|
724 } |
|
725 |
|
726 proc save_wordbox { } { |
|
727 # need to put some error checking in here |
|
728 global save_entry cur_xoffset cur_yoffset WbxEquationsOnly |
|
729 |
|
730 WRITE_WORDBOX $save_entry $cur_xoffset $cur_yoffset $WbxEquationsOnly |
|
731 destroy .save_wordbox |
|
732 } |
|
733 |
|
734 proc popup_save_equations_menu { } { |
|
735 global save_ascii_geometry BACKGROUND FOREGROUND FONT SMALLFONT save_entry OCRCHIE_ROOT face_image cur_xoffset cur_yoffset |
|
736 |
|
737 set save_entry recog.eqn |
|
738 toplevel .save_equations -background $BACKGROUND |
|
739 wm geometry .save_equations $save_ascii_geometry |
|
740 wm title .save_equations "Save Equation boundaries" |
|
741 grab set .save_equations |
|
742 |
|
743 label .save_equations.image -bitmap @$face_image -foreground $FOREGROUND -background $BACKGROUND |
|
744 frame .save_equations.s -background $BACKGROUND |
|
745 label .save_equations.s.txt -text "Save equation boundaries as:" -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
746 entry .save_equations.s.ent -relief sunken -bd 2 -textvariable save_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
747 pack .save_equations.s.txt .save_equations.s.ent -side top |
|
748 frame .save_equations.buttons |
|
749 button .save_equations.buttons.ok -text OK -command save_equations -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
750 button .save_equations.buttons.cancel -text Cancel -command save_equations_cancel -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
751 pack .save_equations.buttons.ok .save_equations.buttons.cancel -side left -expand 1 -fill x |
|
752 pack .save_equations.image .save_equations.s .save_equations.buttons -side top |
|
753 |
|
754 bind .save_equations.s.ent <Return> { |
|
755 save_equations cur_xoffset cur_yoffset |
|
756 } |
|
757 } |
|
758 |
|
759 proc save_equations_cancel { } { |
|
760 destroy .save_equations |
|
761 } |
|
762 |
|
763 proc save_equations { } { |
|
764 # need to put some error checking in here |
|
765 global save_entry |
|
766 # second parameter is line number offset |
|
767 WRITE_EQUATIONS $save_entry 0 |
|
768 destroy .save_equations |
|
769 } |
|
770 |
|
771 |
|
772 proc popup_save_learned_chars_menu { } { |
|
773 global save_ascii_geometry BACKGROUND FOREGROUND FONT SMALLFONT save_entry face_image |
|
774 set save_entry learn.dat |
|
775 toplevel .save_learned_chars -background $BACKGROUND |
|
776 wm geometry .save_learned_chars $save_ascii_geometry |
|
777 wm title .save_learned_chars "Write Learned Characters" |
|
778 grab set .save_learned_chars |
|
779 |
|
780 label .save_learned_chars.image -bitmap @$face_image -foreground $FOREGROUND -background $BACKGROUND |
|
781 frame .save_learned_chars.s -background $BACKGROUND |
|
782 label .save_learned_chars.s.txt -text "Save learned characters as:" -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
783 entry .save_learned_chars.s.ent -relief sunken -bd 2 -textvariable save_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
784 pack .save_learned_chars.s.txt .save_learned_chars.s.ent -side top |
|
785 frame .save_learned_chars.buttons |
|
786 button .save_learned_chars.buttons.ok -text OK -command save_learned_chars -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
787 button .save_learned_chars.buttons.cancel -text Cancel -command save_learned_chars_cancel -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
788 pack .save_learned_chars.buttons.ok .save_learned_chars.buttons.cancel -side left -expand 1 -fill x |
|
789 pack .save_learned_chars.image .save_learned_chars.s .save_learned_chars.buttons -side top |
|
790 |
|
791 bind .save_learned_chars.s.ent <Return> { |
|
792 save_learned_chars |
|
793 } |
|
794 } |
|
795 |
|
796 proc save_learned_chars_cancel { } { |
|
797 destroy .save_learned_chars |
|
798 } |
|
799 |
|
800 proc save_learned_chars { } { |
|
801 # need to put some error checking in here? |
|
802 global save_entry |
|
803 WRITE_LEARNED_CHARS $save_entry |
|
804 destroy .save_learned_chars |
|
805 } |
|
806 |
|
807 proc popup_read_learned_chars_menu { } { |
|
808 global save_ascii_geometry BACKGROUND FOREGROUND FONT SMALLFONT save_entry eye_image |
|
809 set save_entry learn.dat |
|
810 toplevel .read_learned_chars -background $BACKGROUND |
|
811 wm geometry .read_learned_chars $save_ascii_geometry |
|
812 wm title .read_learned_chars "Read Learned Characters" |
|
813 grab set .read_learned_chars |
|
814 |
|
815 label .read_learned_chars.image -bitmap @$eye_image -foreground $FOREGROUND -background $BACKGROUND |
|
816 frame .read_learned_chars.s -background $BACKGROUND |
|
817 label .read_learned_chars.s.txt -text "Read learned characters from:" -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
818 entry .read_learned_chars.s.ent -relief sunken -bd 2 -textvariable save_entry -foreground $FOREGROUND -background $BACKGROUND -font $SMALLFONT |
|
819 pack .read_learned_chars.s.txt .read_learned_chars.s.ent -side top |
|
820 frame .read_learned_chars.buttons |
|
821 button .read_learned_chars.buttons.ok -text OK -command read_learned_chars -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
822 button .read_learned_chars.buttons.cancel -text Cancel -command read_learned_chars_cancel -fg $FOREGROUND -background $BACKGROUND -font $SMALLFONT -width 5 |
|
823 pack .read_learned_chars.buttons.ok .read_learned_chars.buttons.cancel -side left -expand 1 -fill x |
|
824 pack .read_learned_chars.image .read_learned_chars.s .read_learned_chars.buttons -side top |
|
825 |
|
826 bind .read_learned_chars.s.ent <Return> { |
|
827 read_learned_chars |
|
828 } |
|
829 } |
|
830 |
|
831 proc read_learned_chars_cancel { } { |
|
832 destroy .read_learned_chars |
|
833 } |
|
834 |
|
835 proc read_learned_chars { } { |
|
836 # need to put some error checking in here |
|
837 global save_entry |
|
838 LEARN_DATA $save_entry |
|
839 destroy .read_learned_chars |
|
840 } |
|
841 |
|
842 |
|
843 proc PAGE_OPEN { filename } { |
|
844 # unused |
|
845 return 1 |
|
846 } |
|
847 |
|
848 proc clear_directory_box { } { |
|
849 .open_menu.dirstuff.directory delete 0 end |
|
850 } |
|
851 |
|
852 proc fill_in_directory_box { dirname {pattern *} } { |
|
853 # fills in the directory box with directories or files matching the pattern |
|
854 foreach i [exec ls -aF $dirname] { |
|
855 if [file isdirectory $i] { |
|
856 .open_menu.dirstuff.directory insert end $i |
|
857 } elseif [string match $pattern $i] { |
|
858 .open_menu.dirstuff.directory insert end $i |
|
859 } |
|
860 } |
|
861 } |
|
862 |
|
863 |
|
864 proc popup_quit_dialog_box { } { |
|
865 global quit_dialog_geometry BACKGROUND FOREGROUND FONT OCRCHIE_ROOT |
|
866 |
|
867 toplevel .quit_dialog |
|
868 wm geometry .quit_dialog $quit_dialog_geometry |
|
869 wm title .quit_dialog Quit |
|
870 grab set .quit_dialog |
|
871 |
|
872 append caution_image_name $OCRCHIE_ROOT caution.xbm |
|
873 label .quit_dialog.image -bitmap @$caution_image_name -foreground $FOREGROUND -background $BACKGROUND |
|
874 message .quit_dialog.msg -text "You are about to quit OCRchie. All changes you have made will be lost." -font $FONT -background $BACKGROUND -fg $FOREGROUND -width 275 -justify center |
|
875 frame .quit_dialog.buttons |
|
876 button .quit_dialog.buttons.ok -text OK -command quit_ok -fg $FOREGROUND -background $BACKGROUND -font $FONT -width 5 |
|
877 button .quit_dialog.buttons.cancel -text Cancel -command quit_cancel -fg $FOREGROUND -background $BACKGROUND -font $FONT -width 5 |
|
878 pack .quit_dialog.buttons.ok .quit_dialog.buttons.cancel -side left -expand 1 -fill x |
|
879 pack .quit_dialog.image .quit_dialog.msg .quit_dialog.buttons -side top -fill x |
|
880 |
|
881 |
|
882 } |
|
883 |
|
884 proc quit_ok { } { |
|
885 # destroy .t |
|
886 # destroy .histogram |
|
887 destroy .main_window |
|
888 destroy .quit_dialog |
|
889 QUIT |
|
890 } |
|
891 |
|
892 proc quit_cancel { } { |
|
893 global command_not_in_progress |
|
894 set command_not_in_progress 1 |
|
895 destroy .quit_dialog |
|
896 } |
|
897 |
|
898 proc clear_canvas { } { |
|
899 destroy .main_window.display.work_space |
|
900 destroy .main_window.display.xscroller |
|
901 destroy .main_window.display.yscroller |
|
902 destroy .main_window.display |
|
903 init_display |
|
904 } |
|
905 |
|
906 proc spellcheck { word } { |
|
907 # spellchecks a word |
|
908 # could change to use spell or some faster program |
|
909 global x |
|
910 set x [exec echo $word | ispell -a] |
|
911 if { ([string last * $x] == -1) && ([string last + $x] == -1) } { |
|
912 return MISPELLED |
|
913 } else { |
|
914 return SPELLED_CORRECTLY |
|
915 } |
|
916 } |
|
917 |
|
918 |
|
919 #Not used right now |
|
920 proc box_begin { w x y } { |
|
921 global box |
|
922 set box(anchor) [list $x $y] |
|
923 catch {unset box(last)} |
|
924 } |
|
925 |
|
926 proc box_drag { w x y } { |
|
927 global box |
|
928 catch { $w delete $box(last) } |
|
929 set box(last) [eval {$w create rect -fill yellow} $box(anchor) {$x $y -tag box} ] |
|
930 } |
|
931 |
|
932 |
|
933 |
|
934 proc equation_mark { w x y } { |
|
935 global curline curline_startrow curline_endrow curline_startcol \ |
|
936 curline_endcol curx cury in_equation |
|
937 global prevline prevline_startrow prevline_endrow prevx prevy |
|
938 |
|
939 # have to adjust x and y for scrolling canvas |
|
940 set thisx [.main_window.display.work_space canvasx $x] |
|
941 set thisy [.main_window.display.work_space canvasy $y] |
|
942 |
|
943 # save the last mark |
|
944 set prevline $curline |
|
945 set prevline_startrow $curline_startrow |
|
946 set prevline_endrow $curline_endrow |
|
947 set prevx $curx |
|
948 set prevy $cury |
|
949 |
|
950 #set curline and prevline variables by calling Page::get_linenum |
|
951 |
|
952 GET_LINENUM $thisx $thisy |
|
953 |
|
954 set curx $thisx |
|
955 set cury $thisy |
|
956 |
|
957 if { $in_equation == 0 } { |
|
958 set in_equation 1 |
|
959 puts stdout "$curx $cury $curline $curline_startrow $curline_endrow" |
|
960 puts stdout "$curx $cury $prevline $prevline_startrow $prevline_endrow" |
|
961 |
|
962 } else { |
|
963 set in_equation 0 |
|
964 puts stdout "$curx $cury $curline $curline_startrow $curline_endrow" |
|
965 puts stdout "$curx $cury $prevline $prevline_startrow $prevline_endrow" |
|
966 if { $curline == $prevline } { |
|
967 .main_window.display.work_space create rectangle $prevx \ |
|
968 $prevline_startrow $curx $curline_endrow -fill yellow \ |
|
969 -outline black -stipple @grey.25 -tags IMAGE_TAG |
|
970 } else { |
|
971 # polygon is 8 points (9 to connect) which surrounds the equation |
|
972 .main_window.display.work_space create polygon \ |
|
973 $prevx $prevline_startrow \ |
|
974 $curline_endcol $prevline_startrow\ |
|
975 $curline_endcol $curline_startrow \ |
|
976 $curx $curline_startrow \ |
|
977 $curx $curline_endrow \ |
|
978 $curline_startcol $curline_endrow \ |
|
979 $curline_startcol $prevline_endrow \ |
|
980 $prevx $prevline_endrow \ |
|
981 $prevx $prevline_startrow \ |
|
982 -fill yellow -outline black -stipple @grey.25 -tags IMAGE_TAG |
|
983 } |
|
984 # argv[1] starting line of equation, [2] startcol [3] endline [4] endcol |
|
985 ADD_EQUATION $prevline $prevx $curline $curx |
|
986 |
|
987 } |
|
988 |
|
989 } |
|
990 |
|
991 |
|
992 proc equation_delete { w x y } { |
|
993 global curline curline_startrow curline_endrow curline_startcol \ |
|
994 curline_endcol curx cury in_equation |
|
995 global prevline prevline_startrow prevline_endrow prevx prevy |
|
996 global deleted |
|
997 set deleted 0 |
|
998 # have to adjust x and y for scrolling canvas |
|
999 set thisx [.main_window.display.work_space canvasx $x] |
|
1000 set thisy [.main_window.display.work_space canvasy $y] |
|
1001 |
|
1002 #deletes equation and sets prevline and curline vars for deletion |
|
1003 #also sets deleted var to 1 if equation was deleted 0 otherwise. |
|
1004 |
|
1005 DELETE_EQUATION $thisx $thisy |
|
1006 |
|
1007 |
|
1008 |
|
1009 puts stdout "$curx $cury $curline $curline_startrow $curline_endrow" |
|
1010 puts stdout "$curx $cury $prevline $prevline_startrow $prevline_endrow" |
|
1011 if { $deleted == 0 } { return 0 } |
|
1012 if { $curline == $prevline } { |
|
1013 .main_window.display.work_space create rectangle $prevx \ |
|
1014 $prevline_startrow $curx $curline_endrow -fill white \ |
|
1015 -outline white -stipple @grey.25 -tags IMAGE_TAG |
|
1016 } else { |
|
1017 # polygon is 8 points (9 to connect) which surrounds the equation |
|
1018 .main_window.display.work_space create polygon \ |
|
1019 $prevx $prevline_startrow \ |
|
1020 $curline_endcol $prevline_startrow\ |
|
1021 $curline_endcol $curline_startrow \ |
|
1022 $curx $curline_startrow \ |
|
1023 $curx $curline_endrow \ |
|
1024 $curline_startcol $curline_endrow \ |
|
1025 $curline_startcol $prevline_endrow \ |
|
1026 $prevx $prevline_endrow \ |
|
1027 $prevx $prevline_startrow \ |
|
1028 -fill white -outline white -stipple @grey.25 -tags IMAGE_TAG |
|
1029 } |
|
1030 } |
|
1031 |
|
1032 |
|
1033 |
|
1034 proc component_select { w x y } { |
|
1035 global curCompId validComponent |
|
1036 |
|
1037 set thisx [.main_window.display.work_space canvasx $x] |
|
1038 set thisy [.main_window.display.work_space canvasy $y] |
|
1039 SELECT_COMP $thisx $thisy |
|
1040 return $validComponent ;#Set in SELECT_COMP |
|
1041 |
|
1042 } |
|
1043 |
|
1044 proc init_global_menu { lst } { |
|
1045 global FOREGROUND BACKGROUND FONT |
|
1046 puts stdout "Entering init_global_menu \n" |
|
1047 |
|
1048 set gm [menu .main_window.menu_bar.options.menu.globals] |
|
1049 puts stdout "This is our frame " |
|
1050 puts stdout $gm |
|
1051 foreach var $lst { |
|
1052 set varWindow [string tolower $var] |
|
1053 frame $gm.$varWindow |
|
1054 label $gm.$varWindow.l -text $var -width 20 -fg $FOREGROUND -background $BACKGROUND -font $FONT |
|
1055 entry $gm.$varWindow.set -width 4 -relief sunken -textvariable $var -fg $FOREGROUND -background $BACKGROUND -font $FONT |
|
1056 pack $gm.$varWindow.l -side left |
|
1057 pack $gm.$varWindow.set -side right |
|
1058 pack $gm.$varWindow -side top |
|
1059 } |
|
1060 |
|
1061 } |
|
1062 |
|
1063 |
|
1064 init_user_interface |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |