Made branch work with python3.

This commit is contained in:
Tomas Groth 2013-10-04 21:06:31 +02:00
parent bc3f2d3422
commit a45dfd2d1b
4 changed files with 100 additions and 100 deletions

View File

@ -250,7 +250,7 @@ class PresentationMediaItem(MediaManagerItem):
if not self.display_type_combo_box.currentText(): if not self.display_type_combo_box.currentText():
return False return False
if context == ServiceItemContext.Live and (file_type == u'pdf' or file_type == u'xps'): if context == ServiceItemContext.Live and (file_type == 'pdf' or file_type == 'xps'):
service_item.add_capability(ItemCapabilities.CanMaintain) service_item.add_capability(ItemCapabilities.CanMaintain)
service_item.add_capability(ItemCapabilities.CanPreview) service_item.add_capability(ItemCapabilities.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.CanLoop)
@ -270,15 +270,15 @@ class PresentationMediaItem(MediaManagerItem):
controller = self.controllers[processor] controller = self.controllers[processor]
service_item.processor = None service_item.processor = None
doc = controller.add_document(filename) doc = controller.add_document(filename)
if doc.get_thumbnail_path(1, True) is None or not os.path.isfile(os.path.join(doc.get_temp_folder(), u'mainslide001.png')): if doc.get_thumbnail_path(1, True) is None or not os.path.isfile(os.path.join(doc.get_temp_folder(), 'mainslide001.png')):
doc.load_presentation() doc.load_presentation()
i = 1 i = 1
imagefile = u'mainslide%03d.png' % i imagefile = 'mainslide%03d.png' % i
img = os.path.join(doc.get_temp_folder(), imagefile) img = os.path.join(doc.get_temp_folder(), imagefile)
while os.path.isfile(img): while os.path.isfile(img):
service_item.add_from_image(img, name) service_item.add_from_image(img, name)
i += 1 i += 1
imagefile = u'mainslide%03d.png' % i imagefile = 'mainslide%03d.png' % i
img = os.path.join(doc.get_temp_folder(), imagefile) img = os.path.join(doc.get_temp_folder(), imagefile)
doc.close_presentation() doc.close_presentation()
return True return True

View File

@ -32,110 +32,115 @@ import logging
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
import re import re
from subprocess import check_output, CalledProcessError, STDOUT from subprocess import check_output, CalledProcessError, STDOUT
from PyQt4 import QtCore, QtGui #from PyQt4 import QtCore, QtGui
from openlp.core.utils import AppLocation from openlp.core.utils import AppLocation
from openlp.core.lib import ScreenList, Settings from openlp.core.lib import ScreenList, Settings
from presentationcontroller import PresentationController, PresentationDocument from .presentationcontroller import PresentationController, PresentationDocument
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def check_binary(program_path):
"""
Function that checks whether a binary is either ghostscript or mudraw or neither.
"""
program_type = None
runlog = u''
try:
runlog = check_output([program_path, u'--help'], stderr=STDOUT)
except CalledProcessError as e:
runlog = e.output
except Exception:
runlog = u''
# Analyse the output to see it the program is mudraw, ghostscript or neither
for line in runlog.splitlines():
found_mudraw = re.search(u'usage: mudraw.*', line)
if found_mudraw:
program_type = u'mudraw'
break
found_gs = re.search(u'GPL Ghostscript.*', line)
if found_gs:
program_type = u'gs'
break
return program_type
class PdfController(PresentationController): class PdfController(PresentationController):
""" """
Class to control PDF presentations Class to control PDF presentations
""" """
log.info(u'PdfController loaded') log.info('PdfController loaded')
def __init__(self, plugin): def __init__(self, plugin):
""" """
Initialise the class Initialise the class
""" """
log.debug(u'Initialising') log.debug('Initialising')
self.process = None self.process = None
PresentationController.__init__(self, plugin, u'Pdf', PdfDocument) PresentationController.__init__(self, plugin, 'Pdf', PdfDocument)
self.supports = [u'pdf'] self.supports = ['pdf']
self.mudrawbin = u'' self.mudrawbin = ''
self.gsbin = u'' self.gsbin = ''
if self.check_installed() and self.mudrawbin != u'': if self.check_installed() and self.mudrawbin != '':
self.also_supports = [u'xps'] self.also_supports = ['xps']
def check_binary(program_path):
"""
Function that checks whether a binary is either ghostscript or mudraw or neither.
"""
program_type = None
runlog = ''
try:
runlog = check_output([program_path, '--help'], stderr=STDOUT)
except CalledProcessError as e:
runlog = e.output
except Exception:
runlog = ''
# Analyse the output to see it the program is mudraw, ghostscript or neither
for line in runlog.splitlines():
found_mudraw = re.search('usage: mudraw.*', line)
if found_mudraw:
program_type = 'mudraw'
break
found_gs = re.search('GPL Ghostscript.*', line)
if found_gs:
program_type = 'gs'
break
log.info('in check_binary, found: ' + program_type)
return program_type
def check_available(self): def check_available(self):
""" """
PdfController is able to run on this machine. PdfController is able to run on this machine.
""" """
log.debug(u'check_available Pdf') log.debug('check_available Pdf')
return self.check_installed() return self.check_installed()
def check_installed(self): def check_installed(self):
""" """
Check the viewer is installed. Check the viewer is installed.
""" """
log.debug(u'check_installed Pdf') log.debug('check_installed Pdf')
# Use the user defined program if given # Use the user defined program if given
if (Settings().value(u'presentations/enable_given_pdf_program')): if (Settings().value('presentations/enable_given_pdf_program')):
given_pdf_program = Settings().value(u'presentations/given_pdf_program') given_pdf_program = Settings().value('presentations/given_pdf_program')
type = check_binary(given_pdf_program) type = self.check_binary(given_pdf_program)
if type == u'gs': if type == 'gs':
self.gsbin = given_pdf_program self.gsbin = given_pdf_program
return True return True
elif type == u'mudraw': elif type == 'mudraw':
self.mudrawbin = given_pdf_program self.mudrawbin = given_pdf_program
return True return True
# Fallback to autodetection # Fallback to autodetection
application_path = AppLocation.get_directory(AppLocation.AppDir) application_path = AppLocation.get_directory(AppLocation.AppDir)
if os.name != u'nt': if os.name != 'nt':
# First try to find mupdf # First try to find mupdf
try: try:
self.mudrawbin = check_output([u'which', u'mudraw']).rstrip('\n') self.mudrawbin = check_output(['which', 'mudraw']).decode(encoding='UTF-8').rstrip('\n')
except CalledProcessError: except CalledProcessError:
self.mudrawbin = u'' self.mudrawbin = ''
# if mupdf isn't installed, fallback to ghostscript # if mupdf isn't installed, fallback to ghostscript
if self.mudrawbin == u'': if self.mudrawbin == '':
try: try:
self.gsbin = check_output([u'which', u'gs']).rstrip('\n') self.gsbin = check_output(['which', 'gs']).rstrip('\n')
except CalledProcessError: except CalledProcessError:
self.gsbin = u'' self.gsbin = ''
# Last option: check if mudraw is placed in OpenLP base folder # Last option: check if mudraw is placed in OpenLP base folder
if self.mudrawbin == u'' and self.gsbin == u'': if self.mudrawbin == '' and self.gsbin == '':
application_path = AppLocation.get_directory(AppLocation.AppDir) application_path = AppLocation.get_directory(AppLocation.AppDir)
if os.path.isfile(application_path + u'/../mudraw'): if os.path.isfile(application_path + '/../mudraw'):
self.mudrawbin = application_path + u'/../mudraw' self.mudrawbin = application_path + '/../mudraw'
else: else:
# for windows we only accept mudraw.exe in the base folder # for windows we only accept mudraw.exe in the base folder
application_path = AppLocation.get_directory(AppLocation.AppDir) application_path = AppLocation.get_directory(AppLocation.AppDir)
if os.path.isfile(application_path + u'/../mudraw.exe'): if os.path.isfile(application_path + '/../mudraw.exe'):
self.mudrawbin = application_path + u'/../mudraw.exe' self.mudrawbin = application_path + '/../mudraw.exe'
if self.mudrawbin == u'' and self.gsbin == u'': if self.mudrawbin == '' and self.gsbin == '':
return False return False
else: else:
return True return True
@ -144,7 +149,7 @@ class PdfController(PresentationController):
""" """
Called at system exit to clean up any running presentations Called at system exit to clean up any running presentations
""" """
log.debug(u'Kill pdfviewer') log.debug('Kill pdfviewer')
while self.docs: while self.docs:
self.docs[0].close_presentation() self.docs[0].close_presentation()
@ -157,7 +162,7 @@ class PdfDocument(PresentationDocument):
""" """
Constructor, store information about the file and initialise. Constructor, store information about the file and initialise.
""" """
log.debug(u'Init Presentation Pdf') log.debug('Init Presentation Pdf')
PresentationDocument.__init__(self, controller, presentation) PresentationDocument.__init__(self, controller, presentation)
self.presentation = None self.presentation = None
self.blanked = False self.blanked = False
@ -172,7 +177,7 @@ class PdfDocument(PresentationDocument):
to get the ratio bewteen the screen size and the PDF to scale to get the ratio bewteen the screen size and the PDF to scale
""" """
# Use a postscript script to get size of the pdf. It is assumed that all pages have same size # Use a postscript script to get size of the pdf. It is assumed that all pages have same size
postscript = u'%!PS \n\ postscript = '%!PS \n\
() = \n\ () = \n\
File dup (r) file runpdfbegin \n\ File dup (r) file runpdfbegin \n\
1 pdfgetpage dup \n\ 1 pdfgetpage dup \n\
@ -191,9 +196,9 @@ quit \n\
# Run the script on the pdf to get the size # Run the script on the pdf to get the size
runlog = [] runlog = []
try: try:
runlog = check_output([self.controller.gsbin, u'-dNOPAUSE', u'-dNODISPLAY', u'-dBATCH', u'-sFile=' + self.filepath, tmpfile.name]) runlog = check_output([self.controller.gsbin, '-dNOPAUSE', '-dNODISPLAY', '-dBATCH', '-sFile=' + self.filepath, tmpfile.name])
except CalledProcessError as e: except CalledProcessError as e:
log.debug(u' '.join(e.cmd)) log.debug(' '.join(e.cmd))
log.debug(e.output) log.debug(e.output)
os.unlink(tmpfile.name) os.unlink(tmpfile.name)
@ -202,8 +207,8 @@ quit \n\
height = 0 height = 0
for line in runlog.splitlines(): for line in runlog.splitlines():
try: try:
width = re.search(u'.*Size: x: (\d+\.?\d*), y: \d+.*', line).group(1) width = re.search('.*Size: x: (\d+\.?\d*), y: \d+.*', line).group(1)
height = re.search(u'.*Size: x: \d+\.?\d*, y: (\d+\.?\d*).*', line).group(1) height = re.search('.*Size: x: \d+\.?\d*, y: (\d+\.?\d*).*', line).group(1)
break; break;
except AttributeError: except AttributeError:
pass pass
@ -225,10 +230,10 @@ quit \n\
""" """
Called when a presentation is added to the SlideController. It generates images from the PDF. Called when a presentation is added to the SlideController. It generates images from the PDF.
""" """
log.debug(u'load_presentation pdf') log.debug('load_presentation pdf')
# Check if the images has already been created, and if yes load them # Check if the images has already been created, and if yes load them
if os.path.isfile(os.path.join(self.get_temp_folder(), u'mainslide001.png')): if os.path.isfile(os.path.join(self.get_temp_folder(), 'mainslide001.png')):
created_files = sorted(os.listdir(self.get_temp_folder())) created_files = sorted(os.listdir(self.get_temp_folder()))
for fn in created_files: for fn in created_files:
if os.path.isfile(os.path.join(self.get_temp_folder(), fn)): if os.path.isfile(os.path.join(self.get_temp_folder(), fn)):
@ -236,17 +241,17 @@ quit \n\
self.num_pages = len(self.image_files) self.num_pages = len(self.image_files)
return True return True
size = ScreenList().current[u'size'] size = ScreenList().current['size']
# Generate images from PDF that will fit the frame. # Generate images from PDF that will fit the frame.
runlog = u'' runlog = ''
try: try:
if not os.path.isdir(self.get_temp_folder()): if not os.path.isdir(self.get_temp_folder()):
os.makedirs(self.get_temp_folder()) os.makedirs(self.get_temp_folder())
if self.controller.mudrawbin != u'': if self.controller.mudrawbin != '':
runlog = check_output([self.controller.mudrawbin, u'-w', str(size.right()), u'-h', str(size.bottom()), u'-o', os.path.join(self.get_temp_folder(), u'mainslide%03d.png'), self.filepath]) 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.filepath])
elif self.controller.gsbin != u'': elif self.controller.gsbin != '':
resolution = self.gs_get_resolution(size) resolution = self.gs_get_resolution(size)
runlog = check_output([self.controller.gsbin, u'-dSAFER', u'-dNOPAUSE', u'-dBATCH', u'-sDEVICE=png16m', u'-r' + str(resolution), u'-dTextAlphaBits=4', u'-dGraphicsAlphaBits=4', u'-sOutputFile=' + os.path.join(self.get_temp_folder(), u'mainslide%03d.png'), self.filepath]) 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.filepath])
created_files = sorted(os.listdir(self.get_temp_folder())) created_files = sorted(os.listdir(self.get_temp_folder()))
for fn in created_files: for fn in created_files:
if os.path.isfile(os.path.join(self.get_temp_folder(), fn)): if os.path.isfile(os.path.join(self.get_temp_folder(), fn)):
@ -265,10 +270,10 @@ quit \n\
""" """
Generates thumbnails Generates thumbnails
""" """
log.debug(u'create_thumbnails pdf') log.debug('create_thumbnails pdf')
if self.check_thumbnails(): if self.check_thumbnails():
return return
log.debug(u'create_thumbnails proceeding') log.debug('create_thumbnails proceeding')
# use builtin function to create thumbnails from generated images # use builtin function to create thumbnails from generated images
index = 1 index = 1
@ -281,14 +286,14 @@ quit \n\
Close presentation and clean up objects. Triggered by new object being added to SlideController or OpenLP being Close presentation and clean up objects. Triggered by new object being added to SlideController or OpenLP being
shut down. shut down.
""" """
log.debug(u'close_presentation pdf') log.debug('close_presentation pdf')
self.controller.remove_doc(self) self.controller.remove_doc(self)
def is_loaded(self): def is_loaded(self):
""" """
Returns true if a presentation is loaded. Returns true if a presentation is loaded.
""" """
log.debug(u'is_loaded pdf') log.debug('is_loaded pdf')
if self.num_pages < 0: if self.num_pages < 0:
return False return False
return True return True
@ -297,6 +302,6 @@ quit \n\
""" """
Returns true if a presentation is currently active. Returns true if a presentation is currently active.
""" """
log.debug(u'is_active pdf') log.debug('is_active pdf')
return self.is_loaded() and not self.hidden return self.is_loaded() and not self.hidden

View File

@ -31,7 +31,9 @@ from PyQt4 import QtGui
from openlp.core.lib import Settings, SettingsTab, UiStrings, translate, build_icon from openlp.core.lib import Settings, SettingsTab, UiStrings, translate, build_icon
from openlp.core.lib.ui import critical_error_message_box from openlp.core.lib.ui import critical_error_message_box
from pdfcontroller import check_binary from .pdfcontroller import PdfController
#from openlp.plugins.presentations.lib.pdfcontroller import PdfController
#from pdfcontroller import check_binary
class PresentationTab(SettingsTab): class PresentationTab(SettingsTab):
""" """
@ -75,22 +77,22 @@ class PresentationTab(SettingsTab):
# Pdf options # Pdf options
self.pdf_group_box = QtGui.QGroupBox(self.left_column) self.pdf_group_box = QtGui.QGroupBox(self.left_column)
self.pdf_group_box.setObjectName(u'pdf_group_box') self.pdf_group_box.setObjectName('pdf_group_box')
self.pdf_layout = QtGui.QFormLayout(self.pdf_group_box) self.pdf_layout = QtGui.QFormLayout(self.pdf_group_box)
self.pdf_layout.setObjectName(u'pdf_layout') self.pdf_layout.setObjectName('pdf_layout')
self.pdf_program_check_box = QtGui.QCheckBox(self.pdf_group_box) self.pdf_program_check_box = QtGui.QCheckBox(self.pdf_group_box)
self.pdf_program_check_box.setObjectName(u'pdf_program_check_box') self.pdf_program_check_box.setObjectName('pdf_program_check_box')
self.pdf_layout.addWidget(self.pdf_program_check_box) self.pdf_layout.addWidget(self.pdf_program_check_box)
self.pdf_program_path_layout = QtGui.QHBoxLayout() self.pdf_program_path_layout = QtGui.QHBoxLayout()
self.pdf_program_path_layout.setObjectName(u'pdf_program_path_layout') self.pdf_program_path_layout.setObjectName('pdf_program_path_layout')
self.pdf_program_path = QtGui.QLineEdit(self.pdf_group_box) self.pdf_program_path = QtGui.QLineEdit(self.pdf_group_box)
self.pdf_program_path.setObjectName(u'pdf_program_path') self.pdf_program_path.setObjectName('pdf_program_path')
self.pdf_program_path.setReadOnly(True) self.pdf_program_path.setReadOnly(True)
self.pdf_program_path.setPalette(self.get_grey_text_palette(True)) self.pdf_program_path.setPalette(self.get_grey_text_palette(True))
self.pdf_program_path_layout.addWidget(self.pdf_program_path) self.pdf_program_path_layout.addWidget(self.pdf_program_path)
self.pdf_program_browse_button = QtGui.QToolButton(self.pdf_group_box) self.pdf_program_browse_button = QtGui.QToolButton(self.pdf_group_box)
self.pdf_program_browse_button.setObjectName(u'pdf_program_browse_button') self.pdf_program_browse_button.setObjectName('pdf_program_browse_button')
self.pdf_program_browse_button.setIcon(build_icon(u':/general/general_open.png')) self.pdf_program_browse_button.setIcon(build_icon(':/general/general_open.png'))
self.pdf_program_browse_button.setEnabled(False) self.pdf_program_browse_button.setEnabled(False)
self.pdf_program_path_layout.addWidget(self.pdf_program_browse_button) self.pdf_program_path_layout.addWidget(self.pdf_program_browse_button)
self.pdf_layout.addRow(self.pdf_program_path_layout) self.pdf_layout.addRow(self.pdf_program_path_layout)
@ -173,26 +175,19 @@ class PresentationTab(SettingsTab):
pdf_program = self.pdf_program_path.text() pdf_program = self.pdf_program_path.text()
enable_given_pdf_program = self.pdf_program_check_box.checkState() enable_given_pdf_program = self.pdf_program_check_box.checkState()
# If the given program is blank disable using the program # If the given program is blank disable using the program
if pdf_program == u'': if pdf_program == '':
enable_given_pdf_program = 0 enable_given_pdf_program = 0
if pdf_program != Settings().value(self.settings_section + u'/given_pdf_program'): if pdf_program != Settings().value(self.settings_section + '/given_pdf_program'):
Settings().setValue(self.settings_section + u'/given_pdf_program', pdf_program) Settings().setValue(self.settings_section + '/given_pdf_program', pdf_program)
changed = True changed = True
if enable_given_pdf_program != Settings().value(self.settings_section + u'/enable_given_pdf_program'): if enable_given_pdf_program != Settings().value(self.settings_section + '/enable_given_pdf_program'):
Settings().setValue(self.settings_section + u'/enable_given_pdf_program', enable_given_pdf_program) Settings().setValue(self.settings_section + '/enable_given_pdf_program', enable_given_pdf_program)
changed = True changed = True
if changed: if changed:
<<<<<<< TREE
self.settings_form.register_post_process(u'mediaitem_suffix_reset')
self.settings_form.register_post_process(u'mediaitem_presentation_rebuild')
self.settings_form.register_post_process(u'mediaitem_suffixes')
=======
self.settings_form.register_post_process('mediaitem_suffix_reset') self.settings_form.register_post_process('mediaitem_suffix_reset')
self.settings_form.register_post_process('mediaitem_presentation_rebuild') self.settings_form.register_post_process('mediaitem_presentation_rebuild')
self.settings_form.register_post_process('mediaitem_suffixes') self.settings_form.register_post_process('mediaitem_suffixes')
>>>>>>> MERGE-SOURCE
def tab_visible(self): def tab_visible(self):
""" """
@ -210,8 +205,8 @@ class PresentationTab(SettingsTab):
After selecting/typing in a program it is validated that it is a actually ghostscript or mudraw After selecting/typing in a program it is validated that it is a actually ghostscript or mudraw
""" """
type = None type = None
if self.pdf_program_path.text() != u'': if self.pdf_program_path.text() != '':
type = check_binary(self.pdf_program_path.text()) type = PdfController.check_binary(self.pdf_program_path.text())
if not type: if not type:
critical_error_message_box(UiStrings().Error, critical_error_message_box(UiStrings().Error,
translate('PresentationPlugin.PresentationTab', 'The program is not ghostscript or mudraw which is required.')) translate('PresentationPlugin.PresentationTab', 'The program is not ghostscript or mudraw which is required.'))

View File

@ -46,7 +46,7 @@ log = logging.getLogger(__name__)
__default_settings__ = { __default_settings__ = {
'presentations/override app': QtCore.Qt.Unchecked, 'presentations/override app': QtCore.Qt.Unchecked,
'presentations/enable_given_pdf_program': QtCore.Qt.Unchecked, 'presentations/enable_given_pdf_program': QtCore.Qt.Unchecked,
'presentations/given_pdf_program': u'', 'presentations/given_pdf_program': '',
'presentations/Impress': QtCore.Qt.Checked, 'presentations/Impress': QtCore.Qt.Checked,
'presentations/Powerpoint': QtCore.Qt.Checked, 'presentations/Powerpoint': QtCore.Qt.Checked,
'presentations/Powerpoint Viewer': QtCore.Qt.Checked, 'presentations/Powerpoint Viewer': QtCore.Qt.Checked,