home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / mini-volume.tcl < prev    next >
Encoding:
Text File  |  2006-06-15  |  4.5 KB  |  172 lines

  1. #!/bin/sh
  2. # =====
  3. # USAGE
  4. # =====
  5. # This application can receive two parameters
  6. # -orientation [horizontal | vertical] 
  7. #                         Specifies the orientation for the volume slider
  8. #                         the default is vertical
  9. # -image <imagefilename>
  10. #                         Specifies an image to be used in the volume button
  11. #                         The image must be a gif image.
  12. # Both parameters are optional. You can use shorhand for the parameters -o -i
  13. # e.g.
  14. #  mini-volume -o hor -i /root/myimage.gif
  15. #
  16. # =======
  17. # LICENSE
  18. # =======
  19. # This program can be used and modified freely and you are welcome to
  20. # redistribute it under the following terms:
  21. # - This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. # - Any derived works should be also distributed freely under an all-permisive
  25. # license. Share the spirit of open source.
  26. # - The following is not a requirement but a request:
  27. # If you make changes to the application to fit a particular purpose or
  28. # feature please share them with me contacting me at (rarsa at yahoo.com)
  29.  
  30. # the next line restarts using wish \
  31. exec wish "$0" "$@"
  32.  
  33. set volcommand {setvol 0 | cut -d" " -f2}
  34.  
  35. set orient "vert"
  36. set imagepath "/usr/local/lib/X11/mini-icons/mini-volume.gif"
  37. set showing "false"
  38. set bgcolor "gray"
  39.  
  40. proc setvolume { level } {
  41.     exec setvol 0 $level
  42. }
  43.  
  44. proc getvolume { } {
  45.     set volcommand { setvol 0 | cut -d" " -f2 }
  46.     set gain [exec sh -c ($volcommand)]
  47. }
  48.     
  49. proc parseParams { params } {
  50.     global orient
  51.     global imagepath
  52.     global bgcolor
  53.  
  54.     for {set i 0} {$i < [llength $params]} {incr i} {
  55.         set arg [lindex $params $i]
  56.         if {[string first "-o" $arg] == 0} {
  57.             incr i;
  58.             if {[string first "h" [lindex $params $i]] == 0} {
  59.                 set orient "hor"
  60.             }
  61.         }
  62.         if {[string first "-i" $arg] == 0} {
  63.             incr i;
  64.             set imagepath [lindex $params $i]
  65.         }
  66.         if {[string first "-bg" $arg] == 0} {
  67.             incr i;
  68.             set bgcolor [lindex $params $i]
  69.         }
  70.     }
  71. }
  72.  
  73. proc tooltip:show {w arg} {
  74.     global prev
  75.     if {[eval winfo containing  [winfo pointerxy .]]!=$w} {return}
  76.     if {[expr abs($prev - [clock clicks -milliseconds])] < 200 } {
  77.         set prev [clock clicks -milliseconds]
  78.         return
  79.     }
  80.       set prev [clock clicks -milliseconds]
  81.     
  82.     set top $w.tooltip
  83.     catch {destroy $top}
  84.     toplevel $top -bd 1 -bg black
  85.     wm overrideredirect $top 1
  86.     pack [message $top.txt -aspect 10000 -bg lightyellow \
  87.             -font fixed -text [concat $arg [ getvolume ]]]
  88.     set wmx [winfo rootx $w]
  89.     set wmy [expr [winfo rooty $w]-[winfo height $w]]
  90.     wm geometry $top \
  91.       [winfo reqwidth $top.txt]x[winfo reqheight $top.txt]+$wmx+$wmy
  92.     raise $top
  93.  }
  94.  
  95. proc volume:show {w} {
  96.     global gain
  97.     global orient
  98.     global showing
  99.     global bgcolor
  100.  
  101.     set top $w.volume
  102.     catch {destroy $top}
  103.     if { $showing == "true" } {
  104.         set showing "false"
  105.     } else    {
  106.         toplevel $top -bd 0 -bg black
  107.         wm overrideredirect $top 1
  108.         set gain [ getvolume ]
  109.     
  110.         set wmx [winfo rootx $w]
  111.         if {$orient == "vert"} {
  112.             pack [scale $top.sv -show no -orient ver -from 100 -to 0 \
  113.                 -sliderlength 5 -command { setvolume } \
  114.                 -len 70 -bg $bgcolor -var gain]
  115.             set wmy [expr [winfo rooty $w]-75]
  116.         } else {
  117.             pack [scale $top.sv -show no -orient hor \
  118.                 -sliderlength 5 -command { setvolume } \
  119.                 -len 70 -bg $bgcolor -var gain]
  120.             set wmy [expr [winfo rooty $w]-[winfo height $w]]
  121.         }
  122.         bind $top.sv <Button-4> { volume:up %W }
  123.         bind $top.sv <Button-5> { volume:down %W }
  124.     
  125.         wm geometry $top \
  126.           [winfo reqwidth $top.sv]x[winfo reqheight $top.sv]+$wmx+$wmy
  127.         bind $w.volume <Any-Leave> {after 500 destroy %W
  128.             set showing "false"}
  129.         raise $top
  130.         set showing "true"
  131.     }
  132. }
  133.  
  134. proc volume:up { w } {
  135.     global gain
  136.     if { $gain > 98 } {
  137.         set gain 100
  138.     } else {
  139.         set gain [expr $gain + 2]
  140.     }
  141.     setvolume $gain
  142.     after 200 [list tooltip:show $w Volume] 
  143. }
  144.  
  145. proc volume:down { w } {
  146.     global gain
  147.         
  148.     if { $gain < 2 } {
  149.         set gain 0
  150.     } else {
  151.         set gain [expr $gain - 2]
  152.     }
  153.     setvolume $gain
  154.     after 200 [list tooltip:show $w Volume] 
  155. }
  156.  
  157. parseParams $argv
  158.  
  159. set gain [ getvolume ]
  160. set prev [clock clicks -milliseconds]
  161.  
  162. image create photo img-mini-vol -file $imagepath
  163. button  .b -text V -image img-mini-vol -bd 0 -bg $bgcolor
  164. bind .b <ButtonPress-1> { list volume:show %W }
  165. bind .b <Any-Enter> { after 500 [list tooltip:show %W Volume] }
  166. bind .b <Any-Leave> { destroy .b.tooltip }
  167. bind .b <ButtonPress-1> { volume:show %W }
  168. bind .b <Button-4> { volume:up %W }
  169. bind .b <Button-5> { volume:down %W }
  170. pack .b
  171.