本文整理汇总了Python中PyQt5.QtWidgets.QDial.setFocus方法的典型用法代码示例。如果您正苦于以下问题:Python QDial.setFocus方法的具体用法?Python QDial.setFocus怎么用?Python QDial.setFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QDial
的用法示例。
在下文中一共展示了QDial.setFocus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QDial [as 别名]
# 或者: from PyQt5.QtWidgets.QDial import setFocus [as 别名]
class MainWindow(QMainWindow):
"""Voice Changer main window."""
def __init__(self, parent=None):
super(MainWindow, self).__init__()
self.statusBar().showMessage("Move Dial to Deform Microphone Voice !.")
self.setWindowTitle(__doc__)
self.setMinimumSize(240, 240)
self.setMaximumSize(480, 480)
self.resize(self.minimumSize())
self.setWindowIcon(QIcon.fromTheme("audio-input-microphone"))
self.tray = QSystemTrayIcon(self)
self.center()
QShortcut("Ctrl+q", self, activated=lambda: self.close())
self.menuBar().addMenu("&File").addAction("Quit", lambda: exit())
self.menuBar().addMenu("Sound").addAction(
"STOP !", lambda: call('killall rec', shell=True))
windowMenu = self.menuBar().addMenu("&Window")
windowMenu.addAction("Hide", lambda: self.hide())
windowMenu.addAction("Minimize", lambda: self.showMinimized())
windowMenu.addAction("Maximize", lambda: self.showMaximized())
windowMenu.addAction("Restore", lambda: self.showNormal())
windowMenu.addAction("FullScreen", lambda: self.showFullScreen())
windowMenu.addAction("Center", lambda: self.center())
windowMenu.addAction("Top-Left", lambda: self.move(0, 0))
windowMenu.addAction("To Mouse", lambda: self.move_to_mouse_position())
# widgets
group0 = QGroupBox("Voice Deformation")
self.setCentralWidget(group0)
self.process = QProcess(self)
self.process.error.connect(
lambda: self.statusBar().showMessage("Info: Process Killed", 5000))
self.control = QDial()
self.control.setRange(-10, 20)
self.control.setSingleStep(5)
self.control.setValue(0)
self.control.setCursor(QCursor(Qt.OpenHandCursor))
self.control.sliderPressed.connect(
lambda: self.control.setCursor(QCursor(Qt.ClosedHandCursor)))
self.control.sliderReleased.connect(
lambda: self.control.setCursor(QCursor(Qt.OpenHandCursor)))
self.control.valueChanged.connect(
lambda: self.control.setToolTip(f"<b>{self.control.value()}"))
self.control.valueChanged.connect(
lambda: self.statusBar().showMessage(
f"Voice deformation: {self.control.value()}", 5000))
self.control.valueChanged.connect(self.run)
self.control.valueChanged.connect(lambda: self.process.kill())
# Graphic effect
self.glow = QGraphicsDropShadowEffect(self)
self.glow.setOffset(0)
self.glow.setBlurRadius(99)
self.glow.setColor(QColor(99, 255, 255))
self.control.setGraphicsEffect(self.glow)
self.glow.setEnabled(False)
# Timer to start
self.slider_timer = QTimer(self)
self.slider_timer.setSingleShot(True)
self.slider_timer.timeout.connect(self.on_slider_timer_timeout)
# an icon and set focus
QLabel(self.control).setPixmap(
QIcon.fromTheme("audio-input-microphone").pixmap(32))
self.control.setFocus()
QVBoxLayout(group0).addWidget(self.control)
self.menu = QMenu(__doc__)
self.menu.addAction(__doc__).setDisabled(True)
self.menu.setIcon(self.windowIcon())
self.menu.addSeparator()
self.menu.addAction(
"Show / Hide",
lambda: self.hide() if self.isVisible() else self.showNormal())
self.menu.addAction("STOP !", lambda: call('killall rec', shell=True))
self.menu.addSeparator()
self.menu.addAction("Quit", lambda: exit())
self.tray.setContextMenu(self.menu)
self.make_trayicon()
def run(self):
"""Run/Stop the QTimer."""
if self.slider_timer.isActive():
self.slider_timer.stop()
self.glow.setEnabled(True)
call('killall rec ; killall play', shell=True)
self.slider_timer.start(3000)
def on_slider_timer_timeout(self):
"""Run subprocess to deform voice."""
self.glow.setEnabled(False)
value = int(self.control.value()) * 100
command = f'play -q -V0 "|rec -q -V0 -n -d -R riaa bend pitch {value} "'
print(f"Voice Deformation Value: {value}")
print(f"Voice Deformation Command: {command}")
self.process.start(command)
if self.isVisible():
self.statusBar().showMessage("Minimizing to System TrayIcon", 3000)
print("Minimizing Main Window to System TrayIcon now...")
sleep(3)
self.hide()
#.........这里部分代码省略.........