From b7a32ebbb2875064473827fe7aa1d0600cd8819f Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 30 Apr 2016 11:05:10 +0200 Subject: [PATCH] Added support for using the new mutool in mudraw mode --- openlp/plugins/media/mediaplugin.py | 1 - .../presentations/lib/pdfcontroller.py | 42 +++++++++++++++---- .../presentations/lib/presentationtab.py | 2 +- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 1d5529084..e258b5809 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -160,7 +160,6 @@ def process_check_binary(program_path): """ program_type = None runlog = check_binary_exists(program_path) - print(runlog, type(runlog)) # Analyse the output to see it the program is mediainfo for line in runlog.splitlines(): decoded_line = line.decode() diff --git a/openlp/plugins/presentations/lib/pdfcontroller.py b/openlp/plugins/presentations/lib/pdfcontroller.py index 48150a9f2..9bfc25eb1 100644 --- a/openlp/plugins/presentations/lib/pdfcontroller.py +++ b/openlp/plugins/presentations/lib/pdfcontroller.py @@ -77,6 +77,12 @@ class PdfController(PresentationController): if found_mudraw: program_type = 'mudraw' break + found_mutool = re.search('usage: mutool.*', decoded_line, re.IGNORECASE) + if found_mutool: + # Test that mutool contains mudraw + if re.search('draw\s+--\s+convert document.*', runlog.decode(), re.IGNORECASE | re.MULTILINE): + program_type = 'mutool' + break found_gs = re.search('GPL Ghostscript.*', decoded_line, re.IGNORECASE) if found_gs: program_type = 'gs' @@ -101,6 +107,7 @@ class PdfController(PresentationController): """ log.debug('check_installed Pdf') self.mudrawbin = '' + self.mutoolbin = '' self.gsbin = '' self.also_supports = [] # Use the user defined program if given @@ -111,27 +118,36 @@ class PdfController(PresentationController): self.gsbin = pdf_program elif program_type == 'mudraw': self.mudrawbin = pdf_program + elif program_type == 'mutool': + self.mutoolbin = pdf_program else: # Fallback to autodetection application_path = AppLocation.get_directory(AppLocation.AppDir) if is_win(): - # for windows we only accept mudraw.exe in the base folder + # for windows we only accept mudraw.exe or mutool.exe in the base folder application_path = AppLocation.get_directory(AppLocation.AppDir) if os.path.isfile(os.path.join(application_path, 'mudraw.exe')): self.mudrawbin = os.path.join(application_path, 'mudraw.exe') + elif os.path.isfile(os.path.join(application_path, 'mutool.exe')): + self.mutoolbin = os.path.join(application_path, 'mutool.exe') else: DEVNULL = open(os.devnull, 'wb') - # First try to find mupdf + # First try to find mudraw self.mudrawbin = which('mudraw') - # if mupdf isn't installed, fallback to ghostscript + # if mudraw isn't installed, try mutool if not self.mudrawbin: - self.gsbin = which('gs') - # Last option: check if mudraw is placed in OpenLP base folder - if not self.mudrawbin and not self.gsbin: + self.mutoolbin = which('mutool') + # Check we got a working mutool + if not self.mutoolbin or self.process_check_binary(self.mutoolbin) != 'mutool': + self.gsbin = which('gs') + # Last option: check if mudraw or mutool is placed in OpenLP base folder + if not self.mudrawbin and not self.mutoolbin and not self.gsbin: application_path = AppLocation.get_directory(AppLocation.AppDir) - if os.path.isfile(os.path.join(application_path, 'mudraw')): - self.mudrawbin = os.path.join(application_path, 'mudraw') - if self.mudrawbin: + if os.path.isfile(os.path.join(application_path, 'mudraw.exe')): + self.mudrawbin = os.path.join(application_path, 'mudraw.exe') + elif os.path.isfile(os.path.join(application_path, 'mutool.exe')): + self.mutoolbin = os.path.join(application_path, 'mutool.exe') + if self.mudrawbin or self.mutoolbin: self.also_supports = ['xps', 'oxps'] return True elif self.gsbin: @@ -238,10 +254,18 @@ class PdfDocument(PresentationDocument): if not os.path.isdir(self.get_temp_folder()): os.makedirs(self.get_temp_folder()) if self.controller.mudrawbin: + log.debug('loading presentation using mudraw') runlog = check_output([self.controller.mudrawbin, '-w', str(size.width()), '-h', str(size.height()), '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path], startupinfo=self.startupinfo) + elif self.controller.mutoolbin: + log.debug('loading presentation using mutool') + runlog = check_output([self.controller.mutoolbin, 'draw', '-w', str(size.width()), '-h', + str(size.height()), + '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path], + startupinfo=self.startupinfo) elif self.controller.gsbin: + log.debug('loading presentation using gs') resolution = self.gs_get_resolution(size) runlog = check_output([self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m', '-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4', diff --git a/openlp/plugins/presentations/lib/presentationtab.py b/openlp/plugins/presentations/lib/presentationtab.py index cbe881853..8076b33fe 100644 --- a/openlp/plugins/presentations/lib/presentationtab.py +++ b/openlp/plugins/presentations/lib/presentationtab.py @@ -235,7 +235,7 @@ class PresentationTab(SettingsTab): self, translate('PresentationPlugin.PresentationTab', 'Select mudraw or ghostscript binary.'), self.pdf_program_path.text()) if filename: - program_type = PdfController.check_binary(filename) + program_type = PdfController.process_check_binary(filename) if not program_type: critical_error_message_box(UiStrings().Error, translate('PresentationPlugin.PresentationTab',