普通の文章
Pythonのコード
class ControlWindow(QtGui.QWidget):
def __init__(self, filename='', Parent=None):
super(ControlWindow, self).__init__(Parent)
devices = Phonon.BackendCapabilities.availableAudioOutputDevices()
# jack_pattern = re.compile('[Jj]ack')
jack_pattern = re.compile('[jJ]ack')
self.jack = None
# print(devices)
for dev in devices:
print((dev.index(), dev.name(), dev.description()))
if jack_pattern.search(dev.name()) is not None:
self.jack = dev
# return
self.set_title()
self.temp_file = ""
# self.timer = QtCore.QTimer()
# self.timer.setInterval(100)
# self.timer.timeout.connect(self.get_play_status)
# Play buttons
self.play_btn = QtGui.QPushButton("PLAY", self)
self.play_btn.setCheckable(True)
self.play_btn.clicked[bool].connect(self.play)
self.play_btn_style = {}
self.play_btn_style['normal'] = 'color:red;font-weight:bold'
self.play_btn_style['posed'] = 'color:green;font-weight:bold'
self.play_btn_style['playing'] = 'color:red;font-weight:bold;'
# + 'background-color:white'
self.play_btn.setStyleSheet(self.play_btn_style['normal'])
self.stop_btn = QtGui.QPushButton("STOP", self)
self.stop_btn.setEnabled(False)
self.stop_btn.clicked.connect(self.play_stop)
self.stop_btn_style = {}
self.stop_btn_style['normal'] = 'color:rgba(180, 50, 40, 180);'
self.stop_btn_style['posed'] = 'color:red;font-weight:bold'
self.stop_btn_style['playing'] = 'color:red;font-weight:bold'
self.stop_btn.setStyleSheet(self.stop_btn_style['normal'])
self.prev_btn = QtGui.QPushButton("Prev", self)
self.prev_btn.setCheckable(False)
self.next_btn = QtGui.QPushButton("Next", self)
self.next_btn.setCheckable(False)
# self.output = Phonon.AudioOutput()
# self.output.setOutputDevice(self.jack)
# ProgressBar
self.seek_slider = Phonon.SeekSlider()
self.volume_slder = Phonon.VolumeSlider()
# self.volume_slder.setAudioOutput(self.output)
progress_layout = QtGui.QVBoxLayout()
progress_layout.addWidget(self.seek_slider)
progress_layout.addWidget(self.volume_slder)
# progress_layout.addWidget(self.progress_label)
# File control
self.open_btn = QtGui.QPushButton("Open", self)
self.open_btn.clicked.connect(self.open_file)
button_layout = QtGui.QHBoxLayout()
button_layout.addWidget(self.play_btn)
button_layout.addWidget(self.stop_btn)
button_layout.addWidget(self.prev_btn)
button_layout.addWidget(self.next_btn)
button_layout.addWidget(self.open_btn)
# Time controls
main_layout = QtGui.QVBoxLayout()
main_layout.addLayout(button_layout)
main_layout.addLayout(progress_layout)
self.setLayout(main_layout)
self.setGeometry(100, 100, 600, 100)
# self.start()
# self.play_btn.click()
# self.stop_btn.click()
def start(self):
self.show()
def play(self, pressed):
if self.temp_file == "":
self.temp_file = "./tmpout.avi"
self.temp_file = "./toho.flv"
# self.open_file()
if pressed:
if os.path.isfile(self.temp_file):
self.play_win = PlayWindow(filename=self.temp_file,
button=self.play_btn,
output=None)
self.play_win.show()
self.play_win.play()
self.play_btn.setStyleSheet(self.play_btn_style['playing'])
self.seek_slider.setMediaObject(self.play_win.player.mediaObject())
# temp_ audio = self.play_win.player.audioOutput()
# temp_audio.setOutputDevice(self.jack)
# print(temp_audio.outputDevice().name())
# print(self.jack.name())
self.stop_btn.setEnabled(True)
self.stop_btn.setStyleSheet(self.stop_btn_style['playing'])
else:
print('NoFile')
else:
if 'play_win' in self.__dict__:
# self.play_win.stop()
self.play_stop()
def closeEvent(self, a):
if 'play_win' in self.__dict__:
self.play_win.close()
def set_title(self, filename=None):
if filename is None:
title = ' - MOVIE - '
else:
title = os.path.basename(filename)
self.setWindowTitle(title)
def open_file(self):
filedir = os.path.dirname(__file__)
self.temp_file = QtGui.QFileDialog.getOpenFileName(self, 'Open file', filedir,)
if DEBUG:
print(self.temp_file)
# self.set_title(self.temp_file)
self.play_btn.click()
def set_default(self):
self.play_btn.setStyleSheet(self.play_btn_style['normal'])
self.play_btn.setChecked(False)
self.stop_btn.setStyleSheet(self.stop_btn_style['normal'])
self.stop_btn.setEnabled(False)
def get_play_status(self):
if 'play_win' in self.__dict__ and self.play_win is not None:
self.get_time()
if self.play_win.player.isPlaying():
return True
return False
def get_time(self):
if 'play_win' in self.__dict__ and self.play_win is not None:
print(self.play_win.player.currentTime())
def play_stop(self):
self.set_default()
self.play_win.stop()