diff options
author | jerous <jerous@gmail.com> | 2008-06-07 23:06:51 +0200 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-06-07 23:09:41 +0200 |
commit | c0e62a0f0d190f161a5268df2fbfda0d4b3c38fb (patch) | |
tree | 58bd0bbfb59eed5dd2a566ac7f74b39b82343948 /winMain.py | |
parent | 1a98fe2c142fabe0275ed788722e6dc3ccd4b4fa (diff) |
using DockWidgets allowing more flexibility
removed resizer
Diffstat (limited to 'winMain.py')
-rw-r--r-- | winMain.py | 354 |
1 files changed, 194 insertions, 160 deletions
@@ -12,33 +12,179 @@ from winSettings import winSettings from wgSongList import SongList from wgPlaylist import Playlist -from wgResizer import VResizer clrRowSel=QtGui.QColor(180,180,180) -class winMain(QtGui.QWidget): - """The winMain class is mpc's main window, showing the playlists and control-interface""" - "Elements" - " label with info" +class wgSongStatus(QtGui.QWidget): + """Displays the status of the current song, if playing.""" + " label containing the info" lblInfo=None - " label with current status, at the bottom" - lblStatus=None - " lstLibrary of songs" - lstLibrary=None - " current lstPlaylist" - lstPlaylist=None - " slider for current time" - slrTime=None - " slider for volume" - slrVolume=None + def __init__(self, parent=None): + QtGui.QWidget.__init__(self, parent) + + self.lblInfo=QtGui.QLabel() + self.setMinimumWidth(400) + + layout=QtGui.QHBoxLayout() + self.setLayout(layout) + + layout.addWidget(self.lblInfo) + + monty.addListener('onSongChange', self.update) + monty.addListener('onTimeChange', self.update) + monty.addListener('onStateChange', self.update) + monty.addListener('onConnect', self.update) + monty.addListener('onDisconnect', self.update) + + def update(self, params): + status=monty.getStatus() + curSong=monty.getCurrentSong() + line=["Status:\t", "Song:\t", "Time:\t"] + + try: + line[0]="%s%s"%(line[0], {'play':'playing', 'stop':'not playing' + , 'pause':'paused'}[status['state']]) + if status['state']!='stop': + line[1]="%s%s by %s [%s]"% (line[1], curSong.getTitle(), + curSong.getArtist(), curSong.getAlbum()) + line[2]="%s%s/%s" % (line[2], sec2min(status['time']) + , sec2min(status['length'])) + except: + pass + # merge lines + self.lblInfo.setText("%s\n%s\n%s"%(line[0],line[1],line[2])) + + def text(self): + return self.lblInfo.text() + +class wgPlayControl(QtGui.QWidget): + """Displays controls for interacting with playing, like play, volume ...""" " control buttons" btnPlayPause=None btnStop=None btnPrevious=None btnNext=None + " slider for current time" + slrTime=None + " slider for volume" + slrVolume=None + " indicator for volume" + svgVolume=None + " all objects in this widget" + objects=None + def __init__(self, parent=None): + QtGui.QWidget.__init__(self, parent) + + self.slrTime=QtGui.QSlider(QtCore.Qt.Horizontal, self) + self.slrVolume=QtGui.QSlider(QtCore.Qt.Horizontal, self) + self.slrVolume.setMaximum(100) + self.slrVolume.setMinimumWidth(100) + self.slrVolume.setMaximumWidth(400) + # set to some value that'll never be chosen, that way onChange will be called automatically :) + self.slrVolume.setValue(3.141595) + self.svgVolume=QtSvg.QSvgWidget() + self.svgVolume.setMaximumWidth(64) + self.svgVolume.setMaximumHeight(64) + self.btnPlayPause=Button("play", self.onBtnPlayPauseClick, 'gfx/media-playback-start.svg', True) + self.btnStop=Button("stop", self.onBtnStopClick, 'gfx/media-playback-stop.svg', True) + self.btnPrevious=Button("prev", self.onBtnPreviousClick, 'gfx/media-skip-backward.svg', True) + self.btnNext=Button("next", self.onBtnNextClick, 'gfx/media-skip-forward.svg', True) + + self.objects=[self.slrVolume, self.svgVolume, self.slrTime, + self.btnStop, self.btnNext, self.btnPrevious] + + layout=QtGui.QHBoxLayout(parent) + self.setLayout(layout) + + layout.addWidget(self.btnPrevious) + layout.addWidget(self.btnPlayPause) + layout.addWidget(self.btnStop) + layout.addWidget(self.btnNext) + layout.addWidget(self.slrTime) + layout.addWidget(self.svgVolume) + layout.addWidget(self.slrVolume) + + self.connect(self.slrVolume, QtCore.SIGNAL('valueChanged(int)'),self.onVolumeSliderChange) + self.connect(self.slrTime, QtCore.SIGNAL('sliderReleased()'),self.onTimeSliderChange) + + monty.addListener('onStateChange', self.onStateChange) + monty.addListener('onSongChange', self.onSongChange) + monty.addListener('onVolumeChange', self.onVolumeChange) + monty.addListener('onReady', self.onReady) + monty.addListener('onDisconnect', self.onDisconnect) + monty.addListener('onTimeChange', self.onTimeChange) + + def onStateChange(self, params): + newState=params['newState'] + + map(lambda o: o.setEnabled(newState!='stop'), self.objects) + + if newState=='play': + self.btnPlayPause.changeIcon('gfx/media-playback-pause.svg') + self.btnPlayPause.setText('pauze') + elif newState=='pause' or newState=='stop': + self.btnPlayPause.changeIcon('gfx/media-playback-start.svg') + self.btnPlayPause.setText('play') + def onVolumeChange(self, params): + self.slrVolume.setValue(params['newVolume']) + def onReady(self, params): + map(lambda o: o.setEnabled(True), self.objects) + def onDisconnect(self, params): + map(lambda o: o.setEnabled(False), self.objects) + def onTimeChange(self, params): + if not self.slrTime.isSliderDown(): + self.slrTime.setValue(params['newTime']) + def onSongChange(self, params): + try: + self.slrTime.setMaximum(monty.getStatus()['length']) + self.slrTime.setEnabled(True) + except: + pass + + + def onBtnPlayPauseClick(self): + status=monty.getStatus() + if status['state']=='play': + monty.pause() + elif status['state']=='stop': + monty.play(None) + #if self.lstPlaylist.getSelItemID()==-1: + #if nothing selected, set it on first row + #self.lstPlaylist.selectRow(0) + #self.onPlaylistDoubleClick() + else: + monty.resume() + def onBtnStopClick(self): + monty.stop() + self.updatePlayingInfo() + def onBtnPreviousClick(self): + monty.previous() + def onBtnNextClick(self): + monty.next() + def onTimeSliderChange(self): + monty.seek(self.slrTime.value()) + def onVolumeSliderChange(self): + v=self.slrVolume.value() + monty.setVolume(v) + if v<=1: + mode='mute' + else: + mode=('0', 'min', 'med', 'max')[int(3*v/100)] + self.svgVolume.load('gfx/stock_volume-%s.svg'%(mode)) - btnSettings=None +class winMain(QtGui.QMainWindow): + """The winMain class is mpc's main window, showing the playlists and control-interface""" + "Elements" + " song status" + songStatus=None + " control of playing" + playControl=None + " lstLibrary of songs" + lstLibrary=None + " current lstPlaylist" + lstPlaylist=None + " control buttons" lstResize=None @@ -61,78 +207,50 @@ class winMain(QtGui.QWidget): , self.onPlaylistDoubleClick, self.onPlaylistKeyPress) self.lstLibrary=Playlist(parent, self, ['song'], 'The Library' , self.onLibraryDoubleClick, self.onLibraryKeyPress) - self.lblStatus=QtGui.QLabel() - self.lblInfo=QtGui.QLabel() - self.lblInfo.setMinimumWidth(400) - self.txtFilterPlaylist=QtGui.QLineEdit() - self.slrTime=QtGui.QSlider(QtCore.Qt.Horizontal, self) - self.slrVolume=QtGui.QSlider(QtCore.Qt.Horizontal, self) - self.slrVolume.setMaximum(100) - self.slrVolume.setMinimumWidth(100) - self.slrVolume.setMaximumWidth(400) - # set to some value that'll never be chosen, that way onChange will be called automatically :) - self.slrVolume.setValue(3.141595) - self.svgVolume=QtSvg.QSvgWidget() - self.svgVolume.resize(64,64) - self.btnPlayPause=Button("play", self.onBtnPlayPauseClick, 'gfx/media-playback-start.svg', True) - self.btnStop=Button("stop", self.onBtnStopClick, 'gfx/media-playback-stop.svg', True) - self.btnPrevious=Button("prev", self.onBtnPreviousClick, 'gfx/media-skip-backward.svg', True) - self.btnNext=Button("next", self.onBtnNextClick, 'gfx/media-skip-forward.svg', True) - self.btnSettings=Button("settings", self.onBtnSettingsClick, 'gfx/gtk-preferences.svg') - self.lstResizer=VResizer(self.lstLibrary, self.lstPlaylist, 'winMain.lstResizer', parent) + self.songStatus=wgSongStatus(parent) + self.playControl=wgPlayControl(parent) self.lstLibrary.showColumn(0,False) self.lstLibrary.setMode('library', 'artist/album') self.lstPlaylist.setMode('playlist') - " set the layouts" - window=QtGui.QVBoxLayout() - tables=QtGui.QHBoxLayout() - lib=QtGui.QVBoxLayout() - plList=QtGui.QVBoxLayout() - controls=QtGui.QHBoxLayout() - info=QtGui.QHBoxLayout() - self.setLayout(window) + dockLibrary=QtGui.QDockWidget("Library", parent) + dockPlaylist=QtGui.QDockWidget("Playlist", parent) + dockPlayControl=QtGui.QDockWidget("Playcontrol", parent) + dockStatus=QtGui.QDockWidget("Status", parent) + + dockLibrary.setWidget(self.lstLibrary) + dockPlaylist.setWidget(self.lstPlaylist) + dockPlayControl.setWidget(self.playControl) + dockStatus.setWidget(self.songStatus) - " add the widgets" - window.addLayout(info) - window.addLayout(controls) - window.addWidget(self.lstResizer) - window.addWidget(self.lblStatus) - controls.addWidget(self.btnPrevious) - controls.addWidget(self.btnPlayPause) - controls.addWidget(self.btnStop) - controls.addWidget(self.btnNext) - controls.addWidget(self.slrTime) - info.addWidget(self.lblInfo) - info.addStretch() - info.addWidget(self.slrVolume) - info.addWidget(self.svgVolume) - info.addWidget(self.btnSettings) + opts=QtGui.QDockWidget.DockWidgetClosable|QtGui.QDockWidget.DockWidgetMovable + #opts=QtGui.QDockWidget.AllDockWidgetFeatures + dockLibrary.setFeatures(opts) + dockPlaylist.setFeatures(opts) + dockPlayControl.setFeatures(opts) + dockStatus.setFeatures(opts) + + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dockStatus) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dockPlayControl) + self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dockLibrary) + self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dockPlaylist) + + self.statusBar() # create a statusbar self.resize(1024,960) - self.controlObjects=[self.lstPlaylist, self.lstLibrary, self.slrTime - , self.slrVolume - , self.btnPlayPause, self.btnStop, self.btnPrevious - , self.btnNext] + self.controlObjects=[self.lstPlaylist, self.lstLibrary] " add event handlers" - self.connect(self.slrVolume, QtCore.SIGNAL('valueChanged(int)'), - self.onVolumeSliderChange) - - self.connect(self.slrTime, QtCore.SIGNAL('sliderReleased()'), - self.onTimeSliderChange) - monty.addListener('onSongChange', self.onSongChange) monty.addListener('onTimeChange', self.onTimeChange) monty.addListener('onStateChange', self.onStateChange) - monty.addListener('onVolumeChange', self.onVolumeChange) monty.addListener('onReady', self.onReady) monty.addListener('onConnect', self.onConnect) monty.addListener('onDisconnect', self.onDisconnect) - self.enableObjects(self.controlObjects, False) + map(lambda o: o.setEnabled(False), self.controlObjects) self.setWindowIcon(appIcon) # set icon in system tray self.sysTray=QtGui.QSystemTrayIcon(appIcon, parent) @@ -151,28 +269,11 @@ class winMain(QtGui.QWidget): def setStatus(self, status): """Set the text of the statusbar.""" - self.lblStatus.setText(status) + self.statusBar().showMessage(status) def updatePlayingInfo(self): """Update status, current song, and current song time.""" - status=monty.getStatus() - curSong=monty.getCurrentSong() - line=["Status:\t", "Song:\t", "Time:\t"] - - try: - line[0]="%s%s"%(line[0], {'play':'playing', 'stop':'not playing' - , 'pause':'paused'}[status['state']]) - if status['state']!='stop': - line[1]="%s%s by %s [%s]"% (line[1], curSong.getTitle(), - curSong.getArtist(), curSong.getAlbum()) - line[2]="%s%s/%s" % (line[2], sec2min(self.slrTime.value()) - , sec2min(status['length'])) - except: - pass - # merge lines - self.lblInfo.setText(reduce(lambda x, y: x+'\n'+y, line)) - - self.sysTray.setToolTip("%s\n%s" % ('montypc', self.lblInfo.text())) + self.sysTray.setToolTip("%s\n%s" % ('montypc', self.songStatus.text())) _rowColorModifier=0 _rowColorAdder=1 @@ -228,46 +329,19 @@ class winMain(QtGui.QWidget): self.addLibrarySelToPlaylist() return QtGui.QWidget.keyPressEvent(self, event) - def enableObjects(self, objects, enable): - """Enables or disables all $objects""" - for object in objects: - object.setEnabled(enable) - def onStateChange(self, params): self.updatePlayingInfo() - newState=params['newState'] - - self.enableObjects([self.slrTime, self.btnStop, self.btnNext, self.btnPrevious], newState!='stop') - - if newState=='play': - self.btnPlayPause.changeIcon('gfx/media-playback-pause.svg') - self.btnPlayPause.setText('pauze') - elif newState=='pause' or newState=='stop': - self.btnPlayPause.changeIcon('gfx/media-playback-start.svg') - self.btnPlayPause.setText('play') def onTimeChange(self, params): self.updatePlayingInfo() - if self.slrTime.isSliderDown()==False: - self.slrTime.setValue(params['newTime']) def onSongChange(self, params): lst=self.lstPlaylist lst.colorID(int(params['newSongID']), clrRowSel) - if params['newSongID']==-1: - self.slrTime.setEnabled(False) - else: - try: - self.slrTime.setMaximum(monty.getStatus()['length']) - self.slrTime.setEnabled(True) - lst.ensureVisible(params['newSongID']) - except: - pass + if params['newSongID']!=-1: + lst.ensureVisible(params['newSongID']) - def onVolumeChange(self, params): - self.slrVolume.setValue(params['newVolume']) - def onReady(self, params): self.initialiseData() self._timerID=self.startTimer(200) @@ -290,14 +364,14 @@ class winMain(QtGui.QWidget): self.setStatus("Doing the rest ...") doEvents() - self.enableObjects(self.controlObjects, True) + map(lambda o: o.setEnabled(True), self.controlObjects) self.updatePlayingInfo() self.setStatus("") doEvents() def onDisconnect(self, params): - self.enableObjects(self.controlObjects, False) + map(lambda o: o.setEnabled(False), self.controlObjects) def fillPlaylist(self): """Fill the playlist.""" @@ -312,43 +386,3 @@ class winMain(QtGui.QWidget): def onPlaylistDoubleClick(self): monty.play(self.lstPlaylist.getSelItemID()) - - def onTimeSliderChange(self): - monty.seek(self.slrTime.value()) - - def onVolumeSliderChange(self): - v=self.slrVolume.value() - monty.setVolume(v) - if v<=1: - mode='mute' - else: - mode=('0', 'min', 'med', 'max')[int(3*v/100)] - self.svgVolume.load('gfx/stock_volume-%s.svg'%(mode)) - - def onBtnPlayPauseClick(self): - status=monty.getStatus() - if status['state']=='play': - monty.pause() - elif status['state']=='stop': - if self.lstPlaylist.getSelItemID()==-1: - # if nothing selected, set it on first row - self.lstPlaylist.selectRow(0) - self.onPlaylistDoubleClick() - else: - monty.resume() - self.updatePlayingInfo() - - def onBtnStopClick(self): - monty.stop() - self.updatePlayingInfo() - - def onBtnPreviousClick(self): - monty.previous() - self.updatePlayingInfo() - def onBtnNextClick(self): - monty.next() - self.updatePlayingInfo() - - def onBtnSettingsClick(self): - self.winSettings=winSettings() - self.winSettings.show() |