Import and line ending fixes

This commit is contained in:
Jon Tibble 2010-04-11 18:52:51 +01:00
parent 3f5ac846f6
commit cbc93259cb
2 changed files with 55 additions and 55 deletions

View File

@ -27,7 +27,6 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsTab, str_to_bool
from openlp.plugins.alerts.lib.models import AlertItem
from openlp.plugins.alerts.lib import alertsmanager
class AlertsTab(SettingsTab):
"""

View File

@ -29,10 +29,11 @@
# http://www.oooforum.org/forum/viewtopic.phtml?t=14409
# http://wiki.services.openoffice.org/wiki/Python
import re
import os
import time
import re
from PyQt4 import QtCore
from songimport import SongImport
if os.name == u'nt':
@ -69,9 +70,9 @@ class SofImport(object):
Initialise the class. Requires a songmanager class which is passed
to SongImport for writing song to disk
"""
self.song = None
self.song = None
self.manager = songmanager
self.process_started = False
self.process_started = False
def import_sof(self, filename):
self.start_ooo()
@ -86,7 +87,7 @@ class SofImport(object):
"""
if os.name == u'nt':
self.start_ooo_process()
self.desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop')
self.desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop')
else:
context = uno.getComponentContext()
resolver = context.ServiceManager.createInstanceWithContext(
@ -110,10 +111,10 @@ class SofImport(object):
if os.name == u'nt':
self.manager = Dispatch(u'com.sun.star.ServiceManager')
self.manager._FlagAsMethod(u'Bridge_GetStruct')
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
else:
cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' \
+ u'-nofirststartwizard ' \
cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' \
+ u'-nofirststartwizard ' \
+ '-accept="socket,host=localhost,port=2002;urp;"'
process = QtCore.QProcess()
process.startDetached(cmd)
@ -283,21 +284,21 @@ class SofImport(object):
"""
Add a song number, store as alternate title. Also use the song
number to work out which songbook we're in
"""
"""
self.song.set_song_number(song_no)
self.song.set_alternate_title(song_no + u'.')
if int(song_no) <= 640:
self.song.set_song_book(u'Songs of Fellowship 1',
u'Kingsway Publications')
elif int(song_no) <= 1150:
self.song.set_song_book(u'Songs of Fellowship 2',
u'Kingsway Publications')
elif int(song_no) <= 1690:
self.song.set_song_book(u'Songs of Fellowship 3',
u'Kingsway Publications')
else:
self.song.set_song_book(u'Songs of Fellowship 4',
u'Kingsway Publications')
self.song.set_alternate_title(song_no + u'.')
if int(song_no) <= 640:
self.song.set_song_book(u'Songs of Fellowship 1',
u'Kingsway Publications')
elif int(song_no) <= 1150:
self.song.set_song_book(u'Songs of Fellowship 2',
u'Kingsway Publications')
elif int(song_no) <= 1690:
self.song.set_song_book(u'Songs of Fellowship 3',
u'Kingsway Publications')
else:
self.song.set_song_book(u'Songs of Fellowship 4',
u'Kingsway Publications')
def add_title(self, text):
"""
@ -328,9 +329,9 @@ class SofImport(object):
+ authors[i + 1].strip().split(u' ')[-1]
if author2.endswith(u'.'):
author2 = author2[:-1]
if author2:
self.song.add_author(author2)
if author2:
self.song.add_author(author2)
def add_verse_line(self, text):
"""
Add a line to the current verse. If the formatting has changed and
@ -349,36 +350,36 @@ class SofImport(object):
Verse is finished, store it. Note in book 1+2, some songs are formatted
incorrectly. Here we try and split songs with missing line breaks into
the correct number of verses.
"""
if self.currentverse.strip() == u'':
return
"""
if self.currentverse.strip() == u'':
return
if self.is_chorus:
versetag = u'C'
splitat = None
else:
versetag = u'V'
splitat = self.verse_splits(self.song.get_song_number())
if splitat:
ln = 0
verse = u''
for line in self.currentverse.split(u'\n'):
ln += 1
if line == u'' or ln > splitat:
self.song.add_verse(verse, versetag)
ln = 0
if line:
verse = line + u'\n'
else:
verse = u''
else:
verse += line + u'\n'
if verse:
self.song.add_verse(verse, versetag)
else:
self.song.add_verse(self.currentverse, versetag)
self.currentverse = u''
self.is_chorus = False
versetag = u'C'
splitat = None
else:
versetag = u'V'
splitat = self.verse_splits(self.song.get_song_number())
if splitat:
ln = 0
verse = u''
for line in self.currentverse.split(u'\n'):
ln += 1
if line == u'' or ln > splitat:
self.song.add_verse(verse, versetag)
ln = 0
if line:
verse = line + u'\n'
else:
verse = u''
else:
verse += line + u'\n'
if verse:
self.song.add_verse(verse, versetag)
else:
self.song.add_verse(self.currentverse, versetag)
self.currentverse = u''
self.is_chorus = False
def tidy_text(self, text):
"""
Get rid of some dodgy unicode and formatting characters we're not