last fixes

This commit is contained in:
Andreas Preikschat 2012-05-23 18:14:03 +02:00
parent a5fa986bdd
commit c15ac3a84e
3 changed files with 50 additions and 19 deletions

View File

@ -70,7 +70,7 @@ class Renderer(object):
self.themeManager = themeManager self.themeManager = themeManager
self.imageManager = imageManager self.imageManager = imageManager
self.screens = ScreenList.get_instance() self.screens = ScreenList.get_instance()
self.service_theme = u'' self.service_theme_name = u''
self.theme_level = u'' self.theme_level = u''
self.override_background = None self.override_background = None
self.bg_frame = None self.bg_frame = None
@ -94,12 +94,31 @@ class Renderer(object):
self.bg_frame = None self.bg_frame = None
self._calculate_default() self._calculate_default()
def update_theme(self): def update_theme(self, theme_name, old_theme_name=None):
self._theme_dimensions = {} """
This method updates the theme in ``_theme_dimensions`` when a theme
has been edited or renamed.
``theme_name``
The current theme name.
``old_theme_name``
The old theme name. Has only to be passed, when the theme has been
renamed. Defaults to *None*.
"""
if old_theme_name is not None and \
old_theme_name in self._theme_dimensions:
del self._theme_dimensions[old_theme_name]
if theme_name in self._theme_dimensions:
del self._theme_dimensions[theme_name]
self._set_theme(theme_name)
def _set_theme(self, theme_name): def _set_theme(self, theme_name):
""" """
Helper method to save theme names and theme data. Helper method to save theme names and theme data.
``theme_name``
The theme name.
""" """
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)
@ -116,18 +135,25 @@ class Renderer(object):
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=None): def pre_render(self, override_theme_data=None):
""" """
Set up the theme to be used before rendering an item.
``override_theme_data``
The theme data should be passed, when we want to use our own theme
data, regardless of the theme level. This should for example be used
in the theme manager. **Note**, this is **not** to be mixed up with
the ``set_item_theme`` method.
""" """
# Just assume we use the global theme. # Just assume we use the global theme.
theme_to_use = self.global_theme theme_to_use = self.global_theme_name
if self.theme_level == ThemeLevel.Service: if self.theme_level == ThemeLevel.Service:
# When the theme level is at Service and we actually have a service # When the theme level is at Service and we actually have a service
# theme then use it. # theme then use it.
if self.service_theme: if self.service_theme_name:
theme_to_use = self.service_theme theme_to_use = self.service_theme_name
elif self.theme_level == ThemeLevel.Song and self.item_theme: elif self.theme_level == ThemeLevel.Song and self.item_theme_name:
theme_to_use = self.item_theme theme_to_use = self.item_theme_name
if override_theme_data is None: if override_theme_data is None:
theme_data, main_rect, footer_rect = \ theme_data, main_rect, footer_rect = \
self._theme_dimensions[theme_to_use] self._theme_dimensions[theme_to_use]
@ -156,7 +182,7 @@ class Renderer(object):
The global-level theme's name. 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_name = global_theme_name
def set_service_theme(self, service_theme_name): def set_service_theme(self, service_theme_name):
""" """
@ -166,9 +192,9 @@ class Renderer(object):
The service level theme's name. 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_name = service_theme_name
def set_override_theme(self, override_theme_name): def set_item_theme(self, item_theme_name):
""" """
Set the appropriate theme depending on the theme level. Set the appropriate theme depending on the theme level.
Called by the service item when building a display frame Called by the service item when building a display frame
@ -177,8 +203,8 @@ 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(item_theme_name)
self.item_theme = override_theme_name self.item_theme_name = item_theme_name
def generate_preview(self, theme_data, force_page=False): def generate_preview(self, theme_data, force_page=False):
""" """

View File

@ -166,14 +166,17 @@ class ServiceItem(object):
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.
``provides_own_theme_data``
""" """
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: if not provides_own_theme_data:
self.renderer.set_override_theme(self.theme) self.renderer.set_item_theme(self.theme)
self.themedata, self.main, self.footer = self.renderer.post_render() self.themedata, self.main, self.footer = self.renderer.pre_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:

View File

@ -283,6 +283,8 @@ class ThemeManager(QtGui.QWidget):
if plugin.usesTheme(old_theme_name): if plugin.usesTheme(old_theme_name):
plugin.renameTheme(old_theme_name, new_theme_name) plugin.renameTheme(old_theme_name, new_theme_name)
self.loadThemes() self.loadThemes()
self.mainwindow.renderer.update_theme(
new_theme_name, old_theme_name)
def onCopyTheme(self): def onCopyTheme(self):
""" """
@ -319,9 +321,8 @@ class ThemeManager(QtGui.QWidget):
Loads the settings for the theme that is to be edited and launches the Loads the settings for the theme that is to be edited and launches the
theme editing form so the user can make their changes. theme editing form so the user can make their changes.
""" """
if check_item_selected(self.themeListWidget, if check_item_selected(self.themeListWidget, translate(
translate('OpenLP.ThemeManager', 'OpenLP.ThemeManager', 'You must select a theme to edit.')):
'You must select a theme to edit.')):
item = self.themeListWidget.currentItem() item = self.themeListWidget.currentItem()
theme = self.getThemeData( theme = self.getThemeData(
unicode(item.data(QtCore.Qt.UserRole).toString())) unicode(item.data(QtCore.Qt.UserRole).toString()))
@ -330,6 +331,7 @@ class ThemeManager(QtGui.QWidget):
self.themeForm.theme = theme self.themeForm.theme = theme
self.themeForm.exec_(True) self.themeForm.exec_(True)
self.old_background_image = None self.old_background_image = None
self.mainwindow.renderer.update_theme(theme.theme_name)
def onDeleteTheme(self): def onDeleteTheme(self):
""" """