forked from openlp/openlp
- Added support for titles (and improved notes) for impresscontroller.py
- Removed \x0b and \n from the titles
This commit is contained in:
parent
348ebee661
commit
3bbaff362d
@ -60,7 +60,7 @@ from PyQt4 import QtCore
|
|||||||
|
|
||||||
from openlp.core.lib import ScreenList
|
from openlp.core.lib import ScreenList
|
||||||
from openlp.core.utils import delete_file, get_uno_command, get_uno_instance
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
@ -252,6 +252,7 @@ class ImpressDocument(PresentationDocument):
|
|||||||
self.presentation.Display = ScreenList().current['number'] + 1
|
self.presentation.Display = ScreenList().current['number'] + 1
|
||||||
self.control = None
|
self.control = None
|
||||||
self.create_thumbnails()
|
self.create_thumbnails()
|
||||||
|
self.create_titles_and_notes()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def create_thumbnails(self):
|
def create_thumbnails(self):
|
||||||
@ -447,9 +448,9 @@ class ImpressDocument(PresentationDocument):
|
|||||||
``slide_no``
|
``slide_no``
|
||||||
The slide the notes are required for, starting at 1
|
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.
|
Return any text extracted from the presentation page.
|
||||||
|
|
||||||
@ -459,17 +460,40 @@ class ImpressDocument(PresentationDocument):
|
|||||||
text = ''
|
text = ''
|
||||||
pages = self.document.getDrawPages()
|
pages = self.document.getDrawPages()
|
||||||
page = pages.getByIndex(slide_no - 1)
|
page = pages.getByIndex(slide_no - 1)
|
||||||
if notes:
|
if text_type==TextType.Notes:
|
||||||
page = page.getNotesPage()
|
page = page.getNotesPage()
|
||||||
for index in range(page.getCount()):
|
for index in range(page.getCount()):
|
||||||
shape = page.getByIndex(index)
|
shape = page.getByIndex(index)
|
||||||
|
shapeType = shape.getShapetype()
|
||||||
if shape.supportsService("com.sun.star.drawing.Text"):
|
if shape.supportsService("com.sun.star.drawing.Text"):
|
||||||
|
if text_type!=TextType.Title or shapeType == "com.sun.star.presentation.TitleTextShape":
|
||||||
text += shape.getString() + '\n'
|
text += shape.getString() + '\n'
|
||||||
return text
|
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):
|
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 super().get_titles_and_notes()
|
||||||
return [],[]
|
|
||||||
|
@ -328,7 +328,8 @@ class PowerpointDocument(PresentationDocument):
|
|||||||
num = 0
|
num = 0
|
||||||
for slide in self.presentation.Slides:
|
for slide in self.presentation.Slides:
|
||||||
try:
|
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
|
num += 1
|
||||||
notes = _get_text_from_shapes(slide.NotesPage.Shapes)
|
notes = _get_text_from_shapes(slide.NotesPage.Shapes)
|
||||||
if len(notes) > 0:
|
if len(notes) > 0:
|
||||||
@ -345,9 +346,7 @@ class PowerpointDocument(PresentationDocument):
|
|||||||
|
|
||||||
def get_titles_and_notes(self):
|
def get_titles_and_notes(self):
|
||||||
"""
|
"""
|
||||||
Reads the titles from the titles file and
|
let the super class handle it
|
||||||
the notes files and returns the contents
|
|
||||||
in a two lists
|
|
||||||
"""
|
"""
|
||||||
return super().get_titles_and_notes()
|
return super().get_titles_and_notes()
|
||||||
|
|
||||||
|
@ -204,6 +204,10 @@ class PptviewDocument(PresentationDocument):
|
|||||||
text += '\n'
|
text += '\n'
|
||||||
text += node.text
|
text += node.text
|
||||||
print( 'slide file: ' + zip_info.filename + ' ' + 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
|
listToAdd[index] = text
|
||||||
|
|
||||||
print( titles )
|
print( titles )
|
||||||
@ -318,8 +322,6 @@ class PptviewDocument(PresentationDocument):
|
|||||||
|
|
||||||
def get_titles_and_notes(self):
|
def get_titles_and_notes(self):
|
||||||
"""
|
"""
|
||||||
Reads the titles from the titles file and
|
let the super class handle it
|
||||||
the notes files and returns the contents
|
|
||||||
in a two lists
|
|
||||||
"""
|
"""
|
||||||
return super().get_titles_and_notes()
|
return super().get_titles_and_notes()
|
||||||
|
@ -459,3 +459,11 @@ class PresentationController(object):
|
|||||||
return self._plugin_manager
|
return self._plugin_manager
|
||||||
|
|
||||||
plugin_manager = property(_get_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
|
||||||
|
Loading…
Reference in New Issue
Block a user