Changeset 649
- Timestamp:
- Dec 4, 2009 5:09:42 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fillcif.tcl
- Property rcs:date changed from 2002/09/05 18:21:33 to 2002/09/05 20:59:20
- Property rcs:lines changed from +1 -1 to +209 -180
- Property rcs:rev changed from 1.2 to 1.3
r644 r649 1 #!/usr/bin/wish2 1 # A routine for editing CIF template file(s) adapted for specific 3 2 # use with GSAS2CIF. This program edits files template_*.cif or … … 5 4 # from the GSAS data directory ../data (relative to this file) 6 5 # 6 7 7 # $Id$ 8 8 … … 11 11 # These routines are included with EXPGUI 12 12 # 13 # 2) file browsecif.tcl must be in the same directory as this file14 # (Included with EXPGUI)13 # 2) files browsecif.tcl & gsascmds.tcl must be in the same directory as 14 # this file (Included with EXPGUI) 15 15 # 16 16 # 3) file CIF_index must be in the same directory as this file … … 112 112 } 113 113 114 proc EnableSaveEdits {w args} {115 global CIF116 if {$CIF(changes)} {117 $w config -state normal118 } else {119 $w config -state disabled120 }121 }122 114 123 115 proc SaveCIFtoFile {} { 124 116 global CIF 125 117 set CIF(changes) 0 118 set CIF(undolist) {} 119 set CIF(redolist) {} 126 120 # at least for the moment, keep the previous version 127 121 file rename -force $CIF(lastCIFfilename) $CIF(lastCIFfilename).old … … 152 146 } 153 147 154 proc ShowDefWindow {button window} {155 if {[lindex [$button cget -text] 0] == "Show"} {156 $button config -text "Hide CIF\nDefinitions"157 # this is an attempt to put the window under the browser158 set x [winfo x .]159 set y [expr 5 + [winfo y .] + [winfo height .]]160 wm geometry $window +$x+$y161 wm deiconify $window162 } else {163 $button config -text "Show CIF\nDefinitions"164 wm withdraw $window165 }166 }167 proc ShowCIFWindow {button window} {168 if {[lindex [$button cget -text] 0] == "Show"} {169 $button config -text "Hide CIF\nContents"170 # this is an attempt to put the window under the browser171 set x [winfo x .]172 set y [expr 5 + [winfo y .] + [winfo height .]]173 wm geometry $window +$x+$y174 wm deiconify $window175 } else {176 $button config -text "Show CIF\nContents"177 wm withdraw $window178 }179 }180 181 proc ParseShowCIF {frame} {182 global CIF183 184 # check for edits in progress185 if {[CheckForCIFEdits]} return186 # check for unsaved changes here187 if {$CIF(changes) != 0} {188 set ans [MyMessageBox -parent . -title "Discard Changes?" \189 -message "You have changed this CIF. Do you want to save or discard your changes?" \190 -icon question -type {Save Discard Cancel} -default Save]191 if {$ans == "save"} {192 SaveCIFtoFile193 } elseif {$ans == "cancel"} {194 set CIF(CIFfilename) $CIF(lastCIFfilename)195 return196 }197 }198 set CIF(changes) 0199 200 $CIF(txt) delete 1.0 end201 set CIF(maxblocks) [ParseCIF $CIF(txt) $CIF(CIFfilename)]202 set CIF(lastCIFfilename) $CIF(CIFfilename)203 wm title . "CIF Browser: file $CIF(CIFfilename)"204 205 set allblocks {}206 if {[array names block0] != ""} {207 set i 0208 } else {209 set i 1210 }211 set errors {}212 for {} {$i <= $CIF(maxblocks)} {incr i} {213 lappend allblocks $i214 if {![catch {set block${i}(errors)} errmsg]} {215 append errors "Block $i ([set block${i}(data_)]) errors: [set block${i}(errors)]\n"216 }217 if {$errors != ""} {218 MyMessageBox -parent . -title "CIF errors" \219 -message "Note: file $CIF(CIFfilename) has errors.\n$errors" \220 -icon error -type Continue -default continue221 }222 }223 224 if {$allblocks != ""} {225 CIFBrowser $CIF(txt) $allblocks "" $frame226 }227 }228 229 # create window/text widget for CIF file230 catch {destroy [set file .file]}231 toplevel $file232 wm title $file "CIF file contents"233 bind $file <Key-F1> "MakeWWWHelp gsas2cif.html filltemplate"234 set CIF(txt) $file.t235 grid [text $CIF(txt) -height 10 -width 80 -yscrollcommand "$file.s set"] \236 -col 0 -row 0 -sticky news237 grid [scrollbar $file.s -command "$CIF(txt) yview"] -col 1 -row 0 -sticky ns238 grid columnconfig $file 0 -weight 1239 grid rowconfig $file 0 -weight 1240 # hide it241 wm withdraw $file242 243 # create window/text widget for the CIF definition244 catch {destroy [set defw .def]}245 toplevel $defw246 bind $defw <Key-F1> "MakeWWWHelp gsas2cif.html filltemplate"247 wm title $defw "CIF definitions"248 set CIF(defBox) $defw.t249 grid [text $CIF(defBox) -width 65 -xscrollcommand "$defw.x set" \250 -yscrollcommand "$defw.y set"] -col 0 -row 0 -sticky news251 grid [scrollbar $defw.y -command "$CIF(defBox) yview"] -col 1 -row 0 -sticky ns252 grid [scrollbar $defw.x -command "$CIF(defBox) xview" \253 -orient horizontal] -col 0 -row 1 -sticky ew254 grid columnconfig $defw 0 -weight 1255 grid rowconfig $defw 0 -weight 1256 # hide it257 wm withdraw $defw258 259 if {![file exists [file join $scriptdir CIF_index]]} {260 MyMessageBox -parent . -title "No CIF index" \261 -message "File CIF_index was not found in directory $scriptdir. Without this file, CIF definitions can not be read and editing is not recommended. See routine indexCIFdict.tcl for info on creating CIF_index" \262 -icon error -type {"Oh darn"} -default "oh darn"263 } elseif [catch {264 source [file join $scriptdir CIF_index]265 } errmsg] {266 MyMessageBox -parent . -title "CIF index error" \267 -message "An error occured reading file CIF_index (directory $scriptdir). Without this file, CIF definitions can not be read and editing is not recommended. See routine indexCIFdict.tcl for info on creating CIF_index. Error: $errmsg" \268 -icon error -type {"Oh darn"} -default "oh darn"269 }270 271 272 # add location of these files & the typical GSAS data directory273 # to the dictionary search path274 lappend CIF(cif_path) $scriptdir [file join [file dirname $scriptdir] data]275 276 # make frame for the CIF browser277 wm title . "CIF Browser"278 grid [set CIF(browserBox) [frame .top]] -column 0 -row 0 -sticky ew279 grid [set box [frame .box]] -column 0 -row 1 -sticky ew280 281 set filemenu [tk_optionMenu $box.file CIF(CIFfilename) ""]282 $box.file config -width 25283 $filemenu delete 0 end284 foreach f $CIF(filelist) {285 $filemenu add radiobutton -value $f -label $f -variable CIF(CIFfilename) \286 -command "ParseShowCIF $CIF(browserBox)"287 }288 289 set col -1290 grid [label $box.lf -text "template\nfile:"] -column [incr col] \291 -row 1 -rowspan 2292 grid $box.file -column [incr col] -row 1 -rowspan 2 -sticky w293 grid [button $box.next -text "Next ? in\ntemplate" \294 -command NextCIFtemplate] -column [incr col] -row 1 -rowspan 2295 grid columnconfig $box $col -weight 1296 incr col297 grid [button $box.c -text Exit -command ConfirmDestroy] \298 -column [incr col] -row 1 -rowspan 2 -sticky w299 wm protocol . WM_DELETE_WINDOW ConfirmDestroy300 grid columnconfig $box $col -weight 1301 incr col302 grid [button $box.f -text "Show CIF\nContents" \303 -command "ShowCIFWindow $box.f $file"] -column [incr col] \304 -row 1 -rowspan 2305 wm protocol $file WM_DELETE_WINDOW "ShowCIFWindow $box.f $file"306 grid [button $box.d -text "Show CIF\nDefinitions" \307 -command "ShowDefWindow $box.d $defw"] -column [incr col] \308 -row 1 -rowspan 2 -sticky w309 wm protocol $defw WM_DELETE_WINDOW "ShowDefWindow $box.d $defw"310 311 grid [button $box.6 -text "Save\nEdits" \312 -command SaveCIFtoFile -state disabled] -column [incr col] \313 -row 1 -rowspan 2314 grid [checkbutton $box.7a -text "Auto-Accept" \315 -variable CIF(autosave_edits)] -column [incr col] -row 1 -sticky w316 grid [checkbutton $box.7b -text "Auto-Save" \317 -variable CIF(autosavetodisk)] -column $col -row 2 -sticky w318 grid [button $box.help -text Help -bg yellow \319 -command "MakeWWWHelp gsas2cif.html filltemplate"] \320 -column [incr col] -row 1 -rowspan 2 -sticky nw321 322 set CIF(autosavetodisk) 0323 set CIF(editmode) 1324 set CIF(changes) 0325 trace variable CIF(changes) w "EnableSaveEdits $box.6"326 set CIF(CIFfilename) [lindex $CIF(filelist) 0]327 CIFBrowserWindow $CIF(browserBox)328 ParseShowCIF $CIF(browserBox)329 330 #------- work in progress331 332 set CIF(TemplateIgnoreList) {_journal_*}333 334 148 proc NextCIFtemplate {} { 335 149 global CIF CIFtreeindex 150 if {[CheckForCIFEdits]} return 336 151 set loopindex "" 337 152 set pointer "" … … 361 176 } 362 177 # go on to the next file 363 if {[CheckForCIFEdits]} return364 178 if {$CIF(changes) != 0 && $CIF(autosavetodisk)} { 365 179 SaveCIFtoFile … … 407 221 proc FindNextCIFQuestionMark {block dataname loopindex} { 408 222 global CIF 409 # make a list of blocks 410 set allblocks {} 411 global block0 412 if {[array names block0] != ""} { 413 set i 0 414 } else { 415 set i 1 416 } 417 for {} {$i <= $CIF(maxblocks)} {incr i} { 418 lappend allblocks block${i} 419 } 420 421 set i [lsearch $allblocks $block] 422 if {$i != -1} { 423 set blocklist [lrange $allblocks $i end] 424 } else { 425 set blocklist $allblocks 426 } 223 224 set blocklist {} 225 foreach i $CIF(blocklist) { 226 if {$block == "block$i"} { 227 set blocklist block$i 228 } else { 229 lappend blocklist block$i 230 } 231 } 232 427 233 set first -1 428 234 foreach n $blocklist { … … 487 293 } 488 294 } 295 296 proc ShowDefWindow {button window} { 297 if {[lindex [$button cget -text] 0] == "Show"} { 298 $button config -text "Hide CIF\nDefinitions" 299 # this is an attempt to put the window under the browser 300 set x [winfo x .] 301 set y [expr 5 + [winfo y .] + [winfo height .]] 302 wm geometry $window +$x+$y 303 wm deiconify $window 304 } else { 305 $button config -text "Show CIF\nDefinitions" 306 wm withdraw $window 307 } 308 } 309 proc ShowCIFWindow {button window} { 310 if {[lindex [$button cget -text] 0] == "Show"} { 311 $button config -text "Hide CIF\nContents" 312 # this is an attempt to put the window under the browser 313 set x [winfo x .] 314 set y [expr 5 + [winfo y .] + [winfo height .]] 315 wm geometry $window +$x+$y 316 wm deiconify $window 317 } else { 318 $button config -text "Show CIF\nContents" 319 wm withdraw $window 320 } 321 } 322 323 proc ParseShowCIF {frame} { 324 global CIF 325 # check for edits in progress 326 if {[CheckForCIFEdits]} return 327 # check for unsaved changes here 328 if {$CIF(changes) != 0} { 329 set ans [MyMessageBox -parent . -title "Discard Changes?" \ 330 -message "You have changed this CIF. Do you want to save or discard your changes?" \ 331 -icon question -type {Save Discard Cancel} -default Save] 332 if {$ans == "save"} { 333 SaveCIFtoFile 334 } elseif {$ans == "cancel"} { 335 set CIF(CIFfilename) $CIF(lastCIFfilename) 336 return 337 } 338 } 339 set CIF(changes) 0 340 set CIF(undolist) {} 341 set CIF(redolist) {} 342 343 $CIF(txt) configure -state normal 344 $CIF(txt) delete 1.0 end 345 $CIF(txt) configure -state disabled 346 foreach i $CIF(blocklist) { 347 global block$i 348 unset block$i 349 } 350 set CIF(maxblocks) [ParseCIF $CIF(txt) $CIF(CIFfilename)] 351 set CIF(lastCIFfilename) $CIF(CIFfilename) 352 wm title . "CIF Browser: file $CIF(CIFfilename)" 353 354 # make a list of blocks 355 set CIF(blocklist) {} 356 set errors {} 357 global block0 358 if {[array names block0] != ""} { 359 set i 0 360 } else { 361 set i 1 362 } 363 for {} {$i <= $CIF(maxblocks)} {incr i} { 364 lappend CIF(blocklist) ${i} 365 if {![catch {set block${i}(errors)} errmsg]} { 366 append errors "Block $i ([set block${i}(data_)]) errors: [set block${i}(errors)]\n" 367 } 368 if {$errors != ""} { 369 MyMessageBox -parent . -title "CIF errors" \ 370 -message "Note: file $CIF(CIFfilename) has errors.\n$errors" \ 371 -icon error -type Continue -default continue 372 } 373 } 374 375 if {$CIF(blocklist) != ""} { 376 CIFBrowser $CIF(txt) $CIF(blocklist) "" $frame 377 } 378 } 379 380 # create window/text widget for CIF file 381 catch {destroy [set file .file]} 382 toplevel $file 383 wm title $file "CIF file contents" 384 bind $file <Key-F1> "MakeWWWHelp gsas2cif.html filltemplate" 385 386 set CIF(txt) $file.t 387 grid [text $CIF(txt) -height 10 -width 80 -yscrollcommand "$file.s set"] \ 388 -col 0 -row 0 -sticky news 389 grid [scrollbar $file.s -command "$CIF(txt) yview"] -col 1 -row 0 -sticky ns 390 grid columnconfig $file 0 -weight 1 391 grid rowconfig $file 0 -weight 1 392 # hide it 393 wm withdraw $file 394 395 # create window/text widget for the CIF definition 396 catch {destroy [set defw .def]} 397 toplevel $defw 398 bind $defw <Key-F1> "MakeWWWHelp gsas2cif.html filltemplate" 399 wm title $defw "CIF definitions" 400 set CIF(defBox) $defw.t 401 grid [text $CIF(defBox) -width 65 -xscrollcommand "$defw.x set" \ 402 -yscrollcommand "$defw.y set"] -col 0 -row 0 -sticky news 403 grid [scrollbar $defw.y -command "$CIF(defBox) yview"] -col 1 -row 0 -sticky ns 404 grid [scrollbar $defw.x -command "$CIF(defBox) xview" \ 405 -orient horizontal] -col 0 -row 1 -sticky ew 406 grid columnconfig $defw 0 -weight 1 407 grid rowconfig $defw 0 -weight 1 408 # hide it 409 wm withdraw $defw 410 411 if {![file exists [file join $scriptdir CIF_index]]} { 412 MyMessageBox -parent . -title "No CIF index" \ 413 -message "File CIF_index was not found in directory $scriptdir. Without this file, CIF definitions can not be read and editing is not recommended. See routine indexCIFdict.tcl for info on creating CIF_index" \ 414 -icon error -type {"Oh darn"} -default "oh darn" 415 } elseif [catch { 416 source [file join $scriptdir CIF_index] 417 } errmsg] { 418 MyMessageBox -parent . -title "CIF index error" \ 419 -message "An error occured reading file CIF_index (directory $scriptdir). Without this file, CIF definitions can not be read and editing is not recommended. See routine indexCIFdict.tcl for info on creating CIF_index. Error: $errmsg" \ 420 -icon error -type {"Oh darn"} -default "oh darn" 421 } 422 423 424 # add location of these files & the typical GSAS data directory 425 # to the dictionary search path 426 lappend CIF(cif_path) $scriptdir [file join [file dirname $scriptdir] data] 427 428 # make frame for the CIF browser 429 wm title . "CIF Browser" 430 grid [set CIF(browserBox) [frame .top]] -column 0 -row 0 -sticky ew 431 grid [set box [frame .box]] -column 0 -row 1 -sticky ew 432 433 set filemenu [tk_optionMenu $box.file CIF(CIFfilename) ""] 434 $box.file config -width 25 435 $filemenu delete 0 end 436 foreach f $CIF(filelist) { 437 $filemenu add radiobutton -value $f -label $f -variable CIF(CIFfilename) \ 438 -command "ParseShowCIF $CIF(browserBox)" 439 } 440 441 set col -1 442 grid [label $box.lf -text "template\nfile:"] -column [incr col] \ 443 -row 1 -rowspan 2 444 grid $box.file -column [incr col] -row 1 -rowspan 2 -sticky w 445 grid [button $box.next -text "Next ? in\ntemplate" \ 446 -command NextCIFtemplate] -column [incr col] -row 1 -rowspan 2 447 grid columnconfig $box $col -weight 1 448 incr col 449 grid [button $box.c -text Exit -command ConfirmDestroy] \ 450 -column [incr col] -row 1 -rowspan 2 -sticky w 451 grid columnconfig $box $col -weight 1 452 453 incr col 454 grid [button $box.f -text "Show CIF\nContents" \ 455 -command "ShowCIFWindow $box.f $file"] -column [incr col] \ 456 -row 1 -rowspan 2 457 grid [button $box.d -text "Show CIF\nDefinitions" \ 458 -command "ShowDefWindow $box.d $defw"] -column [incr col] \ 459 -row 1 -rowspan 2 -sticky w 460 461 incr col 462 grid [button $box.u -text "Undo" -command UndoChanges \ 463 -state disabled] \ 464 -column $col -row 1 -rowspan 2 -sticky w 465 incr col 466 grid [button $box.r -text "Redo" -command RedoChanges \ 467 -state disabled] \ 468 -column $col -row 1 -rowspan 2 -sticky w 469 470 incr col 471 grid [button $box.6 -text "Save" \ 472 -command SaveCIFtoFile -state disabled] -column $col \ 473 -row 1 474 grid [checkbutton $box.7b -text "Auto-Save" \ 475 -variable CIF(autosavetodisk)] -column $col -columnspan 2 \ 476 -row 2 -sticky w 477 478 grid [button $box.help -text Help -bg yellow \ 479 -command "MakeWWWHelp gsas2cif.html filltemplate"] \ 480 -column [incr col] -row 1 -rowspan 2 -sticky nw 481 482 set CIF(autosavetodisk) 0 483 set CIF(editmode) 1 484 485 wm protocol . WM_DELETE_WINDOW ConfirmDestroy 486 wm protocol $file WM_DELETE_WINDOW "ShowCIFWindow $box.f $file" 487 wm protocol $defw WM_DELETE_WINDOW "ShowDefWindow $box.d $defw" 488 489 trace variable CIF(changes) w "EnableSaveEdits $box.6" 490 proc EnableSaveEdits {w args} { 491 global CIF 492 if {$CIF(changes)} { 493 $w config -state normal 494 } else { 495 $w config -state disabled 496 } 497 } 498 trace variable CIF(undolist) w "EnableUndo $box.u undolist" 499 trace variable CIF(redolist) w "EnableUndo $box.r redolist" 500 proc EnableUndo {w var args} { 501 global CIF 502 if {[llength $CIF($var)] > 0} { 503 $w config -state normal 504 } else { 505 $w config -state disabled 506 } 507 } 508 509 set CIF(blocklist) {} 510 set CIF(CIFfilename) [lindex $CIF(filelist) 0] 511 CIFBrowserWindow $CIF(browserBox) 512 ParseShowCIF $CIF(browserBox) 513 514 #------- work in progress 515 516 set CIF(TemplateIgnoreList) {_journal_*} 517
Note: See TracChangeset
for help on using the changeset viewer.