Beispiel #1
0
    def __init__(self):
	QMainWindow.__init__(self)
	# This is always the same
	self.ui = Ui_MainWindow()
	self.ui.setupUi(self)
	#Model View Playlist
	self.playlistModel = PlayListModel()
	self.ui.playtableView.setModel(self.playlistModel)
	self.ui.playtableView.horizontalHeader().setStretchLastSection(True)
	#NavigationModel
	self.navigationModel = QDirModel()
	self.navigationModel.setFilter(QDir.Files | QDir.AllDirs | QDir.NoSymLinks | QDir.NoDotAndDotDot)
	nameFilters = []
	nameFilters.append("*.mid")
	nameFilters.append("*.midi")
	self.navigationModel.setNameFilters(nameFilters)
	self.ui.navigationView.setModel(self.navigationModel)
	self.ui.navigationView.setRootIndex(self.navigationModel.index(QDir.currentPath()))
	#Associate Actions to buttons
	self.ui.nextButton.setDefaultAction(self.ui.actionNext)
	self.ui.prevButton.setDefaultAction(self.ui.actionPrev)
	self.ui.playButton.setDefaultAction(self.ui.actionPlay)
	self.ui.stopButton.setDefaultAction(self.ui.actionStop)
	self.ui.homeButton.setDefaultAction(self.ui.actionNavigationHome)
	self.ui.upButton.setDefaultAction(self.ui.actionNavigationUp)
	# If soundfonts are installed and configured disable configuration wizard
	if os.path.exists(SOUNDFONT_FILE_DESTINATION_PATH):
	    self.ui.actionConfWizard.setEnabled(False)
	# Connect actionQuick to default quit SLOT
	self.connect(self.ui.actionQuit, SIGNAL("triggered()"), self, SLOT("close()"));
	#File actually playing
	self.play = None
	#Statusbar nowplaying label
	self.nowPlayingLabel = QLabel()
	self.nowPlayingLabel.setText(self.tr("Playing: <b>Nothing</b>"))
	self.ui.statusbar.addWidget(self.nowPlayingLabel)
	# If a path is passed via commandline enquee the midi and play it
	try:
	    fileInfo = QFileInfo(sys.argv[1])
	    row = self.playlistModel.rowCount()
	    self.playlistModel.insertRows(row, 1, fileInfo)
	    self.ui.playtableView.resizeRowToContents(row)
	    self.ui.navigationView.setRootIndex(self.navigationModel.index(fileInfo.path()))
	    self.playlistModel.setFilePlaying(1)
	    self.ui.actionPlay.trigger()
	except IndexError:
	    pass
	#Empty thread
	self.thread = None
Beispiel #2
0
class Main(QMainWindow):
    def __init__(self):
	QMainWindow.__init__(self)
	# This is always the same
	self.ui = Ui_MainWindow()
	self.ui.setupUi(self)
	#Model View Playlist
	self.playlistModel = PlayListModel()
	self.ui.playtableView.setModel(self.playlistModel)
	self.ui.playtableView.horizontalHeader().setStretchLastSection(True)
	#NavigationModel
	self.navigationModel = QDirModel()
	self.navigationModel.setFilter(QDir.Files | QDir.AllDirs | QDir.NoSymLinks | QDir.NoDotAndDotDot)
	nameFilters = []
	nameFilters.append("*.mid")
	nameFilters.append("*.midi")
	self.navigationModel.setNameFilters(nameFilters)
	self.ui.navigationView.setModel(self.navigationModel)
	self.ui.navigationView.setRootIndex(self.navigationModel.index(QDir.currentPath()))
	#Associate Actions to buttons
	self.ui.nextButton.setDefaultAction(self.ui.actionNext)
	self.ui.prevButton.setDefaultAction(self.ui.actionPrev)
	self.ui.playButton.setDefaultAction(self.ui.actionPlay)
	self.ui.stopButton.setDefaultAction(self.ui.actionStop)
	self.ui.homeButton.setDefaultAction(self.ui.actionNavigationHome)
	self.ui.upButton.setDefaultAction(self.ui.actionNavigationUp)
	# If soundfonts are installed and configured disable configuration wizard
	if os.path.exists(SOUNDFONT_FILE_DESTINATION_PATH):
	    self.ui.actionConfWizard.setEnabled(False)
	# Connect actionQuick to default quit SLOT
	self.connect(self.ui.actionQuit, SIGNAL("triggered()"), self, SLOT("close()"));
	#File actually playing
	self.play = None
	#Statusbar nowplaying label
	self.nowPlayingLabel = QLabel()
	self.nowPlayingLabel.setText(self.tr("Playing: <b>Nothing</b>"))
	self.ui.statusbar.addWidget(self.nowPlayingLabel)
	# If a path is passed via commandline enquee the midi and play it
	try:
	    fileInfo = QFileInfo(sys.argv[1])
	    row = self.playlistModel.rowCount()
	    self.playlistModel.insertRows(row, 1, fileInfo)
	    self.ui.playtableView.resizeRowToContents(row)
	    self.ui.navigationView.setRootIndex(self.navigationModel.index(fileInfo.path()))
	    self.playlistModel.setFilePlaying(1)
	    self.ui.actionPlay.trigger()
	except IndexError:
	    pass
	#Empty thread
	self.thread = None
	
    def on_navigationView_doubleClicked(self,newIndex):
	''' On dir doubleclick set new directory in navigation view, on doubleclick on midi file enqueue it in playlist'''
	if (QDirModel.isDir(self.navigationModel,newIndex) == True):
	    self.ui.navigationView.setRootIndex(newIndex)
	else:
	    fileInfo = QDirModel.fileInfo(self.navigationModel, newIndex)
	    row = self.playlistModel.rowCount()
	    self.playlistModel.insertRows(row, 1, fileInfo)
	    self.ui.playtableView.resizeRowToContents(row)
	    
	    
    
    def on_playtableView_doubleClicked(self, playtableIndex):
	'''Play double clicked items in playlist'''
	self.playlistModel.setFilePlaying(playtableIndex.row() + 1)
	self.ui.actionPlay.trigger()
	
    def on_actionNext_triggered(self, checked=None):
	'''Play current item in playlistWidget'''
	if checked is None: return
	if (self.playlistModel.filePlaying == self.playlistModel.rowCount()):
	    return
	else:
	    self.playlistModel.setFilePlaying(self.playlistModel.filePlaying + 1)
	    self.ui.actionStop.trigger()
	    self.ui.actionPlay.trigger()
	    
    def on_actionPrev_triggered(self, checked=None):
	'''Play current item in playlistWidget'''
	if checked is None: return
	if (self.playlistModel.filePlaying == 1):
	    return
	else:
	    self.playlistModel.setFilePlaying(self.playlistModel.filePlaying - 1)
	    self.ui.actionStop.trigger()
	    self.ui.actionPlay.trigger()
    
    def on_actionRemove_triggered(self, checked=None):
	if checked is None: return
	if self.playlistModel.filePlaying == self.ui.playtableView.currentIndex().row() + 1:
	    self.playlistModel.removeRows(self.ui.playtableView.currentIndex().row())
	    self.ui.actionStop.trigger()
	    self.ui.actionPlay.trigger()
	else:
	    self.playlistModel.removeRows(self.ui.playtableView.currentIndex().row())

    def on_actionPlay_triggered(self, checked=None):
	if checked is None: return
	if not self.thread == None:
	    self.ui.actionStop.trigger()
	self.thread = timidityThread(self.playlistModel, self.nowPlayingLabel)
	self.thread.start()

	    
    def on_actionStop_triggered(self, checked=None):
	'''Stop current playing file '''
	if checked is None: return
	self.thread.emptyPlaylist()
	self.thread.terminate()
	self.thread.play.terminate()
	self.thread.play.kill()
	self.nowPlayingLabel.setText(self.tr("Playing: <b>Nothing</b>"))

    def closeEvent(self,event):
	'''Stop current playing song before exit app'''
	self.thread.terminate()
	self.thread.play.terminate()
	self.thread.play.kill()
    
    def on_actionNavigationUp_triggered(self, checked=None):
	if checked is None: return
	currentDir = QDir(self.navigationModel.filePath(self.ui.navigationView.rootIndex()))
	QDir.cdUp(currentDir)
	self.ui.navigationView.setRootIndex(self.navigationModel.index(currentDir.canonicalPath()))
	
    def on_actionNavigationHome_triggered(self, checked=None):
	if checked is None: return
	self.ui.navigationView.setRootIndex(self.navigationModel.index(QDir.homePath()))
	
    def on_actionConfWizard_triggered(self, checked=None):
	if checked is None: return
	import configWizard
	self.dialog = configWizard.Form(self)
	self.dialog.exec_()
	self.ui.actionConfWizard.setEnabled(False)