Finish the Theme work to save all themes and replay them on reload

Add rules as to which theme to use in the RenderManager
This commit is contained in:
Tim Bentley 2009-05-18 20:04:25 +01:00
parent d5b2a1e496
commit 47c0b69d36
8 changed files with 95 additions and 21 deletions

View File

@ -118,6 +118,7 @@ class Renderer:
"""
log.debug(u'format_slide %s', words)
verses = []
words=words.replace("\r\n", "\n")
verses_text = words.split(u'\n\n')
for verse in verses_text:
lines = verse.split(u'\n')

View File

@ -64,14 +64,34 @@ class RenderManager:
self.current_display = 0
self.renderer = Renderer()
self.calculate_default(self.screen_list[self.current_display]['size'])
self.theme = u''
def set_global_theme(self, global_theme, global_style = u'Global'):
self.global_theme = global_theme
self.global_style = global_style
def set_service_theme(self, service_theme):
self.service_theme = service_theme
def set_override_theme(self, theme):
log.debug(u'set override theme to %s', theme)
if theme is not None:
self.theme = theme
if self.global_style == u'Global':
self.theme = self.global_theme
elif self.global_style == u'Service':
if self.service_theme == u'':
self.theme = self.global_theme
else:
self.theme = self.service_theme
else:
self.theme = self.default_theme
if self.theme != self.renderer.theme_name:
if theme is not None:
self.theme = theme
elif self.global_style == u'Service':
if self.service_theme == u'':
self.theme = self.global_theme
else:
self.theme = self.service_theme
if self.theme is not self.renderer.theme_name:
log.debug(u'theme is now %s', self.theme)
self.themedata = self.theme_manager.getThemeData(self.theme)
self.calculate_default(self.screen_list[self.current_display]['size'])

View File

@ -24,7 +24,7 @@ from openlp.core import translate
class MainDisplay(QtGui.QWidget):
def __init__(self, parent, screens):
def __init__(self, parent , screens):
QtGui.QWidget.__init__(self, parent)
self.setWindowTitle(u'OpenLP Display')
self.screens = screens

View File

@ -43,7 +43,7 @@ class MainWindow(object):
self.EventManager = EventManager()
self.alert_form = AlertForm()
self.about_form = AboutForm()
self.settings_form = SettingsForm(self.screen_list)
self.settings_form = SettingsForm(self.screen_list, self)
pluginpath = os.path.split(os.path.abspath(__file__))[0]
pluginpath = os.path.abspath(os.path.join(pluginpath, u'..', u'..', u'plugins'))

View File

@ -21,7 +21,7 @@ import os
import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import PluginConfig
from openlp.core.lib import OpenLPToolbar
from openlp.core.lib import ServiceItem
from openlp.core.lib import RenderManager
@ -103,6 +103,9 @@ class ServiceManager(QtGui.QWidget):
QtCore.QObject.connect(self.ThemeComboBox,
QtCore.SIGNAL("activated(int)"), self.onThemeComboBoxSelected)
self.config = PluginConfig(u'Main')
self.service_theme = self.config.get_config(u'theme service theme', u'')
def contextMenuAction(self, base, icon, text, slot):
"""
Utility method to help build context menus for plugins
@ -142,7 +145,9 @@ class ServiceManager(QtGui.QWidget):
pass
def onThemeComboBoxSelected(self, currentIndex):
self.RenderManager.default_theme = self.ThemeComboBox.currentText()
self.service_theme = self.ThemeComboBox.currentText()
self.RenderManager.set_service_theme(self.service_theme)
self.config.set_config(u'theme service theme', self.service_theme)
def addServiceItem(self, item):
self.serviceItems.append({u'data': item, u'order': len(self.serviceItems)+1})
@ -224,7 +229,11 @@ class ServiceManager(QtGui.QWidget):
Called from ThemeManager when the Themes have changed
"""
self.ThemeComboBox.clear()
self.ThemeComboBox.addItem(u'')
for theme in theme_list:
self.ThemeComboBox.addItem(theme)
self.RenderManager.default_theme = self.ThemeComboBox.currentText()
id = self.ThemeComboBox.findText(str(self.service_theme), QtCore.Qt.MatchExactly)
if id == -1:
id = 0 # Not Found
self.service_theme = u''
self.ThemeComboBox.setCurrentIndex(id)

View File

@ -31,14 +31,14 @@ log = logging.getLogger('SettingsForm')
class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
def __init__(self, screen_list, parent=None):
QtGui.QDialog.__init__(self, parent)
def __init__(self, screen_list, mainWindow, parent=None):
QtGui.QDialog.__init__(self, None)
self.setupUi(self)
# General tab
self.GeneralTab = GeneralTab(screen_list)
self.addTab(self.GeneralTab)
# Themes tab
self.ThemesTab = ThemesTab()
self.ThemesTab = ThemesTab(mainWindow)
self.addTab(self.ThemesTab)
# Alert tab
self.AlertsTab = AlertsTab()

View File

@ -28,7 +28,8 @@ class ThemesTab(SettingsTab):
"""
ThemesTab is the theme settings tab in the settings dialog.
"""
def __init__(self):
def __init__(self, parent):
self.parent = parent
SettingsTab.__init__(self, u'Themes')
def setupUi(self):
@ -45,11 +46,8 @@ class ThemesTab(SettingsTab):
self.GlobalGroupBoxLayout.setObjectName(u'GlobalGroupBoxLayout')
self.DefaultComboBox = QtGui.QComboBox(self.GlobalGroupBox)
self.DefaultComboBox.setObjectName(u'DefaultComboBox')
self.DefaultComboBox.addItem(QtCore.QString())
self.DefaultComboBox.addItem(QtCore.QString())
self.DefaultComboBox.addItem(QtCore.QString())
self.GlobalGroupBoxLayout.addWidget(self.DefaultComboBox)
self.DefaultListView = QtGui.QListView(self.GlobalGroupBox)
self.DefaultListView = QtGui.QLabel(self.GlobalGroupBox)
self.DefaultListView.setObjectName(u'DefaultListView')
self.GlobalGroupBoxLayout.addWidget(self.DefaultListView)
self.ThemesTabLayout.addWidget(self.GlobalGroupBox)
@ -93,11 +91,18 @@ class ThemesTab(SettingsTab):
self.GlobalLevelLabel)
self.ThemesTabLayout.addWidget(self.LevelGroupBox)
QtCore.QObject.connect(self.SongLevelRadioButton,
QtCore.SIGNAL("pressed()"), self.onSongLevelButtonPressed)
QtCore.QObject.connect(self.ServiceLevelRadioButton,
QtCore.SIGNAL("pressed()"), self.onServiceLevelButtonPressed)
QtCore.QObject.connect(self.GlobalLevelRadioButton,
QtCore.SIGNAL("pressed()"), self.onGlobalLevelButtonPressed)
QtCore.QObject.connect(self.DefaultComboBox,
QtCore.SIGNAL("activated(int)"), self.onDefaultComboBoxChanged)
def retranslateUi(self):
self.GlobalGroupBox.setTitle(translate(u'ThemesTab', u'Global theme'))
self.DefaultComboBox.setItemText(0, translate(u'ThemesTab', u'African Sunset'))
self.DefaultComboBox.setItemText(1, translate(u'ThemesTab', u'Snowy Mountains'))
self.DefaultComboBox.setItemText(2, translate(u'ThemesTab', u'Wilderness'))
self.LevelGroupBox.setTitle(translate(u'ThemesTab', u'Theme level'))
self.SongLevelRadioButton.setText(translate(u'ThemesTab', u'Song level'))
self.SongLevelLabel.setText(translate(u'ThemesTab', u'Use the theme from each song in the database. If a song doesn\'t have a theme associated with it, then use the service\'s theme. If the service doesn\'t have a theme, then use the global theme.'))
@ -106,6 +111,36 @@ class ThemesTab(SettingsTab):
self.GlobalLevelRadioButton.setText(translate(u'ThemesTab', u'Global level'))
self.GlobalLevelLabel.setText(translate(u'ThemesTab', u'Use the global theme, overriding any themes associated wither either the service or the songs.'))
def load(self):
self.global_style = self.config.get_config(u'theme global style', u'Global')
self.global_theme = self.config.get_config(u'theme global theme', u'')
if self.global_style == u'Global':
self.GlobalLevelRadioButton.setChecked(True)
elif self.global_style == u'Service':
self.ServiceLevelRadioButton.setChecked(True)
else:
self.SongLevelRadioButton.setChecked(True)
def save(self):
self.config.set_config(u'theme global style', self.global_style )
self.config.set_config(u'theme global theme',self.global_theme)
def onSongLevelButtonPressed(self):
self.global_style= u'Song'
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
def onServiceLevelButtonPressed(self):
self.global_style= u'Service'
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
def onGlobalLevelButtonPressed(self):
self.global_style= u'Global'
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
def onDefaultComboBoxChanged(self, value):
self.global_theme = self.DefaultComboBox.currentText()
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
def updateThemeList(self, theme_list):
"""
Called from ThemeManager when the Themes have changed
@ -113,3 +148,11 @@ class ThemesTab(SettingsTab):
self.DefaultComboBox.clear()
for theme in theme_list:
self.DefaultComboBox.addItem(theme)
id = self.DefaultComboBox.findText(str(self.global_theme), QtCore.Qt.MatchExactly)
if id == -1:
id = 0 # Not Found
self.global_theme = u''
self.DefaultComboBox.setCurrentIndex(id)
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)

View File

@ -118,6 +118,7 @@ class PresentationMediaItem(MediaManagerItem):
self.loadPresentationList(list)
self.DisplayTypeComboBox.addItem(u'Impress')
self.DisplayTypeComboBox.addItem(u'Powerpoint')
self.DisplayTypeComboBox.addItem(u'Keynote')
def onPresentationNewClick(self):
files = QtGui.QFileDialog.getOpenFileNames(None,