Convert strings in plugins part 2

- Convert strings in custom
- Convert strings in images
- Convert strings in media
- Convert strings in presentations
- Update projector-pjlink test

--------------------------------
lp:~alisonken1/openlp/strings-plugins2 (revision 2667)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1571/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1482/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1420/
[SUCCESS] https://ci.openlp.io/jo...

bzr-revno: 2668
This commit is contained in:
Ken Roberts 2016-05-24 17:18:25 +01:00 committed by Tim Bentley
commit 473772c505
16 changed files with 141 additions and 91 deletions

View File

@ -128,7 +128,7 @@ class CustomXMLParser(object):
try:
self.custom_xml = objectify.fromstring(xml)
except etree.XMLSyntaxError:
log.exception('Invalid xml %s', xml)
log.exception('Invalid xml {xml}'.format(xml=xml))
def get_verses(self):
"""

View File

@ -94,7 +94,7 @@ class CustomMediaItem(MediaManagerItem):
"""
"""
self.search_text_label.setText('%s:' % UiStrings().Search)
self.search_text_label.setText('{text}:'.format(text=UiStrings().Search))
self.search_text_button.setText(UiStrings().Search)
def initialise(self):
@ -105,7 +105,8 @@ class CustomMediaItem(MediaManagerItem):
[(CustomSearch.Titles, ':/songs/song_search_title.png', translate('SongsPlugin.MediaItem', 'Titles'),
translate('SongsPlugin.MediaItem', 'Search Titles...')),
(CustomSearch.Themes, ':/slides/slide_theme.png', UiStrings().Themes, UiStrings().SearchThemes)])
self.search_text_edit.set_current_search_type(Settings().value('%s/last search type' % self.settings_section))
text = '{section}/last search type'.format(section=self.settings_section)
self.search_text_edit.set_current_search_type(Settings().value(text))
self.load_list(self.plugin.db_manager.get_all_objects(CustomSlide, order_by_ref=CustomSlide.title))
self.config_update()
@ -190,7 +191,8 @@ class CustomMediaItem(MediaManagerItem):
if QtWidgets.QMessageBox.question(
self, UiStrings().ConfirmDelete,
translate('CustomPlugin.MediaItem',
'Are you sure you want to delete the "%d" selected custom slide(s)?') % len(items),
'Are you sure you want to delete the "{items:d}" '
'selected custom slide(s)?').format(items=len(items)),
QtWidgets.QMessageBox.StandardButtons(
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No),
QtWidgets.QMessageBox.Yes) == QtWidgets.QMessageBox.No:
@ -249,10 +251,11 @@ class CustomMediaItem(MediaManagerItem):
Search the plugin database
"""
# Save the current search type to the configuration.
Settings().setValue('%s/last search type' % self.settings_section, self.search_text_edit.current_search_type())
Settings().setValue('{section}/last search type'.format(section=self.settings_section),
self.search_text_edit.current_search_type())
# Reload the list considering the new search type.
search_type = self.search_text_edit.current_search_type()
search_keywords = '%' + self.whitespace.sub(' ', self.search_text_edit.displayText()) + '%'
search_keywords = '%{search}%'.format(search=self.whitespace.sub(' ', self.search_text_edit.displayText()))
if search_type == CustomSearch.Titles:
log.debug('Titles Search')
search_results = self.plugin.db_manager.get_all_objects(CustomSlide,
@ -347,7 +350,7 @@ class CustomMediaItem(MediaManagerItem):
:param string: The search string
:param show_error: The error string to be show.
"""
search = '%' + string.lower() + '%'
search = '%{search}%'.forma(search=string.lower())
search_results = self.plugin.db_manager.get_all_objects(CustomSlide,
or_(func.lower(CustomSlide.title).like(search),
func.lower(CustomSlide.text).like(search)),

View File

@ -74,7 +74,7 @@ class ImageMediaItem(MediaManagerItem):
def retranslateUi(self):
self.on_new_prompt = translate('ImagePlugin.MediaItem', 'Select Image(s)')
file_formats = get_images_filter()
self.on_new_file_masks = '%s;;%s (*)' % (file_formats, UiStrings().AllFiles)
self.on_new_file_masks = '{formats};;{files} (*)'.format(formats=file_formats, files=UiStrings().AllFiles)
self.add_group_action.setText(UiStrings().AddGroup)
self.add_group_action.setToolTip(UiStrings().AddGroup)
self.replace_action.setText(UiStrings().ReplaceBG)
@ -113,7 +113,7 @@ class ImageMediaItem(MediaManagerItem):
self.list_view = TreeWidgetWithDnD(self, self.plugin.name)
self.list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.list_view.setAlternatingRowColors(True)
self.list_view.setObjectName('%sTreeView' % self.plugin.name)
self.list_view.setObjectName('{name}TreeView'.format(name=self.plugin.name))
# Add to pageLayout
self.page_layout.addWidget(self.list_view)
# define and add the context menu
@ -127,21 +127,21 @@ class ImageMediaItem(MediaManagerItem):
create_widget_action(self.list_view, separator=True)
create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()),
'listView{name}{preview}Item'.format(name=self.plugin.name.title(), preview=StringContent.Preview.title()),
text=self.plugin.get_string(StringContent.Preview)['title'],
icon=':/general/general_preview.png',
can_shortcuts=True,
triggers=self.on_preview_click)
create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()),
'listView{name}{live}Item'.format(name=self.plugin.name.title(), live=StringContent.Live.title()),
text=self.plugin.get_string(StringContent.Live)['title'],
icon=':/general/general_live.png',
can_shortcuts=True,
triggers=self.on_live_click)
create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()),
'listView{name}{service}Item'.format(name=self.plugin.name.title(), service=StringContent.Service.title()),
can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)['title'],
icon=':/general/general_add.png',
@ -157,7 +157,7 @@ class ImageMediaItem(MediaManagerItem):
if self.has_delete_icon:
create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()),
'listView{name}{delete}Item'.format(name=self.plugin.name.title(), delete=StringContent.Delete.title()),
text=self.plugin.get_string(StringContent.Delete)['title'],
icon=':/general/general_delete.png',
can_shortcuts=True, triggers=self.on_delete_click)
@ -245,8 +245,8 @@ class ImageMediaItem(MediaManagerItem):
self.list_view.parent(),
translate('ImagePlugin.MediaItem', 'Remove group'),
translate('ImagePlugin.MediaItem',
'Are you sure you want to remove "%s" and everything in it?') %
item_data.group_name,
'Are you sure you want to remove "{name}" and everything in it?'
).format(name=item_data.group_name),
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes |
QtWidgets.QMessageBox.No)
) == QtWidgets.QMessageBox.Yes:
@ -355,7 +355,7 @@ class ImageMediaItem(MediaManagerItem):
# characters.
images.sort(key=lambda image_object: get_locale_key(os.path.split(str(image_object.filename))[1]))
for image_file in images:
log.debug('Loading image: %s', image_file.filename)
log.debug('Loading image: {name}'.format(name=image_file.filename))
filename = os.path.split(image_file.filename)[1]
thumb = self.generate_thumbnail_path(image_file)
if not os.path.exists(image_file.filename):
@ -481,7 +481,7 @@ class ImageMediaItem(MediaManagerItem):
for filename in images_list:
if not isinstance(filename, str):
continue
log.debug('Adding new image: %s', filename)
log.debug('Adding new image: {name}'.format(name=filename))
image_file = ImageFilenames()
image_file.group_id = group_id
image_file.filename = str(filename)
@ -589,14 +589,15 @@ class ImageMediaItem(MediaManagerItem):
if not remote:
critical_error_message_box(
translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s')
% '\n'.join(missing_items_file_names))
translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: {names}'
).format(names='\n'.join(missing_items_file_names)))
return False
# We have missing as well as existing images. We ask what to do.
elif missing_items_file_names and QtWidgets.QMessageBox.question(
self, translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s\n'
'Do you want to add the other images anyway?') % '\n'.join(missing_items_file_names),
translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: {names}\n'
'Do you want to add the other images anyway?'
).format(names='\n'.join(missing_items_file_names)),
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes)) == \
QtWidgets.QMessageBox.No:
return False
@ -688,7 +689,7 @@ class ImageMediaItem(MediaManagerItem):
critical_error_message_box(
UiStrings().LiveBGError,
translate('ImagePlugin.MediaItem', 'There was a problem replacing your background, '
'the image file "%s" no longer exists.') % filename)
'the image file "{name}" no longer exists.').format(name=filename))
def search(self, string, show_error=True):
"""

View File

@ -46,7 +46,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
"""
Class to manage the clip selection
"""
log.info('%s MediaClipSelectorForm loaded', __name__)
log.info('{name} MediaClipSelectorForm loaded'.format(name=__name__))
def __init__(self, media_item, parent, manager):
"""
@ -265,7 +265,8 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
# Enable audio track combobox if anything is in it
if len(titles) > 0:
self.titles_combo_box.setDisabled(False)
log.debug('load_disc_button end - vlc_media_player state: %s' % self.vlc_media_player.get_state())
log.debug('load_disc_button end - '
'vlc_media_player state: {state}'.format(state=self.vlc_media_player.get_state()))
@QtCore.pyqtSlot(bool)
def on_play_button_clicked(self, clicked):
@ -374,7 +375,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
:param index: The index of the newly chosen title track.
"""
log.debug('in on_titles_combo_box_changed, index: %d', index)
log.debug('in on_titles_combo_box_changed, index: {index:d}'.format(index=index))
vlc = get_vlc()
if not self.vlc_media_player:
log.error('vlc_media_player was None')
@ -407,7 +408,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
self.vlc_media_player.audio_set_mute(True)
# Get audio tracks
audio_tracks = self.vlc_media_player.audio_get_track_description()
log.debug('number of audio tracks: %d' % len(audio_tracks))
log.debug('number of audio tracks: {tracks:d}'.format(tracks=len(audio_tracks)))
# Clear the audio track combobox, insert new tracks
self.audio_tracks_combobox.clear()
for audio_track in audio_tracks:
@ -433,14 +434,14 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
self.toggle_disable_player(False)
# Set media length info
self.playback_length = self.vlc_media_player.get_length()
log.debug('playback_length: %d ms' % self.playback_length)
log.debug('playback_length: {length:d} ms'.format(length=self.playback_length))
# if length is 0, wait a bit, maybe vlc will change its mind...
loop_count = 0
while self.playback_length == 0 and loop_count < 20:
sleep(0.1)
self.playback_length = self.vlc_media_player.get_length()
loop_count += 1
log.debug('in loop, playback_length: %d ms' % self.playback_length)
log.debug('in loop, playback_length: {length:d} ms'.format(length=self.playback_length))
self.position_slider.setMaximum(self.playback_length)
# setup start and end time
rounded_vlc_ms_length = int(round(self.playback_length / 100.0) * 100.0)
@ -455,7 +456,8 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
sleep(0.1)
self.vlc_media_player.set_pause(1)
loop_count += 1
log.debug('titles_combo_box end - vlc_media_player state: %s' % self.vlc_media_player.get_state())
log.debug('titles_combo_box end - '
'vlc_media_player state: {state}'.format(state=self.vlc_media_player.get_state()))
self.application.set_normal_cursor()
@QtCore.pyqtSlot(int)
@ -468,7 +470,8 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
if not self.vlc_media_player:
return
audio_track = self.audio_tracks_combobox.itemData(index)
log.debug('in on_audio_tracks_combobox_currentIndexChanged, index: %d audio_track: %s' % (index, audio_track))
log.debug('in on_audio_tracks_combobox_currentIndexChanged, '
'index: {index:d} audio_track: {tracks}'.format(index=index, tracks=audio_track))
if audio_track and int(audio_track) > 0:
self.vlc_media_player.audio_set_track(int(audio_track))
@ -566,7 +569,9 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
translate('MediaPlugin.MediaClipSelectorForm',
'The CD was not loaded correctly, please re-load and try again.'))
return
optical = 'optical:%d:-1:-1:%d:%d:' % (title, start_time_ms, end_time_ms)
optical = 'optical:{title:d}:-1:-1:{start:d}:{end:d}:'.format(title=title,
start=start_time_ms,
end=end_time_ms)
else:
audio_track = self.audio_tracks_combobox.itemData(self.audio_tracks_combobox.currentIndex())
subtitle_track = self.subtitle_tracks_combobox.itemData(self.subtitle_tracks_combobox.currentIndex())
@ -577,7 +582,11 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
translate('MediaPlugin.MediaClipSelectorForm',
'The DVD was not loaded correctly, please re-load and try again.'))
return
optical = 'optical:%d:%d:%d:%d:%d:' % (title, audio_track, subtitle_track, start_time_ms, end_time_ms)
optical = 'optical:{title:d}:{audio:d}:{sub:d}:{start:d}:{end:d}:'.format(title=title,
audio=audio_track,
sub=subtitle_track,
start=start_time_ms,
end=end_time_ms)
# Ask for an alternative name for the mediaclip
while True:
new_optical_name, ok = QtWidgets.QInputDialog.getText(self, translate('MediaPlugin.MediaClipSelectorForm',
@ -634,10 +643,10 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
# use win api to find optical drives
fso = Dispatch('scripting.filesystemobject')
for drive in fso.Drives:
log.debug('Drive %s has type %d' % (drive.DriveLetter, drive.DriveType))
log.debug('Drive {drive} has type {types:d}'.format(drive=drive.DriveLetter, types=drive.DriveType))
# if type is 4, it is a cd-rom drive
if drive.DriveType == 4:
self.media_path_combobox.addItem('%s:\\' % drive.DriveLetter)
self.media_path_combobox.addItem('{drive}:\\'.format(drive=drive.DriveLetter))
elif is_linux():
# Get disc devices from dbus and find the ones that are optical
bus = dbus.SystemBus()

View File

@ -51,7 +51,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
"""
media_go_live = QtCore.pyqtSignal(list)
media_add_to_service = QtCore.pyqtSignal(list)
log.info('%s MediaMediaItem loaded', __name__)
log.info('{name} MediaMediaItem loaded'.format(name=__name__))
def __init__(self, parent, plugin):
self.setup()
@ -232,7 +232,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
critical_error_message_box(UiStrings().LiveBGError,
translate('MediaPlugin.MediaItem',
'There was a problem replacing your background, '
'the media file "%s" no longer exists.') % filename)
'the media file "{name}" no longer exists.').format(name=filename))
def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False,
context=ServiceItemContext.Service):
@ -258,7 +258,8 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
# Optical disc is no longer present
critical_error_message_box(
translate('MediaPlugin.MediaItem', 'Missing Media File'),
translate('MediaPlugin.MediaItem', 'The optical disc %s is no longer available.') % name)
translate('MediaPlugin.MediaItem',
'The optical disc {name} is no longer available.').format(name=name))
return False
service_item.processor = self.display_type_combo_box.currentText()
service_item.add_from_command(filename, name, CLAPPERBOARD)
@ -275,7 +276,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
# File is no longer present
critical_error_message_box(
translate('MediaPlugin.MediaItem', 'Missing Media File'),
translate('MediaPlugin.MediaItem', 'The file %s no longer exists.') % filename)
translate('MediaPlugin.MediaItem', 'The file {name} no longer exists.').format(name=filename))
return False
(path, name) = os.path.split(filename)
service_item.title = name
@ -308,9 +309,11 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
Rebuild the tab in the media manager when changes are made in the settings.
"""
self.populate_display_types()
self.on_new_file_masks = translate('MediaPlugin.MediaItem', 'Videos (%s);;Audio (%s);;%s (*)') % (
' '.join(self.media_controller.video_extensions_list),
' '.join(self.media_controller.audio_extensions_list), UiStrings().AllFiles)
self.on_new_file_masks = translate('MediaPlugin.MediaItem',
'Videos ({video});;Audio ({audio});;{files} '
'(*)').format(video=' '.join(self.media_controller.video_extensions_list),
audio=' '.join(self.media_controller.audio_extensions_list),
files=UiStrings().AllFiles)
def populate_display_types(self):
"""
@ -365,7 +368,9 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
item_name = QtWidgets.QListWidgetItem(clip_name)
item_name.setIcon(self.optical_icon)
item_name.setData(QtCore.Qt.UserRole, track)
item_name.setToolTip('%s@%s-%s' % (file_name, format_milliseconds(start), format_milliseconds(end)))
item_name.setToolTip('{name}@{start}-{end}'.format(name=file_name,
start=format_milliseconds(start),
end=format_milliseconds(end)))
elif not os.path.exists(track):
# File doesn't exist, mark as error.
file_name = os.path.split(str(track))[1]
@ -377,7 +382,8 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
# Normal media file handling.
file_name = os.path.split(str(track))[1]
item_name = QtWidgets.QListWidgetItem(file_name)
if '*.%s' % (file_name.split('.')[-1].lower()) in self.media_controller.audio_extensions_list:
search = file_name.split('.')[-1].lower()
if '*.{text}'.format(text=search) in self.media_controller.audio_extensions_list:
item_name.setIcon(self.audio_icon)
else:
item_name.setIcon(self.video_icon)

View File

@ -49,7 +49,7 @@ class MediaPlugin(Plugin):
"""
The media plugin adds the ability to playback audio and video content.
"""
log.info('%s MediaPlugin loaded', __name__)
log.info('{name} MediaPlugin loaded'.format(name=__name__))
def __init__(self):
super(MediaPlugin, self).__init__('media', __default_settings__, MediaMediaItem)

View File

@ -236,7 +236,7 @@ class ImpressDocument(PresentationDocument):
try:
self.document = desktop.loadComponentFromURL(url, '_blank', 0, properties)
except:
log.warning('Failed to load presentation %s' % url)
log.warning('Failed to load presentation {url}'.format(url=url))
return False
self.presentation = self.document.getPresentation()
self.presentation.Display = ScreenList().current['number'] + 1
@ -269,16 +269,16 @@ class ImpressDocument(PresentationDocument):
for index in range(pages.getCount()):
page = pages.getByIndex(index)
doc.getCurrentController().setCurrentPage(page)
url_path = '%s/%s.png' % (thumb_dir_url, str(index + 1))
url_path = '{path}/{name}.png'.format(path=thumb_dir_url, name=str(index + 1))
path = os.path.join(self.get_temp_folder(), str(index + 1) + '.png')
try:
doc.storeToURL(url_path, properties)
self.convert_thumbnail(path, index + 1)
delete_file(path)
except ErrorCodeIOException as exception:
log.exception('ERROR! ErrorCodeIOException %d' % exception.ErrCode)
log.exception('ERROR! ErrorCodeIOException {error:d}'.format(error=exception.ErrCode))
except:
log.exception('%s - Unable to store openoffice preview' % path)
log.exception('{path} - Unable to store openoffice preview'.format(path=path))
def create_property(self, name, value):
"""

View File

@ -88,9 +88,10 @@ class PresentationMediaItem(MediaManagerItem):
file_types = self.controllers[controller].supports + self.controllers[controller].also_supports
for file_type in file_types:
if file_type not in file_type_string:
file_type_string += '*.%s ' % file_type
file_type_string += '*.{text} '.format(text=file_type)
self.service_manager.supported_suffixes(file_type)
self.on_new_file_masks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % file_type_string
self.on_new_file_masks = translate('PresentationPlugin.MediaItem',
'Presentations ({text})').format(text=file_type_string)
def required_icons(self):
"""
@ -306,13 +307,13 @@ class PresentationMediaItem(MediaManagerItem):
os.path.join(doc.get_temp_folder(), 'mainslide001.png')):
doc.load_presentation()
i = 1
image = os.path.join(doc.get_temp_folder(), 'mainslide%03d.png' % i)
image = os.path.join(doc.get_temp_folder(), 'mainslide{number:0>3d}.png'.format(number=i))
thumbnail = os.path.join(doc.get_thumbnail_folder(), 'slide%d.png' % i)
while os.path.isfile(image):
service_item.add_from_image(image, name, thumbnail=thumbnail)
i += 1
image = os.path.join(doc.get_temp_folder(), 'mainslide%03d.png' % i)
thumbnail = os.path.join(doc.get_thumbnail_folder(), 'slide%d.png' % i)
image = os.path.join(doc.get_temp_folder(), 'mainslide{number:0>3d}.png'.format(number=i))
thumbnail = os.path.join(doc.get_thumbnail_folder(), 'slide{number:d}.png'.format(number=i))
service_item.add_capability(ItemCapabilities.HasThumbnails)
doc.close_presentation()
return True
@ -321,7 +322,8 @@ class PresentationMediaItem(MediaManagerItem):
if not remote:
critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
translate('PresentationPlugin.MediaItem',
'The presentation %s no longer exists.') % filename)
'The presentation {name} no longer exists.'
).format(name=filename))
return False
else:
service_item.processor = self.display_type_combo_box.currentText()
@ -367,15 +369,16 @@ class PresentationMediaItem(MediaManagerItem):
critical_error_message_box(translate('PresentationPlugin.MediaItem',
'Missing Presentation'),
translate('PresentationPlugin.MediaItem',
'The presentation %s is incomplete, please reload.')
% filename)
'The presentation {name} is incomplete, '
'please reload.').format(name=filename))
return False
else:
# File is no longer present
if not remote:
critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
translate('PresentationPlugin.MediaItem',
'The presentation %s no longer exists.') % filename)
'The presentation {name} no longer exists.'
).format(name=filename))
return False
def find_controller_by_type(self, filename):

View File

@ -48,14 +48,14 @@ class Controller(object):
self.is_live = live
self.doc = None
self.hide_mode = None
log.info('%s controller loaded' % live)
log.info('{name} controller loaded'.format(name=live))
def add_handler(self, controller, file, hide_mode, slide_no):
"""
Add a handler, which is an instance of a presentation and slidecontroller combination. If the slidecontroller
has a display then load the presentation.
"""
log.debug('Live = %s, add_handler %s' % (self.is_live, file))
log.debug('Live = {live}, add_handler {handler}'.format(live=self.is_live, handler=file))
self.controller = controller
if self.doc is not None:
self.shutdown()
@ -67,7 +67,7 @@ class Controller(object):
return
self.doc.slidenumber = slide_no
self.hide_mode = hide_mode
log.debug('add_handler, slide_number: %d' % slide_no)
log.debug('add_handler, slide_number: {slide:d}'.format(slide=slide_no))
if self.is_live:
if hide_mode == HideMode.Screen:
Registry().execute('live_display_hide', HideMode.Screen)
@ -87,14 +87,14 @@ class Controller(object):
"""
Active the presentation, and show it on the screen. Use the last slide number.
"""
log.debug('Live = %s, activate' % self.is_live)
log.debug('Live = {live}, activate'.format(live=self.is_live))
if not self.doc:
return False
if self.doc.is_active():
return True
if not self.doc.is_loaded():
if not self.doc.load_presentation():
log.warning('Failed to activate %s' % self.doc.file_path)
log.warning('Failed to activate {path}'.format(path=self.doc.file_path))
return False
if self.is_live:
self.doc.start_presentation()
@ -105,14 +105,14 @@ class Controller(object):
if self.doc.is_active():
return True
else:
log.warning('Failed to activate %s' % self.doc.file_path)
log.warning('Failed to activate {path}'.format(path=self.doc.file_path))
return False
def slide(self, slide):
"""
Go to a specific slide
"""
log.debug('Live = %s, slide' % self.is_live)
log.debug('Live = {live}, slide'.format(live=self.is_live))
if not self.doc:
return
if not self.is_live:
@ -130,7 +130,7 @@ class Controller(object):
"""
Based on the handler passed at startup triggers the first slide.
"""
log.debug('Live = %s, first' % self.is_live)
log.debug('Live = {live}, first'.format(live=self.is_live))
if not self.doc:
return
if not self.is_live:
@ -148,7 +148,7 @@ class Controller(object):
"""
Based on the handler passed at startup triggers the last slide.
"""
log.debug('Live = %s, last' % self.is_live)
log.debug('Live = {live}, last'.format(live=self.is_live))
if not self.doc:
return
if not self.is_live:
@ -166,7 +166,7 @@ class Controller(object):
"""
Based on the handler passed at startup triggers the next slide event.
"""
log.debug('Live = %s, next' % self.is_live)
log.debug('Live = {live}, next'.format(live=self.is_live))
if not self.doc:
return
if not self.is_live:
@ -191,7 +191,7 @@ class Controller(object):
"""
Based on the handler passed at startup triggers the previous slide event.
"""
log.debug('Live = %s, previous' % self.is_live)
log.debug('Live = {live}, previous'.formta(live=self.is_live))
if not self.doc:
return
if not self.is_live:
@ -212,7 +212,7 @@ class Controller(object):
"""
Based on the handler passed at startup triggers slide show to shut down.
"""
log.debug('Live = %s, shutdown' % self.is_live)
log.debug('Live = {live}, shutdown'.format(live=self.is_live))
if not self.doc:
return
self.doc.close_presentation()
@ -222,7 +222,7 @@ class Controller(object):
"""
Instruct the controller to blank the presentation.
"""
log.debug('Live = %s, blank' % self.is_live)
log.debug('Live = {live}, blank'.format(live=self.is_live))
self.hide_mode = hide_mode
if not self.doc:
return
@ -243,7 +243,7 @@ class Controller(object):
"""
Instruct the controller to stop and hide the presentation.
"""
log.debug('Live = %s, stop' % self.is_live)
log.debug('Live = {live}, stop'.format(live=self.is_live))
# The document has not been loaded yet, so don't do anything. This can happen when going live with a
# presentation while blanked to desktop.
if not self.doc:
@ -266,7 +266,7 @@ class Controller(object):
"""
Instruct the controller to unblank the presentation.
"""
log.debug('Live = %s, unblank' % self.is_live)
log.debug('Live = {live}, unblank'.format(live=self.is_live))
self.hide_mode = None
if not self.doc:
return
@ -321,7 +321,7 @@ class MessageListener(object):
"""
Start of new presentation. Save the handler as any new presentations start here
"""
log.debug('Startup called with message %s' % message)
log.debug('Startup called with message {text}'.format(text=message))
is_live = message[1]
item = message[0]
hide_mode = message[2]
@ -332,7 +332,7 @@ class MessageListener(object):
# the conversion has already been done at this point.
file_type = os.path.splitext(file.lower())[1][1:]
if file_type in PDF_CONTROLLER_FILETYPES:
log.debug('Converting from pdf/xps/oxps to images for serviceitem with file %s', file)
log.debug('Converting from pdf/xps/oxps to images for serviceitem with file {name}'.format(name=file))
# Create a copy of the original item, and then clear the original item so it can be filled with images
item_cpy = copy.copy(item)
item.__init__(None)

View File

@ -87,7 +87,7 @@ class PdfController(PresentationController):
if found_gs:
program_type = 'gs'
break
log.debug('in check_binary, found: %s', program_type)
log.debug('in check_binary, found: {text}'.format(text=program_type))
return program_type
def check_available(self):
@ -255,11 +255,13 @@ class PdfDocument(PresentationDocument):
os.makedirs(self.get_temp_folder())
if self.controller.mudrawbin:
log.debug('loading presentation using mudraw')
# TODO: Find out where the string conversion actually happens
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')
# TODO: Find out where the string convertsion actually happens
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],
@ -267,6 +269,7 @@ class PdfDocument(PresentationDocument):
elif self.controller.gsbin:
log.debug('loading presentation using gs')
resolution = self.gs_get_resolution(size)
# TODO: Find out where the string conversion actually happens
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'),

View File

@ -179,7 +179,7 @@ class PowerpointDocument(PresentationDocument):
if not self.presentation.Slides(num + 1).SlideShowTransition.Hidden:
self.index_map[key] = num + 1
self.presentation.Slides(num + 1).Export(
os.path.join(self.get_thumbnail_folder(), 'slide%d.png' % (key)), 'png', 320, 240)
os.path.join(self.get_thumbnail_folder(), 'slide{key:d}.png'.format(key=key)), 'png', 320, 240)
key += 1
self.slide_count = key - 1
@ -345,8 +345,9 @@ class PowerpointDocument(PresentationDocument):
# Find the presentation window and save the handle for later
self.presentation_hwnd = None
if ppt_window:
log.debug('main display size: y=%d, height=%d, x=%d, width=%d'
% (size.y(), size.height(), size.x(), size.width()))
log.debug('main display size: y={y:d}, height={height:d}, '
'x={x:d}, width={width:d}'.format(y=size.y(), height=size.height(),
x=size.x(), width=size.width()))
win32gui.EnumWindows(self._window_enum_callback, size)
# Make sure powerpoint doesn't steal focus, unless we're on a single screen setup
if len(ScreenList().screen_list) > 1:
@ -361,10 +362,18 @@ class PowerpointDocument(PresentationDocument):
# it is the powerpoint presentation window.
(left, top, right, bottom) = win32gui.GetWindowRect(hwnd)
window_title = win32gui.GetWindowText(hwnd)
log.debug('window size: left=%d, top=%d, right=%d, width=%d' % (left, top, right, bottom))
log.debug('compare size: %d and %d, %d and %d, %d and %d, %d and %d'
% (size.y(), top, size.height(), (bottom - top), size.x(), left, size.width(), (right - left)))
log.debug('window title: %s' % window_title)
log.debug('window size: left=left:d}, top={top:d}, '
'right={right:d}, bottom={bottom:d}'.format(left=left, top=top, right=right, bottom=bottom))
log.debug('compare size: {y:d} and {top:d}, {height:d} and {vertical:d}, '
'{x:d} and {left}, {width:d} and {horizontal:d}'.format(y=size.y(),
top=top,
height=size.height(),
vertical=(bottom - top),
x=size.x(),
left=left,
width=size.width(),
horizontal=(right - left)))
log.debug('window title: {title}'.format(title=window_title))
filename_root, filename_ext = os.path.splitext(os.path.basename(self.file_path))
if size.y() == top and size.height() == (bottom - top) and size.x() == left and \
size.width() == (right - left) and filename_root in window_title:
@ -416,8 +425,8 @@ class PowerpointDocument(PresentationDocument):
and self.get_slide_number() == slide_no:
click_index = self.presentation.SlideShowWindow.View.GetClickIndex()
click_count = self.presentation.SlideShowWindow.View.GetClickCount()
log.debug('We are already on this slide - go to next effect if any left, idx: %d, count: %d'
% (click_index, click_count))
log.debug('We are already on this slide - go to next effect if any left, idx: '
'{index:d}, count: {count:d}'.format(index=click_index, count=click_count))
if click_index < click_count:
self.next_step()
else:

View File

@ -148,7 +148,7 @@ class PptviewDocument(PresentationDocument):
return
log.debug('create_thumbnails proceeding')
for idx in range(self.get_slide_count()):
path = '%s\\slide%s.bmp' % (self.get_temp_folder(), str(idx + 1))
path = '{folder}\\slide{index}.bmp'.format(folder=self.get_temp_folder(), index=str(idx + 1))
self.convert_thumbnail(path, idx + 1)
def create_titles_and_notes(self):

View File

@ -278,7 +278,7 @@ class PresentationDocument(object):
prefix = 'live'
else:
prefix = 'preview'
Registry().execute('slidecontroller_%s_change' % prefix, self.slide_number - 1)
Registry().execute('slidecontroller_{prefix}_change'.format(prefix=prefix), self.slide_number - 1)
def get_slide_text(self, slide_no):
"""
@ -312,7 +312,7 @@ class PresentationDocument(object):
log.exception('Failed to open/read existing titles file')
titles = []
for slide_no, title in enumerate(titles, 1):
notes_file = os.path.join(self.get_thumbnail_folder(), 'slideNotes%d.txt' % slide_no)
notes_file = os.path.join(self.get_thumbnail_folder(), 'slideNotes{number:d}.txt'.format(number=slide_no))
note = ''
if os.path.exists(notes_file):
try:
@ -335,7 +335,8 @@ class PresentationDocument(object):
fo.writelines(titles)
if notes:
for slide_no, note in enumerate(notes, 1):
notes_file = os.path.join(self.get_thumbnail_folder(), 'slideNotes%d.txt' % slide_no)
notes_file = os.path.join(self.get_thumbnail_folder(),
'slideNotes{number:d}.txt'.format(number=slide_no))
with open(notes_file, mode='wt', encoding='utf-8') as fn:
fn.write(note)

View File

@ -137,7 +137,8 @@ class PresentationTab(SettingsTab):
if checkbox.isEnabled():
checkbox.setText(controller.name)
else:
checkbox.setText(translate('PresentationPlugin.PresentationTab', '%s (unavailable)') % controller.name)
checkbox.setText(translate('PresentationPlugin.PresentationTab',
'{name} (unavailable)').format(name=controller.name))
def load(self):
"""

View File

@ -128,11 +128,11 @@ class PresentationPlugin(Plugin):
path = os.path.join(controller_dir, filename)
if os.path.isfile(path):
module_name = 'openlp.plugins.presentations.lib.' + os.path.splitext(filename)[0]
log.debug('Importing controller %s', module_name)
log.debug('Importing controller {name}'.format(name=module_name))
try:
__import__(module_name, globals(), locals(), [])
except ImportError:
log.warning('Failed to import %s on path %s', module_name, path)
log.warning('Failed to import {name} on path {path}'.format(name=module_name, path=path))
controller_classes = PresentationController.__subclasses__()
for controller_class in controller_classes:
controller = controller_class(self)

View File

@ -250,3 +250,17 @@ class TestPJLink(TestCase):
# THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should have been set to closed')
self.assertTrue(pjlink.mute, 'Audio should be on')
def projector_process_input_test(self):
"""
Test input source status shows current input
"""
# GIVEN: Test object
pjlink = pjlink_test
pjlink.source = '0'
# WHEN: Called with input source
pjlink.process_inpt('1')
# THEN: Input selected should reflect current input
self.assertEquals(pjlink.source, '1', 'Input source should be set to "1"')