From 9dbbe9d5bee41c812e4c46d4061b19c4af9c944b Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 3 Oct 2014 11:57:35 +0200 Subject: [PATCH] Fixed console popping up on windows when running mudraw.exe --- .../presentations/lib/pdfcontroller.py | 29 +++++++++++++++---- .../openlp_core_ui/test_slidecontroller.py | 6 ++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/presentations/lib/pdfcontroller.py b/openlp/plugins/presentations/lib/pdfcontroller.py index 7545aac1f..8fb00d917 100644 --- a/openlp/plugins/presentations/lib/pdfcontroller.py +++ b/openlp/plugins/presentations/lib/pdfcontroller.py @@ -34,10 +34,13 @@ import re from subprocess import check_output, CalledProcessError, STDOUT from openlp.core.utils import AppLocation -from openlp.core.common import Settings, is_win +from openlp.core.common import Settings, is_win, trace_error_handler from openlp.core.lib import ScreenList from .presentationcontroller import PresentationController, PresentationDocument +if is_win(): + from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW + log = logging.getLogger(__name__) @@ -74,11 +77,19 @@ class PdfController(PresentationController): runlog = '' log.debug('testing program_path: %s', program_path) try: - runlog = check_output([program_path, '--help'], stderr=STDOUT) + # Setup startupinfo options for check_output to avoid console popping up on windows + if is_win(): + startupinfo = STARTUPINFO() + startupinfo.dwFlags |= STARTF_USESHOWWINDOW + else: + startupinfo = None + runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo) except CalledProcessError as e: runlog = e.output except Exception: + trace_error_handler(log) runlog = '' + log.debug('check_output returned: %s' % runlog) # Analyse the output to see it the program is mudraw, ghostscript or neither for line in runlog.splitlines(): decoded_line = line.decode() @@ -182,6 +193,12 @@ class PdfDocument(PresentationDocument): self.hidden = False self.image_files = [] self.num_pages = -1 + # Setup startupinfo options for check_output to avoid console popping up on windows + if is_win(): + self.startupinfo = STARTUPINFO() + self.startupinfo.dwFlags |= STARTF_USESHOWWINDOW + else: + self.startupinfo = None def gs_get_resolution(self, size): """ @@ -199,7 +216,8 @@ class PdfDocument(PresentationDocument): runlog = [] try: runlog = check_output([self.controller.gsbin, '-dNOPAUSE', '-dNODISPLAY', '-dBATCH', - '-sFile=' + self.file_path, gs_resolution_script]) + '-sFile=' + self.file_path, gs_resolution_script], + startupinfo=self.startupinfo) except CalledProcessError as e: log.debug(' '.join(e.cmd)) log.debug(e.output) @@ -248,13 +266,14 @@ class PdfDocument(PresentationDocument): os.makedirs(self.get_temp_folder()) if self.controller.mudrawbin: runlog = check_output([self.controller.mudrawbin, '-w', str(size.right()), '-h', str(size.bottom()), - '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path]) + '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path], + startupinfo=self.startupinfo) elif self.controller.gsbin: resolution = self.gs_get_resolution(size) runlog = check_output([self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m', '-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4', '-sOutputFile=' + os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), - self.file_path]) + self.file_path], startupinfo=self.startupinfo) created_files = sorted(os.listdir(self.get_temp_folder())) for fn in created_files: if os.path.isfile(os.path.join(self.get_temp_folder(), fn)): diff --git a/tests/interfaces/openlp_core_ui/test_slidecontroller.py b/tests/interfaces/openlp_core_ui/test_slidecontroller.py index b797548a5..f83fb28ba 100644 --- a/tests/interfaces/openlp_core_ui/test_slidecontroller.py +++ b/tests/interfaces/openlp_core_ui/test_slidecontroller.py @@ -41,7 +41,7 @@ from tests.interfaces import MagicMock, patch from tests.helpers.testmixin import TestMixin -class TestSlideController(TestCase,TestMixin): +class TestSlideController(TestCase, TestMixin): def setUp(self): """ @@ -67,7 +67,6 @@ class TestSlideController(TestCase,TestMixin): """ self.destroy_settings() - def click_preview_widget_test(self): """ Test that when the preview_widget is clicked then on_slide_selected is called @@ -82,7 +81,6 @@ class TestSlideController(TestCase,TestMixin): QtTest.QTest.mouseClick(self.slide_controller.preview_widget, QtCore.Qt.LeftButton) QtTest.QTest.mouseClick(self.slide_controller.preview_widget.verticalHeader(), QtCore.Qt.LeftButton) - # THEN slide_selected should have been called twice self.assertEqual(self.slide_controller.on_slide_selected.call_count, 2, - 'on_slide_selected should have been called 2 times') \ No newline at end of file + 'on_slide_selected should have been called 2 times')