From 3bbaff362d33baa28646b91ddf4c261ceee19bb8 Mon Sep 17 00:00:00 2001 From: Felipe Polo-Wood Date: Thu, 17 Oct 2013 19:55:17 -0400 Subject: [PATCH] - Added support for titles (and improved notes) for impresscontroller.py - Removed \x0b and \n from the titles --- .../presentations/lib/impresscontroller.py | 40 +++++++++++++++---- .../presentations/lib/powerpointcontroller.py | 7 ++-- .../presentations/lib/pptviewcontroller.py | 8 ++-- .../lib/presentationcontroller.py | 8 ++++ 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 298f6be05..fc8c72967 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -60,7 +60,7 @@ from PyQt4 import QtCore from openlp.core.lib import ScreenList from openlp.core.utils import delete_file, get_uno_command, get_uno_instance -from .presentationcontroller import PresentationController, PresentationDocument +from .presentationcontroller import PresentationController, PresentationDocument, TextType log = logging.getLogger(__name__) @@ -252,6 +252,7 @@ class ImpressDocument(PresentationDocument): self.presentation.Display = ScreenList().current['number'] + 1 self.control = None self.create_thumbnails() + self.create_titles_and_notes() return True def create_thumbnails(self): @@ -447,9 +448,9 @@ class ImpressDocument(PresentationDocument): ``slide_no`` The slide the notes are required for, starting at 1 """ - return self.__get_text_from_page(slide_no, True) + return self.__get_text_from_page(slide_no, TextType.Notes) - def __get_text_from_page(self, slide_no, notes=False): + def __get_text_from_page(self, slide_no, text_type=TextType.SlideText): """ Return any text extracted from the presentation page. @@ -459,17 +460,40 @@ class ImpressDocument(PresentationDocument): text = '' pages = self.document.getDrawPages() page = pages.getByIndex(slide_no - 1) - if notes: + if text_type==TextType.Notes: page = page.getNotesPage() for index in range(page.getCount()): shape = page.getByIndex(index) + shapeType = shape.getShapetype() if shape.supportsService("com.sun.star.drawing.Text"): - text += shape.getString() + '\n' + if text_type!=TextType.Title or shapeType == "com.sun.star.presentation.TitleTextShape": + text += shape.getString() + '\n' return text + def create_titles_and_notes(self): + """ + Writes the list of titles (one per slide) + to 'titles.txt' + and the notes to 'slideNotes[x].txt' + in the thumbnails directory + """ + titles = [] + pages = self.document.getDrawPages() + for slideIndex in range(pages.getCount()): + titles.append( self.__get_text_from_page(slideIndex,TextType.Title).replace('\n',' ') + '\n') + notes = self.__get_text_from_page(slideIndex,TextType.Notes) + if len(notes) > 0: + notesfile = os.path.join(self.get_thumbnail_folder(), 'slideNotes%d.txt' % (num)) + with open(notesfile, mode='w') as fn: + fn.write(notes) + + titlesfile = os.path.join(self.get_thumbnail_folder(), 'titles.txt') + with open(titlesfile, mode='w') as fo: + fo.writelines(titles) + return + def get_titles_and_notes(self): """ - Returns a list of titles and a list of notes for the current presentation + let the super class handle it """ - # FIXME: somebody with impress expertise - return [],[] + return super().get_titles_and_notes() diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index 3e6a52361..67d8baef5 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -328,7 +328,8 @@ class PowerpointDocument(PresentationDocument): num = 0 for slide in self.presentation.Slides: try: - titles.append(slide.Shapes.Title.TextFrame.TextRange.Text + '\n') + text = slide.Shapes.Title.TextFrame.TextRange.Text + titles.append(text.replace('\n',' ').replace('\x0b',' ') + '\n') num += 1 notes = _get_text_from_shapes(slide.NotesPage.Shapes) if len(notes) > 0: @@ -345,9 +346,7 @@ class PowerpointDocument(PresentationDocument): def get_titles_and_notes(self): """ - Reads the titles from the titles file and - the notes files and returns the contents - in a two lists + let the super class handle it """ return super().get_titles_and_notes() diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 0ac42add5..4208a52dc 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -204,6 +204,10 @@ class PptviewDocument(PresentationDocument): text += '\n' text += node.text print( 'slide file: ' + zip_info.filename + ' ' + text ) + + # let's remove the nl from the titles and just add one at the end + if nodeType == 'ctrTitle': + text = text.replace('\n',' ').replace('\x0b', ' ') + '\n' listToAdd[index] = text print( titles ) @@ -318,8 +322,6 @@ class PptviewDocument(PresentationDocument): def get_titles_and_notes(self): """ - Reads the titles from the titles file and - the notes files and returns the contents - in a two lists + let the super class handle it """ return super().get_titles_and_notes() diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index f8db6aee7..2d08cc41c 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -459,3 +459,11 @@ class PresentationController(object): return self._plugin_manager plugin_manager = property(_get_plugin_manager) + +class TextType(object): + """ + Type Enumeration for Types of Text to request + """ + Title = 0 + SlideText = 1 + Notes = 2