
#-------------------------------------------------------------------------------
# Module:     mainStatus.tk
# Activation: Loaded during GOBLET startup
# Scope:      Display operating mode, browser and library status information
#-------------------------------------------------------------------------------



frame .infobar
pack .infobar -side bottom -fill x

label .infobar.opMode -textvariable Mode -relief sunken -width 16 -padx 1m \
    -font -*-courier-medium-r-normal--*-120-*-*-p-*-*-* -anchor w
bind .infobar.opMode <Enter> {MakeBalloon2 "operating mode" .infobar.opMode}
bind .infobar.opMode <Leave> {DestroyBalloon}

label .infobar.times -textvariable SystemInfo -relief sunken -width 16 -padx 1m \
    -font -*-courier-medium-r-normal--*-120-*-*-p-*-*-* -anchor w
bind .infobar.times <Enter> {MakeSystemBalloon}
bind .infobar.times <Leave> {DestroyBalloon}
bind .infobar.times <Button-1> {
    incr SystemInfoType
    if {$SystemInfoType==5} {set SystemInfoType 1}
    UpdateSystemInfo
    MakeSystemBalloon
}
.infobar.times config -cursor exchange

label .infobar.current -textvariable StatusInfo -relief sunken -width 150 -padx 1m \
    -font -*-courier-medium-r-normal--*-120-*-*-p-*-*-* -anchor w
bind .infobar.current <Enter> {MakeBalloon2 "status info" .infobar.current}
bind .infobar.current <Leave> {DestroyBalloon}

pack .infobar.opMode -padx 1m -side left
pack .infobar.times -padx 1m -side right
pack .infobar.current -padx 1m -side left

proc UpdateSystemInfo {} {
    global StartTime PrevTime TotalTime SystemInfoType SystemInfo
    if {$SystemInfoType==1} {
        if {$PrevTime=="idle"} {
            set SystemInfo "idle"
        } else {
            if {$PrevTime!="running"} {
                set SystemInfo "$PrevTime seconds"
            } else {
                set SystemInfo "[expr [clock seconds]-$StartTime] seconds"
            }
        }
    }
    if {$SystemInfoType==2} {
        if {$PrevTime=="idle"} {
            set SystemInfo "idle"
        } else {
            if {$PrevTime!="running"} {
                set SystemInfo "$TotalTime seconds"
            } else {
                set SystemInfo "[expr [clock seconds]-$StartTime+$TotalTime] seconds"
            }
        }
    }
    if {$SystemInfoType==3} {set SystemInfo "[goblin size] bytes"}
    if {$SystemInfoType==4} {set SystemInfo "[goblin maxsize] bytes"}
}

proc MakeSystemBalloon {} {
    global SystemInfoType
    if {$SystemInfoType==1} {MakeBalloon2 "previous computation time" .infobar.times}
    if {$SystemInfoType==2} {MakeBalloon2 "total computation time" .infobar.times}
    if {$SystemInfoType==3} {MakeBalloon2 "current heap size" .infobar.times}
    if {$SystemInfoType==4} {MakeBalloon2 "maximum heap size" .infobar.times}
}
