Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor

Showing 1 changed file with 78 additions and 0 deletions. Show diff stats Hide diff stats

  1. +78 0 vol
78 vol
... ... @@ -0,0 +1,78 @@
  1 +#!/usr/bin/env python
  2 +
  3 +# Simple volume control.
  4 +# Because I'm tired of gnome-volume-control changing names or
  5 +# removing features every time I turn around, and no one else
  6 +# seems to be interested in writing a basic volume control app
  7 +# that isn't a windowmanager panel applet.
  8 +
  9 +# Copyright 2005 by Akkana Peck.
  10 +# You may use, distribute, or modify this program under the terms of the GPL.
  11 +
  12 +import string, re, os, sys
  13 +import gtk
  14 +import alsaaudio
  15 +
  16 +def Usage() :
  17 + print "Usage:", os.path.basename(sys.argv[0]), "[-v|-h]"
  18 + sys.exit(0)
  19 +
  20 +# First find a mixer. Use the first one.
  21 +try :
  22 + mixer = alsaaudio.Mixer('Master', 0)
  23 +except alsaaudio.ALSAAudioError :
  24 + sys.stderr.write("No such mixer\n")
  25 + sys.exit(1)
  26 +
  27 +# Get the current system volume.
  28 +def get_volume() :
  29 + return mixer.getvolume()[0]
  30 +
  31 +# Change the system volume (both channels at once).
  32 +def change_volume(scale) :
  33 + newval = int(scale.get_adjustment().value)
  34 + mixer.setvolume(newval, alsaaudio.MIXER_CHANNEL_ALL)
  35 +
  36 +def key_press(w, event) :
  37 + if event.string == "q" :
  38 + sys.exit(0)
  39 + return False
  40 +
  41 +def create_window(vol, verticalP) :
  42 + win = gtk.Window()
  43 + win.set_name("PyVolume")
  44 + win.set_border_width(5)
  45 + win.connect("destroy", gtk.main_quit)
  46 +
  47 + vbox = gtk.VBox()
  48 + win.add(vbox)
  49 +
  50 + adj = gtk.Adjustment(value=vol, lower=0, upper=100,
  51 + step_incr=-1, page_incr=6)
  52 + if (vertical) :
  53 + scale = gtk.VScale(adjustment=adj)
  54 + scale.set_size_request(50, 250)
  55 + else :
  56 + scale = gtk.HScale(adjustment=adj)
  57 + scale.set_size_request(250, 50)
  58 + scale.set_digits(0)
  59 + vbox.pack_start(scale)
  60 + scale.show()
  61 + vbox.show()
  62 +
  63 + scale.connect("value_changed", change_volume)
  64 + scale.connect("key-press-event", key_press)
  65 +
  66 + win.show()
  67 + gtk.main()
  68 +
  69 +# main
  70 +vertical = 0
  71 +if len(sys.argv) > 1 :
  72 + if sys.argv[1] == "-v" or sys.argv[1] == "-V" :
  73 + vertical = 1
  74 + elif sys.argv[1] != "-h" :
  75 + Usage()
  76 +
  77 +create_window(get_volume(), vertical)
  78 +

No commit comments for this range

Something went wrong with that request. Please try again.