https://sysphere.org/~anrxc/local/sources/pvol.py
A simple python-only volume control and OSD.
Nothing fancy, and nothing difficult. There's no configuration, which is both a good and a bad thing.. but I can live with the developer's defaults. No extra dependencies to speak of. Just Python.
- 2016-03-30 - 2009 release, on Slackware 14.1
-
Earlier than 2016-03-26 - 2009 release, on Lubuntu (version not recorded)
2016-03-30 - 2009 release ∞
Does not work
./pvol.py -c 5
Traceback (most recent call last): File "./pvol.py", line 114, in <module> main() File "./pvol.py", line 102, in main volume = Mixer(option.pcm, True, option.percent) File "./pvol.py", line 26, in __init__ self.mixer = ossaudiodev.openmixer() IOError: [Errno 2] No such file or directory: '/dev/mixer'
.. this is because /dev/mixer
does not exist.
I'll just use alsamixer
.
Earlier than 2016-03-26 - 2009 release ∞
Usage ∞
Raise the volume by 5% with:
pvol.py -c 5
Cache ∞
#!/usr/bin/env python
- pvol -- Commandline audio volume utility
- with an optional GTK progressbar
-
Copyright (C) 2009 Adrian C.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
-
(at your option) any later version.
import gtk
import gobject
import os.path
import optparse
import ossaudiodev
appname = "Pvol"
appicon = os.path.expanduser("~/.icons/Tango/22x22/status/audio-volume-high.png")
class Mixer():
def init(self, pcm=False, adj=False, arg=None):
self.mixer = ossaudiodev.openmixer()
get, set = self.mixer.get, self.mixer.set
self.channels = 'MASTER', ossaudiodev.SOUND_MIXER_VOLUME],
['PCM', ossaudiodev.SOUND_MIXER_PCM[doesn't exist]
if pcm == True:
self.channels.insert(0, self.channels.pop())
name, channel = self.channels[0]
self.label = "Volume: " #% name
- There is no simple way to toggle mute on a channel with ossaudiodev?
if adj == True:
if arg == -100:
if not get(channel)[0]: - Copy the PCM channel
#arg = get(self.channels[1][1])[0]
-
Set to a pre-defined value
arg = 94
self.label = "Unmuted: "
else: self.label = "Muted: "
arg = min(100, max(0, get(channel)[0] + int(arg)))
set(channel, (arg, arg))self.percent = get(channel)[0]
self.label = self.label + "%.0fself.mixer.close()
class Pvol:
def init(self, fraction, label, wmname=appname):
self.window = gtk.Window(gtk.WINDOW_POPUP)
self.window.set_title(wmname)
self.window.set_border_width(1)
self.window.set_default_size(180, -1)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.connect("destroy", lambda x: gtk.main_quit())
self.timer = gobject.timeout_add(2000, lambda: gtk.main_quit())
self.widgetbox = gtk.HBox()
self.icon = gtk.Image()
self.icon.set_from_file(appicon)
self.icon.show()
self.progressbar = gtk.ProgressBar()
self.progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
self.progressbar.set_fraction(float(fraction) / 100)
self.progressbar.set_text(label)
self.widgetbox.pack_start(self.icon)
self.widgetbox.pack_start(self.progressbar)
self.window.add(self.widgetbox)
self.window.show_all()
def main():
usage = "%prog [-s] [-m] [-c PERCENT] [-p] [-q]"
parser = optparse.OptionParser(usage=usage)
parser.add_option('-s', '--status', action='store_true', dest='status', help='display current volume')
parser.add_option('-m', '--mute', action='store_true', dest='mute', help='mute the main audio channel')
parser.add_option('-c', '--change', type='int', dest='percent', help='increase or decrease volume by given percentage')
parser.add_option('-p', '--pcm', action='store_true', dest='pcm', default=False, help='change PCM channel (default is MASTER)')
parser.add_option('-q', '--quiet', action='store_true', dest='quiet', help='adjust volume without the progressbar')
(option, args) = parser.parse_args()
if option.percent or option.mute:
if option.mute:
if not option.pcm:
option.percent = -100
else: raise SystemExit(parser.get_usage())
if option.quiet:
raise SystemExit(Mixer(option.pcm, True, option.percent).label)
volume = Mixer(option.pcm, True, option.percent)
elif option.status:
volume = Mixer(option.pcm)
else:
raise SystemExit("Unknown option, use --help to get explanations for these:\n\n\t%s" % parser.get_usage())
Pvol(volume.percent, volume.label)
gtk.main()
return 0
if name == "main":
main()
Last updated 2021-02-24 at 16:26:04