From 8b79abdfe6981fbfbd97c55f80c7878b357a3bfc Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sun, 22 Aug 2010 23:36:11 +0100 Subject: [PATCH 1/4] sof wizard --- openlp/plugins/songs/lib/oooimport.py | 26 +++++++++++++++++++++----- openlp/plugins/songs/lib/sofimport.py | 24 ++++++++++++++++++------ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 76b4b6c0d..7bc602f99 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -28,6 +28,7 @@ import os from PyQt4 import QtCore +from openlp.core.lib import Receiver from songimport import SongImport if os.name == u'nt': @@ -43,23 +44,30 @@ else: except ImportError: pass -class OooImport(object): +class OooImport(SongImport): """ Import songs from Impress/Powerpoint docs using Impress """ - def __init__(self, songmanager): + def __init__(self, master_manager, **kwargs): """ Initialise the class. Requires a songmanager class which is passed to SongImport for writing song to disk """ self.song = None - self.manager = songmanager + self.master_manager = master_manager self.document = None self.process_started = False + self.filenames = kwargs[u'filenames'] + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlp_stop_song_import'), self.stop_import) - def import_docs(self, filenames): + def do_import(self): + self.abort = False self.start_ooo() - for filename in filenames: + for filename in self.filenames: + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return filename = unicode(filename) if os.path.isfile(filename): self.open_ooo_file(filename) @@ -73,6 +81,9 @@ class OooImport(object): self.close_ooo_file() self.close_ooo() + def stop_import(self): + self.abort = True + def start_ooo(self): """ Start OpenOffice.org process @@ -135,6 +146,8 @@ class OooImport(object): "com.sun.star.presentation.PresentationDocument") and not \ self.document.supportsService("com.sun.star.text.TextDocument"): self.close_ooo_file() + else: + self.wizard.incrementProgressBar(u'Processing file ' + filepath) except: pass return @@ -161,6 +174,9 @@ class OooImport(object): slides = doc.getDrawPages() text = u'' for slide_no in range(slides.getCount()): + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return slide = slides.getByIndex(slide_no) slidetext = u'' for idx in range(slide.getCount()): diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index 54cfd07ac..b2374d672 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -68,18 +68,26 @@ class SofImport(OooImport): It attempts to detect italiced verses, and treats these as choruses in the verse ordering. Again not perfect, but a start. """ - def __init__(self, songmanager): + def __init__(self, master_manager, **kwargs): """ Initialise the class. Requires a songmanager class which is passed to SongImport for writing song to disk """ - OooImport.__init__(self, songmanager) + OooImport.__init__(self,master_manager, **kwargs) - def import_sof(self, filename): + def do_import(self): + self.abort = False self.start_ooo() - self.open_ooo_file(filename) - self.process_sof_file() - self.close_ooo_file() + for filename in self.filenames: + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return + filename = unicode(filename) + if os.path.isfile(filename): + self.open_ooo_file(filename) + if self.document: + self.process_sof_file() + self.close_ooo_file() self.close_ooo() def process_sof_file(self): @@ -90,6 +98,9 @@ class SofImport(OooImport): self.new_song() paragraphs = self.document.getText().createEnumeration() while paragraphs.hasMoreElements(): + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return paragraph = paragraphs.nextElement() if paragraph.supportsService("com.sun.star.text.Paragraph"): self.process_paragraph(paragraph) @@ -244,6 +255,7 @@ class SofImport(OooImport): if title.endswith(u','): title = title[:-1] self.song.title = title + self.wizard.incrementProgressBar(u'Processing song ' + title) def add_author(self, text): """ From 0066edecbb091ce181d98cd320777b06d44be47c Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Tue, 24 Aug 2010 13:50:26 +0100 Subject: [PATCH 2/4] Remove comments --- openlp/plugins/songs/lib/oooimport.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index da4bd6f3e..d07d50271 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -65,9 +65,6 @@ class OooImport(SongImport): def do_import(self): self.abort = False self.start_ooo() - # Note this doesn't work, because kwargs[u'filenames'] doesn't appear - # to be anything sensible like an array of strings. No idea what it is - # though, I'm meant to guess for filename in self.filenames: if self.abort: self.wizard.incrementProgressBar(u'Import cancelled') From f717dc10d4a0e29f20e5d9e40f87d69578d87b4e Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Thu, 26 Aug 2010 23:08:09 +0100 Subject: [PATCH 3/4] Bring up to date --- openlp/plugins/songs/lib/oooimport.py | 11 ++++++----- openlp/plugins/songs/lib/sofimport.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 6c9141157..9a3be2843 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -59,16 +59,16 @@ class OooImport(SongImport): self.document = None self.process_started = False self.filenames = kwargs[u'filenames'] - self.import_wizard.importProgressBar.setMaximum(0) QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'openlp_stop_song_import'), self.stop_import) + QtCore.SIGNAL(u'song_stop_import'), self.stop_import) def do_import(self): self.abort = False + self.import_wizard.importProgressBar.setMaximum(0) self.start_ooo() for filename in self.filenames: if self.abort: - self.import_wizard.incrementProgressBar(u'Import cancelled') + self.import_wizard.incrementProgressBar(u'Import cancelled', 0) return filename = unicode(filename) if os.path.isfile(filename): @@ -149,7 +149,8 @@ class OooImport(SongImport): self.document.supportsService("com.sun.star.text.TextDocument"): self.close_ooo_file() else: - self.import_wizard.incrementProgressBar(u'Processing file ' + filepath) + self.import_wizard.incrementProgressBar( + u'Processing file ' + filepath, 0) except: pass return @@ -177,7 +178,7 @@ class OooImport(SongImport): text = u'' for slide_no in range(slides.getCount()): if self.abort: - self.import_wizard.incrementProgressBar(u'Import cancelled') + self.import_wizard.incrementProgressBar(u'Import cancelled', 0) return slide = slides.getByIndex(slide_no) slidetext = u'' diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index af968fafe..0d7c085de 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -80,7 +80,7 @@ class SofImport(OooImport): self.start_ooo() for filename in self.filenames: if self.abort: - self.import_wizard.incrementProgressBar(u'Import cancelled') + self.import_wizard.incrementProgressBar(u'Import cancelled', 0) return filename = unicode(filename) if os.path.isfile(filename): @@ -99,7 +99,7 @@ class SofImport(OooImport): paragraphs = self.document.getText().createEnumeration() while paragraphs.hasMoreElements(): if self.abort: - self.import_wizard.incrementProgressBar(u'Import cancelled') + self.import_wizard.incrementProgressBar(u'Import cancelled', 0) return paragraph = paragraphs.nextElement() if paragraph.supportsService("com.sun.star.text.Paragraph"): @@ -255,7 +255,7 @@ class SofImport(OooImport): if title.endswith(u','): title = title[:-1] self.song.title = title - self.import_wizard.incrementProgressBar(u'Processing song ' + title) + self.import_wizard.incrementProgressBar(u'Processing song ' + title, 0) def add_author(self, text): """ From aa0f4f7af0745702f570dbe4aad01c1f79c397bf Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sun, 5 Sep 2010 16:16:48 +0100 Subject: [PATCH 4/4] Finish wizard integration --- openlp/plugins/songs/lib/oooimport.py | 3 +++ openlp/plugins/songs/lib/sofimport.py | 3 +++ openlp/plugins/songs/lib/songimport.py | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 9a3be2843..e8c723c0e 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -82,6 +82,9 @@ class OooImport(SongImport): self.process_doc() self.close_ooo_file() self.close_ooo() + self.import_wizard.importProgressBar.setMaximum(1) + self.import_wizard.incrementProgressBar(u'', 1) + return True def stop_import(self): self.abort = True diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index 0d7c085de..ab91e1923 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -89,6 +89,9 @@ class SofImport(OooImport): self.process_sof_file() self.close_ooo_file() self.close_ooo() + self.import_wizard.importProgressBar.setMaximum(1) + self.import_wizard.incrementProgressBar(u'', 1) + return True def process_sof_file(self): """ diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 63ef6a8ed..17000a2ba 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -129,13 +129,13 @@ class SongImport(QtCore.QObject): def process_verse_text(self, text): lines = text.split(u'\n') - if text.lower().find(COPYRIGHT_STRING) >= 0 \ - or text.lower().find(COPYRIGHT_SYMBOL) >= 0: + if text.lower().find(self.copyright_string) >= 0 \ + or text.lower().find(self.copyright_symbol) >= 0: copyright_found = False for line in lines: if (copyright_found or - line.lower().find(COPYRIGHT_STRING) >= 0 or - line.lower().find(COPYRIGHT_SYMBOL) >= 0): + line.lower().find(self.copyright_string) >= 0 or + line.lower().find(self.copyright_symbol) >= 0): copyright_found = True self.add_copyright(line) else: