forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvol
executable file
·78 lines (62 loc) · 1.96 KB
/
vol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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)