home *** CD-ROM | disk | FTP | other *** search
/ Dream 46 / Amiga_Dream_46.iso / Linux / Magazine / Tcltk / tkcalc7.tcl < prev    next >
Text File  |  1997-11-13  |  4KB  |  161 lines

  1.  
  2. ######################################
  3. # tkcalc7.tcl                        #
  4. ######################################
  5. # Tkcalculator v0.7                  #
  6. ######################################
  7.  
  8. #################################
  9. # Creer l'interface utilisateur #
  10. #################################
  11.  
  12. # creation d'une ligne de boutons
  13.  
  14. proc MakeRow { list } {
  15.     global NbListRow
  16.  
  17.     incr NbListRow
  18.  
  19.     frame .framerow${NbListRow}
  20.  
  21.     pack .framerow${NbListRow} -side top -fill x -expand true
  22.  
  23.     for { set i 0 } { $i < [llength $list] } { incr i } {
  24.     button .btn${i}row${NbListRow} -command "ButtonCommand $i $NbListRow" -text [ lindex $list $i]  -width 3 -height 1
  25.  
  26.     pack .btn${i}row${NbListRow} -side left -in  .framerow${NbListRow}
  27.     }
  28. }
  29.  
  30. # cette procedure est appelΘe lorsque l'on clique sur un bouton
  31. # elle affiche le numero du bouton dans la ligne (0 = premier bouton)
  32. # et le numero de ligne (entre 1 et le nombre de lignes)
  33.  
  34. proc ButtonCommand { i row } {
  35.     global ListRow1 ListRow2 ListRow3 ListRow4 ListRow5 ListRow6
  36.  
  37.     .viewtxt mark set insert end
  38.     .viewtxt see end
  39.  
  40.     switch $row {
  41.     1 {
  42.         if { $i==4} ResetCommand
  43.     }
  44.     2 {
  45.         if { $i>=3 } {
  46.          .viewtxt insert insert [lindex $ListRow2 $i]
  47.         }
  48.     }
  49.     3 { 
  50.         .viewtxt insert insert [lindex $ListRow3 $i]
  51.     }
  52.     4 { 
  53.         .viewtxt insert insert [lindex $ListRow4 $i]
  54.     }
  55.     5 { 
  56.         .viewtxt insert insert [lindex $ListRow5 $i]
  57.     }
  58.     6 { 
  59.         if { $i == 0  || $i == 2 || $i == 3 } {
  60.         .viewtxt insert insert [lindex $ListRow6 $i]
  61.         } elseif { $i == 1 } {
  62.         NegateCommand
  63.         } elseif { $i == 4 } {
  64.         ExecCommand
  65.         }
  66.     }
  67.  
  68.     }
  69.  
  70.     .viewtxt tag add calcul "insert linestart" "insert lineend"
  71.  
  72. }
  73.  
  74. # zone d'affichage de texte
  75.  
  76. text .viewtxt -height 8 -width 32
  77.  
  78. .viewtxt tag configure calcul -font -adobe-courier-*-o-normal-*-12-*-*-*-*-*-*-* -justify left
  79. .viewtxt tag configure result -font -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-* -justify right
  80.  
  81. pack .viewtxt -side top
  82.  
  83. # configuration des boutons
  84.  
  85. set ListRow1 { "Menu" "Lib" "Graph" "Help" "Reset" }
  86. set ListRow2 { "Mem" "Rcl" "Mem+" "(" ")" }
  87. set ListRow3 { 7 8 9 \/ "E" }
  88. set ListRow4 { 4 5 6 \* "Last" }
  89. set ListRow5 { 1 2 3 \- "Ans"  }
  90. set ListRow6 { 0 "+/-" "." "+" "Exe" }
  91.  
  92. # pour l'instant, aucune ligne initialisΘe
  93.  
  94. set NbListRow 0
  95.  
  96. # crΘer les lignes de boutons
  97.  
  98. MakeRow $ListRow1
  99. MakeRow $ListRow2
  100. MakeRow $ListRow3
  101. MakeRow $ListRow4
  102. MakeRow $ListRow5
  103. MakeRow $ListRow6
  104.  
  105. # boutons de commande : about et quit
  106.  
  107. frame .comframe
  108.  
  109. button .comframe.aboutbtn -text "About ..." -command AboutCommand
  110. button .comframe.quitbtn -text "Quit" -command exit
  111.  
  112. pack .comframe -side top
  113. pack .comframe.aboutbtn -side left
  114. pack .comframe.quitbtn -side left
  115.  
  116. # gestion des Θvenements (bindings)
  117.  
  118. bind .viewtxt <Button-1> { 
  119.     .viewtxt mark set insert end
  120.     .viewtxt see end
  121.  }
  122.  
  123. set ReservedKeys { "Backspace" "Delete" "Left" "Right" }
  124.  
  125. bind .viewtxt <KeyRelease> {    
  126.  
  127.     if { "%K" == "Return" } { 
  128.     ExecCommandKey
  129.     return
  130.     }
  131.  
  132.     if { "%K" == "Escape" } {
  133.     ResetCommand
  134.     }
  135.  
  136.     if { [lsearch -exact $ReservedKeys "%K"]!=-1 } return
  137.     
  138.     .viewtxt mark set insert end
  139.     .viewtxt see end
  140.     .viewtxt tag add calcul "insert linestart" "insert lineend"
  141. }    
  142.           
  143. # interpreter dialogs.tcl au niveau global
  144.  
  145. uplevel 0 [list source dialogs.tcl]
  146. uplevel 0 [list source calc.tcl]
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.