diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 6778a9a21..b46ff5077 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -330,8 +330,8 @@ class ServiceItem(object): The command of/for the slide. """ self.service_item_type = ServiceItemType.Command - self._raw_frames.append({'title': file_name, 'image': image, 'path': path, - 'displaytitle': displaytitle, 'notes': notes}) + self._raw_frames.append({'title': file_name, 'image': image, + 'path': path, 'displaytitle': displaytitle, 'notes': notes}) self._new_item() def get_service_repr(self, lite_save): @@ -376,8 +376,9 @@ class ServiceItem(object): service_data = [slide['title'] for slide in self._raw_frames] elif self.service_item_type == ServiceItemType.Command: for slide in self._raw_frames: - service_data.append({'title': slide['title'], 'image': slide['image'], 'path': slide['path'], - 'displaytitle': slide['displaytitle'], 'notes': slide['notes']}) + service_data.append({'title': slide['title'], + 'image': slide['image'], 'path': slide['path'], + 'displaytitle': slide['displaytitle'], 'notes': slide['notes']}) return {'header': service_header, 'data': service_data} def set_from_service(self, serviceitem, path=None): @@ -449,10 +450,12 @@ class ServiceItem(object): self.title = text_image['title'] if path: self.has_original_files = False - self.add_from_command(path, text_image['title'], text_image['image'], - text_image['displaytitle'], text_image['notes']) + self.add_from_command(path, text_image['title'], + text_image['image'], text_image['displaytitle'], + text_image['notes']) else: - self.add_from_command(text_image['path'], text_image['title'], text_image['image']) + self.add_from_command(text_image['path'], + text_image['title'], text_image['image']) self._new_item() def get_display_title(self): diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index ff36734d7..bad33d4c1 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -464,10 +464,11 @@ class ImpressDocument(PresentationDocument): page = page.getNotesPage() for index in range(page.getCount()): shape = page.getByIndex(index) - shapeType = shape.getShapetype() + shapeType = shape.getShapeType() if shape.supportsService("com.sun.star.drawing.Text"): # if they requested title, make sure it is the title - if text_type!=TextType.Title or shapeType == "com.sun.star.presentation.TitleTextShape": + if text_type!=TextType.Title or \ + shapeType == "com.sun.star.presentation.TitleTextShape": text += shape.getString() + '\n' return text @@ -479,17 +480,16 @@ class ImpressDocument(PresentationDocument): in the thumbnails directory """ titles = [] + notes = [] 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) + titles.append( + self.__get_text_from_page(slideIndex+1,TextType.Title). + replace('\n',' ') + '\n') + note = self.__get_text_from_page(slideIndex+1,TextType.Notes) + if len(note) == 0: + note = ' ' + notes.append(note) + self.save_titles_and_notes(titles,notes) return diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index 359c482b9..a3bfd3d85 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -325,23 +325,21 @@ class PowerpointDocument(PresentationDocument): in the thumbnails directory """ titles = [] + notes = [] num = 0 for slide in self.presentation.Slides: try: 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: - notesfile = os.path.join(self.get_thumbnail_folder(), 'slideNotes%d.txt' % (num)) - with open(notesfile, mode='w') as fn: - fn.write(notes) except Exception as e: log.exception(e) - titles.append('\n') - titlesfile = os.path.join(self.get_thumbnail_folder(), 'titles.txt') - with open(titlesfile, mode='w') as fo: - fo.writelines(titles) + text = '' + titles.append(text.replace('\n',' ').replace('\x0b',' ') + '\n') + num += 1 + note = _get_text_from_shapes(slide.NotesPage.Shapes) + if len(note) == 0: + note = ' ' + notes.append(note) + self.save_titles_and_notes(titles,notes) return def _get_text_from_shapes(shapes): @@ -353,7 +351,8 @@ def _get_text_from_shapes(shapes): """ text = '' for shape in shapes: - if shape.PlaceholderFormat.Type == 2 and shape.HasTextFrame and shape.TextFrame.HasText: + if shape.PlaceholderFormat.Type == 2 and \ + shape.HasTextFrame and shape.TextFrame.HasText: text += shape.TextFrame.TextRange.Text + '\n' return text diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 8829582ed..d6de47e69 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -30,6 +30,8 @@ import os import logging import zipfile +import re +from xml.etree import ElementTree if os.name == 'nt': from ctypes import cdll @@ -155,80 +157,65 @@ class PptviewDocument(PresentationDocument): and the notes to 'slideNotes[x].txt' in the thumbnails directory """ + filename = os.path.normpath(self.filepath) # let's make sure we have a valid zipped presentation if zipfile.is_zipfile(filename): - namespaces = {"p": "http://schemas.openxmlformats.org/presentationml/2006/main", - "a": "http://schemas.openxmlformats.org/drawingml/2006/main"} - + namespaces = {"p": + "http://schemas.openxmlformats.org/presentationml/2006/main", + "a": "http://schemas.openxmlformats.org/drawingml/2006/main"} # open the file with zipfile.ZipFile(filename) as zip_file: - # find the presentation.xml to get the slide count with zip_file.open('ppt/presentation.xml') as pres: tree = ElementTree.parse(pres) - nodes = tree.getroot().findall(".//p:sldIdLst/p:sldId", namespaces=namespaces) + nodes = tree.getroot().findall(".//p:sldIdLst/p:sldId", + namespaces=namespaces) print ("slide count: " + str(len(nodes))) - # initialize the lists titles = ['' for i in range(len(nodes))] notes = ['' for i in range(len(nodes))] - # loop thru the file list to find slides and notes for zip_info in zip_file.infolist(): nodeType = '' index = -1 listToAdd = None - # check if it is a slide match = re.search("slides/slide(.+)\.xml", zip_info.filename) if match: index = int(match.group(1))-1 nodeType = 'ctrTitle' listToAdd = titles - # or a note - match = re.search("notesSlides/notesSlide(.+)\.xml", zip_info.filename) + match = re.search("notesSlides/notesSlide(.+)\.xml", + zip_info.filename) if match: index = int(match.group(1))-1 nodeType = 'body' listToAdd = notes - # if it is one of our files, index shouldn't be -1 if index >= 0: with zip_file.open(zip_info) as zipped_file: tree = ElementTree.parse(zipped_file) - text = '' - nodes = tree.getroot().findall(".//p:ph[@type='" + nodeType + "']../../..//p:txBody//a:t", - namespaces=namespaces) + nodes = tree.getroot().findall(".//p:ph[@type='" + + nodeType + "']../../..//p:txBody//a:t", + namespaces=namespaces) # if we found any content if nodes and len(nodes)>0: for node in nodes: if len(text) > 0: text += '\n' text += node.text - print( 'slide file: ' + zip_info.filename + ' ' + text ) - - # let's remove the \n from the titles and just add one at the end + # Let's remove the \n from the titles and + # just add one at the end if nodeType == 'ctrTitle': - text = text.replace('\n',' ').replace('\x0b', ' ') + '\n' + text = text.replace('\n',' '). \ + replace('\x0b', ' ') + '\n' listToAdd[index] = text - - print( titles ) - print( notes ) - # now let's write the files - titlesfile = os.path.join(self.get_thumbnail_folder(), 'titles.txt') - with open(titlesfile, mode='w') as fo: - fo.writelines(titles) - for num in range(len(notes)): - notesfile = os.path.join(self.get_thumbnail_folder(), 'slideNotes%d.txt' % (num+1)) - with open(notesfile, mode='w') as fn: - fn.write(notes) + self.save_titles_and_notes(titles,notes) return - - def close_presentation(self): """ Close presentation and clean up objects. Triggered by new object being added to SlideController or OpenLP being diff --git a/openlp/plugins/presentations/lib/pptviewlib/ppttest.py b/openlp/plugins/presentations/lib/pptviewlib/ppttest.py index 1e20146d3..a8f093845 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/ppttest.py +++ b/openlp/plugins/presentations/lib/pptviewlib/ppttest.py @@ -177,51 +177,50 @@ class PPTViewer(QtGui.QWidget): int(self.widthEdit.text()), int(self.heightEdit.text())) filename = str(self.pptEdit.text().replace('/', '\\')) folder = str(self.folderEdit.text().replace('/', '\\')) - if zipfile.is_zipfile(filename): - namespaces = {"p": "http://schemas.openxmlformats.org/presentationml/2006/main", - "a": "http://schemas.openxmlformats.org/drawingml/2006/main"} + namespaces = {"p": + "http://schemas.openxmlformats.org/presentationml/2006/main", + "a": "http://schemas.openxmlformats.org/drawingml/2006/main"} with zipfile.ZipFile(filename) as zip_file: with zip_file.open('ppt/presentation.xml') as pres: tree = ElementTree.parse(pres) - nodes = tree.getroot().findall(".//p:sldIdLst/p:sldId", namespaces=namespaces) + nodes = tree.getroot().findall(".//p:sldIdLst/p:sldId", + namespaces=namespaces) print ("slide count: " + str(len(nodes))) titles = [None for i in range(len(nodes))] notes = [None for i in range(len(nodes))] - for zip_info in zip_file.infolist(): nodeType = '' index = -1 listToAdd = None - match = re.search("slides/slide(.+)\.xml", zip_info.filename) + match = re.search("slides/slide(.+)\.xml", + zip_info.filename) if match: index = int(match.group(1))-1 nodeType = 'ctrTitle' listToAdd = titles - match = re.search("notesSlides/notesSlide(.+)\.xml", zip_info.filename) + match = re.search("notesSlides/notesSlide(.+)\.xml", + zip_info.filename) if match: index = int(match.group(1))-1 nodeType = 'body' listToAdd = notes - if len(nodeType)>0: with zip_file.open(zip_info) as zipped_file: tree = ElementTree.parse(zipped_file) text = '' - - nodes = tree.getroot().findall(".//p:ph[@type='" + nodeType + "']../../..//p:txBody//a:t", - namespaces=namespaces) + nodes = tree.getroot().findall(".//p:ph[@type='" + \ + nodeType + "']../../..//p:txBody//a:t", + namespaces=namespaces) if nodes and len(nodes)>0: for node in nodes: if len(text) > 0: text += '\n' text += node.text - print( 'slide file: ' + zip_info.filename + ' ' + text ) + print('slide file: ' + zip_info.filename + ' ' + text) listToAdd[index] = text - - print( titles ) - print( notes ) - + print(titles) + print(notes) print(filename, folder) self.pptid = self.pptdll.OpenPPT(filename, None, rect, folder) print('id: ' + str(self.pptid)) diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index 2d08cc41c..4b15a72f1 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -301,7 +301,8 @@ class PresentationDocument(object): with open(titlesfile) as fi: titles = fi.readlines() for index in range(len(titles)): - notesfile = os.path.join(self.get_thumbnail_folder(), 'slideNotes%d.txt' % (index + 1)) + notesfile = os.path.join(self.get_thumbnail_folder(), + 'slideNotes%d.txt' % (index + 1)) note = '' try: if os.path.exists(notesfile): @@ -312,6 +313,19 @@ class PresentationDocument(object): notes.append(note) return titles, notes + def save_titles_and_notes(self, titles, notes): + """ + Performs the actual persisting of titles to the titles.txt + and notes to the slideNote%.txt + """ + titlesfile = os.path.join(self.get_thumbnail_folder(), 'titles.txt') + with open(titlesfile, mode='w') as fo: + fo.writelines(titles) + for num in range(len(notes)): + notesfile = os.path.join(self.get_thumbnail_folder(), + 'slideNotes%d.txt' % (num+1)) + with open(notesfile, mode='w') as fn: + fn.write(notes[num]) class PresentationController(object): diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index 2fc0647db..c816b0a43 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -351,7 +351,8 @@ class HttpRouter(object): html = None if self.send_appropriate_header(file_name) == '.html': variables = self.template_vars - html = Template(filename=path, input_encoding='utf-8', output_encoding='utf-8').render(**variables) + html = Template(filename=path, input_encoding='utf-8', + output_encoding='utf-8').render(**variables) file_handle = None try: if html: @@ -369,6 +370,11 @@ class HttpRouter(object): return content def send_appropriate_header(self, file_name): + """ + Examines the extension of the file and determines + what header to send back + Returns the extension found + """ ext = os.path.splitext(file_name)[1] if ext == '.html': self.send_header('Content-type', 'text/html') @@ -394,8 +400,9 @@ class HttpRouter(object): """ log.debug('serve thumbnail %s/thumbnails/%s' % (controller_name, file_name)) content = '' - full_path = os.path.join(AppLocation.get_section_data_path(controller_name), - 'thumbnails/' + file_name.replace('/','\\') ) + full_path = os.path.normpath(os.path.join( + AppLocation.get_section_data_path(controller_name), + 'thumbnails/' + file_name)) full_path = urllib.parse.unquote(full_path) if os.path.exists(full_path): @@ -498,9 +505,11 @@ class HttpRouter(object): if current_item.is_capable(ItemCapabilities.HasNotes): item['notes'] = str(frame['notes']) if current_item.is_capable(ItemCapabilities.HasThumbnails): - # if the file is under our app directory tree send the portion after the match - if frame['image'][0:len(AppLocation.get_data_path())] == AppLocation.get_data_path(): - item['img'] = frame['image'][len(AppLocation.get_data_path()):] + # If the file is under our app directory tree send the + # portion after the match + dataPath = AppLocation.get_data_path() + if frame['image'][0:len(dataPath)] == dataPath: + item['img'] = frame['image'][len(dataPath):] #'data:image/png;base64,' + str(image_to_byte(resize_image(frame['image'],80,80))) item['text'] = str(frame['title']) item['html'] = str(frame['title'])