Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 78 additions and 0 deletions.
  1. +78 −0 vol
78 vol
View
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+# Simple volume control.
+# Because I'm tired of gnome-volume-control changing names or
+# removing features every time I turn around, and no one else
+# seems to be interested in writing a basic volume control app
+# that isn't a windowmanager panel applet.
+
+# Copyright 2005 by Akkana Peck.
+# You may use, distribute, or modify this program under the terms of the GPL.
+
+import string, re, os, sys
+import gtk
+import alsaaudio
+
+def Usage() :
+ print "Usage:", os.path.basename(sys.argv[0]), "[-v|-h]"
+ sys.exit(0)
+
+# First find a mixer. Use the first one.
+try :
+ mixer = alsaaudio.Mixer('Master', 0)
+except alsaaudio.ALSAAudioError :
+ sys.stderr.write("No such mixer\n")
+ sys.exit(1)
+
+# Get the current system volume.
+def get_volume() :
+ return mixer.getvolume()[0]
+
+# Change the system volume (both channels at once).
+def change_volume(scale) :
+ newval = int(scale.get_adjustment().value)
+ mixer.setvolume(newval, alsaaudio.MIXER_CHANNEL_ALL)
+
+def key_press(w, event) :
+ if event.string == "q" :
+ sys.exit(0)
+ return False
+
+def create_window(vol, verticalP) :
+ win = gtk.Window()
+ win.set_name("PyVolume")
+ win.set_border_width(5)
+ win.connect("destroy", gtk.main_quit)
+
+ vbox = gtk.VBox()
+ win.add(vbox)
+
+ adj = gtk.Adjustment(value=vol, lower=0, upper=100,
+ step_incr=-1, page_incr=6)
+ if (vertical) :
+ scale = gtk.VScale(adjustment=adj)
+ scale.set_size_request(50, 250)
+ else :
+ scale = gtk.HScale(adjustment=adj)
+ scale.set_size_request(250, 50)
+ scale.set_digits(0)
+ vbox.pack_start(scale)
+ scale.show()
+ vbox.show()
+
+ scale.connect("value_changed", change_volume)
+ scale.connect("key-press-event", key_press)
+
+ win.show()
+ gtk.main()
+
+# main
+vertical = 0
+if len(sys.argv) > 1 :
+ if sys.argv[1] == "-v" or sys.argv[1] == "-V" :
+ vertical = 1
+ elif sys.argv[1] != "-h" :
+ Usage()
+
+create_window(get_volume(), vertical)
+

No commit comments for this range

Something went wrong with that request. Please try again.