forked from openlp/openlp
Head r863
This commit is contained in:
commit
700b41390e
@ -90,7 +90,7 @@ class ServiceItem(object):
|
|||||||
self.from_plugin = False
|
self.from_plugin = False
|
||||||
self.capabilities = []
|
self.capabilities = []
|
||||||
self.is_valid = True
|
self.is_valid = True
|
||||||
self.cache = []
|
self.cache = {}
|
||||||
self.icon = None
|
self.icon = None
|
||||||
|
|
||||||
def add_capability(self, capability):
|
def add_capability(self, capability):
|
||||||
@ -129,7 +129,7 @@ class ServiceItem(object):
|
|||||||
"""
|
"""
|
||||||
log.debug(u'Render called')
|
log.debug(u'Render called')
|
||||||
self._display_frames = []
|
self._display_frames = []
|
||||||
self.cache = []
|
self.clear_cache()
|
||||||
if self.service_item_type == ServiceItemType.Text:
|
if self.service_item_type == ServiceItemType.Text:
|
||||||
log.debug(u'Formatting slides')
|
log.debug(u'Formatting slides')
|
||||||
if self.theme is None:
|
if self.theme is None:
|
||||||
@ -149,7 +149,8 @@ class ServiceItem(object):
|
|||||||
self._display_frames.append({u'title': title,
|
self._display_frames.append({u'title': title,
|
||||||
u'text': lines.rstrip(),
|
u'text': lines.rstrip(),
|
||||||
u'verseTag': slide[u'verseTag'] })
|
u'verseTag': slide[u'verseTag'] })
|
||||||
self.cache.insert(len(self._display_frames), None)
|
if len(self._display_frames) in self.cache.keys():
|
||||||
|
del self.cache[len(self._display_frames)]
|
||||||
log.log(15, u'Formatting took %4s' % (time.time() - before))
|
log.log(15, u'Formatting took %4s' % (time.time() - before))
|
||||||
elif self.service_item_type == ServiceItemType.Image:
|
elif self.service_item_type == ServiceItemType.Image:
|
||||||
for slide in self._raw_frames:
|
for slide in self._raw_frames:
|
||||||
@ -172,8 +173,7 @@ class ServiceItem(object):
|
|||||||
else:
|
else:
|
||||||
self.render_manager.set_override_theme(self.theme)
|
self.render_manager.set_override_theme(self.theme)
|
||||||
format = self._display_frames[row][u'text'].split(u'\n')
|
format = self._display_frames[row][u'text'].split(u'\n')
|
||||||
#if screen blank then do not display footer
|
if self.cache.get(row):
|
||||||
if len(self.cache) > 0 and self.cache[row] is not None:
|
|
||||||
frame = self.cache[row]
|
frame = self.cache[row]
|
||||||
else:
|
else:
|
||||||
if format[0]:
|
if format[0]:
|
||||||
@ -385,3 +385,8 @@ class ServiceItem(object):
|
|||||||
"""
|
"""
|
||||||
return self._raw_frames[row][u'path']
|
return self._raw_frames[row][u'path']
|
||||||
|
|
||||||
|
def clear_cache(self):
|
||||||
|
"""
|
||||||
|
Clear's the service item's cache.
|
||||||
|
"""
|
||||||
|
self.cache = {}
|
||||||
|
@ -661,8 +661,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
filename = unicode(filename)
|
filename = unicode(filename)
|
||||||
name = filename.split(os.path.sep)
|
name = filename.split(os.path.sep)
|
||||||
if filename:
|
if filename:
|
||||||
SettingsManager.set_last_dir(
|
SettingsManager.set_last_dir(self.parent.serviceSettingsSection,
|
||||||
self.parent.serviceSettingsSection,
|
|
||||||
os.path.split(filename)[0])
|
os.path.split(filename)[0])
|
||||||
zip = None
|
zip = None
|
||||||
file_to = None
|
file_to = None
|
||||||
@ -697,7 +696,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
self.onNewService()
|
self.onNewService()
|
||||||
for item in items:
|
for item in items:
|
||||||
serviceitem = ServiceItem()
|
serviceitem = ServiceItem()
|
||||||
serviceitem.RenderManager = self.parent.RenderManager
|
serviceitem.render_manager = self.parent.RenderManager
|
||||||
serviceitem.set_from_service(item, self.servicePath)
|
serviceitem.set_from_service(item, self.servicePath)
|
||||||
self.validateItem(serviceitem)
|
self.validateItem(serviceitem)
|
||||||
self.addServiceItem(serviceitem)
|
self.addServiceItem(serviceitem)
|
||||||
|
@ -537,7 +537,7 @@ class SlideController(QtGui.QWidget):
|
|||||||
before = time.time()
|
before = time.time()
|
||||||
#Clear the old serviceItem cache to release memory
|
#Clear the old serviceItem cache to release memory
|
||||||
if self.serviceItem and self.serviceItem is not serviceItem:
|
if self.serviceItem and self.serviceItem is not serviceItem:
|
||||||
self.serviceItem.cache = []
|
self.serviceItem.clear_cache()
|
||||||
self.serviceItem = serviceItem
|
self.serviceItem = serviceItem
|
||||||
self.PreviewListWidget.clear()
|
self.PreviewListWidget.clear()
|
||||||
self.PreviewListWidget.setRowCount(0)
|
self.PreviewListWidget.setRowCount(0)
|
||||||
|
@ -384,9 +384,6 @@ class Ui_EditSongDialog(object):
|
|||||||
self.CommentsLayout.addWidget(self.CommentsEdit)
|
self.CommentsLayout.addWidget(self.CommentsEdit)
|
||||||
self.ThemeCopyCommentsLayout.addWidget(self.CommentsGroupBox)
|
self.ThemeCopyCommentsLayout.addWidget(self.CommentsGroupBox)
|
||||||
self.ThemeTabLayout.addWidget(self.ThemeCopyCommentsWidget)
|
self.ThemeTabLayout.addWidget(self.ThemeCopyCommentsWidget)
|
||||||
spacerItem5 = QtGui.QSpacerItem(20, 40,
|
|
||||||
QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
|
|
||||||
self.ThemeTabLayout.addItem(spacerItem5)
|
|
||||||
self.SongTabWidget.addTab(self.ThemeTab, u'')
|
self.SongTabWidget.addTab(self.ThemeTab, u'')
|
||||||
self.verticalLayout.addWidget(self.SongTabWidget)
|
self.verticalLayout.addWidget(self.SongTabWidget)
|
||||||
self.ButtonBox = QtGui.QDialogButtonBox(EditSongDialog)
|
self.ButtonBox = QtGui.QDialogButtonBox(EditSongDialog)
|
||||||
|
@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, translate
|
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, translate
|
||||||
from openlp.plugins.songs.forms import EditVerseForm
|
from openlp.plugins.songs.forms import EditVerseForm
|
||||||
|
from openlp.plugins.songs.lib import VerseType
|
||||||
from openlp.plugins.songs.lib.models import Song, Author, Topic, Book
|
from openlp.plugins.songs.lib.models import Song, Author, Topic, Book
|
||||||
from editsongdialog import Ui_EditSongDialog
|
from editsongdialog import Ui_EditSongDialog
|
||||||
|
|
||||||
@ -90,16 +91,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
self.parent.parent.render_manager.theme_manager.onAddTheme)
|
self.parent.parent.render_manager.theme_manager.onAddTheme)
|
||||||
QtCore.QObject.connect(self.MaintenanceButton,
|
QtCore.QObject.connect(self.MaintenanceButton,
|
||||||
QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked)
|
QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked)
|
||||||
QtCore.QObject.connect(self.TitleEditItem,
|
|
||||||
QtCore.SIGNAL(u'editingFinished()'), self.onTitleEditItemLostFocus)
|
|
||||||
QtCore.QObject.connect(self.CCLNumberEdit,
|
|
||||||
QtCore.SIGNAL(u'lostFocus()'), self.onCCLNumberEditLostFocus)
|
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
|
QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
|
||||||
QtCore.QObject.connect(self.CommentsEdit,
|
|
||||||
QtCore.SIGNAL(u'lostFocus()'), self.onCommentsEditLostFocus)
|
|
||||||
QtCore.QObject.connect(self.VerseOrderEdit,
|
|
||||||
QtCore.SIGNAL(u'lostFocus()'), self.onVerseOrderEditLostFocus)
|
|
||||||
self.previewButton = QtGui.QPushButton()
|
self.previewButton = QtGui.QPushButton()
|
||||||
self.previewButton.setObjectName(u'previewButton')
|
self.previewButton.setObjectName(u'previewButton')
|
||||||
self.previewButton.setText(
|
self.previewButton.setText(
|
||||||
@ -247,7 +240,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
self.VerseListWidget.setRowCount(
|
self.VerseListWidget.setRowCount(
|
||||||
self.VerseListWidget.rowCount() + 1)
|
self.VerseListWidget.rowCount() + 1)
|
||||||
item = QtGui.QTableWidgetItem(verse)
|
item = QtGui.QTableWidgetItem(verse)
|
||||||
variant = u'Verse:%s' % unicode(count + 1)
|
variant = u'%s:%s' % \
|
||||||
|
(VerseType.to_string(VerseType.Verse), unicode(count + 1))
|
||||||
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant))
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant))
|
||||||
self.VerseListWidget.setItem(count, 0, item)
|
self.VerseListWidget.setItem(count, 0, item)
|
||||||
self.VerseListWidget.resizeRowsToContents()
|
self.VerseListWidget.resizeRowsToContents()
|
||||||
@ -264,7 +258,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
topic_name = QtGui.QListWidgetItem(unicode(topic.name))
|
topic_name = QtGui.QListWidgetItem(unicode(topic.name))
|
||||||
topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
|
topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
|
||||||
self.TopicsListView.addItem(topic_name)
|
self.TopicsListView.addItem(topic_name)
|
||||||
self._validate_song()
|
|
||||||
self.TitleEditItem.setFocus(QtCore.Qt.OtherFocusReason)
|
self.TitleEditItem.setFocus(QtCore.Qt.OtherFocusReason)
|
||||||
#if not preview hide the preview button
|
#if not preview hide the preview button
|
||||||
self.previewButton.setVisible(False)
|
self.previewButton.setVisible(False)
|
||||||
@ -522,42 +515,75 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
if len(self.TitleEditItem.displayText()) == 0:
|
if len(self.TitleEditItem.displayText()) == 0:
|
||||||
self.SongTabWidget.setCurrentIndex(0)
|
self.SongTabWidget.setCurrentIndex(0)
|
||||||
self.TitleEditItem.setFocus()
|
self.TitleEditItem.setFocus()
|
||||||
return False, translate(u'SongsPlugin.EditSongForm',
|
QtGui.QMessageBox.critical(self,
|
||||||
u'You need to enter a song title.')
|
translate(u'SongsPlugin.EditSongForm', u'Error'),
|
||||||
|
translate(u'SongsPlugin.EditSongForm',
|
||||||
|
u'You need to enter a song title.'))
|
||||||
|
return False
|
||||||
if self.VerseListWidget.rowCount() == 0:
|
if self.VerseListWidget.rowCount() == 0:
|
||||||
self.SongTabWidget.setCurrentIndex(0)
|
self.SongTabWidget.setCurrentIndex(0)
|
||||||
self.VerseListWidget.setFocus()
|
self.VerseListWidget.setFocus()
|
||||||
return False, translate(u'SongsPlugin.EditSongForm',
|
QtGui.QMessageBox.critical(self,
|
||||||
u'You need to enter some verses.')
|
translate(u'SongsPlugin.EditSongForm', u'Error'),
|
||||||
|
translate('uSongsPlugin.EditSongForm',
|
||||||
|
u'You need to enter some verses.'))
|
||||||
|
return False
|
||||||
if self.AuthorsListView.count() == 0:
|
if self.AuthorsListView.count() == 0:
|
||||||
self.SongTabWidget.setCurrentIndex(1)
|
self.SongTabWidget.setCurrentIndex(1)
|
||||||
self.AuthorsListView.setFocus()
|
self.AuthorsListView.setFocus()
|
||||||
#split the verse list by space and mark lower case for testing
|
answer = QtGui.QMessageBox.warning(self,
|
||||||
taglist = unicode(translate(u'SongsPlugin.EditSongForm', u' bitpeovc'))
|
translate(u'SongsPlugin.EditSongForm', u'Warning'),
|
||||||
for verse in unicode(self.VerseOrderEdit.text()).lower().split(u' '):
|
translate('SongsPlugin.EditSongForm',
|
||||||
if len(verse) > 1:
|
'You have set no author.\n'
|
||||||
if taglist.find(verse[0:1]) > -1 \
|
'Do you want to add now a author?'),
|
||||||
and verse[1:].isdigit():
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
|
||||||
pass
|
if answer == QtGui.QMessageBox.Yes:
|
||||||
|
return False
|
||||||
|
if self.song.verse_order:
|
||||||
|
order = []
|
||||||
|
order_names = self.song.verse_order.split(u' ')
|
||||||
|
for item in order_names:
|
||||||
|
if len(item) == 1:
|
||||||
|
order.append(item.lower() + u'1')
|
||||||
else:
|
else:
|
||||||
|
order.append(item.lower())
|
||||||
|
verses = []
|
||||||
|
verse_names = []
|
||||||
|
for index in range (0, self.VerseListWidget.rowCount()):
|
||||||
|
verse = self.VerseListWidget.item(index, 0)
|
||||||
|
verse = unicode(verse.data(QtCore.Qt.UserRole).toString())
|
||||||
|
if verse not in verse_names:
|
||||||
|
verses.append(
|
||||||
|
re.sub(r'(.)[^:]*:(.*)', r'\1\2', verse.lower()))
|
||||||
|
verse_names.append(verse)
|
||||||
|
for count, item in enumerate(order):
|
||||||
|
if item not in verses:
|
||||||
self.SongTabWidget.setCurrentIndex(0)
|
self.SongTabWidget.setCurrentIndex(0)
|
||||||
self.VerseOrderEdit.setFocus()
|
self.VerseOrderEdit.setFocus()
|
||||||
return False, translate(u'SongsPlugin.EditSongForm',
|
valid = verses.pop(0)
|
||||||
u'Invalid verse entry, values must be I,B,T,P,E,O,V,C '
|
for verse in verses:
|
||||||
u'followed by a number')
|
valid = valid + u', ' + verse
|
||||||
return True, u''
|
QtGui.QMessageBox.critical(self,
|
||||||
|
translate(u'SongsPlugin.EditSongForm', u'Error'),
|
||||||
def onTitleEditItemLostFocus(self):
|
unicode(translate('SongsPlugin.EditSongForm',
|
||||||
self.song.title = unicode(self.TitleEditItem.text())
|
'The verse order is invalid. There is no verse '
|
||||||
|
'corresponding to %s. Valid entries are %s.')) % \
|
||||||
def onVerseOrderEditLostFocus(self):
|
(order_names[count], valid))
|
||||||
self.song.verse_order = unicode(self.VerseOrderEdit.text())
|
return False
|
||||||
|
for count, verse in enumerate(verses):
|
||||||
def onCommentsEditLostFocus(self):
|
if verse not in order:
|
||||||
self.song.comments = unicode(self.CommentsEdit.text())
|
self.SongTabWidget.setCurrentIndex(0)
|
||||||
|
self.VerseOrderEdit.setFocus()
|
||||||
def onCCLNumberEditLostFocus(self):
|
answer = QtGui.QMessageBox.warning(self,
|
||||||
self.song.ccli_number = self.CCLNumberEdit.text()
|
translate(u'SongsPlugin.EditSongForm', u'Warning'),
|
||||||
|
unicode(translate('SongsPlugin.EditSongForm',
|
||||||
|
'%s is not addressed in the verse order.\n'
|
||||||
|
'Do you want to save anyhow?')) % \
|
||||||
|
verse_names[count].replace(u':', u' '),
|
||||||
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
|
||||||
|
if answer == QtGui.QMessageBox.No:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def onCopyrightInsertButtonTriggered(self):
|
def onCopyrightInsertButtonTriggered(self):
|
||||||
text = self.CopyrightEditItem.text()
|
text = self.CopyrightEditItem.text()
|
||||||
@ -593,23 +619,19 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def saveSong(self):
|
def saveSong(self):
|
||||||
valid, message = self._validate_song()
|
|
||||||
if not valid:
|
|
||||||
QtGui.QMessageBox.critical(
|
|
||||||
self, translate(u'SongsPlugin.EditSongForm', u'Error'), message,
|
|
||||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
|
||||||
return False
|
|
||||||
self.song.title = unicode(self.TitleEditItem.text())
|
self.song.title = unicode(self.TitleEditItem.text())
|
||||||
self.song.copyright = unicode(self.CopyrightEditItem.text())
|
self.song.copyright = unicode(self.CopyrightEditItem.text())
|
||||||
self.song.search_title = unicode(self.TitleEditItem.text()) + \
|
self.song.search_title = self.song.title + u'@' + \
|
||||||
u'@'+ unicode(self.AlternativeEdit.text())
|
unicode(self.AlternativeEdit.text())
|
||||||
self.song.comments = unicode(self.CommentsEdit.toPlainText())
|
self.song.comments = unicode(self.CommentsEdit.toPlainText())
|
||||||
self.song.verse_order = unicode(self.VerseOrderEdit.text())
|
self.song.verse_order = unicode(self.VerseOrderEdit.text())
|
||||||
self.song.ccli_number = unicode(self.CCLNumberEdit.text())
|
self.song.ccli_number = unicode(self.CCLNumberEdit.text())
|
||||||
self.processLyrics()
|
if self._validate_song():
|
||||||
self.processTitle()
|
self.processLyrics()
|
||||||
self.songmanager.save_song(self.song)
|
self.processTitle()
|
||||||
return True
|
self.songmanager.save_song(self.song)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def processLyrics(self):
|
def processLyrics(self):
|
||||||
log.debug(u'processLyrics')
|
log.debug(u'processLyrics')
|
||||||
@ -617,41 +639,28 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
sxml = SongXMLBuilder()
|
sxml = SongXMLBuilder()
|
||||||
sxml.new_document()
|
sxml.new_document()
|
||||||
sxml.add_lyrics_to_song()
|
sxml.add_lyrics_to_song()
|
||||||
text = u' '
|
text = u''
|
||||||
|
multiple = []
|
||||||
for i in range (0, self.VerseListWidget.rowCount()):
|
for i in range (0, self.VerseListWidget.rowCount()):
|
||||||
item = self.VerseListWidget.item(i, 0)
|
item = self.VerseListWidget.item(i, 0)
|
||||||
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||||
bits = verseId.split(u':')
|
bits = verseId.split(u':')
|
||||||
sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text()))
|
sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text()))
|
||||||
text = text + unicode(self.VerseListWidget.item(i, 0).text()) \
|
text = text + re.sub(r'\W+', u' ',
|
||||||
+ u' '
|
unicode(self.VerseListWidget.item(i, 0).text())) + u' '
|
||||||
text = text.replace(u'\'', u'')
|
if (bits[1] > u'1') and (bits[0][0] not in multiple):
|
||||||
text = text.replace(u',', u'')
|
multiple.append(bits[0][0])
|
||||||
text = text.replace(u';', u'')
|
self.song.search_lyrics = text
|
||||||
text = text.replace(u':', u'')
|
|
||||||
text = text.replace(u'(', u'')
|
|
||||||
text = text.replace(u')', u'')
|
|
||||||
text = text.replace(u'{', u'')
|
|
||||||
text = text.replace(u'}', u'')
|
|
||||||
text = text.replace(u'?', u'')
|
|
||||||
self.song.search_lyrics = unicode(text)
|
|
||||||
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||||
|
for verse in multiple:
|
||||||
|
self.song.verse_order = re.sub(u'([' + verse.upper() +
|
||||||
|
verse.lower() + u'])(\W|$)', r'\g<1>1\2', self.song.verse_order)
|
||||||
except:
|
except:
|
||||||
log.exception(u'Problem processing song Lyrics \n%s',
|
log.exception(u'Problem processing song Lyrics \n%s',
|
||||||
sxml.dump_xml())
|
sxml.dump_xml())
|
||||||
|
|
||||||
def processTitle(self):
|
def processTitle(self):
|
||||||
log.debug(u'processTitle')
|
log.debug(u'processTitle')
|
||||||
self.song.search_title = unicode(self.song.search_title)
|
self.song.search_title = \
|
||||||
self.song.search_title = self.song.search_title.replace(u'\'', u'')
|
re.sub(r'[\'"`,;:(){}?]+', u'', unicode(self.song.search_title))
|
||||||
self.song.search_title = self.song.search_title.replace(u'\"', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u'`', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u',', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u';', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u':', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u'(', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u')', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u'{', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u'}', u'')
|
|
||||||
self.song.search_title = self.song.search_title.replace(u'?', u'')
|
|
||||||
|
|
||||||
|
@ -350,8 +350,8 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
if len(order) == 0:
|
if len(order) == 0:
|
||||||
break
|
break
|
||||||
for verse in verseList:
|
for verse in verseList:
|
||||||
if verse[0][u'label'] == order[1:] and \
|
if verse[0][u'type'][0] == order[0] and \
|
||||||
verse[0][u'type'][0] == order[0]:
|
(verse[0][u'label'] == order[1:] or not order[1:]):
|
||||||
verseTag = u'%s:%s' % \
|
verseTag = u'%s:%s' % \
|
||||||
(verse[0][u'type'], verse[0][u'label'])
|
(verse[0][u'type'], verse[0][u'label'])
|
||||||
service_item.add_from_text(
|
service_item.add_from_text(
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import string
|
import string
|
||||||
|
import re
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
@ -89,9 +90,6 @@ class SongImport(object):
|
|||||||
Get rid of some dodgy unicode and formatting characters we're not
|
Get rid of some dodgy unicode and formatting characters we're not
|
||||||
interested in. Some can be converted to ascii.
|
interested in. Some can be converted to ascii.
|
||||||
"""
|
"""
|
||||||
text = text.replace(u'\t', u' ')
|
|
||||||
text = text.replace(u'\r\n', u'\n')
|
|
||||||
text = text.replace(u'\r', u'\n')
|
|
||||||
text = text.replace(u'\u2018', u'\'')
|
text = text.replace(u'\u2018', u'\'')
|
||||||
text = text.replace(u'\u2019', u'\'')
|
text = text.replace(u'\u2019', u'\'')
|
||||||
text = text.replace(u'\u201c', u'"')
|
text = text.replace(u'\u201c', u'"')
|
||||||
@ -100,15 +98,9 @@ class SongImport(object):
|
|||||||
text = text.replace(u'\u2013', u'-')
|
text = text.replace(u'\u2013', u'-')
|
||||||
text = text.replace(u'\u2014', u'-')
|
text = text.replace(u'\u2014', u'-')
|
||||||
# Remove surplus blank lines, spaces, trailing/leading spaces
|
# Remove surplus blank lines, spaces, trailing/leading spaces
|
||||||
while text.find(u' ') >= 0:
|
text = re.sub(r'[ \t\v]+', u' ', text)
|
||||||
text = text.replace(u' ', u' ')
|
text = re.sub(r' ?(\r\n?|\n) ?', u'\n', text)
|
||||||
text = text.replace(u'\n ', u'\n')
|
text = re.sub(r' ?(\n{5}|\f)+ ?', u'\f', text)
|
||||||
text = text.replace(u' \n', u'\n')
|
|
||||||
text = text.replace(u'\n\n\n\n\n', u'\f')
|
|
||||||
text = text.replace(u'\f ', u'\f')
|
|
||||||
text = text.replace(u' \f', u'\f')
|
|
||||||
while text.find(u'\f\f') >= 0:
|
|
||||||
text = text.replace(u'\f\f', u'\f')
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def process_song_text(self, text):
|
def process_song_text(self, text):
|
||||||
@ -264,11 +256,9 @@ class SongImport(object):
|
|||||||
|
|
||||||
def remove_punctuation(self, text):
|
def remove_punctuation(self, text):
|
||||||
"""
|
"""
|
||||||
Remove punctuation from the string for searchable fields
|
Extracts alphanumeric words for searchable fields
|
||||||
"""
|
"""
|
||||||
for character in string.punctuation:
|
return re.sub(r'\W+', u' ', text)
|
||||||
text = text.replace(character, u'')
|
|
||||||
return text
|
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user