From b674c1a0fbc4612e65139fc0f4f6d0b0a41329cb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 31 Aug 2009 15:12:45 +0200 Subject: [PATCH] switch to PyQt4 API v2 for QStrings --- nephilim.py | 2 ++ nephilim/common.py | 13 ++++++------- nephilim/connect_wg.py | 13 +++++++------ nephilim/plugins/AlbumCover.py | 9 ++++++--- nephilim/plugins/Library.py | 17 +++++++++-------- nephilim/plugins/Lyrics.py | 9 ++++++--- nephilim/plugins/Playlist.py | 4 ++-- nephilim/plugins/Songinfo.py | 6 +++--- nephilim/song.py | 2 -- 9 files changed, 41 insertions(+), 34 deletions(-) diff --git a/nephilim.py b/nephilim.py index 28b4751..e0780cb 100755 --- a/nephilim.py +++ b/nephilim.py @@ -24,6 +24,8 @@ import sys import logging from traceback import print_exc try: + import sip + sip.setapi('QString', 2) from PyQt4 import QtGui except ImportError: sys.exit('PyQt4 not found. Ensure that it is installed.') diff --git a/nephilim/common.py b/nephilim/common.py index b0dac33..2663fa6 100644 --- a/nephilim/common.py +++ b/nephilim/common.py @@ -20,6 +20,7 @@ from PyQt4 import QtCore, QtGui, QtNetwork import socket import logging import os +import re socket.setdefaulttimeout(8) @@ -60,14 +61,12 @@ class Button(QtGui.QPushButton): icon.addFile(iconPath, QtCore.QSize(self.iconSize, self.iconSize)) self.setIcon(icon) -def expand_tags(str, expanders): - #ensure that str is QString - str = QtCore.QString(str) +def expand_tags(string, expanders): for expander in expanders: - str = expander.expand_tags(str) + string = expander.expand_tags(string) #remove unexpanded tags - return str.replace(QtCore.QRegExp('\\$\\w+'), '') + return re.sub('\$\w+', '', string) def generate_metadata_path(song, dir_tag, file_tag): """Generate dirname and (db files only) full file path for reading/writing metadata files @@ -86,8 +85,8 @@ def generate_metadata_path(song, dir_tag, file_tag): class MetadataFetcher(QtCore.QObject): """A basic class for metadata fetchers. Provides a fetch(song) function, - emits a finished(song, metadata) signal when done; lyrics is either a QString, - Python unicode string or None if not found.""" + emits a finished(song, metadata) signal when done; lyrics is either a Python + unicode string or None if not found.""" #public, read-only logger = None name = '' diff --git a/nephilim/connect_wg.py b/nephilim/connect_wg.py index 8df84f1..9884cd0 100644 --- a/nephilim/connect_wg.py +++ b/nephilim/connect_wg.py @@ -57,7 +57,7 @@ class ConnectWidget(QtGui.QWidget): self.setWindowTitle('Connect to MPD') self.center() - self.connect(self.mpclient, QtCore.SIGNAL('connected'), self.on_connected) + self.mpclient.connect_changed.connect(self.on_connected) def center(self): screen = QtGui.QDesktopWidget().screenGeometry() @@ -78,9 +78,10 @@ class ConnectWidget(QtGui.QWidget): self.mpclient.connect_mpd(host, port, passw) - def on_connected(self): - self.settings.setValue('MPD/host', QVariant(self.host_txt.text())) - self.settings.setValue('MPD/port', QVariant(self.port_txt.text())) - self.settings.setValue('MPD/password', QVariant(self.pass_txt.text())) - self.hide() + def on_connected(self, val): + if val: + self.settings.setValue('MPD/host', QVariant(self.host_txt.text())) + self.settings.setValue('MPD/port', QVariant(self.port_txt.text())) + self.settings.setValue('MPD/password', QVariant(self.pass_txt.text())) + self.hide() diff --git a/nephilim/plugins/AlbumCover.py b/nephilim/plugins/AlbumCover.py index 9bf0769..7ccdfa2 100644 --- a/nephilim/plugins/AlbumCover.py +++ b/nephilim/plugins/AlbumCover.py @@ -104,7 +104,7 @@ class AlbumCover(Plugin): # private DEFAULTS = {'coverdir' : '$musicdir/$songdir', 'covername' : '.cover_nephilim_$artist_$album', - 'fetchers': QtCore.QStringList(['local', 'Last.fm']), 'store' : True} + 'fetchers': ['local', 'Last.fm'], 'store' : True} "implemented fetchers" available_fetchers = None "enabled fetchers, those with higher priority first" @@ -206,7 +206,7 @@ class AlbumCover(Plugin): self.settings.setValue('covername', QVariant(self.covername.text())) self.settings.setValue('store', QVariant(self.store.isChecked())) - fetchers = QtCore.QStringList() + fetchers = [] for i in range(self.fetcherlist.count()): it = self.fetcherlist.item(i) if it.checkState() == QtCore.Qt.Checked: @@ -237,7 +237,10 @@ class AlbumCover(Plugin): if token == QtCore.QXmlStreamReader.StartElement: if xml.name() == 'image' and xml.attributes().value('size') == 'extralarge': url = QtCore.QUrl() # the url is already percent-encoded - url.setEncodedUrl(xml.readElementText().toLatin1()) + try: + url.setEncodedUrl(xml.readElementText()) + except TypeError: #no text + url = None if xml.hasError(): self.logger.error('Error parsing seach results: %s'%xml.errorString()) diff --git a/nephilim/plugins/Library.py b/nephilim/plugins/Library.py index 50079ad..89573e6 100644 --- a/nephilim/plugins/Library.py +++ b/nephilim/plugins/Library.py @@ -28,7 +28,7 @@ class Library(Plugin): o = None # private - DEFAULTS = {'grouping' : QtCore.QStringList(['albumartist', 'album'])} + DEFAULTS = {'grouping' : ['albumartist', 'album']} def _load(self): self.o = LibraryWidget(self) @@ -72,7 +72,7 @@ class Library(Plugin): def save_settings(self): self.settings.beginGroup(self.plugin.name) - tags = QtCore.QStringList() + tags = [] for i in range(self.taglist.count()): it = self.taglist.item(i) if it.checkState() == QtCore.Qt.Checked: @@ -149,7 +149,7 @@ class LibraryWidget(QtGui.QWidget): self.plugin = plugin self.logger = plugin.logger self.settings = QtCore.QSettings() - self.filter = QtCore.QString() + self.filter = '' self.filtered_items = [] self.settings.beginGroup(self.plugin.name) @@ -180,20 +180,21 @@ class LibraryWidget(QtGui.QWidget): def fill_library(self): self.logger.info('Refreshing library.') - self.grouping.setText(self.settings.value('grouping').toStringList().join('/')) + self.grouping.setText('/'.join(self.settings.value('grouping').toStringList())) self.library_model.fill(self.plugin.mpclient.library(), self.settings.value('grouping').toStringList()) - @QtCore.pyqtSlot(QtCore.QString) + @QtCore.pyqtSlot(unicode) def filter_library(self, text): """Hide all items that don't contain text.""" to_hide = [] to_show = [] filtered_items = [] + text = text.lower() if not text: # show all items to_show = self.library_model.findItems('*', QtCore.Qt.MatchWildcard|QtCore.Qt.MatchRecursive) - elif self.filter and text.contains(self.filter, QtCore.Qt.CaseInsensitive): + elif self.filter and self.filter in text: for item in self.filtered_items: - if item.text().contains(text, QtCore.Qt.CaseInsensitive): + if text in item.text().lower(): filtered_items.append(item) while item: to_show.append(item) @@ -204,7 +205,7 @@ class LibraryWidget(QtGui.QWidget): item = item.parent() else: for item in self.library_model.findItems('*', QtCore.Qt.MatchWildcard|QtCore.Qt.MatchRecursive): - if item.text().contains(text, QtCore.Qt.CaseInsensitive): + if text in item.text().lower(): filtered_items.append(item) while item: to_show.append(item) diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py index 1efce0a..99eff72 100644 --- a/nephilim/plugins/Lyrics.py +++ b/nephilim/plugins/Lyrics.py @@ -109,7 +109,7 @@ class Lyrics(Plugin): o = None # private - DEFAULTS = {'fetchers' : QtCore.QStringList(['Lyricwiki', 'Animelyrics']), 'lyricdir' : '$musicdir/$songdir', + DEFAULTS = {'fetchers' : ['Lyricwiki', 'Animelyrics'], 'lyricdir' : '$musicdir/$songdir', 'lyricname' : '.lyrics_nephilim_$artist_$album_$title', 'store' : True} "implemented fetchers" available_fetchers = None #XXX SettingsWidget currently uses it @@ -180,7 +180,10 @@ class Lyrics(Plugin): if token == QtCore.QXmlStreamReader.StartElement: if xml.name() == 'url': url = QtCore.QUrl() # the url is already percent-encoded - url.setEncodedUrl(xml.readElementText().toLatin1()) + try: + url.setEncodedUrl(xml.readElementText()) + except TypeError: # no text + url = None elif xml.name() == 'lyrics' and xml.readElementText() == 'Not found': xml.clear() return self.finish() @@ -317,7 +320,7 @@ class Lyrics(Plugin): self.settings.setValue('lyricname', QVariant(self.lyricname.text())) self.settings.setValue('store', QVariant(self.store.isChecked())) - fetchers = QtCore.QStringList() + fetchers = [] for i in range(self.fetcherlist.count()): it = self.fetcherlist.item(i) if it.checkState() == QtCore.Qt.Checked: diff --git a/nephilim/plugins/Playlist.py b/nephilim/plugins/Playlist.py index b85a759..1e1bedb 100644 --- a/nephilim/plugins/Playlist.py +++ b/nephilim/plugins/Playlist.py @@ -28,8 +28,8 @@ class Playlist(Plugin): o = None # private - DEFAULTS = {'columns': QtCore.QStringList(['track', 'title', 'artist', - 'date', 'album', 'length'])} + DEFAULTS = {'columns': ['track', 'title', 'artist', + 'date', 'album', 'length']} def _load(self): self.o = PlaylistWidget(self) diff --git a/nephilim/plugins/Songinfo.py b/nephilim/plugins/Songinfo.py index b2570d5..0701ddb 100644 --- a/nephilim/plugins/Songinfo.py +++ b/nephilim/plugins/Songinfo.py @@ -28,8 +28,8 @@ class Songinfo(Plugin): tags = None # private - DEFAULTS = {'tagtypes' : QtCore.QStringList(['track', 'title', 'artist', 'album', - 'albumartist', 'disc', 'genre', 'date', 'composer', 'performer', 'file'])} + DEFAULTS = {'tagtypes' : ['track', 'title', 'artist', 'album', + 'albumartist', 'disc', 'genre', 'date', 'composer', 'performer', 'file']} #### private #### @@ -63,7 +63,7 @@ class Songinfo(Plugin): def save_settings(self): self.settings.beginGroup(self.plugin.name) - tags = QtCore.QStringList() + tags = [] for i in range(self.taglist.count()): it = self.taglist.item(i) if it.checkState() == QtCore.Qt.Checked: diff --git a/nephilim/song.py b/nephilim/song.py index f2b94ec..2452b97 100644 --- a/nephilim/song.py +++ b/nephilim/song.py @@ -48,8 +48,6 @@ class Song(dict): try: return dict.__getitem__(self, key) except KeyError: - if isinstance(key, QtCore.QString): - return self[str(key)] if key == 'tracknum': try: return int(self['track']) -- 2.11.4.GIT