Fix line calculation for the theme preview. Try to make VLC loading more robust.

This commit is contained in:
Tomas Groth 2019-06-06 22:10:39 +02:00
parent 8b489de954
commit f27fded597
5 changed files with 36 additions and 32 deletions

View File

@ -463,7 +463,7 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
'title': TITLE, 'title': TITLE,
'authors_none_label': translate('OpenLP.Ui', 'Written by'), 'authors_none_label': translate('OpenLP.Ui', 'Written by'),
'authors_words_label': translate('SongsPlugin.AuthorType', 'Words', 'Author who wrote the lyrics of a song'), 'authors_words_label': translate('SongsPlugin.AuthorType', 'Words', 'Author who wrote the lyrics of a song'),
'authors_words': AUTHOR, 'authors_words': [AUTHOR],
'copyright': FOOTER_COPYRIGHT, 'copyright': FOOTER_COPYRIGHT,
'ccli_license': Settings().value('core/ccli number'), 'ccli_license': Settings().value('core/ccli number'),
'ccli_license_label': translate('SongsPlugin.MediaItem', 'CCLI License'), 'ccli_license_label': translate('SongsPlugin.MediaItem', 'CCLI License'),
@ -489,10 +489,10 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
if not self.force_page: if not self.force_page:
self.set_theme(theme_data) self.set_theme(theme_data)
self.theme_height = theme_data.font_main_height self.theme_height = theme_data.font_main_height
slides = self.format_slide(render_tags(VERSE), None) slides = self.format_slide(VERSE, None)
verses = dict() verses = dict()
verses['title'] = TITLE verses['title'] = TITLE
verses['text'] = slides[0] verses['text'] = render_tags(slides[0])
verses['verse'] = 'V1' verses['verse'] = 'V1'
verses['footer'] = self.generate_footer() verses['footer'] = self.generate_footer()
self.load_verses([verses]) self.load_verses([verses])
@ -734,7 +734,7 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
:param text: The text to check. It may contain HTML tags. :param text: The text to check. It may contain HTML tags.
""" """
self.clear_slides() self.clear_slides()
self.run_javascript('Display.addTextSlide("v1", "{text}", "Dummy Footer");'.format(text=text), is_sync=True) self.run_javascript('Display.addTextSlide("v1", "{text}", "Dummy Footer");'.format(text=text.replace('"', '\\"')), is_sync=True)
does_text_fits = self.run_javascript('Display.doesContentFit();', is_sync=True) does_text_fits = self.run_javascript('Display.doesContentFit();', is_sync=True)
return does_text_fits return does_text_fits

View File

@ -28,7 +28,6 @@ import os
import sys import sys
import threading import threading
from datetime import datetime from datetime import datetime
import vlc
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
@ -65,25 +64,27 @@ def get_vlc():
:return: The "vlc" module, or None :return: The "vlc" module, or None
""" """
if 'vlc' in sys.modules: # Import the VLC module if not already done
# If VLC has already been imported, no need to do all the stuff below again if 'vlc' not in sys.modules:
is_vlc_available = False
try: try:
is_vlc_available = bool(sys.modules['vlc'].get_default_instance()) import vlc
except Exception: except ImportError:
pass
if is_vlc_available:
return sys.modules['vlc']
else:
return None return None
else: # Verify that VLC is also loadable
return vlc is_vlc_available = False
try:
is_vlc_available = bool(sys.modules['vlc'].get_default_instance())
except Exception:
pass
if is_vlc_available:
return sys.modules['vlc']
return None
# On linux we need to initialise X threads, but not when running tests. # On linux we need to initialise X threads, but not when running tests.
# This needs to happen on module load and not in get_vlc(), otherwise it can cause crashes on some DE on some setups # This needs to happen on module load and not in get_vlc(), otherwise it can cause crashes on some DE on some setups
# (reported on Gnome3, Unity, Cinnamon, all GTK+ based) when using native filedialogs... # (reported on Gnome3, Unity, Cinnamon, all GTK+ based) when using native filedialogs...
if is_linux() and 'nose' not in sys.argv[0] and get_vlc(): if is_linux() and 'pytest' not in sys.argv[0] and get_vlc():
try: try:
try: try:
x11 = ctypes.cdll.LoadLibrary('libX11.so.6') x11 = ctypes.cdll.LoadLibrary('libX11.so.6')

View File

@ -178,8 +178,10 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
self.display_aspect_ratio = self.renderer.width() / self.renderer.height() self.display_aspect_ratio = self.renderer.width() / self.renderer.height()
except ZeroDivisionError: except ZeroDivisionError:
self.display_aspect_ratio = 1 self.display_aspect_ratio = 1
self.preview_area_layout.set_aspect_ratio(self.display_aspect_ratio) # Make sure we don't resize before the widgets are actually created
self.preview_box.set_scale(float(self.preview_box.width()) / self.renderer.width()) if hasattr(self, 'preview_area_layout'):
self.preview_area_layout.set_aspect_ratio(self.display_aspect_ratio)
self.preview_box.set_scale(float(self.preview_box.width()) / self.renderer.width())
def validateCurrentPage(self): def validateCurrentPage(self):
""" """
@ -212,9 +214,9 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
except ZeroDivisionError: except ZeroDivisionError:
self.display_aspect_ratio = 1 self.display_aspect_ratio = 1
self.preview_area_layout.set_aspect_ratio(self.display_aspect_ratio) self.preview_area_layout.set_aspect_ratio(self.display_aspect_ratio)
self.preview_box.generate_preview(self.theme, False, False)
self.preview_box.show()
self.resizeEvent() self.resizeEvent()
self.preview_box.show()
self.preview_box.generate_preview(self.theme, False, False)
def on_custom_1_button_clicked(self, number): def on_custom_1_button_clicked(self, number):
""" """

View File

@ -476,7 +476,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
if not theme_paths: if not theme_paths:
theme = Theme() theme = Theme()
theme.theme_name = UiStrings().Default theme.theme_name = UiStrings().Default
self._write_theme(theme) self.save_theme(theme)
Settings().setValue(self.settings_section + '/global theme', theme.theme_name) Settings().setValue(self.settings_section + '/global theme', theme.theme_name)
self.application.set_normal_cursor() self.application.set_normal_cursor()

View File

@ -259,35 +259,36 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
# TODO needs to be fixed as no idea why this fails # TODO needs to be fixed as no idea why this fails
# media.sort(key=lambda file_path: get_natural_key(file_path.name)) # media.sort(key=lambda file_path: get_natural_key(file_path.name))
for track in media: for track in media:
track_info = QtCore.QFileInfo(track) track_str = str(track)
track_info = QtCore.QFileInfo(track_str)
item_name = None item_name = None
if track.startswith('optical:'): if track_str.startswith('optical:'):
# Handle optical based item # Handle optical based item
(file_name, title, audio_track, subtitle_track, start, end, clip_name) = parse_optical_path(track) (file_name, title, audio_track, subtitle_track, start, end, clip_name) = parse_optical_path(track_str)
item_name = QtWidgets.QListWidgetItem(clip_name) item_name = QtWidgets.QListWidgetItem(clip_name)
item_name.setIcon(UiIcons().optical) item_name.setIcon(UiIcons().optical)
item_name.setData(QtCore.Qt.UserRole, track) item_name.setData(QtCore.Qt.UserRole, track_str)
item_name.setToolTip('{name}@{start}-{end}'.format(name=file_name, item_name.setToolTip('{name}@{start}-{end}'.format(name=file_name,
start=format_milliseconds(start), start=format_milliseconds(start),
end=format_milliseconds(end))) end=format_milliseconds(end)))
elif not os.path.exists(track): elif not os.path.exists(track):
# File doesn't exist, mark as error. # File doesn't exist, mark as error.
file_name = os.path.split(str(track))[1] file_name = os.path.split(track_str)[1]
item_name = QtWidgets.QListWidgetItem(file_name) item_name = QtWidgets.QListWidgetItem(file_name)
item_name.setIcon(UiIcons().error) item_name.setIcon(UiIcons().error)
item_name.setData(QtCore.Qt.UserRole, track) item_name.setData(QtCore.Qt.UserRole, track_str)
item_name.setToolTip(track) item_name.setToolTip(track_str)
elif track_info.isFile(): elif track_info.isFile():
# Normal media file handling. # Normal media file handling.
file_name = os.path.split(str(track))[1] file_name = os.path.split(track_str)[1]
item_name = QtWidgets.QListWidgetItem(file_name) item_name = QtWidgets.QListWidgetItem(file_name)
search = file_name.split('.')[-1].lower() search = file_name.split('.')[-1].lower()
if '*.{text}'.format(text=search) in self.media_controller.audio_extensions_list: if '*.{text}'.format(text=search) in self.media_controller.audio_extensions_list:
item_name.setIcon(UiIcons().audio) item_name.setIcon(UiIcons().audio)
else: else:
item_name.setIcon(UiIcons().video) item_name.setIcon(UiIcons().video)
item_name.setData(QtCore.Qt.UserRole, track) item_name.setData(QtCore.Qt.UserRole, track_str)
item_name.setToolTip(track) item_name.setToolTip(track_str)
if item_name: if item_name:
self.list_view.addItem(item_name) self.list_view.addItem(item_name)