You are not logged in.

#1 2010-01-26 05:02:47

epinull
Member
Registered: 2010-01-25
Posts: 10

pyvolwheel

Yes, I know about volwheel and gvolwheel. tongue
My main reason for writing this was to allow me to control the volume using my keyboard's volume wheel without spawning a dozen new processes when I scrolled it. (Which is what happens when I bind the keys to amixer, etc.) Anyway...

Description
pyvolwheel is a python application that puts an icon in your system tray from
which you can control the volume using your mouse wheel or optional hot-keys.
It is compatible with both ALSA and OSS and supports muting for controls that
don't natively support it. pyvolwheel can also remember the volume level when
it quits and restore it the next time it starts.

Dependencies
    * pygtk (>=2.16)

Optional Dependencies
    * pyalsaaudio: for ALSA mixer support
    * python-xlib: for global hotkey support

GitHub Page
AUR Package

Offline

#2 2010-02-10 11:15:49

FSX
Member
Registered: 2009-08-06
Posts: 57

Re: pyvolwheel

Hey, I tried this and I get the following error:

Traceback (most recent call last):
  File "/usr/bin/pyvolwheel", line 150, in <module>
    m.run()
  File "/usr/bin/pyvolwheel", line 39, in run
    self.reload()
  File "/usr/bin/pyvolwheel", line 125, in reload
    self.config.mixer.control = mixer.get_controls(driver, device)[0]
IndexError: list index out of range

I am using OSS and I installed Pyvolwheel from the AUR.

Last edited by FSX (2010-02-10 11:16:16)

Offline

#3 2010-02-10 18:34:15

tydell
Member
From: actually: Hannover, DE
Registered: 2009-07-26
Posts: 109
Website

Re: pyvolwheel

For oss volume control try this:

#!/usr/bin/env python
"A simple volume control applet."

import gtk
import subprocess

__author__  = "Joakim \"JockeTF\" Soderlund"
__date__    = "2008-08-22"
__license__ = "Public domain."

# Binaries to execute.
OSSMIX  = "ossmix"
OSSXMIX = "ossxmix"

# The device to control.
DEVICE = "vmix0-outvol"

# The maximum outvol volume in decibels.
MAX_DB = 25.0

# Sets an icon for different volume levels.
LEVELS = (
    (22, "audio-volume-high"),
    (18, "audio-volume-medium"),
    (0,  "audio-volume-low"),
    (-1, "audio-volume-muted"),
)

class StatusIcon():
    "The status icon."
    def __init__(self):
        self.icon = gtk.StatusIcon()
        
        self.icon.connect("scroll-event", self.scrollEvent)
        self.icon.connect("activate", self.clickEvent)
        
        self.set_visible = self.icon.set_visible
        
        self.update()


    def scrollEvent(self, widget, event, *args):
        "Changes the volume when the user scrolls on the volume applet."
        if event.direction == gtk.gdk.SCROLL_UP:
            subprocess.call([OSSMIX, DEVICE, "--", "+%.1f" % self.getStep()])
            
        elif event.direction == gtk.gdk.SCROLL_DOWN:
            subprocess.call([OSSMIX, DEVICE, "--", "-%.1f" % self.getStep()])

        self.update()


    def clickEvent(self, widget, *args):
        "Starts or closes ossxmix when the volume applet is clicked."
        if not hasattr(self, "ossxmix"):
            self.ossxmix = subprocess.Popen([OSSXMIX, "-S"])
        else:
            if self.ossxmix.poll() == None:
                self.ossxmix.terminate()
            else:
                self.ossxmix = subprocess.Popen([OSSXMIX, "-S"])

        self.update()

        
    def getVolume(self):
        "Returns the current volume in decibels as a float."
        process = subprocess.Popen([OSSMIX, DEVICE], stdout=subprocess.PIPE)
        volume = float(process.communicate()[0].split()[-2])
        process.wait()
        
        return volume

    
    def getStep(self):
        "Returns the next volume step to make in decibels as a float."
        return (MAX_DB - self.getVolume() + 1) * 0.1


    def getIconName(self):
        "Returns the icon name for the current volume level."
        volume = self.getVolume()
        
        for level in LEVELS:
            if level[0] < volume:
                return level[1]


    def update(self, *args):
        "Updates the volume applet's tooltip and icon."
        self.icon.set_tooltip("Volume: %.1f dB" % self.getVolume())
        self.icon.set_from_icon_name(self.getIconName())


if __name__ == "__main__":
    icon = StatusIcon()
    icon.set_visible(True)
    
    try:
        gtk.main()
    except KeyboardInterrupt:
        print("")

Save it as python script, volume.py or something and run it. It works excellence. It isn't mine, found it at some thread on this forum

Offline

#4 2010-02-11 09:01:40

epinull
Member
Registered: 2010-01-25
Posts: 10

Re: pyvolwheel

FSX wrote:

Hey, I tried this and I get the following error:

Traceback (most recent call last):
  File "/usr/bin/pyvolwheel", line 150, in <module>
    m.run()
  File "/usr/bin/pyvolwheel", line 39, in run
    self.reload()
  File "/usr/bin/pyvolwheel", line 125, in reload
    self.config.mixer.control = mixer.get_controls(driver, device)[0]
IndexError: list index out of range

I am using OSS and I installed Pyvolwheel from the AUR.

Seems that it can find any controls to use. :S
Could you try creating a file in ~/.config/ called pyvolwheel and put this in it:

[mixer]
control = Vol
driver = OSS
device = /dev/mixer

See if that at least gets it running.

Also, would you mind posting the output of ossmix?

Thanks! smile

Offline

#5 2010-02-11 22:31:38

FSX
Member
Registered: 2009-08-06
Posts: 57

Re: pyvolwheel

This is the output when I use the config you provided:

shinju% pyvolwheel 
Traceback (most recent call last):
  File "/usr/bin/pyvolwheel", line 150, in <module>
    m.run()
  File "/usr/bin/pyvolwheel", line 39, in run
    self.reload()
  File "/usr/bin/pyvolwheel", line 133, in reload
    self.config.mixer.control)
  File "/usr/lib/python2.6/site-packages/pyvolwheel/mixer.py", line 88, in open_mixer
    return OSSMixer(device, control)
  File "/usr/lib/python2.6/site-packages/pyvolwheel/mixer.py", line 217, in __init__
    self._control_idx = self._control_to_idx(control)
  File "/usr/lib/python2.6/site-packages/pyvolwheel/mixer.py", line 231, in _control_to_idx
    raise MixerError("Invalid control '{0}'".format(str(control)))
pyvolwheel.mixer.MixerError: Invalid control 'Vol'

And the output of ossmix:

jack.fp-black.mode <front|rear|center/LFE|side|pcm4|input> (currently front)
jack.fp-black [<leftvol>:<rightvol>] (currently 19.9:19.9 dB)
jack.fp-black.mute ON|OFF (currently OFF)
jack.fp-pink.mode <front|rear|center/LFE|side|pcm4|input> (currently front)
jack.fp-pink [<leftvol>:<rightvol>] (currently 19.9:19.9 dB)
jack.fp-pink.mute ON|OFF (currently OFF)
jack.fp-blue.mode <front|rear|center/LFE|side|pcm4|input> (currently front)
jack.fp-blue [<leftvol>:<rightvol>] (currently 19.9:19.9 dB)
jack.fp-blue.mute ON|OFF (currently OFF)
record.mix.mute.fp-mic1 ON|OFF (currently OFF)
record.mix.mute.fp-linein1 ON|OFF (currently OFF)
record.mix.mute.fp-headphone1 ON|OFF (currently OFF)
record.mix.mute.input-mix1 ON|OFF (currently OFF)
record.mix1 [<leftvol>:<rightvol>] (currently 37.4:37.4 dB)
record.mix.mute.fp-mic2 ON|OFF (currently OFF)
record.mix.mute.fp-linein2 ON|OFF (currently OFF)
record.mix.mute.fp-headphone2 ON|OFF (currently OFF)
record.mix.mute.input-mix2 ON|OFF (currently OFF)
record.mix2 [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
misc.fp-mic [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
misc.fp-linein [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
misc.fp-headphone [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
misc.input-mix <fp-mic|fp-linein> (currently fp-mic)
misc.front-mute ON|OFF (currently OFF)
misc.input-mix-mute1 ON|OFF (currently OFF)
misc.front1 [<leftvol>:<rightvol>] (currently 37.4:37.4 dB)
misc.front2 <front|input-mix> (currently front)
misc.rear-mute ON|OFF (currently OFF)
misc.input-mix-mute2 ON|OFF (currently OFF)
misc.rear1 [<leftvol>:<rightvol>] (currently 37.4:37.4 dB)
misc.rear2 <rear|input-mix> (currently rear)
misc.center/lfe-mute ON|OFF (currently OFF)
misc.input-mix-mute3 ON|OFF (currently OFF)
misc.center/lfe1 [<leftvol>:<rightvol>] (currently 37.4:37.4 dB)
misc.center/lfe2 <center/LFE|input-mix> (currently center/LFE)
misc.side-mute ON|OFF (currently OFF)
misc.input-mix-mute4 ON|OFF (currently OFF)
misc.side1 [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
misc.side2 <side|input-mix> (currently side)
misc.pcm4-mute ON|OFF (currently OFF)
misc.input-mix-mute5 ON|OFF (currently OFF)
misc.pcm41 [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
misc.pcm42 <pcm4|input-mix> (currently pcm4)
vmix0-enable ON|OFF (currently ON)
vmix0-rate <decimal value> (currently 48000) (Read-only)
vmix0-channels <Stereo|Multich> (currently Stereo)
vmix0-src <Fast|High|OFF> (currently Fast)
vmix0-outvol <monovol> (currently 22.1 dB)
vmix0-invol <monovol> (currently 0.0 dB)
vmix0.pcm10 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB) ("mplayer")
vmix0.pcm11 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)
vmix0.pcm12 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)
vmix0.pcm13 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)

Last edited by FSX (2010-02-11 22:32:10)

Offline

#6 2010-02-14 22:07:35

epinull
Member
Registered: 2010-01-25
Posts: 10

Re: pyvolwheel

Thanks for the information, FSX.
This appears to be a problem with ossaudiodev (the Python module I use for OSS support), so I may just add a mixer that uses the ossmix binary.
Thanks for testing! wink

Offline

#7 2010-03-05 15:00:52

ammon
Member
Registered: 2008-12-11
Posts: 413

Re: pyvolwheel

This is nice, ty.

Offline

Board footer

Powered by FluxBB