Page d'accueil Description du projet
#!/usr/bin/wish

global EXEC
global WDIR

global ARRETS 
global ARRIVEE
global DEPART
global TCORRMIN
global CORRMAX
global J
global M
global A
global HOUR
global MINUTE

global LOG
global DETAILS

global DVERSION
global DTROUVES
global DIMPOSSI

set EXEC "./itinR"
set WDIR "."
set LOG ""
set DETAILS ""

set DVERSION ""
set DTROUVES ""
set DIMPOSSI ""

set ARRETS "horaires/TAG.arrets"
set DEPART ""
set ARRIVEE ""
set TCORRMIN 3
set CORRMAX 3
set J 1
set M 1
set A 2000
set HOUR 12
set MINUTE 00

wm title . "Itineraires grenoblois"

proc compare {a b} {
    set name1 [lrange $a 1 end]
    set name2 [lrange $b 1 end]
    set res [string compare "$name1" "$name2"]
    if {$res != 0} {
        return $res
    } else {
        return [[lindex $a 0] < [lindex $b 0]]
    }
}
    

proc liste_arret { } {
    global ARRETS
    set fid [ open $ARRETS ];
    set line [split [ gets $fid ] '='];
    set numligne [string trim [lindex $line 1]]
    #On ignore la ligne d'entete
    gets $fid 
    set liste {}
    for {set i 0} {$i < $numligne} {incr i 1} {
        set line [split [gets $fid] "\t:"];
        set num [format "%3s" [string trim [lindex $line 0]]];
        set nom [string trim [lindex $line 1]];
        set liste [linsert $liste end "$num $nom"]
    }
    close $fid
    return [lsort -command compare $liste ]
}


proc Scrolled_Listbox { f name args } {
        frame $f
        listbox $f.list -selectmode single -font 10 -xscrollcommand [list Scroll_Set $f.xscroll [list grid $f.xscroll -row 2 -column 0 -sticky we]] -yscrollcommand [list Scroll_Set $f.yscroll [ list grid $f.yscroll -row 1 -column 1 -sticky ns]]
        eval {$f.list configure} $args
        scrollbar $f.xscroll -orient horizontal -command [list $f.list xview]
        scrollbar $f.yscroll -orient vertical -command [list $f.list yview]
        label $f.label -text $name -font 10
        grid $f.label -sticky ews
        grid $f.list $f.yscroll -sticky new
        grid $f.xscroll -sticky news
        grid rowconfigure $f 0 -weight 1
        grid columnconfigure $f 0 -weight 1
        return $f.list
}
          
proc Scroll_Set { scrollbar geoCmd offset size } {
  if {$offset != 0.0 || $size != 1.0} {
    eval $geoCmd;
    $scrollbar set $offset $size
  } else {
    set manager [lindex $geoCmd 0]
    $manager forget $scrollbar ;
  }
}

proc Select_Dep {src} {
      global DEPART;
      set DEPART [$src get anchor]
}

proc Select_DepK {src} {
      global DEPART;
      set DEPART [$src get active]
}

proc Select_Arr {src} {
      global ARRIVEE
      set ARRIVEE [$src get anchor]
}

proc Select_ArrK {src} {
      global ARRIVEE
      set ARRIVEE [$src get active]
}

proc InitDetails {} {
    global DETAILS;
    global DVERSION;
    global DTROUVES;
    global DIMPOSSI;
        
    set DETAILS [toplevel .details ]
    frame .details.control
    frame .details.b
    frame .details.b.lbl
    frame .details.b.ety
    wm title .details "A propos de la recherche"
    button .details.control.close -text "close" -command {destroy .details} 
    label .details.b.lbl.lver -text "Version :                "
    label .details.b.lbl.ltro -text "Itineraires trouves :    "
    label .details.b.lbl.limp  -text "Itineraires impossibles :"
    entry .details.b.ety.ever -textvariable DVERSION -state disabled -width 5
    entry .details.b.ety.etro -textvariable DTROUVES -state disabled -width 5
    entry .details.b.ety.eimp -textvariable DIMPOSSI -state disabled -width 5
    pack .details.control.close 
    pack .details.b.lbl.lver .details.b.lbl.ltro .details.b.lbl.limp -side top -anchor w
    pack .details.b.ety.ever .details.b.ety.etro .details.b.ety.eimp -side top
    pack .details.b.lbl .details.b.ety -side left
    pack .details.control .details.b -side top
    bind .details <Destroy>  {set DETAILS ""}
}

proc OuvrirDetails {} {
    global DETAILS;
    if {"$DETAILS" == ""} {
        InitDetails
    } else {
        raise $DETAILS
    }
    
}

proc InitLog {} {
    global LOG
    toplevel .log 
    frame .log.control
    frame .log.data
    wm title .log "Resultat de la recherche"
    set LOG [listbox .log.data.text -width 80 -height 25 -yscrollcommand {.log.data.scroll set} ]
    button .log.control.clear -text "clear" -command {$LOG delete 0 end} 
    button .log.control.close -text "close" -command {destroy .log} 
    button .log.control.details -text "details" -command {OuvrirDetails} 
    scrollbar .log.data.scroll -command {.log.data.text yview}
    pack .log.control.clear .log.control.close .log.control.details -side left
    pack .log.data.text -side left -expand true
    pack .log.data.scroll -side right -fill y -expand true
    pack .log.control .log.data -side top 
    bind .log <Destroy>  {set LOG ""}
}



frame .data
frame .data.depart
frame .data.arrivee
frame .data.date
frame .data.date.j
frame .data.date.m
frame .data.date.a

frame .b
frame .b.scl
frame .b.control
frame .b.void
frame .b.scl.cmin  
frame .b.scl.cmax  
frame .b.scl.hlim  

proc init { } {
  set depart [Scrolled_Listbox .data.depart.depart "Arret de depart" -width 30 -height 8]
  set arrivee [Scrolled_Listbox .data.arrivee.arrivee "Arret d'arrivee" -width 30 -height 8]

  set L [liste_arret]
  foreach arret $L {
      $depart insert end $arret;
      $arrivee insert end $arret;
  }
#  Refresh $notmounted $mounted
  
  bind $depart <ButtonRelease-1> [list Select_Dep %W ] 
  bind $depart <space> [list Select_DepK %W ] 
  bind $arrivee <ButtonRelease-1> [list Select_Arr %W ] 
  bind $arrivee <space> [list Select_Arr %W ] 
}

proc Tps2Str { Hr Mn } {
    set shr "$Hr";
    set smn "$Mn";
    if {$Hr < 10} { set shr "0$Hr" }
    if {$Mn < 10} { set smn "0$Mn" }
    return "$shr$smn";
}

proc GenererQuery {} {
    global ARRIVEE
    global DEPART
    global TCORRMIN
    global CORRMAX
    global J
    global M
    global A
    global HOUR
    global MINUTE
    set fid [open "query" w 0644];
    set dnum [lindex [split [string trim "$DEPART"]] 0]
    set anum [lindex [split [string trim "$ARRIVEE"]] 0]
    puts $fid "Depart = $dnum"
    puts $fid "Arrivee = $anum"
    puts $fid "Limite = [Tps2Str $HOUR $MINUTE]"
    puts $fid "Nb Max de correspondances = $CORRMAX"
    puts $fid "Tps Corresp = [Tps2Str 0 $TCORRMIN]"
    puts $fid "Date = $J/$M/$A"
    close $fid
}

proc OuvrirLog {} {
    global LOG
    if {"$LOG" == ""} {
        InitLog
    } else {
        raise .log
        wm focus .log
    }
}

proc Rechercher {} {
    global ARRIVEE DEPART
    global EXEC WDIR
    global LOG
    global DVERSION DTROUVES DIMPOSSI
    if {"$DEPART" == ""} { return }
    if {"$ARRIVEE" == ""} { return }
    GenererQuery
    set result [split [exec "$EXEC" "$WDIR" "query"] "\n"]
    OuvrirLog
    
    set DVERSION [lindex [split [string trim [lindex $result 1]]] 4];
    set PosTrouve [lsearch -glob $result "-->*"]
    set DTROUVES [lindex [split [lindex $result $PosTrouve]] 1];
    set DIMPOSSI [string trim [lindex [split [lindex $result [expr $PosTrouve + 2]] ":"] 1]]
        
    set attn [lsearch -glob $result "ATTENTION : *"]
    while {$attn >= 0} {
        $LOG insert end "[lindex $result $attn] [string trim [lindex $result [expr $attn + 1]]]"
        set result [lrange $result [expr $attn + 2] end]
        set attn [lsearch -glob $result "ATTENTION : *"]
    }

    set debut [lsearch -glob $result " Depart : *"]
    foreach line [lrange $result $debut end] {
        $LOG insert end $line
    }
    $LOG see end

}





tk_setPalette background #bbbbff


init

label .b.scl.cmin.corrmin -text "Temps minimum de correspondance : ";
scale .b.scl.cmin.tcorrmin -from 0 -to 59 -variable TCORRMIN -orient horizontal -width 10;
label .b.scl.cmin.minutes -text "minutes"

label .b.scl.cmax.corrmax -text "Nombre maximum de correspondances : ";
scale .b.scl.cmax.ncorrmax -from 1 -to 10 -variable CORRMAX -orient horizontal -width 10;

label .b.scl.hlim.lhlim -text "Heure limite d'arrivee : ";
scale .b.scl.hlim.hour -from 0 -to 23 -variable HOUR -orient horizontal -width 10;

label .b.scl.hlim.semicolon -text " : ";
scale .b.scl.hlim.minute -from 0 -to 59 -variable MINUTE -orient horizontal -width 10;

label .data.date.j.ljour -text "Jour : ";
scale .data.date.j.jour -from 1 -to 31 -variable J -orient horizontal -width 10;

label .data.date.m.lmois -text "Mois : ";
scale .data.date.m.mois -from 1 -to 12 -variable M -orient horizontal -width 10;

label .data.date.a.lannee -text "Annee : ";
scale .data.date.a.annee -from 2000 -to 2010 -variable A -orient horizontal -width 10;


entry .data.depart.selected -width 30 -relief sunken -state disabled -textvariable DEPART
entry .data.arrivee.selected -width 30 -relief sunken -state disabled -textvariable ARRIVEE
button .b.control.exit -text "Exit" -font 10 -command exit -width 20
button .b.control.go -text "Rechercher" -font 10 -command Rechercher -width 20

pack .data.depart.depart -side top -expand true
pack .data.depart.selected -side top -expand true -anchor w
pack .data.arrivee.arrivee -side top -expand true
pack .data.arrivee.selected -side top -expand true -anchor w 
pack .data.date.j.ljour .data.date.j.jour -side left -expand true
pack .data.date.m.lmois .data.date.m.mois -side left -expand true
pack .data.date.a.lannee .data.date.a.annee -side left -expand true
pack .data.date.j .data.date.m .data.date.a -side top -expand true
pack .data.depart .data.arrivee .data.date -side left -expand true
pack .b.scl.cmin.corrmin .b.scl.cmin.tcorrmin .b.scl.cmin.minutes -side left -expand true 
pack .b.scl.cmax.corrmax .b.scl.cmax.ncorrmax -side left -expand true 
pack .b.scl.cmin  -side top -expand true -anchor w
pack .b.scl.cmax  -side top -expand true -anchor w
pack .b.scl.hlim.lhlim .b.scl.hlim.hour .b.scl.hlim.semicolon .b.scl.hlim.minute -side left -expand true -anchor w
pack .b.scl.hlim -side top -expand true -anchor w
pack .b.control.go .b.control.exit -side top -expand true -anchor e
pack .b.scl .b.void -side left -expand true -anchor w -fill x
pack .b.control -side left -expand true -anchor e -fill x -padx 30
pack .data .b -side top -expand true -anchor w