summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2008-12-26 15:54:31 +0100
committerAnton Khirnov <wyskas@gmail.com>2008-12-26 15:54:31 +0100
commitafed65b3213ab466e7b769c648a6fb166849639a (patch)
tree531d66a07a070407c184b1838197b019254b7ae6
parentd423d9571091d5907ab07f1a7984a6df9d18fb78 (diff)
Get rid of QApplication-dependent globals.
-rw-r--r--clMonty.py4
-rw-r--r--clPlugin.py7
-rw-r--r--misc.py5
-rwxr-xr-xmontypc.py10
-rw-r--r--plugins/Library.py9
-rw-r--r--plugins/Lyrics.py5
-rw-r--r--plugins/MPD.py5
-rw-r--r--plugins/Notify.py17
-rw-r--r--plugins/PlayControl.py47
-rw-r--r--plugins/Playlist.py15
-rw-r--r--plugins/SongStatus.py9
-rw-r--r--plugins/Systray.py33
-rw-r--r--plugins/Tabs.py7
-rw-r--r--wgSongList.py42
-rw-r--r--winConnect.py14
-rw-r--r--winMain.py54
-rw-r--r--winSettings.py4
17 files changed, 158 insertions, 129 deletions
diff --git a/clMonty.py b/clMonty.py
index 0e71cc6..0e5c100 100644
--- a/clMonty.py
+++ b/clMonty.py
@@ -25,8 +25,6 @@ class Monty(QtCore.QObject):
_timerID=None
- " global palette"
- palette = QtGui.QPalette()
events={
'beforeSongChange':'curSongID',
@@ -319,5 +317,3 @@ class Monty(QtCore.QObject):
if not('updatings_db' in status) and self._updatings_db:
self._updatings_db=None
self._raiseEvent('onUpdateDBFinish')
-monty=Monty()
-
diff --git a/clPlugin.py b/clPlugin.py
index f825458..a5f0a1e 100644
--- a/clPlugin.py
+++ b/clPlugin.py
@@ -1,7 +1,6 @@
from PyQt4 import QtGui, QtSvg, QtCore
import plugins
-from clMonty import monty
from clSettings import settings, mpdSettings
from misc import *
import log
@@ -14,12 +13,14 @@ class Plugin:
winMain=None
loaded=None
listeners=[]
+ monty = None
def __init__(self, winMain, name):
self.name=name
self.winMain=winMain
self.loaded=False
self.listeners=[]
+ self.monty = winMain.monty
def getName(self, lower=False):
if lower:
@@ -50,7 +51,7 @@ class Plugin:
if len(self.listeners):
self.debug("adding %s listeners"%(len(self.listeners)))
for listener in self.listeners:
- monty.addListener(listener[0], listener[1])
+ self.monty.addListener(listener[0], listener[1])
self._load()
opts=QtGui.QDockWidget.DockWidgetClosable|QtGui.QDockWidget.DockWidgetMovable
@@ -63,7 +64,7 @@ class Plugin:
if len(self.listeners):
self.debug("removing %s listeners"%(len(self.listeners)))
for listener in self.listeners:
- monty.removeListener(listener[0], listener[1])
+ self.monty.removeListener(listener[0], listener[1])
self._unload()
self.winMain.removeDock(self.getDockWidget())
diff --git a/misc.py b/misc.py
index b85cab2..9da1e93 100644
--- a/misc.py
+++ b/misc.py
@@ -11,12 +11,11 @@ import log
socket.setdefaulttimeout(8)
-appIcon=QtGui.QIcon('gfx/icon.png')
+appIcon = 'gfx/icon.png'
-eventLoop=QtCore.QEventLoop()
def doEvents():
"""Make some time for necessary events."""
- eventLoop.processEvents(QtCore.QEventLoop.AllEvents)
+ QtCore.QEventLoop().processEvents(QtCore.QEventLoop.AllEvents)
def sec2min(secs):
"""Converts seconds to min:sec."""
diff --git a/montypc.py b/montypc.py
index a88e7c2..a729a3f 100755
--- a/montypc.py
+++ b/montypc.py
@@ -4,16 +4,16 @@
import sys
from PyQt4 import QtCore, QtGui
-
-app = QtGui.QApplication(sys.argv)
-app.setApplicationName("montypc")
-
from winMain import winMain
from winSettings import winSettings
-from clMonty import monty
from traceback import print_exc
try:
+ app = QtGui.QApplication(sys.argv)
+ app.setApplicationName("montypc")
+
+ appIcon = QtGui.QIcon('gfx/icon.png')
+
wMain = winMain()
wMain.show()
app.exec_()
diff --git a/plugins/Library.py b/plugins/Library.py
index 4500895..4676d5f 100644
--- a/plugins/Library.py
+++ b/plugins/Library.py
@@ -1,5 +1,4 @@
from PyQt4 import QtGui
-from clMonty import monty
from clPlugin import *
from misc import *
from wgPlaylist import Playlist
@@ -13,8 +12,10 @@ LIBRARY_MODES_DEFAULT='$artist\n'\
'$genre/$artist - $album\n'
class pluginLibrary(Plugin):
o=None
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Library')
+ self.monty = winMain.monty
def _load(self):
self.o=Playlist(self.winMain, self, ['song'], 'Library'
, self.onDoubleClick, self.onKeyPress, self.getSetting('modes').split('\n'))
@@ -56,14 +57,14 @@ class pluginLibrary(Plugin):
end=len(paths)
self.setStatus('Adding '+str(len(songs))+' songs to library: %i%%'%(int(100*start/len(paths))))
doEvents()
- monty.addToPlaylist(paths[start:end])
+ self.monty.addToPlaylist(paths[start:end])
start+=CHUNK_SIZE
self.setStatus('')
doEvents()
self.getWinMain().fillPlaylist()
- if not monty.isPlaying():
- monty.play(None)
+ if not self.monty.isPlaying():
+ self.monty.play(None)
def _getSettings(self):
modes=QtGui.QTextEdit()
diff --git a/plugins/Lyrics.py b/plugins/Lyrics.py
index 840ec06..518940d 100644
--- a/plugins/Lyrics.py
+++ b/plugins/Lyrics.py
@@ -9,7 +9,6 @@ import webbrowser
import urllib
from misc import *
-from clMonty import monty
from clPlugin import *
class ResetEvent(QtCore.QEvent):
@@ -57,6 +56,7 @@ class wgLyrics(QtGui.QWidget):
editMode=False
lyFormat=None
p=None # plugin
+ monty = None
def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
self.p=p
@@ -65,6 +65,7 @@ class wgLyrics(QtGui.QWidget):
self.btnRefetch=Button("Refetch", self.onBtnRefetchClick)
self.btnSave=Button("Save lyrics", self.onBtnSaveClick)
self.btnSearch=Button("Search www", self.onBtnSearch)
+ self.monty = p.monty
self.txtView=QtGui.QTextEdit(parent)
self.txtView.setReadOnly(True)
@@ -243,12 +244,14 @@ class wgLyrics(QtGui.QWidget):
class pluginLyrics(Plugin):
o=None
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Lyrics')
self.addMontyListener('onSongChange', self.refresh)
self.addMontyListener('onReady', self.refresh)
self.addMontyListener('onDisconnect', self.onDisconnect)
self.addMontyListener('onTimeChange', self.onTimeChange)
+ self.monty = winMain.monty
def _load(self):
self.o=wgLyrics(self, None)
self.o.refresh()
diff --git a/plugins/MPD.py b/plugins/MPD.py
index c7e8c9c..1f6f6d5 100644
--- a/plugins/MPD.py
+++ b/plugins/MPD.py
@@ -1,5 +1,4 @@
from PyQt4 import QtGui
-from clMonty import monty
from clPlugin import *
from misc import *
from clSettings import settings, mpdSettings
@@ -8,8 +7,10 @@ MPD_HOST_DEFAULT='localhost'
MPD_PORT_DEFAULT='6600'
class pluginMPD(Plugin):
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'MPD')
+ self.monty = winMain.monty
def getInfo(self):
return "Provides an interface to the MPD settings."
@@ -23,6 +24,6 @@ class pluginMPD(Plugin):
]
def onBtnUpdateDBClick(self):
self.saveSettings()
- monty.updateDB([mpdSettings.get('music_directory')])
+ self.monty.updateDB([mpdSettings.get('music_directory')])
pass
diff --git a/plugins/Notify.py b/plugins/Notify.py
index f7eb993..04ad045 100644
--- a/plugins/Notify.py
+++ b/plugins/Notify.py
@@ -4,7 +4,6 @@ from traceback import print_exc
import format
from misc import *
-from clMonty import monty
from clPlugin import *
import plugins
@@ -16,6 +15,7 @@ class winNotify(QtGui.QWidget):
resizeWindow=True
winMain=None
p=None
+ monty = None
# data used for showing off
timer=None
@@ -27,6 +27,7 @@ class winNotify(QtGui.QWidget):
QtGui.QWidget.__init__(self, parent)
self.p=p
self.winMain=winMain
+ self.monty = winMain.monty
self.setWindowFlags(QtCore.Qt.ToolTip)
self.setWindowOpacity(0.7)
@@ -97,14 +98,14 @@ class winNotify(QtGui.QWidget):
self.centerH()
# fill up with a nice color :)
- p.fillRect(QtCore.QRect(0,0,self.width(),self.height()), monty.palette.brush(QtGui.QPalette.Base))
+ p.fillRect(QtCore.QRect(0,0,self.width(),self.height()), self.palette().brush(QtGui.QPalette.Base))
# draw album cover if necessary
if img:
rImg=QtCore.QRectF(margin,margin,width,width)
p.drawImage(rImg, img)
- p.setPen(monty.palette.color(QtGui.QPalette.Text))
+ p.setPen(self.palette().color(QtGui.QPalette.Text))
rect=p.boundingRect(width+margin+spacing,margin,
rect.width(),self.height(), QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter, txt)
p.drawText(rect, QtCore.Qt.AlignHCenter, txt)
@@ -119,6 +120,7 @@ class winNotify(QtGui.QWidget):
class pluginNotify(Plugin):
o=None
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Notify')
self.addMontyListener('onSongChange', self.onSongChange)
@@ -126,6 +128,7 @@ class pluginNotify(Plugin):
self.addMontyListener('onDisconnect', self.onDisconnect)
self.addMontyListener('onStateChange', self.onStateChange)
self.addMontyListener('onVolumeChange', self.onVolumeChange)
+ self.monty = winMain.monty
def _load(self):
self.o=winNotify(self, self.winMain)
@@ -135,20 +138,20 @@ class pluginNotify(Plugin):
return "Show interesting events in a popup window."
def onSongChange(self, params):
- self.o.show(self.getSetting('songformat').replace("\n", "\\n"), monty.getCurrentSong()
+ self.o.show(self.getSetting('songformat').replace("\n", "\\n"), self.monty.getCurrentSong()
, time=self.getSetting('timer'))
def onReady(self, params):
- self.o.show('montypc loaded!', monty.getCurrentSong(), time=self.getSetting('timer'))
+ self.o.show('self.montypc loaded!', monty.getCurrentSong(), time=self.getSetting('timer'))
def onDisconnect(self, params):
self.o.show('Disconnected!', time=self.getSetting('timer'))
def onStateChange(self, params):
- self.o.show(params['newState'], monty.getCurrentSong(), time=self.getSetting('timer'))
+ self.o.show(params['newState'], self.monty.getCurrentSong(), time=self.getSetting('timer'))
def onVolumeChange(self, params):
- self.o.show('Volume: %i%%'%(params['newVolume']), monty.getCurrentSong(), time=self.getSetting('timer'))
+ self.o.show('Volume: %i%%'%(params['newVolume']), self.monty.getCurrentSong(), time=self.getSetting('timer'))
def _getSettings(self):
txt=QtGui.QTextEdit()
diff --git a/plugins/PlayControl.py b/plugins/PlayControl.py
index be7006b..b31046a 100644
--- a/plugins/PlayControl.py
+++ b/plugins/PlayControl.py
@@ -1,7 +1,6 @@
from PyQt4 import QtGui, QtSvg, QtCore
from misc import *
-from clMonty import monty
from clPlugin import *
import clSong
from thread import start_new_thread
@@ -49,6 +48,7 @@ class wgPlayControl(QtGui.QWidget):
cmbRepeat=None
cmbShuffle=None
p=None
+ monty = None
" contains the songs of the album the current song is playing. None, if the album is not set"
curAlbumSongs=None
@@ -61,6 +61,7 @@ class wgPlayControl(QtGui.QWidget):
def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
self.p=p
+ self.monty = p.monty
class wgSvgSwitcher(QtSvg.QSvgWidget):
"""Widget showing an svg-image, which, when clicked, will (un)hide an element."""
@@ -152,9 +153,9 @@ class wgPlayControl(QtGui.QWidget):
self.cmbShuffle.setItemText(PC_RANDOM_QUEUE, "Queue (%i)"%(len(self.queuedSongs)))
def onBtnJmpCurrentClick(self):
- plugins.getPlugin("Playlist").getPlaylist().ensureVisible(monty.getCurrentSong().getID())
+ plugins.getPlugin("Playlist").getPlaylist().ensureVisible(self.monty.getCurrentSong().getID())
def onStateChange(self, params):
- newState=monty.getStatus()['state']
+ newState=self.monty.getStatus()['state']
map(lambda o: o.setEnabled(newState!='stop'), self.objects)
@@ -173,7 +174,7 @@ class wgPlayControl(QtGui.QWidget):
self.slrTime.setValue(params['newTime'])
def onSongChange(self, params):
try:
- self.slrTime.setMaximum(monty.getStatus()['length'])
+ self.slrTime.setMaximum(self.monty.getStatus()['length'])
self.slrTime.setEnabled(True)
except:
pass
@@ -183,7 +184,7 @@ class wgPlayControl(QtGui.QWidget):
def beforeSongChange(self, params):
nextID=None
- song=monty.getCurrentSong()
+ song=self.monty.getCurrentSong()
# decide here what next song to play!
repeat=self.cmbRepeat.currentIndex()
random=self.cmbShuffle.currentIndex()
@@ -238,7 +239,7 @@ class wgPlayControl(QtGui.QWidget):
# album.
if eofAlbum and (repeat==PC_REPEAT_PLAYLIST or repeat==PC_REPEAT_NO):
# all first songs of an album
- albums=filter(lambda s: s.getAlbum() and s.getTrack()==1, monty.listPlaylist())
+ albums=filter(lambda s: s.getAlbum() and s.getTrack()==1, self.monty.listPlaylist())
nextID=albums[randint(0,len(albums)-1)].getID()
else:
# we're not at end of album, so we fetch the next id
@@ -254,45 +255,45 @@ class wgPlayControl(QtGui.QWidget):
self.cmbShuffle.setCurrentIndex(int(self.p.getSetting('oldshuffle')))
if nextID!=None:
- monty.play(nextID)
+ self.monty.play(nextID)
def getCurAlbumSongs(self):
return self.curAlbumSongs
def findAlbumSongs(self):
"""This method looks for the songs in the album of current playing song."""
- song=monty.getCurrentSong()
+ song=self.monty.getCurrentSong()
if self.curAlbumSongs and clSong.isSameAlbum(song, self.curAlbumSongs[0]):
return
self.curAlbumSongs=None
if not song or not song.getAlbum():
return
- self.curAlbumSongs=filter(lambda s: clSong.isSameAlbum(s, song), monty.listPlaylist())
+ self.curAlbumSongs=filter(lambda s: clSong.isSameAlbum(s, song), self.monty.listPlaylist())
self.curAlbumSongs=sorted(self.curAlbumSongs, lambda l,r: numeric_compare(l.getTrack(), r.getTrack()))
def onBtnPlayPauseClick(self):
- status=monty.getStatus()
+ status=self.monty.getStatus()
if status['state']=='play':
- monty.pause()
+ self.monty.pause()
self.p.extended("Toggling playback")
elif status['state']=='stop':
- monty.play(None)
+ self.monty.play(None)
self.p.extended("Pausing playback")
else:
- monty.resume()
+ self.monty.resume()
def onBtnStopClick(self):
- monty.stop()
+ self.monty.stop()
self.p.extended("Stopping playback")
def onBtnPreviousClick(self):
- monty.previous()
+ self.monty.previous()
self.p.extended("Playing previous")
def onBtnNextClick(self):
- monty.next()
+ self.monty.next()
self.p.extended("Playing next")
def onTimeSliderChange(self):
- monty.seek(self.slrTime.value())
+ self.monty.seek(self.slrTime.value())
def onVolumeSliderChange(self):
v=self.slrVolume.value()
- monty.setVolume(v)
+ self.monty.setVolume(v)
if v<=1:
mode='mute'
else:
@@ -302,9 +303,9 @@ class wgPlayControl(QtGui.QWidget):
def onCmbRepeatChanged(self, newval):
self.p.setSetting('repeat', newval)
if newval==PC_REPEAT_PLAYLIST:
- monty.repeat(1)
+ self.monty.repeat(1)
else:
- monty.repeat(0)
+ self.monty.repeat(0)
def onCmbShuffleChanged(self, newval):
if newval==PC_RANDOM_QUEUE:
# must do some extra's if moving to queued-mode
@@ -320,9 +321,9 @@ class wgPlayControl(QtGui.QWidget):
self.p.setSetting('shuffle', newval)
if newval==PC_RANDOM_SONG:
- monty.random(1)
+ self.monty.random(1)
else:
- monty.random(0)
+ self.monty.random(0)
# save and load the queue
def saveQueue(self):
@@ -344,6 +345,7 @@ class wgPlayControl(QtGui.QWidget):
class pluginPlayControl(Plugin):
o=None
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'PlayControl')
self.addMontyListener('onStateChange', self.onStateChange)
@@ -353,6 +355,7 @@ class pluginPlayControl(Plugin):
self.addMontyListener('onReady', self.onStateChange)
self.addMontyListener('onDisconnect', self.onDisconnect)
self.addMontyListener('onTimeChange', self.onTimeChange)
+ self.monty = winMain.monty
def _load(self):
self.o=wgPlayControl(self, None)
self.o.loadQueue()
diff --git a/plugins/Playlist.py b/plugins/Playlist.py
index 21e5a8d..ce0132d 100644
--- a/plugins/Playlist.py
+++ b/plugins/Playlist.py
@@ -1,5 +1,4 @@
from PyQt4 import QtGui, QtCore
-from clMonty import monty
from clPlugin import *
from misc import *
from wgPlaylist import Playlist
@@ -17,9 +16,13 @@ PLAYLIST_MODES_DEFAULT='$artist\n'\
# playcontrol
class pluginPlaylist(Plugin):
o=None
+ monty = None
+ palette = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Playlist')
self.addMontyListener('onSongChange', self.onSongChange)
+ self.monty = winMain.monty
+ self.palette = winMain.palette
def _load(self):
self.o=Playlist(self.winMain, self, ['artist', 'title', 'track', 'album'], 'Playlist'
, self.onDoubleClick, self.onKeyPress, self.getSetting('modes').split('\n'))
@@ -37,7 +40,7 @@ class pluginPlaylist(Plugin):
return self._createDock(self.o)
def onDoubleClick(self):
- monty.play(self.o.getSelItemID())
+ self.monty.play(self.o.getSelItemID())
def onKeyPress(self, event):
if event.matches(QtGui.QKeySequence.Delete):
@@ -46,7 +49,7 @@ class pluginPlaylist(Plugin):
self.setStatus('Deleting '+str(len(ids))+' songs from playlist ...')
doEvents()
- monty.deleteFromPlaylist(ids)
+ self.monty.deleteFromPlaylist(ids)
self.setStatus('')
doEvents()
@@ -60,7 +63,7 @@ class pluginPlaylist(Plugin):
def onSongChange(self, params):
lst=self.o
- lst.colorID(int(params['newSongID']), monty.palette.color(QtGui.QPalette.Highlight))
+ lst.colorID(int(params['newSongID']), self.palette().color(QtGui.QPalette.Highlight))
if params['newSongID']!=-1:
lst.ensureVisible(params['newSongID'])
@@ -68,11 +71,11 @@ class pluginPlaylist(Plugin):
_rowColorModifier=0
_rowColorAdder=1
def timerEvent(self, event):
- curSong=monty.getCurrentSong()
+ curSong=self.monty.getCurrentSong()
if curSong:
lst=self.lstPlaylist
# color current playing song
- lst.colorID(curSong.getID(), monty.palette.color(QtGui.QPalette.Highlight))
+ lst.colorID(curSong.getID(), self.palette.color(QtGui.QPalette.Highlight))
# make sure color changes nicely over time
self._rowColorModifier=self._rowColorModifier+self._rowColorAdder
diff --git a/plugins/SongStatus.py b/plugins/SongStatus.py
index 71aa6e4..f5e5ab9 100644
--- a/plugins/SongStatus.py
+++ b/plugins/SongStatus.py
@@ -1,5 +1,4 @@
from PyQt4 import QtGui
-from clMonty import monty
from clPlugin import *
from traceback import print_exc
@@ -17,9 +16,11 @@ class wgSongStatus(QtGui.QWidget):
lblInfo=None
format=None
p=None
+ monty = None
def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
self.p=p
+ self.monty = p.monty
self.lblInfo=QtGui.QLabel()
self.setMinimumWidth(400)
@@ -31,8 +32,8 @@ class wgSongStatus(QtGui.QWidget):
self.updateFormat()
def update(self, params):
- status=monty.getStatus()
- song=monty.getCurrentSong()
+ status=self.monty.getStatus()
+ song=self.monty.getCurrentSong()
values={'state':''}
try:
@@ -57,6 +58,7 @@ class wgSongStatus(QtGui.QWidget):
class pluginSongStatus(Plugin):
o=None
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'SongStatus')
self.addMontyListener('onSongChange', self.update)
@@ -64,6 +66,7 @@ class pluginSongStatus(Plugin):
self.addMontyListener('onStateChange', self.update)
self.addMontyListener('onConnect', self.update)
self.addMontyListener('onDisconnect', self.update)
+ self.monty = winMain.monty
def _load(self):
self.o=wgSongStatus(self, None)
diff --git a/plugins/Systray.py b/plugins/Systray.py
index 571bbc3..5da4507 100644
--- a/plugins/Systray.py
+++ b/plugins/Systray.py
@@ -1,5 +1,4 @@
from PyQt4 import QtGui
-from clMonty import monty
from clPlugin import *
from misc import *
import format
@@ -13,6 +12,8 @@ class pluginSystray(Plugin):
time=None # indicator of current time [0..64]
appIcon=None
pixmap=None
+ monty = None
+ palette = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Systray')
self.addMontyListener('onSongChange', self.update)
@@ -21,8 +22,10 @@ class pluginSystray(Plugin):
self.addMontyListener('onDisconnect', self.update)
# TODO only update this when necessary, i.e. mouse-hover etc
self.addMontyListener('onTimeChange', self.update)
- self.appIcon=appIcon
-
+ self.appIcon=QtGui.QIcon(appIcon)
+ self.monty = winMain.monty
+ self.palette = winMain.palette()
+
def _load(self):
self.format=format.compile(SYSTRAY_FORMAT)
@@ -32,12 +35,12 @@ class pluginSystray(Plugin):
if type(event)==QtGui.QWheelEvent:
numDegrees=event.delta() / 8
numSteps=5*numDegrees/15
- monty.setVolume(int(monty.getStatus()['volume'])+numSteps)
+ self.monty.setVolume(int(monty.getStatus()['volume'])+numSteps)
event.accept()
return True
return False
- self.o=QtGui.QSystemTrayIcon(appIcon, self.winMain)
+ self.o=QtGui.QSystemTrayIcon(QtGui.QIcon(appIcon), self.winMain)
self.eventObj=SystrayWheelEventObject()
self.o.installEventFilter(self.eventObj)
self.winMain.connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)')
@@ -51,11 +54,11 @@ class pluginSystray(Plugin):
self.o=None
self.winMain._wheelEvent=None
def getInfo(self):
- return "Display the montypc icon in the systray."
+ return "Display the self.montypc icon in the systray."
def update(self, params):
- status=monty.getStatus()
- song=monty.getCurrentSong()
+ status=self.monty.getStatus()
+ song=self.monty.getCurrentSong()
values={'state':''}
try:
@@ -69,7 +72,7 @@ class pluginSystray(Plugin):
if song:
self.o.setToolTip(self.format(format.params(song, values)))
else:
- self.o.setToolTip("montypc not playing")
+ self.o.setToolTip("self.montypc not playing")
try:
curTime=(64*status['time'])/status['length']
@@ -80,13 +83,13 @@ class pluginSystray(Plugin):
# redraw the systray icon
self.pixmap=self.appIcon.pixmap(64,64)
painter=QtGui.QPainter(self.pixmap)
- painter.fillRect(1, curTime, 63, 64, monty.palette.brush(QtGui.QPalette.Base))
- appIcon.paint(painter, 1, 0, 63, 64)
+ painter.fillRect(1, curTime, 63, 64, self.palette.brush(QtGui.QPalette.Base))
+ self.appIcon.paint(painter, 1, 0, 63, 64)
self.o.setIcon(QtGui.QIcon(self.pixmap))
elif not song:
self.time=None
- self.o.setIcon(appIcon)
+ self.o.setIcon(QtGui.QIcon(appIcon))
def onSysTrayClick(self, reason):
@@ -106,8 +109,8 @@ class pluginSystray(Plugin):
w.move(x, y)
elif reason==QtGui.QSystemTrayIcon.MiddleClick:
# middle mouse button
- if monty.isPlaying():
- monty.pause()
+ if self.monty.isPlaying():
+ self.monty.pause()
else:
- monty.resume()
+ self.monty.resume()
diff --git a/plugins/Tabs.py b/plugins/Tabs.py
index 8914a4b..4862f12 100644
--- a/plugins/Tabs.py
+++ b/plugins/Tabs.py
@@ -5,7 +5,6 @@ from thread import start_new_thread
from traceback import print_exc
from misc import *
-from clMonty import monty
from clPlugin import *
class ResetEvent(QtCore.QEvent):
@@ -29,6 +28,7 @@ class wgTabs(QtGui.QWidget):
" contains the tabs"
txt=None
p=None # plugin
+ monty = None
def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
self.p=p
@@ -38,10 +38,11 @@ class wgTabs(QtGui.QWidget):
layout=QtGui.QVBoxLayout()
layout.addWidget(self.txt)
self.setLayout(layout)
+ self.monty = p.monty
def refresh(self):
- song=monty.getCurrentSong()
+ song=self.monty.getCurrentSong()
try:
song._data['file']
except:
@@ -132,11 +133,13 @@ class wgTabs(QtGui.QWidget):
class pluginTabs(Plugin):
o=None
+ monty = None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Tabs')
self.addMontyListener('onSongChange', self.refresh)
self.addMontyListener('onReady', self.refresh)
self.addMontyListener('onDisconnect', self.onDisconnect)
+ self.monty = winMain.monty
def _load(self):
self.o=wgTabs(self, None)
self.refresh(None)
diff --git a/wgSongList.py b/wgSongList.py
index 0088621..ba32bc3 100644
--- a/wgSongList.py
+++ b/wgSongList.py
@@ -39,14 +39,12 @@ class SongList(QtGui.QWidget):
scrollbarWidth=15
" minimum column width"
minColumnWidth=50
- " palette"
- palette = QPalette()
" colors for alternating rows"
- colors = [palette.color(QPalette.Base), palette.color(QPalette.AlternateBase)]
+ colors = []
" color of selection"
- clrSel = palette.color(QPalette.Highlight)
+ clrSel = None
" background color"
- clrBg = palette.color(QPalette.Window)
+ clrBg = None
" indentation of hierarchy, in pixels"
indentation=lineHeight
@@ -107,6 +105,10 @@ class SongList(QtGui.QWidget):
self.numVisEntries=None
self.xOffset=0
self.resizeColumn=None
+
+ self.colors = [self.palette().color(QPalette.Base), self.palette().color(QPalette.AlternateBase)]
+ self.clrSel = self.palette().color(QPalette.Highlight)
+ self.clrBg = self.palette().color(QPalette.Window)
self._filters=[]
@@ -705,10 +707,10 @@ class SongList(QtGui.QWidget):
return
# paint the headers!
- p.fillRect(QtCore.QRect(0,0,width+self.vScrollbar.width(),lineHeight), self.palette.brush(QPalette.Button))
+ p.fillRect(QtCore.QRect(0,0,width+self.vScrollbar.width(),lineHeight), self.palette().brush(QPalette.Button))
p.drawRect(QtCore.QRect(0,0,width+self.vScrollbar.width()-1,lineHeight-1))
x=margin+self.xOffset
- p.setPen(self.palette.color(QPalette.ButtonText))
+ p.setPen(self.palette().color(QPalette.ButtonText))
for hdr in self.headers:
if hdr[2]:
p.drawText(x, vmargin, hdr[1], lineHeight, QtCore.Qt.AlignLeft, hdr[0])
@@ -737,7 +739,7 @@ class SongList(QtGui.QWidget):
# determine color of row. Default is row-color, but can be overridden by
# (in this order): selection, special row color!
clr=self.colors[row%2] # background color of the row
- clrTxt = self.palette.color(QPalette.Text) # color of the printed text
+ clrTxt = self.palette().color(QPalette.Text) # color of the printed text
# is it selected?
values=[]
if self.selMode:
@@ -751,17 +753,17 @@ class SongList(QtGui.QWidget):
# is selected if in range, which depends on the selection-mode
if checkID>=min(range) and checkID<=max(range):
clr=self.clrSel
- clrTxt = self.palette.color(QPalette.HighlightedText) # color of the printed text
+ clrTxt = self.palette().color(QPalette.HighlightedText) # color of the printed text
# it has a VIP-status!
if id==int(self.clrID[0]):
- clrTxt = self.palette.color(QPalette.HighlightedText) # color of the printed text
+ clrTxt = self.palette().color(QPalette.HighlightedText) # color of the printed text
clr=self.clrID[1]
# draw the row background
p.fillRect(QtCore.QRect(2, y, width-3, lineHeight), QtGui.QBrush(clr))
# draw a subtile rectangle
- p.setPen(self.palette.color(QPalette.Highlight))
+ p.setPen(self.palette().color(QPalette.Highlight))
p.drawRect(QtCore.QRect(2, y, width-3, lineHeight))
# draw the column
@@ -781,7 +783,7 @@ class SongList(QtGui.QWidget):
p.fillRect(x+hdr[1]-15,y+1,15,lineHeight-1, QtGui.QBrush(clr))
p.drawText(x+hdr[1]-15,y+vmargin,15,lineHeight-1, QtCore.Qt.AlignLeft, "...")
x+=hdr[1]
- p.setPen(self.palette.color(QPalette.Base))
+ p.setPen(self.palette().color(QPalette.Base))
p.drawLine(QtCore.QPoint(x-margin,y), QtCore.QPoint(x-margin,y+lineHeight))
def libFirstVisRowIndex(self):
@@ -833,9 +835,9 @@ class SongList(QtGui.QWidget):
vmargin=self.vmargin
# paint the headers!
- p.fillRect(QtCore.QRect(0,0,width+self.vScrollbar.width(),lineHeight), self.palette.brush(QPalette.Button))
+ p.fillRect(QtCore.QRect(0,0,width+self.vScrollbar.width(),lineHeight), self.palette().brush(QPalette.Button))
p.drawRect(QtCore.QRect(0,0,width+self.vScrollbar.width()-1,lineHeight-1))
- p.setPen(self.palette.color(QPalette.ButtonText))
+ p.setPen(self.palette().color(QPalette.ButtonText))
p.drawText(margin, vmargin, width, lineHeight, QtCore.Qt.AlignLeft, self.groupByStr.replace('$', ''))
entries=self.fSongs
@@ -860,7 +862,7 @@ class SongList(QtGui.QWidget):
text=entry[LIB_VALUE]
clr=self.colors[row%2] # background color of the row
- clrTxt = self.palette.color(QPalette.Text)
+ clrTxt = self.palette().color(QPalette.Text)
values=[]
if self.selMode:
@@ -875,16 +877,16 @@ class SongList(QtGui.QWidget):
# is selected if in range, which depends on the selection-mode
if checkID>=min(range) and checkID<=max(range):
clr=self.clrSel
- clrTxt = self.palette.color(QPalette.HighlightedText)
+ clrTxt = self.palette().color(QPalette.HighlightedText)
for i in self.selMiscs:
if index==i:
clr=self.clrSel
- clrTxt = self.palette.color(QPalette.HighlightedText)
+ clrTxt = self.palette().color(QPalette.HighlightedText)
# it has a VIP-status!
if isSong and entry[LIB_VALUE].getID()==int(self.clrID[0]):
- clrTxt = self.palette.color(QPalette.HighlightedText)
+ clrTxt = self.palette().color(QPalette.HighlightedText)
clr=self.clrID[1]
left=x+indent*(1+level)
@@ -935,7 +937,7 @@ class SongList(QtGui.QWidget):
if self.hasFocus():
p.drawRect(QtCore.QRect(1,1,self.width()-3,self.height()-3))
else:
- p.setPen(self.palette.color(QPalette.Button))
+ p.setPen(self.palette().color(QPalette.Button))
p.drawRect(QtCore.QRect(1,1,self.width()-3,self.height()-3))
self._paintCnt=0
@@ -948,6 +950,6 @@ class SongList(QtGui.QWidget):
#text='%s - %s'%(str(self.topRow), str(self.numVisEntries))
if text:
r=QtCore.QRect(10,self.height()-40,self.width()-20,20)
- p.fillRect(r, self.palette.brush(QPalette.Base))
+ p.fillRect(r, self.palette().brush(QPalette.Base))
p.drawText(r,QtCore.Qt.AlignLeft, text)
diff --git a/winConnect.py b/winConnect.py
index 80fa011..533d1ba 100644
--- a/winConnect.py
+++ b/winConnect.py
@@ -1,6 +1,5 @@
from PyQt4 import QtGui, QtCore
import time
-from clMonty import monty
from misc import *
from traceback import print_exc
from clSettings import settings
@@ -10,12 +9,15 @@ class winConnect(QtGui.QWidget):
txtPort=None
lblInfo=None
_timerID=None
+ monty = None
+
- def __init__(self, parent=None):
+ def __init__(self,parent):
QtGui.QWidget.__init__(self, parent)
self.txtHost=QtGui.QLineEdit(settings.get('host', 'localhost'))
self.txtPort=QtGui.QLineEdit(settings.get('port', '6600'))
self.lblInfo=QtGui.QLabel("connecting ...")
+ self.monty = parent.monty
frame=QtGui.QVBoxLayout()
inputs=QtGui.QHBoxLayout()
@@ -26,15 +28,15 @@ class winConnect(QtGui.QWidget):
inputs.addWidget(self.txtHost)
inputs.addWidget(self.txtPort)
- self.setWindowIcon(appIcon)
+ self.setWindowIcon(QtGui.QIcon(appIcon))
self.setWindowTitle('Connect to mpd')
self.setLayout(frame)
self.resize(200,80)
self.center()
doEvents()
- monty.addListener('onReady', self.onReady)
- monty.addListener('onConnect', self.onConnect)
+ self.monty.addListener('onReady', self.onReady)
+ self.monty.addListener('onConnect', self.onConnect)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
@@ -78,7 +80,7 @@ class winConnect(QtGui.QWidget):
self.lblInfo.setText('Trying to connect to '+host+':'+str(port)+' ...')
doEvents()
- monty.connect(host, port)
+ self.monty.connect(host, port)
doEvents()
def windowActivationChange(self, bool):
diff --git a/winMain.py b/winMain.py
index 100262a..9a4e766 100644
--- a/winMain.py
+++ b/winMain.py
@@ -5,7 +5,7 @@ import copy
from misc import *
from clSettings import settings,mpdSettings
-from clMonty import monty
+from clMonty import Monty
import plugins
@@ -28,11 +28,15 @@ class winMain(QtGui.QMainWindow):
wConnect=None
wSettings=None
+ " MPD object"
+ monty = None
+
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
- self.setWindowTitle("montypc - An MPD client")
+ self.setWindowTitle("self.montypc - An MPD client")
+ self.monty = Monty()
- self.wConnect=winConnect()
+ self.wConnect=winConnect(self)
self.statusBar() # create a statusbar
mBar=self.menuBar() # create a menubar
@@ -41,9 +45,9 @@ class winMain(QtGui.QMainWindow):
m.setTearOffEnabled(True)
# connect
self.mConnect=m.addAction('Connect ...', self.wConnect.monitor)
- self.mConnect.setIcon(QtGui.QIcon('gfx/connect.png'))
+ self.mConnect.setIcon(QtGui.QIcon(appIcon))
# disconnect
- self.mDisconnect=m.addAction('Disconnect', monty.disconnect)
+ self.mDisconnect=m.addAction('Disconnect', self.monty.disconnect)
self.mDisconnect.setIcon(QtGui.QIcon('gfx/disconnect.png'))
# separator
m.addSeparator()
@@ -91,21 +95,21 @@ class winMain(QtGui.QMainWindow):
self.restoreLayout()
" add event handlers"
- monty.addListener('onReady', self.onReady)
- monty.addListener('onConnect', self.onConnect)
- monty.addListener('onDisconnect', self.onDisconnect)
- monty.addListener('onUpdateDBStart', self.onUpdateDBStart)
- monty.addListener('onUpdateDBFinish', self.onUpdateDBFinish)
+ self.monty.addListener('onReady', self.onReady)
+ self.monty.addListener('onConnect', self.onConnect)
+ self.monty.addListener('onDisconnect', self.onDisconnect)
+ self.monty.addListener('onUpdateDBStart', self.onUpdateDBStart)
+ self.monty.addListener('onUpdateDBFinish', self.onUpdateDBFinish)
self.enableAll(True)
- self.setWindowIcon(appIcon)
+ self.setWindowIcon(QtGui.QIcon(appIcon))
# set icon in system tray
self.wConnect.monitor()
self.show()
if newPlugins:
self.showWinSettings()
- doEvents()
+ doEvents
def quit(self):
# unload all plugins
@@ -169,9 +173,11 @@ class winMain(QtGui.QMainWindow):
self.mMenuVisible=a
ret.addAction(self.mMenuVisible)
ret.addSeparator()
- actions=QtGui.QMainWindow.createPopupMenu(self).actions()
- for i in xrange(len(actions)-1):
- ret.addAction(actions[i])
+ menu = QtGui.QMainWindow.createPopupMenu(self)
+ if menu:
+ actions = menu.actions()
+ for i in xrange(len(actions)-1):
+ ret.addAction(actions[i])
return ret
def switchMenubar(self, val):
self.menuBar().setVisible(val)
@@ -207,7 +213,7 @@ class winMain(QtGui.QMainWindow):
self.setStatus('Restoring library and playlist ...')
self.mDisconnect.setEnabled(True)
self.mConnect.setEnabled(False)
- doEvents()
+ doEvents
def enableAll(self, value):
for k,entry in plugins.listPlugins().iteritems():
@@ -220,20 +226,20 @@ class winMain(QtGui.QMainWindow):
def initialiseData(self):
"""Initialise the library, playlist and some other small things"""
self.setStatus("Filling library ...")
- doEvents()
+ doEvents
self.fillLibrary()
- doEvents()
+ doEvents
self.setStatus("Filling playlist ...")
- doEvents()
+ doEvents
self.fillPlaylist()
- doEvents()
+ doEvents
self.setStatus("Doing the rest ...")
- doEvents()
+ doEvents
self.enableAll(True)
self.setStatus("")
- doEvents()
+ doEvents
def resizeEvent(self, event):
settings.set('winMain.size', '%i %i'%(self.width(),self.height()))
@@ -258,14 +264,14 @@ class winMain(QtGui.QMainWindow):
def fillPlaylist(self):
"""Fill the playlist."""
try:
- self.getPlaylistList().updateSongs(monty.listPlaylist())
+ self.getPlaylistList().updateSongs(self.monty.listPlaylist())
except:
pass
def fillLibrary(self):
"""Fill the library."""
try:
- self.getLibraryList().updateSongs(monty.listLibrary())
+ self.getLibraryList().updateSongs(self.monty.listLibrary())
except:
pass
diff --git a/winSettings.py b/winSettings.py
index f6f1a95..da34f0e 100644
--- a/winSettings.py
+++ b/winSettings.py
@@ -2,7 +2,6 @@ from PyQt4 import QtGui, QtCore
import sys
from misc import *
-from clMonty import monty
from clSettings import settings
import plugins
@@ -14,6 +13,7 @@ class winSettings(QtGui.QWidget):
winMain=None
+
def __init__(self, winMain, parent=None):
QtGui.QWidget.__init__(self, parent)
self.winMain=winMain
@@ -44,7 +44,7 @@ class winSettings(QtGui.QWidget):
self.connect(self.lstPlugins, QtCore.SIGNAL('itemChanged (QListWidgetItem*)'), self.onlstPluginItemChanged)
- self.setWindowIcon(appIcon)
+ self.setWindowIcon(QtGui.QIcon(appIcon))
self.setWindowTitle('Settings')
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.center()