diff options
-rw-r--r-- | clMonty.py | 46 | ||||
-rw-r--r-- | montypc.py | 14 | ||||
-rw-r--r-- | run.sh | 1 | ||||
-rw-r--r-- | song.py | 3 | ||||
-rw-r--r-- | winMain.py | 95 |
5 files changed, 159 insertions, 0 deletions
diff --git a/clMonty.py b/clMonty.py new file mode 100644 index 0000000..efcbbd1 --- /dev/null +++ b/clMonty.py @@ -0,0 +1,46 @@ +import mpd + +class Monty: + _client=None + + def __init__(self): + self._client=None + + def connect(self): + host="localhost" + port=6600 + self._client = mpd.MPDClient() + self._client.connect(host, port) + print "Connected to "+host+":"+str(port)+"" + print "MPD version: "+self._client.mpd_version + + def disconnect(self): + self._client.close() + self._client.disconnect() + self._client=None + + def listPlaylist(self): + ret=[] + for song in self._client.playlistinfo(): + ret.append(song) + + return ret + + def listLibrary(self): + ret=[] + for song in self._client.listallinfo(): + ret.append(song) + + return ret + + def play(self, index): + self._client.playid(index) + + def addToPlaylist(self, path): + print "Adding "+path + self._client.add(path) + + +monty=Monty() +monty.connect() + diff --git a/montypc.py b/montypc.py new file mode 100644 index 0000000..0ab3c00 --- /dev/null +++ b/montypc.py @@ -0,0 +1,14 @@ +import sys + +from PyQt4 import QtGui +from winMain import winMain + +import mpd + +app = QtGui.QApplication(sys.argv) +wMain = winMain() +wMain.show() +wMain.fillLibrary() +wMain.fillPlaylist() + +app.exec_() @@ -0,0 +1 @@ +python montypc.py @@ -0,0 +1,3 @@ +class Song: + def __init__(self): + pass diff --git a/winMain.py b/winMain.py new file mode 100644 index 0000000..3ac9eeb --- /dev/null +++ b/winMain.py @@ -0,0 +1,95 @@ +from clMonty import monty +from PyQt4 import QtGui, QtCore + +class winMain(QtGui.QWidget): + " label with info" + lblInfo=None + " library of songs" + library=None + " current playlist" + playlist=None + " headers showing up in the playlist" + hItems=None + + def __init__(self, parent=None): + QtGui.QWidget.__init__(self, parent) + self.setWindowTitle("montypc - An MPD client") + + self.hItems=["artist", "title", "album", "file"] + + self.playlist=QtGui.QTableWidget() + self.library=QtGui.QTableWidget() + self.lblInfo=QtGui.QLabel() + + vbox=QtGui.QVBoxLayout() + hbox=QtGui.QHBoxLayout() + + vbox.addWidget(self.lblInfo) + hbox.addWidget(self.library) + hbox.addWidget(self.playlist) + vbox.addLayout(hbox) + + + self.setLayout(vbox) + self.resize(800,600) + + self.connect(self.library, + QtCore.SIGNAL('itemDoubleClicked(QTableWidgetItem*)'), + self._onLibraryDoubleClick) + self.connect(self.playlist, + QtCore.SIGNAL('itemDoubleClicked(QTableWidgetItem*)'), + self._onPlaylistDoubleClick) + + def fillPlaylist(self): + """Fill the playlist view""" + entries=monty.listPlaylist() + row=-1 + + " update the playlist column headers" + self.playlist.setColumnCount(len(self.hItems)) + headers=QtCore.QStringList() + for h in self.hItems: + headers.append(h) + self.playlist.setHorizontalHeaderLabels(headers) + + self.playlist.setRowCount(len(entries)) + + for song in entries: + row+=1 + col=-1 + for h in self.hItems: + col+=1 + try: + self.playlist.setItem(row, col, QtGui.QTableWidgetItem(song[h])) + except: + pass + + def fillLibrary(self): + """Fill the library view""" + entries=monty.listLibrary() + row=-1 + + self.library.setRowCount(len(entries)) + self.library.setColumnCount(1) + + curdir="" + for song in entries: + row+=1 + entry=QtGui.QTableWidgetItem() + if "directory" in song: + curdir=song["directory"] + entry.setText(curdir) + elif "file" in song: + fname=song['file'][len(curdir)+1:] + entry.setText(" "+fname) + + self.library.setItem(row, 0, entry) + + + def _onLibraryDoubleClick(self): + monty.addToPlaylist(self.library.currentItem().text()) + self.fillPlaylist() + + def _onPlaylistDoubleClick(self): + self.lblInfo.setText(str(self.playlist.currentRow())) + monty.play(self.playlist.currentRow()) |