本文整理汇总了Python中PySide.QtCore.QFile.seek方法的典型用法代码示例。如果您正苦于以下问题:Python QFile.seek方法的具体用法?Python QFile.seek怎么用?Python QFile.seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QFile
的用法示例。
在下文中一共展示了QFile.seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MyMainWindow
# 需要导入模块: from PySide.QtCore import QFile [as 别名]
# 或者: from PySide.QtCore.QFile import seek [as 别名]
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, frequency, parent=None):
super(MyMainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
wd = os.path.dirname(os.path.abspath(__file__))
self.tick_pixmaps = {True: QtGui.QPixmap(os.path.join(wd, 'pics', 'blinkenlicht_on.png')),
False: QtGui.QPixmap(os.path.join(wd, 'pics', 'blinkenlicht_off.png'))}
self.speaker_pixmaps = {True: QtGui.QIcon(QtGui.QPixmap(os.path.join(wd, 'pics', 'speaker_on.png'))),
False: QtGui.QIcon(QtGui.QPixmap(os.path.join(wd, 'pics', 'speaker_off.png')))}
self.tick_soundFile=QFile()
self.tick_soundFile.setFileName(os.path.join(wd, 'sounds', 'tick.raw'))
self.tick_soundFile.open(QIODevice.ReadOnly)
self.play_sound = True
self.format = QAudioFormat()
self.format.setChannels(1)
self.format.setFrequency(44050)
self.format.setSampleSize(16)
self.format.setCodec("audio/pcm")
self.format.setByteOrder(QAudioFormat.LittleEndian)
self.format.setSampleType(QAudioFormat.SignedInt)
self.audio_output = QAudioOutput(self.format)
self.ui.ping_icon.setPixmap(self.tick_pixmaps[False])
self.ui.speaker_button.setIcon(self.speaker_pixmaps[self.play_sound])
self.blink_timer = QTimer()
self.blink_timer.setSingleShot(True)
self.blink_timer.timeout.connect(self.clear_blink)
self.timer = QTimer()
self.frequency = frequency
self.last_played = 0
self.count = 0
self.ui.f_spin.setValue(self.frequency)
self.set_speed()
self.timer.timeout.connect(self.play_tick)
self.play_ctrl = {True: 'Stop',
False: 'Start'}
self.ui.play_button.setText(self.play_ctrl[False])
self.ui.statusBar.showMessage('{count:04d} - Dev.: {delta:.3f} ms'.format(delta=0, count=self.count))
def set_frequency(self, frequency):
self.frequency = frequency
self.set_speed()
self.last_played = 0
self.count = 0
def set_speed(self):
self.speed = 1000.0 / (self.frequency / 60.0)
self.timer.setInterval(self.speed)
def clear_blink(self):
self.ui.ping_icon.setPixmap(self.tick_pixmaps[False])
def toggle_play(self):
if self.timer.isActive():
self.timer.stop()
self.last_played = 0
self.count = 0
self.ui.statusBar.clearMessage()
else:
self.timer.start(self.speed)
self.play_tick()
self.ui.play_button.setText(self.play_ctrl[self.timer.isActive()])
def toggle_play_sound(self):
if self.play_sound:
self.play_sound = False
self.audio_output.stop()
else:
self.play_sound = True
self.ui.speaker_button.setIcon(self.speaker_pixmaps[self.play_sound])
def play_tick(self):
if self.last_played:
delta = ((time.time() - self.last_played) * 1000.0) - self.speed
else:
delta = 0
self.last_played = time.time()
self.audio_output.stop()
self.audio_output.reset()
if self.play_sound:
self.tick_soundFile.seek(0)
self.audio_output.start(self.tick_soundFile)
self.count += 1
self.ui.statusBar.showMessage('{count:04d} - Dev.: {delta:.3f} ms'.format(delta=delta, count=self.count))
#.........这里部分代码省略.........