Changeset 664


Ignore:
Timestamp:
Dec 4, 2009 5:09:57 PM (11 years ago)
Author:
toby
Message:

# on 2002/12/30 17:00:34, toby did:
updated pleasewait
implement CIF(maxvalues) to control max CIF size
define contents of CIF(status) , to be displayed on "pleasewait" & check

CIF size against maximum

check to see if skip forward is in fact going backwards (prevent infinite loop)
scroll text box while parsing -- looks neat!
implement (&comment out) multiple selection of looped items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/browsecif.tcl

    • Property rcs:date changed from 2002/09/24 20:49:58 to 2002/12/30 17:00:34
    • Property rcs:lines changed from +8 -1 to +76 -20
    • Property rcs:rev changed from 1.4 to 1.5
    r654 r664  
    292292
    293293# tell'em what is happening
    294 proc pleasewait {{message {}}} {
     294proc pleasewait {{message {}} {statusvar {}} {parent .} {button ""}} {
    295295    catch {destroy .msg}
    296296    toplevel .msg
    297297    wm transient .msg [winfo toplevel .]
    298298    pack [frame .msg.f -bd 4 -relief groove] -padx 5 -pady 5
    299     pack [message .msg.f.m -text "Please wait $message"]
     299    pack [message .msg.f.m -text "Please wait $message"] -side top
     300    if {$statusvar != ""} {
     301        pack [label .msg.f.status -textvariable $statusvar] -side top
     302    }
     303    if {$button != ""} {
     304        pack [button .msg.f.button -text [lindex $button 0] \
     305                -command [lindex $button 1]] -side top
     306    }
    300307    wm withdraw .msg
    301308    update idletasks
    302     # place the message on top of the main window
    303     set x [expr [winfo x .] + [winfo width .]/2 - \
    304             [winfo reqwidth .msg]/2 - [winfo vrootx .]]
     309    # place the message on top of the parent window
     310    set x [expr [winfo x $parent] + [winfo width $parent]/2 - \
     311            [winfo reqwidth .msg]/2 - [winfo vrootx $parent]]
    305312    if {$x < 0} {set x 0}
    306     set y [expr [winfo y .] + [winfo height .]/2 - \
    307             [winfo reqheight .msg]/2 - [winfo vrooty .]]
     313    set y [expr [winfo y $parent] + [winfo height $parent]/2 - \
     314            [winfo reqheight .msg]/2 - [winfo vrooty $parent]]
    308315    if {$y < 0} {set y 0}
    309316    wm geom .msg +$x+$y
     
    389396#------------------------------------------------------------------------------
    390397
    391 #------------------------------------------------------------------------------# ParseCIF reads and parses a CIF file putting the contents of
     398#------------------------------------------------------------------------------
     399# ParseCIF reads and parses a CIF file putting the contents of
    392400# each block into arrays block1, block2,... in the caller's level
    393401#    the name of the block is saved as blockN(data_)
     
    431439    }
    432440
     441    # maximum size of file
     442    set maxvalues 0
     443    catch {
     444        set maxvalues $CIF(maxvalues)
     445    }
    433446
    434447    set CIF(undolist) {}
     
    447460    # loop over tokens
    448461    while {$EOF} {
     462        if {$CIF(markcount) % 1000 == 0} {
     463            $txt see $pos
     464            set CIF(status) "($CIF(markcount) values read.)"
     465            update
     466            # are we over the limit?
     467            if {$maxvalues > 0 && $CIF(markcount) > $maxvalues} {
     468                donewait
     469                set msg "Too many data values to parse; stopping at $CIF(markcount), line [lindex [split $pos .] 0].\n\nIf your computer has sufficient memory to read more, increase CIF(maxvalues) in cifedit.tcl"
     470                set ans [MyMessageBox -parent . -title "CIF Too big" \
     471                        -message $msg -icon error -type "{Stop Parsing}" \
     472                        -default "stop parsing"]
     473               
     474                return $blocks
     475            }
     476        }
    449477        # skip forward to the first non-blank character
    450         set pos [$txt search -regexp {[^[:space:]]} $pos end]
     478        set npos [$txt search -regexp {[^[:space:]]} $pos end]
    451479        # is this the end?
    452         if {$pos == ""} {
     480        if {$npos == "" || \
     481                [lindex [split $npos .] 0] < [lindex [split $pos .] 0] } {
    453482            set EOF 0
    454483            break
     484        } else {
     485            set pos $npos
    455486        }
    456487
     
    463494        # find end of token
    464495        set epos [$txt search -regexp {[[:space:]]} $pos "$pos lineend"]
    465         if {$epos == ""} {set epos [$txt index "$pos lineend"]}
     496        if {$epos == ""} {
     497            set epos [$txt index "$pos lineend"]
     498        }
    466499
    467500        set token [$txt get $pos $epos]
     
    683716        }
    684717    }
     718    $txt see 1.0
    685719    return $blocks
    686720}
    687721
    688 #------------------------------------------------------------------------------# Create a CIF browser/editor
     722#------------------------------------------------------------------------------
     723# Create a CIF browser/editor
    689724#  $txt is a text widget with the entire CIF loaded
    690725#  blocklist contains the list of defined blocks (by #)
     
    695730    toplevel $frame
    696731    wm title $frame "CIF Browser"
    697     CIFBrowserWindow $frame
     732    CIFOpenBrowser $frame
    698733    CIFBrowser $txt $blocklist $selected $frame
    699734    grid [button $frame.c -text Close -command "destroy $frame"] -column 0 -row 1
     
    785820#   (where $frame is a frame or toplevel)
    786821#   note that the BWidget package is required
    787 proc CIFBrowserWindow {frame} {
     822proc CIFOpenBrowser {frame} {
    788823    global CIF
    789824    if [catch {package require BWidget}] {
     
    878913
    879914    global CIF
    880     set pointer [$CIF(tree) itemcget $name -data]
    881     set dataname [lindex [$CIF(tree) itemcget $name -text] 0]
    882     set CIF(lastShownTreeID) $name
    883     showCIFbyDataname $pointer $dataname
     915    # code to allow multiple selection within loops
     916    #set loopname [lindex [$CIF(tree) itemcget $name -data] 1]
     917    #set addtolist 1
     918    #if {$loopname == "" || $loopname == "loop"} {set addtolist 0}
     919    #foreach n $CIF(treeSelectedList) {
     920        #if {$loopname != [lindex [$CIF(tree) itemcget $n -data] 1]} {
     921        #    set addtolist 0
     922        #    break
     923        #}
     924    #}
     925    #if {$addtolist} {
     926        #catch {$CIF(tree) itemconfigure $name -fill red}
     927        #lappend CIF(treeSelectedList) $name
     928    #} else {
     929        foreach n $CIF(treeSelectedList) {
     930            catch {$CIF(tree) itemconfigure $n -fill black}
     931        }
     932        set CIF(treeSelectedList) $name
     933        catch {$CIF(tree) itemconfigure $name -fill red}
     934        set CIF(lastShownTreeID) $name
     935        set pointer [$CIF(tree) itemcget $name -data]
     936        set dataname [lindex [$CIF(tree) itemcget $name -text] 0]
     937        showCIFbyDataname $pointer $dataname
     938    #}
    884939}
    885940
     
    901956        return
    902957    }
    903     # create list of defined widgets
     958    # create list of widgets defined here
    904959    set CIF(widgetlist) {}
    905960
     
    15091564    # if this widget is a label, the info above will not be defined & checks are not needed
    15101565    if {$dataname == ""} {return 0}
     1566    if {$dataname == "errors"} {return 0}
    15111567
    15121568    global ${block}
Note: See TracChangeset for help on using the changeset viewer.