File: volume.py

package info (click to toggle)
python-osd 0.2.12-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 124 kB
  • ctags: 136
  • sloc: ansic: 447; python: 283; makefile: 85
file content (57 lines) | stat: -rw-r--r-- 1,353 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env python
#
# $Id: volume.py,v 1.3 2003/06/11 11:31:26 resolve Exp $
#
# Time-stamp: <2002-04-01 00:25:37 resolve>
#
# Copyright (C) Damien Elmes <resolve@repose.cx>, 2001.
# This file is licensed under the GPL. Please see COPYING for more details.
#


"""
Plugin for PyOSDd which facilitates changing volume
"""

import commands
import os
import re

import pyosd, pyosd.daemon as pyd

class plugin:

    def __init__(self):
        self.plugin_name = "volume"
        self.plugin_desc = "Alter main system volume"
        self.plugin_keys = ["vol"]

    def vol(self, *args):
        """ Set or display the volume """

        if args:
            vol_str = args[0]

            # set the new volume
            os.system("aumix -v %s" % vol_str)

        self.display_volume()

    def display_volume(self):
        """ Determine current volume, and display it. """

        # twisted bug
        import signal
        signal.signal(signal.SIGCHLD, signal.SIG_DFL)

        # read volume in
        output = commands.getoutput("aumix -q")
        # locate main volume
        m = re.match("vol (\d+),", output)
        vol = int(m.group(1))

        # display!
        pyd.top.set_colour("#bbbbFF")
        pyd.top.set_timeout(3)
        pyd.top.display("Volume (%d%%)" % vol)
        pyd.top.display(vol, type=pyosd.TYPE_PERCENT, line=1)