本文整理汇总了Python中PyQt5.QtWidgets.QSlider.isSliderDown方法的典型用法代码示例。如果您正苦于以下问题:Python QSlider.isSliderDown方法的具体用法?Python QSlider.isSliderDown怎么用?Python QSlider.isSliderDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QSlider
的用法示例。
在下文中一共展示了QSlider.isSliderDown方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlayerControls
# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import isSliderDown [as 别名]
class PlayerControls(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
layout = QHBoxLayout(self)
self.seek_slider = QSlider(orientation=Qt.Horizontal, parent=self)
self.volume_slider = QSlider(orientation=Qt.Horizontal, maximum=1000,
parent=self)
self.playback_time = QLabel(parent=self)
self.duration = QLabel(parent=self)
layout.addWidget(self.seek_slider)
layout.addWidget(self.volume_slider)
layout.addWidget(self.playback_time)
layout.addWidget(self.duration)
self.setLayout(layout)
@pyqtSlot(float)
def update_seek_slider_position(self, val):
if not self.seek_slider.isSliderDown():
self.seek_slider.setSliderPosition(val * 1000)
@pyqtSlot(float)
def update_seek_slider_maximum(self, val):
self.seek_slider.setMaximum(val * 1000)
@pyqtSlot(float)
def update_duration(self, val):
self.duration.setText('{:.2f}'.format(val))
@pyqtSlot(float)
def update_playback_time(self, val):
self.playback_time.setText('{:.2f}'.format(val))
示例2: Player
# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import isSliderDown [as 别名]
#.........这里部分代码省略.........
self.fullScreenButton.setEnabled(False)
self.metaDataChanged()
self.addToPlaylist(playlist)
def open(self):
fileNames, _ = QFileDialog.getOpenFileNames(self, "Open Files")
self.addToPlaylist(fileNames)
def addToPlaylist(self, fileNames):
for name in fileNames:
fileInfo = QFileInfo(name)
if fileInfo.exists():
url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
if fileInfo.suffix().lower() == 'm3u':
self.playlist.load(url)
else:
self.playlist.addMedia(QMediaContent(url))
else:
url = QUrl(name)
if url.isValid():
self.playlist.addMedia(QMediaContent(url))
def durationChanged(self, duration):
duration /= 1000
self.duration = duration
self.slider.setMaximum(duration)
def positionChanged(self, progress):
progress /= 1000
if not self.slider.isSliderDown():
self.slider.setValue(progress)
self.updateDurationInfo(progress)
def metaDataChanged(self):
if self.player.isMetaDataAvailable():
self.setTrackInfo("%s - %s" % (
self.player.metaData(QMediaMetaData.AlbumArtist),
self.player.metaData(QMediaMetaData.Title)))
def previousClicked(self):
# Go to the previous track if we are within the first 5 seconds of
# playback. Otherwise, seek to the beginning.
if self.player.position() <= 5000:
self.playlist.previous()
else:
self.player.setPosition(0)
def jump(self, index):
if index.isValid():
self.playlist.setCurrentIndex(index.row())
self.player.play()
def playlistPositionChanged(self, position):
self.playlistView.setCurrentIndex(
self.playlistModel.index(position, 0))
def seek(self, seconds):
self.player.setPosition(seconds * 1000)
def statusChanged(self, status):
self.handleCursor(status)
示例3: MusicPlayer
# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import isSliderDown [as 别名]
#.........这里部分代码省略.........
def press_playback(self, event):
"""Change the playback of the player on cover art mouse event.
When the cover art is clicked, the player will play the media if the player is
either paused or stopped. If the media is playing, the media is set
to pause.
"""
if event.button() == 1 and configuration.Playback().cover_art_playback.isChecked():
if (self.player.state() == QMediaPlayer.StoppedState or
self.player.state() == QMediaPlayer.PausedState):
self.player.play()
elif self.player.state() == QMediaPlayer.PlayingState:
self.player.pause()
def seek(self, seconds):
"""Set the position of the song to the position dragged to by the user."""
self.player.setPosition(seconds * 1000)
def song_duration(self, duration):
"""Set the slider to the duration of the currently played media."""
duration /= 1000
self.duration = duration
self.slider.setMaximum(duration)
def song_position(self, progress):
"""Move the horizontal slider in sync with the duration of the song.
The progress is relayed to update_duration() in order
to display the time label next to the slider.
"""
progress /= 1000
if not self.slider.isSliderDown():
self.slider.setValue(progress)
self.update_duration(progress)
def update_duration(self, current_duration):
"""Calculate the time played and the length of the song.
Both of these times are sent to duration_label() in order to display the
times on the toolbar.
"""
duration = self.duration
if current_duration or duration:
time_played = QTime((current_duration / 3600) % 60, (current_duration / 60) % 60,
(current_duration % 60), (current_duration * 1000) % 1000)
song_length = QTime((duration / 3600) % 60, (duration / 60) % 60, (duration % 60),
(duration * 1000) % 1000)
if duration > 3600:
time_format = "hh:mm:ss"
else:
time_format = "mm:ss"
time_display = "{} / {}" .format(time_played.toString(time_format), song_length.toString(time_format))
else:
time_display = ""
self.duration_label.setText(time_display)
def set_state(self, state):
"""Change the icon in the toolbar in relation to the state of the player.
示例4: Widget
# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import isSliderDown [as 别名]
#.........这里部分代码省略.........
def stop(self):
"""Stops the MIDI player."""
self._player.stop()
def restart(self):
"""Restarts the MIDI player.
If another file is in the file selector, or the file was updated,
the new file is loaded.
"""
self._player.seek(0)
self.updateTimeSlider()
self._display.reset()
if self._document:
files = midifiles.MidiFiles.instance(self._document)
index = self._fileSelector.currentIndex()
if files and (files.song(index) is not self._player.song()):
self.loadSong(index)
def slotTempoChanged(self, value):
"""Called when the user drags the tempo."""
# convert -50 to 50 to 0.5 to 2.0
factor = 2 ** (value / 50.0)
self._player.set_tempo_factor(factor)
self._display.setTempo("{0}%".format(int(factor * 100)))
def slotTimeSliderChanged(self, value):
self._player.seek(value)
self._display.setTime(value)
if self._player.song():
self._display.setBeat(*self._player.song().beat(value)[1:])
def slotTimeSliderMoved(self, value):
self._display.setTime(value)
if self._player.song():
self._display.setBeat(*self._player.song().beat(value)[1:])
def updateTimeSlider(self):
if not self._timeSlider.isSliderDown():
with qutil.signalsBlocked(self._timeSlider):
self._timeSlider.setMaximum(self._player.total_time())
self._timeSlider.setValue(self._player.current_time())
def updateDisplayBeat(self, measnum, beat, num, den):
if not self._timeSlider.isSliderDown():
self._display.setBeat(measnum, beat, num, den)
def updateDisplayTime(self, time):
if not self._timeSlider.isSliderDown():
self._display.setTime(time)
def slotUpdatedFiles(self, document, job=None):
"""Called when there are new MIDI files."""
mainwindow = self.parentWidget().mainwindow()
import engrave
if document not in (mainwindow.currentDocument(), engrave.engraver(mainwindow).document()):
return
import jobattributes
if job and jobattributes.get(job).mainwindow != mainwindow:
return
self.loadResults(document)
def loadResults(self, document):
files = midifiles.MidiFiles.instance(document)
if files.update():
self._document = document
self._fileSelector.setModel(files.model())
self._fileSelector.setCurrentIndex(files.current)
if not self._player.is_playing():
self.loadSong(files.current)
def loadSong(self, index):
files = midifiles.MidiFiles.instance(self._document)
self._player.set_song(files.song(index))
m, s = divmod(self._player.total_time() // 1000, 60)
name = self._fileSelector.currentText()
self.updateTimeSlider()
self._display.reset()
self._display.statusMessage(
_("midi lcd screen", "LOADED"), name,
_("midi lcd screen", "TOTAL"), "{0}:{1:02}".format(m, s))
def slotFileSelected(self, index):
if self._document:
self._player.stop()
files = midifiles.MidiFiles.instance(self._document)
if files:
files.current = index
self.restart()
def slotDocumentClosed(self, document):
if document == self._document:
self._document = None
self._fileSelector.clear()
self._player.stop()
self._player.clear()
self.updateTimeSlider()
self._display.reset()
示例5: VideoWidget
# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import isSliderDown [as 别名]
#.........这里部分代码省略.........
def _repaintPlayer(self):
if self._ratio == 0:
margin = 0
else:
newWidth = self._playerWidget.height() * self._ratio
margin = int((self._background.width() - newWidth) / 2)
if margin < 0:
margin = 0
self._background.layout().setContentsMargins(margin, 0, margin, 0)
def _initWidget(self):
self.setObjectName("video_player")
mainLayout = QVBoxLayout()
mainLayout.setContentsMargins(0, 0, 0, 0)
mainLayout.setSpacing(0)
# Separate background to keep black background when playerWidget resizes
self._background = QWidget(self)
self._background.setStyleSheet("background: black")
mainLayout.addWidget(self._background, 1)
self._playerWidget = QWidget(self)
backgroundLayout = QHBoxLayout()
self._background.setLayout(backgroundLayout)
backgroundLayout.addWidget(self._playerWidget)
controls = self._initControlPanel()
mainLayout.addLayout(controls)
self.setLayout(mainLayout)
def _initControlPanel(self):
layout = QHBoxLayout()
layout.setContentsMargins(0,0,0,0)
self._playButton = QPushButton(QIcon.fromTheme("media-playback-start"), "", self)
self._playButton.setCheckable(True)
self._playButton.setFocusPolicy(Qt.NoFocus)
self._playButton.setToolTip(_("Play/Pause"))
self._slider = QSlider(Qt.Horizontal, self)
self._slider.setDisabled(True)
self._timeLabel = QLabel("0:00:00.000", self)
layout.addWidget(self._playButton)
layout.addWidget(self._slider)
layout.addWidget(self._timeLabel)
layout.addSpacing(5)
return layout
def saveWidgetState(self, settings):
settings = SubSettings()
settings.setHidden(self, self.isHidden())
def restoreWidgetState(self, settings):
if settings.getHidden(self) is True:
self.hide()
else:
self.show()
def _moviePositionChanged(self, frame):
if not self._slider.isSliderDown():
self._movieFrame = frame
if frame % self._modulo == 0:
self._slider.setValue(self._movieFrame)
fps = self._player.videoData.fps
ft = FrameTime(fps, frames=frame)
self._timeLabel.setText(ft.toStr())
def _sliderActionHandle(self, action):
if action == QAbstractSlider.SliderPageStepAdd:
self._player.seek(1.0)
elif action == QAbstractSlider.SliderPageStepSub:
self._player.seek(-1.0)
elif action == QAbstractSlider.SliderSingleStepAdd:
self.forward()
elif action == QAbstractSlider.SliderSingleStepSub:
self.rewind()
elif action == QAbstractSlider.SliderMove:
position = self._slider.sliderPosition()
self._changePosition(position)
if self._slider.isSliderDown() and self._player.videoData.fps is not None:
fps = self._player.videoData.fps
ft = FrameTime(fps, frames=position)
self._timeLabel.setText(ft.toStr())
def _dataAvailabilityChanged(self, val):
if val is True:
fps = self._player.videoData.fps
length = self._player.videoData.length
self._slider.setRange(0, int(fps * length))
else:
self._slider.setRange(0, 99)
def _playButtonToggled(self, checked):
if checked is True:
self.play()
else:
self.pause()