forked from openlp/openlp
continued work
This commit is contained in:
parent
060718be32
commit
a5fa986bdd
@ -77,8 +77,10 @@ class Renderer(object):
|
|||||||
self.force_page = False
|
self.force_page = False
|
||||||
self.display = MainDisplay(None, self.imageManager, False, self)
|
self.display = MainDisplay(None, self.imageManager, False, self)
|
||||||
self.display.setup()
|
self.display.setup()
|
||||||
self.theme_dimensions = {}
|
self._theme_dimensions = {}
|
||||||
self._calculate_default()
|
self._calculate_default()
|
||||||
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
|
QtCore.SIGNAL(u'theme_update_global'), self.set_global_theme)
|
||||||
|
|
||||||
def update_display(self):
|
def update_display(self):
|
||||||
"""
|
"""
|
||||||
@ -92,23 +94,29 @@ class Renderer(object):
|
|||||||
self.bg_frame = None
|
self.bg_frame = None
|
||||||
self._calculate_default()
|
self._calculate_default()
|
||||||
|
|
||||||
def set_theme(self, theme_name):
|
def update_theme(self):
|
||||||
|
self._theme_dimensions = {}
|
||||||
|
|
||||||
|
def _set_theme(self, theme_name):
|
||||||
"""
|
"""
|
||||||
|
Helper method to save theme names and theme data.
|
||||||
"""
|
"""
|
||||||
if theme_name not in self.theme_dimensions:
|
if theme_name not in self._theme_dimensions:
|
||||||
theme_data = self.themeManager.getThemeData(theme_name)
|
theme_data = self.themeManager.getThemeData(theme_name)
|
||||||
main_rect = self.get_main_rectangle(theme_data)
|
main_rect = self.get_main_rectangle(theme_data)
|
||||||
footer_rect = self.get_footer_rectangle(theme_data)
|
footer_rect = self.get_footer_rectangle(theme_data)
|
||||||
self.theme_dimensions[theme_name] = [theme_data, main_rect, footer_rect]
|
self._theme_dimensions[theme_name] = \
|
||||||
|
[theme_data, main_rect, footer_rect]
|
||||||
else:
|
else:
|
||||||
theme_data, main_rect, footer_rect = self.theme_dimensions[theme_name]
|
theme_data, main_rect, footer_rect = \
|
||||||
|
self._theme_dimensions[theme_name]
|
||||||
# if No file do not update cache
|
# if No file do not update cache
|
||||||
if theme_data.background_filename:
|
if theme_data.background_filename:
|
||||||
self.imageManager.add_image(theme_data.theme_name,
|
self.imageManager.add_image(theme_data.theme_name,
|
||||||
theme_data.background_filename, u'theme',
|
theme_data.background_filename, u'theme',
|
||||||
QtGui.QColor(theme_data.background_border_color))
|
QtGui.QColor(theme_data.background_border_color))
|
||||||
|
|
||||||
def post_render(self, override_theme_data):
|
def post_render(self, override_theme_data=None):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
# Just assume we use the global theme.
|
# Just assume we use the global theme.
|
||||||
@ -120,35 +128,44 @@ class Renderer(object):
|
|||||||
theme_to_use = self.service_theme
|
theme_to_use = self.service_theme
|
||||||
elif self.theme_level == ThemeLevel.Song and self.item_theme:
|
elif self.theme_level == ThemeLevel.Song and self.item_theme:
|
||||||
theme_to_use = self.item_theme
|
theme_to_use = self.item_theme
|
||||||
theme_data, main_rect, footer_rect = self.theme_dimensions[theme_to_use]
|
if override_theme_data is None:
|
||||||
if override_theme_data:
|
theme_data, main_rect, footer_rect = \
|
||||||
|
self._theme_dimensions[theme_to_use]
|
||||||
|
else:
|
||||||
|
# Ignore everything and use own theme data.
|
||||||
theme_data = override_theme_data
|
theme_data = override_theme_data
|
||||||
|
main_rect = self.get_main_rectangle(override_theme_data)
|
||||||
|
footer_rect = self.get_footer_rectangle(override_theme_data)
|
||||||
self._set_text_rectangle(theme_data, main_rect, footer_rect)
|
self._set_text_rectangle(theme_data, main_rect, footer_rect)
|
||||||
return theme_data, self._rect, self._rect_footer
|
return theme_data, self._rect, self._rect_footer
|
||||||
|
|
||||||
def set_theme_level(self, theme_level):
|
def set_theme_level(self, theme_level):
|
||||||
"""
|
"""
|
||||||
|
Sets the theme level.
|
||||||
|
|
||||||
|
``theme_level``
|
||||||
|
The theme level to be used.
|
||||||
"""
|
"""
|
||||||
self.theme_level = theme_level
|
self.theme_level = theme_level
|
||||||
|
|
||||||
def set_global_theme(self, global_theme_name):
|
def set_global_theme(self, global_theme_name):
|
||||||
"""
|
"""
|
||||||
Set the global-level theme and the theme level.
|
Set the global-level theme name.
|
||||||
|
|
||||||
``global_theme``
|
``global_theme_name``
|
||||||
The global-level theme to be set.
|
The global-level theme's name.
|
||||||
"""
|
"""
|
||||||
self.set_theme(global_theme_name)
|
self._set_theme(global_theme_name)
|
||||||
self.global_theme = global_theme_name
|
self.global_theme = global_theme_name
|
||||||
|
|
||||||
def set_service_theme(self, service_theme_name):
|
def set_service_theme(self, service_theme_name):
|
||||||
"""
|
"""
|
||||||
Set the service-level theme.
|
Set the service-level theme.
|
||||||
|
|
||||||
``service_theme``
|
``service_theme_name``
|
||||||
The service-level theme to be set.
|
The service level theme's name.
|
||||||
"""
|
"""
|
||||||
self.set_theme(service_theme_name)
|
self._set_theme(service_theme_name)
|
||||||
self.service_theme = service_theme_name
|
self.service_theme = service_theme_name
|
||||||
|
|
||||||
def set_override_theme(self, override_theme_name):
|
def set_override_theme(self, override_theme_name):
|
||||||
@ -160,7 +177,7 @@ class Renderer(object):
|
|||||||
The name of the song-level theme. None means the service
|
The name of the song-level theme. None means the service
|
||||||
item wants to use the given value.
|
item wants to use the given value.
|
||||||
"""
|
"""
|
||||||
self.set_theme(override_theme_name)
|
self._set_theme(override_theme_name)
|
||||||
self.item_theme = override_theme_name
|
self.item_theme = override_theme_name
|
||||||
|
|
||||||
def generate_preview(self, theme_data, force_page=False):
|
def generate_preview(self, theme_data, force_page=False):
|
||||||
@ -178,8 +195,6 @@ class Renderer(object):
|
|||||||
self.force_page = force_page
|
self.force_page = force_page
|
||||||
# build a service item to generate preview
|
# build a service item to generate preview
|
||||||
serviceItem = ServiceItem()
|
serviceItem = ServiceItem()
|
||||||
serviceItem.theme = theme_data.theme_name
|
|
||||||
#self.set_override_theme(theme_data)
|
|
||||||
if self.force_page:
|
if self.force_page:
|
||||||
# make big page for theme edit dialog to get line count
|
# make big page for theme edit dialog to get line count
|
||||||
serviceItem.add_from_text(u'', VERSE_FOR_LINE_COUNT)
|
serviceItem.add_from_text(u'', VERSE_FOR_LINE_COUNT)
|
||||||
@ -188,7 +203,16 @@ class Renderer(object):
|
|||||||
serviceItem.add_from_text(u'', VERSE)
|
serviceItem.add_from_text(u'', VERSE)
|
||||||
serviceItem.renderer = self
|
serviceItem.renderer = self
|
||||||
serviceItem.raw_footer = FOOTER
|
serviceItem.raw_footer = FOOTER
|
||||||
serviceItem.render(theme_data)
|
# if No file do not update cache
|
||||||
|
if theme_data.background_filename:
|
||||||
|
self.imageManager.add_image(theme_data.theme_name,
|
||||||
|
theme_data.background_filename, u'theme',
|
||||||
|
QtGui.QColor(theme_data.background_border_color))
|
||||||
|
theme_data, main, footer = self.post_render(theme_data)
|
||||||
|
serviceItem.themedata = theme_data
|
||||||
|
serviceItem.main = main
|
||||||
|
serviceItem.footer = footer
|
||||||
|
serviceItem.render(True)
|
||||||
if not self.force_page:
|
if not self.force_page:
|
||||||
self.display.buildHtml(serviceItem)
|
self.display.buildHtml(serviceItem)
|
||||||
raw_html = serviceItem.get_rendered_frame(0)
|
raw_html = serviceItem.get_rendered_frame(0)
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
The :mod:`serviceitem` provides the service item functionality including the
|
The :mod:`serviceitem` provides the service item functionality including the
|
||||||
type and capability of an item.
|
type and capability of an item.
|
||||||
"""
|
"""
|
||||||
|
import time
|
||||||
import cgi
|
import cgi
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
@ -39,6 +39,9 @@ from openlp.core.lib import build_icon, clean_tags, expand_tags, translate
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
COUNT = 0
|
||||||
|
TIME_ = datetime.timedelta()
|
||||||
|
|
||||||
class ServiceItemType(object):
|
class ServiceItemType(object):
|
||||||
"""
|
"""
|
||||||
Defines the type of service item
|
Defines the type of service item
|
||||||
@ -158,20 +161,19 @@ class ServiceItem(object):
|
|||||||
self.icon = icon
|
self.icon = icon
|
||||||
self.iconic_representation = build_icon(icon)
|
self.iconic_representation = build_icon(icon)
|
||||||
|
|
||||||
def render(self, use_override=False):
|
def render(self, provides_own_theme_data=False):
|
||||||
"""
|
"""
|
||||||
The render method is what generates the frames for the screen and
|
The render method is what generates the frames for the screen and
|
||||||
obtains the display information from the renderer. At this point all
|
obtains the display information from the renderer. At this point all
|
||||||
slides are built for the given display size.
|
slides are built for the given display size.
|
||||||
"""
|
"""
|
||||||
import time
|
|
||||||
import datetime
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
log.debug(u'Render called')
|
log.debug(u'Render called')
|
||||||
self._display_frames = []
|
self._display_frames = []
|
||||||
self.bg_image_bytes = None
|
self.bg_image_bytes = None
|
||||||
|
if not provides_own_theme_data:
|
||||||
self.renderer.set_override_theme(self.theme)
|
self.renderer.set_override_theme(self.theme)
|
||||||
self.themedata, self.main, self.footer = self.renderer.post_render(use_override)
|
self.themedata, self.main, self.footer = self.renderer.post_render()
|
||||||
if self.service_item_type == ServiceItemType.Text:
|
if self.service_item_type == ServiceItemType.Text:
|
||||||
log.debug(u'Formatting slides')
|
log.debug(u'Formatting slides')
|
||||||
for slide in self._raw_frames:
|
for slide in self._raw_frames:
|
||||||
@ -197,7 +199,13 @@ class ServiceItem(object):
|
|||||||
if self.raw_footer is None:
|
if self.raw_footer is None:
|
||||||
self.raw_footer = []
|
self.raw_footer = []
|
||||||
self.foot_text = u'<br>'.join(filter(None, self.raw_footer))
|
self.foot_text = u'<br>'.join(filter(None, self.raw_footer))
|
||||||
print unicode(datetime.timedelta(seconds=(time.time() - start)))
|
global COUNT
|
||||||
|
COUNT += 1
|
||||||
|
global TIME_
|
||||||
|
TIME_ += datetime.timedelta(seconds=(time.time() - start))
|
||||||
|
print u'%s (average %s)' % (
|
||||||
|
unicode(datetime.timedelta(seconds=(time.time() - start))),
|
||||||
|
unicode(TIME_ / COUNT))
|
||||||
|
|
||||||
def add_from_image(self, path, title, background=None):
|
def add_from_image(self, path, title, background=None):
|
||||||
"""
|
"""
|
||||||
|
@ -250,7 +250,6 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
Generate layout preview and display the form.
|
Generate layout preview and display the form.
|
||||||
"""
|
"""
|
||||||
self.updateTheme()
|
self.updateTheme()
|
||||||
screen_size = self.screens.current[u'size']
|
|
||||||
width = self.thememanager.mainwindow.renderer.width
|
width = self.thememanager.mainwindow.renderer.width
|
||||||
height = self.thememanager.mainwindow.renderer.height
|
height = self.thememanager.mainwindow.renderer.height
|
||||||
pixmap = QtGui.QPixmap(width, height)
|
pixmap = QtGui.QPixmap(width, height)
|
||||||
|
@ -247,8 +247,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
QtCore.QSettings().setValue(
|
QtCore.QSettings().setValue(
|
||||||
self.settingsSection + u'/global theme',
|
self.settingsSection + u'/global theme',
|
||||||
QtCore.QVariant(self.global_theme))
|
QtCore.QVariant(self.global_theme))
|
||||||
Receiver.send_message(u'theme_update_global',
|
Receiver.send_message(u'theme_update_global', self.global_theme)
|
||||||
self.global_theme)
|
|
||||||
self._pushThemes()
|
self._pushThemes()
|
||||||
|
|
||||||
def onAddTheme(self):
|
def onAddTheme(self):
|
||||||
@ -667,6 +666,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
u'theme', QtGui.QColor(theme.background_border_color))
|
u'theme', QtGui.QColor(theme.background_border_color))
|
||||||
self.mainwindow.imageManager.process_updates()
|
self.mainwindow.imageManager.process_updates()
|
||||||
self.loadThemes()
|
self.loadThemes()
|
||||||
|
#self.mainwindow.renderer.update_theme()
|
||||||
|
|
||||||
def _writeTheme(self, theme, image_from, image_to):
|
def _writeTheme(self, theme, image_from, image_to):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user