好吧,冒着回答我自己问题的风险,我从上面问题中的链接中想出了一些被伪造的pyqt版本的pvol。如果没有别的,也许其他人可以改善我的代码。最终,我打算摆脱脚本中未使用的部分,或者将bash脚本排除在等式之外,并让一个pyqt脚本处理所有按钮事件。现在,OSD从第一次按下按钮开始就以恒定的速率超时,而不是在最后一次按下按钮后保持固定的时间。
只需复制,粘贴和保存文件(名称以粗体显示),将它们全部放在同一目录中,设置可执行位,并根据保存它们的位置修改pyqt脚本中的系统调用,或将它们全部放入路径中的目录。然后,将外壳程序脚本映射到Compiz命令,Openbox快捷方式或类似内容,如果不使用多媒体键盘音量按钮,则更改pyqt脚本。
注意:类名Qvol是一个有效的标题,我没有费心去更改它。另请注意,静音按钮未使用-这只是一个原型,用来表达实现所需功能的可能途径,并且当前不与任何类型的托管项目或标准开发模型相关联。从下面的代码获得的任何重大发展都应该属于Sourceforge,GitHub或项目网站。就是说,随时编辑此答案或建议一个允许其功能和设计相似的现有项目。
vol_step_down
#!/bin/bash
pulseaudio --check
#if [ $? -ne 0 ] ; then
if [ $? -eq 0 ] ; then
pactl set-sink-volume 0 -- -3db
else
amixer -c0 set Master playback 3-
fi
if [ -z "$1" ] ; then
pqvol -s
fi
vol_step_up
#!/bin/bash
pulseaudio --check
#if [ $? -ne 0 ] ; then
if [ $? -eq 0 ] ; then
pactl set-sink-volume 0 -- +3db
else
amixer -c0 set Master playback 3+
fi
if [ -z "$1" ] ; then
pqvol -s
fi
pqvol
#!/usr/bin/env python2
# pvol -- Commandline audio volume utility
# with an optional GTK progressbar
# Copyright (C) 2009 Adrian C. <anrxc_sysphere_org>
# Modified by 2011 Reza Jelveh
# Ported to pyqt and renamed to pqvol 2013 by Adam R.
# 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 os.path
import optparse
import alsaaudio
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QTimer
appname = "Qvol"
#appicon = "/usr/share/icons/ubuntu-mono-light/status/24/audio-volume-high-panel.svg"
DEFAULT_STYLE = """
QProgressBar{
border: 2px solid grey;
border-radius: 5px;
background-color: transparent;
}
QProgressBar::chunk {
background-color: Gainsboro;
}
"""
class AlsaMixer():
def __init__(self, pcm=False, mute=False, arg=None):
self.mixer = alsaaudio.Mixer()
self.percent = self.mixer.getvolume()[0]
print self.percent
self.label = "dB" #% name
if arg:
self.percent = min(100, max(0, self.percent + int(arg)))
self.mixer.setvolume(self.percent)
if mute:
mutestate = self.mixer.getmute()[0]
if mutestate:
self.label = "Unmuted: "
else:
self.label = "Muted: "
self.mixer.setmute(mutestate^1)
# self.label = self.label + "%.0f%%" % self.percent
class Qvol(QtGui.QWidget):
def __init__(self):
super(Qvol, self).__init__()
# self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setWindowFlags(QtCore.Qt.Popup)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.setWindowTitle("Qvol")
self.initUI()
def initUI(self):
self.pbar = QtGui.QProgressBar(self)
self.pbar.setGeometry(5, 5, 20, 470)
self.pbar.setOrientation(QtCore.Qt.Vertical)
self.pbar.setRange(0,100)
volume = AlsaMixer()
self.pbar.setValue(volume.percent)
self.pbar.setTextVisible(False)
self.setStyleSheet(DEFAULT_STYLE)
self.setGeometry(1260, 180, 30, 480)
self.setWindowTitle('QtGui.QProgressBar')
self.show()
QTimer.singleShot(2000, finished)
def keyPressEvent(self, event):
if event.key()==QtCore.Qt.Key_VolumeMute:
# QtGui.QWidget.paintEvent()
finished()
elif event.key()==QtCore.Qt.Key_VolumeDown:
launch_process ("vol_step_down silent")
volume=AlsaMixer()
self.pbar.setValue(volume.percent)
# finished()
elif event.key()==QtCore.Qt.Key_VolumeUp:
launch_process ("vol_step_up silent")
volume=AlsaMixer()
self.pbar.setValue(volume.percent)
# finished()
# else:
# QtGui.QWidget.keyPressEvent(self, event)
processes = set([])
def launch_process(process):
# Do something asynchronously
proc = QtCore.QProcess()
processes.add(proc)
proc.start(process)
proc.waitForFinished(-1)
def finished():
print "The process is done!"
# Quit the app
QtCore.QCoreApplication.instance().quit()
def main():
app = QtGui.QApplication(sys.argv)
ex = Qvol()
sys.exit(app.exec_())
if __name__ == '__main__':
main()