# TimeStamp (unix) : 13 Décembre 99 17:13 -- listgh.tcl ## ## /***************************************************************/ ## /* */ ## /* listgh.tcl - (gH) 1999 : */ ## /* */ ## /* +================================================+ */ ## /* + + */ ## /* + permet de voir le contenu de fichiers texte + */ ## /* + + */ ## /* +================================================+ */ ## /* */ ## /* */ ## /* fonctionne avec tcl/tk 8.0 ou supérieur */ ## /* */ ## /* sous Windows ET sous Linux */ ## /* */ ## /* installe de nombreux raccourcis clavier */ ## /* */ ## /***************************************************************/ ## /* */ ## /* Auteur */ ## /* */ ## /* gilles.hunault@univ-angers.fr */ ## /* http://www.info.univ-angers.fr/~gh/index.html */ ## /* */ ## /* d'après un logiciel original sous Dos nommé LIST */ ## /* de Vernon D. Buerg */ ## /* */ ## /***************************************************************/ ## proc avertit { texteAver } { set repu [tk_messageBox -type ok -message $texteAver -icon warning -title " pour Information " ] }; # fin de proc avertit proc tailleWin { parm } { # utilise tout l'écran pour un affichage maximal ou à 80% pour un affichage réduit set ww [winfo screenwidth .] ; set wh [winfo screenheight .] ; set decale 0 if { $parm == 0 } { set ww [expr round($ww*0.8)] ; set wh [expr round($wh*0.8)] ; set decale 30 } ; # fin si set ghm "wm geometry . $ww" ; append ghm "x$wh+$decale+$decale" ; eval $ghm } ; # fin proc tailleWin proc remonteRep { } { global chemin ; # remonte au répertoire père cd .. ; set chemin [pwd] ; changeRep } ; # fin proc remonteRep proc descendRep { } { global chemin specsf ; # descend dans le premier répertoire set ochemin [pwd] ; catch { unset ldr } set tdr [glob -nocomplain -- [file join *] ] set i 0 ; set nfr 0 foreach fn $tdr { if { [file isdirectory $fn] } { if { $nfr == 0 } { set nfr $fn ; set i [incr i ] } } ; # fin de si } ; # fin de pourchaque if { $i>0 } { cd $nfr } else { cd $ochemin } set chemin [pwd] ; changeRep } ; # fin proc descendRep proc suitRep { } { global chemin specsf ; # va dans le sous-répertoire suivant au même niveau set ochemin $chemin ; cd .. ; set chemin [pwd] catch { unset ldr } ; set tdr [glob -nocomplain -- [file join *] ] set i 0 ; set nfr 0 foreach fn $tdr { if { [file isdirectory $fn] } { set i [incr i ] ; set ldr($i) $fn ; set nrc [file join $chemin $fn] if { $nrc == $ochemin } { set nfr $i } } ; # fin de si } ; # fin de pourchaque if { $i>0 } { set as [array size ldr] ; set rfi [incr nfr] if { $rfi < 1 } { set rfi $as } ; if { $rfi > $as } { set rfi 1 } cd $ldr($rfi) } else { cd $ochemin } set chemin [pwd] ; changeRep } ; # fin proc suitRep proc changeSpecs { } { global nfi ldf chemin ordf specsf ; # change les spécifs de fichier set especsf $specsf catch { destroy .fspec } toplevel .fspec wm title .fspec " File specifications " wm geometry .fspec "+100+200" label .fspec.la -font { System 14 bold } -text " Fichiers ? " -bg blue -fg yellow entry .fspec.en -font { System 14 bold } -textvariable especsf bind .fspec.en { finSpecs $especsf } pack .fspec.la -side left pack .fspec.en -side right focus -force .fspec.en } ; # fin proc changeSpecs proc finSpecs { nspecsf } { global nfi ldf chemin ordf specsf ; # change les spécifs de fichier if { [llength $nspecsf]==0 } { set nspecsf "*" } set specsf $nspecsf catch { destroy .fspec.la .fspec.bu .fspec.en } catch { destroy .fspec } changeRep focus -force .list } ; # fin proc finSpecs proc changeOrdre { } { global nfi ldf chemin ordf set ordf [incr ordf] if { $ordf == 7 } { set ordf 1 } changeRep } ; # fin proc changeOrdre proc changeNumLig { } { global nfi ldf chemin ordf alndl set alndl [incr alndl ] if { $alndl == 2 } { set alndl 0 } changeRep } ; # fin proc changeOrdre proc changeInfo { } { global nfi ldf chemin ordf alndl mdinf set mdinf [incr mdinf ] if { $mdinf == 2 } { set mdinf 0 } if { $mdinf == 1 } { .list.status.s9 configure -text " t " } if { $mdinf == 0 } { .list.status.s9 configure -text " i " } changeRep } ; # fin proc changeOrdre proc changeRep { } { global nfi ldf chemin ordf specsf ; # gère l'affichage de gauche quand on change de répertoire .list.milieu.g.tgauche delete 1.0 end catch { unset ldf } ; cd $chemin ; set tdf [glob -nocomplain -- [file join $specsf ] ] set nfi [incr nfi] # construction de la liste des fichiers set i 0 foreach fn $tdf { if { ![file isdirectory $fn] } { set i [incr i ] ; set ldf($i) $fn ; } ; # fin de si } ; # fin de pourchaque set nbfic $i # tri de la liste des fichiers selon la variable order set i 1 while { $i <= [expr $nbfic -1] } { set j $i while { $j <= $nbfic } { if { $ordf == 0 } { set v1 0 ; set v2 1 } if { $ordf == 1 } { set v1 $ldf($i) ; set v2 $ldf($j) } if { $ordf == 2 } { set v1 $ldf($j) ; set v2 $ldf($i) } if { $ordf == 3 } { set v1 [file size $ldf($i)] ; set v2 [file size $ldf($j)] } if { $ordf == 4 } { set v1 [file size $ldf($j)] ; set v2 [file size $ldf($i)] } if { $ordf == 5 } { set v1 [file mtime $ldf($i)] ; set v2 [file mtime $ldf($j)] } if { $ordf == 6 } { set v1 [file mtime $ldf($j)] ; set v2 [file mtime $ldf($i)] } if { $v1 > $v2 } { ; # on permute les fichiers set lndf $ldf($i) set ldf($i) $ldf($j) set ldf($j) $lndf } ; # fin de si set j [incr j ] } ; # fin de tant que sur j set i [incr i ] } ; # fin tant que sur i # affichage de la liste des fichiers set i 1 while { $i <= $nbfic } { set fn $ldf($i) .list.milieu.g.tgauche insert insert "$fn\n" set i [incr i ] } ; # fin de pourchaque .list.milieu.g.tgauche tag add cur 1.0 1.end set nfi 1 ; if { $i == 0 } { set nfi 0 } if { $nbfic == 0 } { set nfi 0 } metAjour $nfi } ; # fin proc changeRep proc changeFic { pas } { global nfi ldf ; # change de fichier dans le répertoire ; 0.1 -> 1st, 0.2 last, 0.3 previous if { $nfi > 0 } { .list.milieu.g.tgauche tag remove cur 1.0 end set as [array size ldf] if { $pas > 0.9 } { set nfi [incr nfi $pas] } if { $pas == 0.1 } { set nfi 1 } if { $pas == 0.2 } { set nfi $as } if { $pas == 0.3 } { set nfi [expr $nfi-1] } if { $nfi < 1 } { set nfi $as } if { $nfi > $as } { set nfi 1 } .list.milieu.g.tgauche tag add cur $nfi.0 $nfi.end if { $nfi < [expr $as/4 ] } { .list.milieu.g.tgauche yview moveto 0.00 } if { $nfi > [expr $as/4 ] } { .list.milieu.g.tgauche yview moveto 0.20 } if { $nfi > [expr $as/2 ] } { .list.milieu.g.tgauche yview moveto 0.40 } if { $nfi > [expr 3*$as/4 ] } { .list.milieu.g.tgauche yview moveto 0.60 } if { $nfi > [expr 7*$as/8 ] } { .list.milieu.g.tgauche yview moveto 0.80 } metAjour $nfi } ; # fin de si # .list.status.s6 configure -text $nfi } ; # fin proc changeFic proc metAjour { num } { global nfi ldf tailp alndl mdinf specsf ; # gère le panneau de droite etc. pour un fichier donné .list.milieu.d.tdroite delete 1.0 end ; .list.entete.ch configure -text "[pwd]/$specsf" if { $nfi == 0 } { # s'il n'y a pas de fichier... if { $specsf == "*" } { .list.milieu.d.tdroite insert insert "\n Aucun fichier dans ce répertoire ! \n" } else { .list.milieu.d.tdroite insert insert "\n Aucun fichier correspondant à $specsf dans ce répertoire ! \n" } catch { unset tdr } set tdr [glob -nocomplain -- [file join * ] ] set i 0 foreach fn $tdr { if { [file isdirectory $fn] } { set i [incr i ] if { $i == 1 } { .list.milieu.d.tdroite insert insert " ...mais on y trouve le(s) répertoire(s) : \n\n" } .list.milieu.d.tdroite insert insert " - $fn\n" } ; # fin de si } ; # fin de pourchaque if {$i == 0 } { .list.milieu.d.tdroite insert insert "\n et pas de répertoire non plus.\n\n" } .list.status.s1 configure -text "(aucun)" ; .list.status.s2 configure -text "" ; .list.status.s3 configure -text "" } else { ; # cas normal : il y a un ou des fichier(s) à afficher if { $mdinf == 1 } { ; # affichage des caractéristiques set idf 1 set ndfi [array size ldf] while { $idf <= $ndfi } { set nomF $ldf($idf) set pdf [expr [file size $nomF]/1024.0] if { $pdf < 1 } { set tdF "[format "%9.0f o" [file size $nomF]]" } else { if { $pdf > 1024 } { set tdF "[format "%9.0f Mo" [expr $pdf/1024.0]]" } else { set tdF "[format "%9.0f kO" $pdf]" } } ; # fin de si set ddF "[file mtime $nomF]" set fdF "%d/%H/%Y" set hdF "[clock format $ddF -format $fdF]" set ld "$tdF $hdF" .list.milieu.d.tdroite insert insert "$ld\n" set idf [incr idf] } ; # fin de tant que } else { set nomF $ldf($nfi) set numdF [array size ldf] .list.status.s1 configure -text $nomF ; .list.status.s3 configure -text "$nfi / $numdF" set fd [open $nomF r] ; set td "" ; set limfs 100 set fs [expr [file size $nomF]/1024] if { $fs > $limfs } { # on prévient qu'on n'affiche pas les fichiers de plus de 100 k set nblig "???? ligne(s)" .list.status.s2 configure -text $nblig .list.milieu.d.tdroite insert insert "\n Taille du fichier : $fs Ko.\n" .list.milieu.d.tdroite insert insert " (les fichiers de plus de $limfs Ko ne sont pas affichés).\n\n" } else { # cas normal modinf = 0 ; on montre les lignes du fichier set nbl 0 while { [gets $fd ld] >= 0} { set nbl [incr nbl] if { $alndl == 1 } { set lendl [format "%4d : " $nbl] ; set ld "$lendl $ld"} if { $mdinf == 0 } { .list.milieu.d.tdroite insert insert "$ld\n" } } ; # fin tant que close $fd set nblig "$nbl ligne(s)" ; .list.status.s2 configure -text $nblig } } ; # fin de si } ; # fin de si } ; # fin proc metAjour proc changePol { pasP } { global tailp nfi ; # changement de taille de police (0 remet en taille 9) set tailp [incr tailp $pasP] ; if { $tailp < 1 } { set tailp 1 } if { $pasP == 0 } { set tailp 12 } eval "set police { System $tailp bold } " .list.milieu.d.tdroite configure -font $police ; .list.milieu.g.tgauche configure -font $police } ; # fin proc changePol proc choixRep { } { global chemin ; # ouvre une fenêtre de dialogue pour choisir le répertoire set chemin [file dirname [tk_getOpenFile ]] cd $chemin changeRep } ; # fin proc choixRep proc lesScroll { } { global dfile tailp nfi ; # montre/masque les barres de défilement # avertit $nfi eval "set police { System $tailp bold } " catch { destroy .list.milieu.g.tgauche .list.milieu.d.tdroite .list.milieu.g.yscroll .list.milieu.d.yscroll } if { $dfile == 0 } { # on les montre text .list.milieu.g.tgauche -width 10 -yscrollcommand { .list.milieu.g.yscroll set } .list.milieu.g.tgauche configure -font $police scrollbar .list.milieu.g.yscroll -orient vertical -command { .list.milieu.g.tgauche yview } pack .list.milieu.g.yscroll -side right -padx 0 -pady 0 -fill both -expand false pack .list.milieu.g.tgauche -side left -padx 0 -pady 0 -fill both -expand true text .list.milieu.d.tdroite -foreground blue -background yellow -yscrollcommand { .list.milieu.d.yscroll set } .list.milieu.d.tdroite configure -font $police scrollbar .list.milieu.d.yscroll -orient vertical -command { .list.milieu.d.tdroite yview } -cursor sb_v_double_arrow pack .list.milieu.d.yscroll -side right -padx 0 -pady 0 -fill both -expand false pack .list.milieu.d.tdroite -side left -padx 0 -pady 0 -fill both -expand true } else { # on les cache text .list.milieu.g.tgauche -width 10 .list.milieu.g.tgauche configure -font $police pack .list.milieu.g.tgauche -side left -padx 0 -pady 0 -fill both -expand true text .list.milieu.d.tdroite -foreground blue -background yellow .list.milieu.d.tdroite configure -font $police pack .list.milieu.d.tdroite -side right -padx 2 -pady 0 -fill both -expand true } ; # fin de si .list.milieu.g.tgauche tag configure cur -foreground blue -background yellow set dfile [expr 1-$dfile] set onfi [expr 1-$nfi] ; set nnfi $nfi ; catch { changeRep ; set nfi $nnfi ; changeFic 0.3 ; changeFic +1 } } ; # fin proc lesScroll proc Aide { } { changePol 0 ; tailleWin 0 catch { destroy .aide } toplevel .aide ; wm title .aide " Help for gilles.hunault@univ-angers.fr's simple File Viewer" wm geometry .aide "700x600+200+100" ; focus -force .aide text .aide.t -font { System 14 bold } pack .aide.t -fill both -side top -expand true -padx 1 -pady 1 set txt "\n" append txt " listgh : a simple File Viewer that lists files' contents\n -- gilles.hunault@univ-angers.fr \n\n" append txt " To use this program, just play around with the buttons \n" append txt " and the keyboard : \n\n" append txt " Button Key(s) Action \n" append txt " ------ ------ ------ \n" append txt " + +, shows next file \n" append txt " - -, shows previous file \n" append txt " (none) 1 shows 1st file in dir \n" append txt " (none) l,0 shows last file in dir \n" append txt " = =, goes to next directory (same level) \n" append txt " .. . goes to father directory \n" append txt " > > goes to 1st son directory \n" append txt " * * brings a dialog to select files\n" append txt " f f uses a smaller font \n" append txt " F F,g uses a bigger font \n" append txt " (none) m maximises the window\n" append txt " (none) r restores the window to 80% of the screen \n" append txt " Aide h, shows this help \n" append txt " (none) c closes this help \n" append txt " Exit q as it is written ! \n\n" append txt " (none) s reveals/masks scrollbars ! \n\n" append txt " To scroll the file's text click in the file and\n" append txt " use the usual and keys. \n" append txt "\n\n\n" .aide.t insert insert $txt } ; # fin proc Aide ################################################################### Programme Principal wm title . " listgh : a simple File Viewer that lists files' contents -- gilles.hunault@univ-angers.fr " set nfi 0 ; set chemin [pwd] ; set tailp 11 ; set osv " listgh " ; # valeurs par défaut eval "set police { Arial $tailp bold } " ; set ordf 1 ; # numero d'ordre de tri pour les listes de fichiers set alndl 0 ; # affichage du numéro de la ligne dans le fichier si alndl = 1 set mdinf 0 ; # affichage du texte du fichier si 0, des info taille date si 1 set specsf "*" ; # spécifications du filtre de noms de fichier #if { $argc > 0 } { set specsf [lindex $argv 0] } frame .list ; pack .list -fill both -side top -expand true -padx 1 -pady 1 frame .list.entete -borderwidth 0 ; pack .list.entete -fill both -side top -expand false -padx 0 -pady 0 frame .list.milieu -borderwidth 0 ; pack .list.milieu -fill both -side top -expand true -padx 0 -pady 0 frame .list.status -borderwidth 0 ; pack .list.status -fill both -side top -expand false -padx 0 -pady 0 # partie du haut button .list.entete.cr -bg "#0000BB" -fg yellow -width 12 -anchor w -borderwidth 10 -text " $osv v2.1" -font $police -command changeRep button .list.entete.b1 -bg "#0000BB" -fg yellow -width 1 -anchor w -borderwidth 10 -text "+" -font $police -command { changeFic +1 } button .list.entete.b2 -bg "#0000BB" -fg yellow -width 1 -anchor w -borderwidth 10 -text "-" -font $police -command { changeFic -1 } button .list.entete.b3 -bg "#0000BB" -fg yellow -width 1 -anchor w -borderwidth 10 -text "=" -font $police -command suitRep button .list.entete.b4 -bg "#0000BB" -fg yellow -width 1 -anchor w -borderwidth 10 -text ".." -font $police -command remonteRep button .list.entete.b5 -bg "#0000BB" -fg yellow -width 1 -anchor w -borderwidth 10 -text ">" -font $police -command descendRep button .list.entete.b6 -bg "#0000BB" -fg yellow -width 1 -anchor w -borderwidth 10 -text "*" -font $police -command choixRep label .list.entete.ch -bg white -fg blue -width 35 -anchor w -borderwidth 10 -text [pwd] -font { Arial 10 bold } button .list.entete.cs -bg "#00FF00" -fg blue -width 7 -anchor e -borderwidth 10 -text " Specs " -font $police -command { changeSpecs } button .list.entete.ai -bg "#FF0000" -fg yellow -width 7 -anchor e -borderwidth 10 -text " Aide " -font $police -command { Aide } foreach nomW "cr b1 b2 b3 b4 b5 b6" { pack .list.entete.$nomW -side left -padx 2 -pady 1 -fill none } ; # fin pour chaque pack .list.entete.ch -side left -padx 2 -pady 1 -fill x -expand true pack .list.entete.cs -side left -padx 2 -pady 1 -fill none pack .list.entete.ai -side right -padx 2 -pady 1 -fill none # partie médiane frame .list.milieu.g -width 10 pack .list.milieu.g -side left -padx 1 -pady 1 -fill both -expand true frame .list.milieu.d pack .list.milieu.d -side right -padx 1 -pady 1 -fill both -expand true set dfile 1 ; lesScroll ; # par défaut les barres de défilement sont masquées # partie du bas label .list.status.s1 -relief sunken -bg "#005500" -fg yellow -anchor w -borderwidth 10 -font $police -text " (aucun fichier ouvert) " -font $police -width 35 label .list.status.s2 -relief sunken -bg "#005500" -fg yellow -anchor w -borderwidth 10 -font $police -text " " label .list.status.s3 -relief sunken -bg "#005500" -fg yellow -anchor w -borderwidth 10 -font $police -text " " button .list.status.s4 -relief sunken -bg "#550044" -fg yellow -anchor w -borderwidth 01 -font $police -text "f" -command { changePol -1 } button .list.status.s5 -relief sunken -bg "#550044" -fg yellow -anchor w -borderwidth 01 -font $police -text "F" -command { changePol +1 } button .list.status.s6 -relief sunken -bg "#550044" -fg yellow -anchor w -borderwidth 01 -font $police -text " o " -font $police -command { changeOrdre } button .list.status.s7 -relief sunken -bg "#550044" -fg yellow -anchor w -borderwidth 01 -font $police -text " n " -font $police -command { changeNumLig } button .list.status.s8 -relief sunken -bg "#550044" -fg yellow -anchor w -borderwidth 01 -font $police -text " s " -font $police -command { lesScroll } button .list.status.s9 -relief sunken -bg "#550044" -fg yellow -anchor w -borderwidth 01 -font $police -text " T " -font $police -command { changeInfo } button .list.status.ss -relief sunken -bg "#550000" -fg yellow -anchor w -borderwidth 10 -font $police -text " Exit " -font $police -command exit pack .list.status.s1 -side left -padx 2 -pady 1 -fill x -expand true foreach i "2 3 4 5 6 7 9" { pack .list.status.s$i -side left -padx 2 -pady 1 -fill none } ; # fin pour chaque pack .list.status.ss -side right -padx 2 -pady 1 -fill none changeRep bind .list * { choixRep } bind .list + { changeFic +1 } bind .list - { changeFic 0.3 } bind .list . remonteRep bind .list 0 { changeFic 0.2 } bind .list 1 { changeFic 0.1 } bind .list 1 { set ordf 1 ; changeRep } bind .list 2 { set ordf 2 ; changeRep } bind .list 3 { set ordf 3 ; changeRep } bind .list 4 { set ordf 4 ; changeRep } bind .list 5 { set ordf 5 ; changeRep } bind .list 6 { set ordf 6 ; changeRep } bind .list 9 { changePol 0 } bind .list { changeFic +1 } bind .list Aide bind .list { changeFic 0.2 } bind .list { changeFic 0.1 } bind .list { changeFic +1 } bind .list remonteRep bind .list { changeFic 0.3 } bind .list suitRep bind .list suitRep bind .list { changeFic 0.3 } bind .list exit bind .list = suitRep bind .list > descendRep bind .list A { set ordf 2 ; changeRep } bind .list D { set ordf 4 ; changeRep } bind .list F { changePol +1 } bind .list I { changeInfo } bind .list S { set ordf 6 ; changeRep } bind .list T { changeInfo } ; # affiche texte du fichier ou (taille et date) bind .list a { set ordf 1 ; changeRep } bind .list b { remonteRep } bind .list b { lesScroll } bind .list c { catch { destroy .aide } } bind .list d { descendRep } bind .list d { set ordf 3 ; changeRep } bind .list f { changePol -1 } bind .list g { changePol +1 } bind .list h { Aide } bind .list i { changeInfo } bind .list l { changeFic 0.2 } bind .list m { tailleWin 1 } bind .list n { changeNumLig } ; # numéro de ligne dans texte du fichier bind .list o { changeOrdre } ; # ordre de tri dans l'affichage des listes de fichier bind .list r { tailleWin 0 } bind .list s { set ordf 5 ; changeRep } bind .list t { changeInfo } bind .list u { remonteRep } bind .list v { changeSpecs } ; # spécifications de fichier # my favourite for Windows : if { [lindex $tcl_platform(os) 0]=="Windows" } { changePol 0 ; tailleWin 1 ; set specs "*.*" } focus -force .list # fin de programme list.tcl