forked from openlp/openlp
standards for thememanager and more Registry
This commit is contained in:
parent
4c26ff8f80
commit
aa14303003
@ -128,7 +128,7 @@ class Renderer(object):
|
|||||||
The theme name.
|
The theme name.
|
||||||
"""
|
"""
|
||||||
if theme_name not in self._theme_dimensions:
|
if theme_name not in self._theme_dimensions:
|
||||||
theme_data = self.theme_manager.getThemeData(theme_name)
|
theme_data = self.theme_manager.get_theme_data(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]
|
||||||
|
@ -198,7 +198,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
self.themeComboBox.addItem(item.text())
|
self.themeComboBox.addItem(item.text())
|
||||||
if self.hasRunWizard:
|
if self.hasRunWizard:
|
||||||
# Add any existing themes to list.
|
# Add any existing themes to list.
|
||||||
for theme in self.parent().themeManagerContents.getThemes():
|
for theme in self.parent().themeManagerContents.get_themes():
|
||||||
index = self.themeComboBox.findText(theme)
|
index = self.themeComboBox.findText(theme)
|
||||||
if index == -1:
|
if index == -1:
|
||||||
self.themeComboBox.addItem(theme)
|
self.themeComboBox.addItem(theme)
|
||||||
|
@ -496,9 +496,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
self.copyData = False
|
self.copyData = False
|
||||||
# Set up signals and slots
|
# Set up signals and slots
|
||||||
QtCore.QObject.connect(self.importThemeItem, QtCore.SIGNAL(u'triggered()'),
|
QtCore.QObject.connect(self.importThemeItem, QtCore.SIGNAL(u'triggered()'),
|
||||||
self.themeManagerContents.onImportTheme)
|
self.themeManagerContents.on_import_theme)
|
||||||
QtCore.QObject.connect(self.exportThemeItem, QtCore.SIGNAL(u'triggered()'),
|
QtCore.QObject.connect(self.exportThemeItem, QtCore.SIGNAL(u'triggered()'),
|
||||||
self.themeManagerContents.onExportTheme)
|
self.themeManagerContents.on_export_theme)
|
||||||
QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||||
self.viewMediaManagerItem.setChecked)
|
self.viewMediaManagerItem.setChecked)
|
||||||
QtCore.QObject.connect(self.serviceManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
QtCore.QObject.connect(self.serviceManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||||
@ -576,7 +576,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
self.settingsForm.postSetUp()
|
self.settingsForm.postSetUp()
|
||||||
# Once all components are initialised load the Themes
|
# Once all components are initialised load the Themes
|
||||||
log.info(u'Load Themes')
|
log.info(u'Load Themes')
|
||||||
self.themeManagerContents.loadThemes(True)
|
self.themeManagerContents.load_themes(True)
|
||||||
# Hide/show the theme combobox on the service manager
|
# Hide/show the theme combobox on the service manager
|
||||||
self.serviceManagerContents.theme_change()
|
self.serviceManagerContents.theme_change()
|
||||||
# Reset the cursor
|
# Reset the cursor
|
||||||
@ -687,7 +687,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
self.activePlugin.toggleStatus(PluginStatus.Inactive)
|
self.activePlugin.toggleStatus(PluginStatus.Inactive)
|
||||||
self.themeManagerContents.configUpdated()
|
self.themeManagerContents.configUpdated()
|
||||||
self.themeManagerContents.loadThemes(True)
|
self.themeManagerContents.load_themes(True)
|
||||||
Receiver.send_message(u'theme_update_global', self.themeManagerContents.global_theme)
|
Receiver.send_message(u'theme_update_global', self.themeManagerContents.global_theme)
|
||||||
# Check if any Bibles downloaded. If there are, they will be
|
# Check if any Bibles downloaded. If there are, they will be
|
||||||
# processed.
|
# processed.
|
||||||
@ -760,7 +760,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
Updates the new theme preview images.
|
Updates the new theme preview images.
|
||||||
"""
|
"""
|
||||||
self.themeManagerContents.updatePreviewImages()
|
self.themeManagerContents.update_preview_images()
|
||||||
|
|
||||||
def onFormattingTagItemClicked(self):
|
def onFormattingTagItemClicked(self):
|
||||||
"""
|
"""
|
||||||
|
@ -32,7 +32,7 @@ import os
|
|||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import Receiver, translate, UiStrings
|
from openlp.core.lib import Receiver, translate, UiStrings, Registry
|
||||||
from openlp.core.lib.theme import BackgroundType, BackgroundGradientType
|
from openlp.core.lib.theme import BackgroundType, BackgroundGradientType
|
||||||
from openlp.core.lib.ui import critical_error_message_box
|
from openlp.core.lib.ui import critical_error_message_box
|
||||||
from openlp.core.ui import ThemeLayoutForm
|
from openlp.core.ui import ThemeLayoutForm
|
||||||
@ -56,7 +56,6 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
The QWidget-derived parent of the wizard.
|
The QWidget-derived parent of the wizard.
|
||||||
"""
|
"""
|
||||||
QtGui.QWizard.__init__(self, parent)
|
QtGui.QWizard.__init__(self, parent)
|
||||||
self.thememanager = parent
|
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.registerFields()
|
self.registerFields()
|
||||||
self.updateThemeAllowed = True
|
self.updateThemeAllowed = True
|
||||||
@ -149,7 +148,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
# Do not trigger on start up
|
# Do not trigger on start up
|
||||||
if self.currentPage != self.welcomePage:
|
if self.currentPage != self.welcomePage:
|
||||||
self.updateTheme()
|
self.updateTheme()
|
||||||
self.thememanager.generateImage(self.theme, True)
|
self.theme_manager.generate_image(self.theme, True)
|
||||||
|
|
||||||
def updateLinesText(self, lines):
|
def updateLinesText(self, lines):
|
||||||
"""
|
"""
|
||||||
@ -196,7 +195,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
self.setOption(QtGui.QWizard.HaveCustomButton1, enabled)
|
self.setOption(QtGui.QWizard.HaveCustomButton1, enabled)
|
||||||
if self.page(pageId) == self.previewPage:
|
if self.page(pageId) == self.previewPage:
|
||||||
self.updateTheme()
|
self.updateTheme()
|
||||||
frame = self.thememanager.generateImage(self.theme)
|
frame = self.theme_manager.generate_image(self.theme)
|
||||||
self.previewBoxLabel.setPixmap(frame)
|
self.previewBoxLabel.setPixmap(frame)
|
||||||
self.displayAspectRatio = float(frame.width()) / frame.height()
|
self.displayAspectRatio = float(frame.width()) / frame.height()
|
||||||
self.resizeEvent()
|
self.resizeEvent()
|
||||||
@ -206,15 +205,15 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
Generate layout preview and display the form.
|
Generate layout preview and display the form.
|
||||||
"""
|
"""
|
||||||
self.updateTheme()
|
self.updateTheme()
|
||||||
width = self.thememanager.mainwindow.renderer.width
|
width = self.renderer.width
|
||||||
height = self.thememanager.mainwindow.renderer.height
|
height = self.renderer.height
|
||||||
pixmap = QtGui.QPixmap(width, height)
|
pixmap = QtGui.QPixmap(width, height)
|
||||||
pixmap.fill(QtCore.Qt.white)
|
pixmap.fill(QtCore.Qt.white)
|
||||||
paint = QtGui.QPainter(pixmap)
|
paint = QtGui.QPainter(pixmap)
|
||||||
paint.setPen(QtGui.QPen(QtCore.Qt.blue, 2))
|
paint.setPen(QtGui.QPen(QtCore.Qt.blue, 2))
|
||||||
paint.drawRect(self.thememanager.mainwindow.renderer.get_main_rectangle(self.theme))
|
paint.drawRect(self.renderer.get_main_rectangle(self.theme))
|
||||||
paint.setPen(QtGui.QPen(QtCore.Qt.red, 2))
|
paint.setPen(QtGui.QPen(QtCore.Qt.red, 2))
|
||||||
paint.drawRect(self.thememanager.mainwindow.renderer.get_footer_rectangle(self.theme))
|
paint.drawRect(self.renderer.get_footer_rectangle(self.theme))
|
||||||
paint.end()
|
paint.end()
|
||||||
self.themeLayoutForm.exec_(pixmap)
|
self.themeLayoutForm.exec_(pixmap)
|
||||||
|
|
||||||
@ -514,9 +513,9 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
filename = os.path.split(unicode(self.theme.background_filename))[1]
|
filename = os.path.split(unicode(self.theme.background_filename))[1]
|
||||||
saveTo = os.path.join(self.path, self.theme.theme_name, filename)
|
saveTo = os.path.join(self.path, self.theme.theme_name, filename)
|
||||||
saveFrom = self.theme.background_filename
|
saveFrom = self.theme.background_filename
|
||||||
if not self.edit_mode and not self.thememanager.checkIfThemeExists(self.theme.theme_name):
|
if not self.edit_mode and not self.theme_manager.check_if_theme_exists(self.theme.theme_name):
|
||||||
return
|
return
|
||||||
self.thememanager.saveTheme(self.theme, saveFrom, saveTo)
|
self.theme_manager.save_theme(self.theme, saveFrom, saveTo)
|
||||||
return QtGui.QDialog.accept(self)
|
return QtGui.QDialog.accept(self)
|
||||||
|
|
||||||
def _colorButton(self, field):
|
def _colorButton(self, field):
|
||||||
@ -527,3 +526,24 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||||||
if new_color.isValid():
|
if new_color.isValid():
|
||||||
field = new_color.name()
|
field = new_color.name()
|
||||||
return field
|
return field
|
||||||
|
|
||||||
|
def _get_renderer(self):
|
||||||
|
"""
|
||||||
|
Adds the Renderer to the class dynamically
|
||||||
|
"""
|
||||||
|
if not hasattr(self, u'_renderer'):
|
||||||
|
self._renderer = Registry().get(u'renderer')
|
||||||
|
return self._renderer
|
||||||
|
|
||||||
|
renderer = property(_get_renderer)
|
||||||
|
|
||||||
|
def _get_theme_manager(self):
|
||||||
|
"""
|
||||||
|
Adds the theme manager to the class dynamically
|
||||||
|
"""
|
||||||
|
if not hasattr(self, u'_theme_manager'):
|
||||||
|
self._theme_manager = Registry().get(u'theme_manager')
|
||||||
|
return self._theme_manager
|
||||||
|
|
||||||
|
theme_manager = property(_get_theme_manager)
|
||||||
|
|
@ -72,67 +72,67 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
text=translate('OpenLP.ThemeManager', 'Edit Theme'),
|
text=translate('OpenLP.ThemeManager', 'Edit Theme'),
|
||||||
icon=u':/themes/theme_edit.png',
|
icon=u':/themes/theme_edit.png',
|
||||||
tooltip=translate('OpenLP.ThemeManager', 'Edit a theme.'),
|
tooltip=translate('OpenLP.ThemeManager', 'Edit a theme.'),
|
||||||
triggers=self.onEditTheme)
|
triggers=self.on_edit_theme)
|
||||||
self.deleteToolbarAction = self.toolbar.addToolbarAction(u'deleteTheme',
|
self.deleteToolbarAction = self.toolbar.addToolbarAction(u'delete_theme',
|
||||||
text=translate('OpenLP.ThemeManager', 'Delete Theme'),
|
text=translate('OpenLP.ThemeManager', 'Delete Theme'),
|
||||||
icon=u':/general/general_delete.png',
|
icon=u':/general/general_delete.png',
|
||||||
tooltip=translate('OpenLP.ThemeManager', 'Delete a theme.'),
|
tooltip=translate('OpenLP.ThemeManager', 'Delete a theme.'),
|
||||||
triggers=self.onDeleteTheme)
|
triggers=self.on_delete_theme)
|
||||||
self.toolbar.addSeparator()
|
self.toolbar.addSeparator()
|
||||||
self.toolbar.addToolbarAction(u'importTheme',
|
self.toolbar.addToolbarAction(u'importTheme',
|
||||||
text=translate('OpenLP.ThemeManager', 'Import Theme'),
|
text=translate('OpenLP.ThemeManager', 'Import Theme'),
|
||||||
icon=u':/general/general_import.png',
|
icon=u':/general/general_import.png',
|
||||||
tooltip=translate('OpenLP.ThemeManager', 'Import a theme.'),
|
tooltip=translate('OpenLP.ThemeManager', 'Import a theme.'),
|
||||||
triggers=self.onImportTheme)
|
triggers=self.on_import_theme)
|
||||||
self.toolbar.addToolbarAction(u'exportTheme',
|
self.toolbar.addToolbarAction(u'exportTheme',
|
||||||
text=translate('OpenLP.ThemeManager', 'Export Theme'),
|
text=translate('OpenLP.ThemeManager', 'Export Theme'),
|
||||||
icon=u':/general/general_export.png',
|
icon=u':/general/general_export.png',
|
||||||
tooltip=translate('OpenLP.ThemeManager', 'Export a theme.'),
|
tooltip=translate('OpenLP.ThemeManager', 'Export a theme.'),
|
||||||
triggers=self.onExportTheme)
|
triggers=self.on_export_theme)
|
||||||
self.layout.addWidget(self.toolbar)
|
self.layout.addWidget(self.toolbar)
|
||||||
self.themeWidget = QtGui.QWidgetAction(self.toolbar)
|
self.theme_widget = QtGui.QWidgetAction(self.toolbar)
|
||||||
self.themeWidget.setObjectName(u'themeWidget')
|
self.theme_widget.setObjectName(u'theme_widget')
|
||||||
# create theme manager list
|
# create theme manager list
|
||||||
self.themeListWidget = QtGui.QListWidget(self)
|
self.theme_list_widget = QtGui.QListWidget(self)
|
||||||
self.themeListWidget.setAlternatingRowColors(True)
|
self.theme_list_widget.setAlternatingRowColors(True)
|
||||||
self.themeListWidget.setIconSize(QtCore.QSize(88, 50))
|
self.theme_list_widget.setIconSize(QtCore.QSize(88, 50))
|
||||||
self.themeListWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
self.theme_list_widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||||
self.themeListWidget.setObjectName(u'themeListWidget')
|
self.theme_list_widget.setObjectName(u'theme_list_widget')
|
||||||
self.layout.addWidget(self.themeListWidget)
|
self.layout.addWidget(self.theme_list_widget)
|
||||||
QtCore.QObject.connect(self.themeListWidget, QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
|
QtCore.QObject.connect(self.theme_list_widget, QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
|
||||||
self.contextMenu)
|
self.context_menu)
|
||||||
# build the context menu
|
# build the context menu
|
||||||
self.menu = QtGui.QMenu()
|
self.menu = QtGui.QMenu()
|
||||||
self.editAction = create_widget_action(self.menu,
|
self.edit_action = create_widget_action(self.menu,
|
||||||
text=translate('OpenLP.ThemeManager', '&Edit Theme'),
|
text=translate('OpenLP.ThemeManager', '&Edit Theme'),
|
||||||
icon=u':/themes/theme_edit.png', triggers=self.onEditTheme)
|
icon=u':/themes/theme_edit.png', triggers=self.on_edit_theme)
|
||||||
self.copyAction = create_widget_action(self.menu,
|
self.copy_action = create_widget_action(self.menu,
|
||||||
text=translate('OpenLP.ThemeManager', '&Copy Theme'),
|
text=translate('OpenLP.ThemeManager', '&Copy Theme'),
|
||||||
icon=u':/themes/theme_edit.png', triggers=self.onCopyTheme)
|
icon=u':/themes/theme_edit.png', triggers=self.on_copy_theme)
|
||||||
self.renameAction = create_widget_action(self.menu,
|
self.rename_action = create_widget_action(self.menu,
|
||||||
text=translate('OpenLP.ThemeManager', '&Rename Theme'),
|
text=translate('OpenLP.ThemeManager', '&Rename Theme'),
|
||||||
icon=u':/themes/theme_edit.png', triggers=self.onRenameTheme)
|
icon=u':/themes/theme_edit.png', triggers=self.on_rename_theme)
|
||||||
self.deleteAction = create_widget_action(self.menu,
|
self.delete_action = create_widget_action(self.menu,
|
||||||
text=translate('OpenLP.ThemeManager', '&Delete Theme'),
|
text=translate('OpenLP.ThemeManager', '&Delete Theme'),
|
||||||
icon=u':/general/general_delete.png', triggers=self.onDeleteTheme)
|
icon=u':/general/general_delete.png', triggers=self.on_delete_theme)
|
||||||
self.menu.addSeparator()
|
self.menu.addSeparator()
|
||||||
self.globalAction = create_widget_action(self.menu,
|
self.global_action = create_widget_action(self.menu,
|
||||||
text=translate('OpenLP.ThemeManager', 'Set As &Global Default'),
|
text=translate('OpenLP.ThemeManager', 'Set As &Global Default'),
|
||||||
icon=u':/general/general_export.png',
|
icon=u':/general/general_export.png',
|
||||||
triggers=self.changeGlobalFromScreen)
|
triggers=self.changeGlobalFromScreen)
|
||||||
self.exportAction = create_widget_action(self.menu,
|
self.exportAction = create_widget_action(self.menu,
|
||||||
text=translate('OpenLP.ThemeManager', '&Export Theme'),
|
text=translate('OpenLP.ThemeManager', '&Export Theme'),
|
||||||
icon=u':/general/general_export.png', triggers=self.onExportTheme)
|
icon=u':/general/general_export.png', triggers=self.on_export_theme)
|
||||||
# Signals
|
# Signals
|
||||||
QtCore.QObject.connect(self.themeListWidget,
|
QtCore.QObject.connect(self.theme_list_widget,
|
||||||
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.changeGlobalFromScreen)
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.changeGlobalFromScreen)
|
||||||
QtCore.QObject.connect(self.themeListWidget,
|
QtCore.QObject.connect(self.theme_list_widget,
|
||||||
QtCore.SIGNAL(u'currentItemChanged(QListWidgetItem *, QListWidgetItem *)'), self.checkListState)
|
QtCore.SIGNAL(u'currentItemChanged(QListWidgetItem *, QListWidgetItem *)'), self.check_list_state)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'theme_update_global'), self.changeGlobalFromTab)
|
QtCore.SIGNAL(u'theme_update_global'), self.change_global_from_tab)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated)
|
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated)
|
||||||
# Variables
|
# Variables
|
||||||
self.themeList = []
|
self.theme_list = []
|
||||||
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
||||||
check_directory_exists(self.path)
|
check_directory_exists(self.path)
|
||||||
self.thumbPath = os.path.join(self.path, u'thumbnails')
|
self.thumbPath = os.path.join(self.path, u'thumbnails')
|
||||||
@ -141,27 +141,27 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
self.oldBackgroundImage = None
|
self.oldBackgroundImage = None
|
||||||
self.badV1NameChars = re.compile(r'[%+\[\]]')
|
self.badV1NameChars = re.compile(r'[%+\[\]]')
|
||||||
# Last little bits of setting up
|
# Last little bits of setting up
|
||||||
self.configUpdated()
|
self.config_updated()
|
||||||
|
|
||||||
def firstTime(self):
|
def first_time(self):
|
||||||
"""
|
"""
|
||||||
Import new themes downloaded by the first time wizard
|
Import new themes downloaded by the first time wizard
|
||||||
"""
|
"""
|
||||||
Receiver.send_message(u'cursor_busy')
|
Receiver.send_message(u'cursor_busy')
|
||||||
files = SettingsManager.get_files(self.settingsSection, u'.otz')
|
files = SettingsManager.get_files(self.settingsSection, u'.otz')
|
||||||
for file in files:
|
for file_name in files:
|
||||||
file = os.path.join(self.path, file)
|
file_name = os.path.join(self.path, file_name)
|
||||||
self.unzipTheme(file, self.path)
|
self.unzip_theme(file_name, self.path)
|
||||||
delete_file(file)
|
delete_file(file)
|
||||||
Receiver.send_message(u'cursor_normal')
|
Receiver.send_message(u'cursor_normal')
|
||||||
|
|
||||||
def configUpdated(self):
|
def config_updated(self):
|
||||||
"""
|
"""
|
||||||
Triggered when Config dialog is updated.
|
Triggered when Config dialog is updated.
|
||||||
"""
|
"""
|
||||||
self.global_theme = Settings().value(self.settingsSection + u'/global theme')
|
self.global_theme = Settings().value(self.settingsSection + u'/global theme')
|
||||||
|
|
||||||
def checkListState(self, item):
|
def check_list_state(self, item):
|
||||||
"""
|
"""
|
||||||
If Default theme selected remove delete button.
|
If Default theme selected remove delete button.
|
||||||
"""
|
"""
|
||||||
@ -175,41 +175,41 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
else:
|
else:
|
||||||
self.deleteToolbarAction.setVisible(False)
|
self.deleteToolbarAction.setVisible(False)
|
||||||
|
|
||||||
def contextMenu(self, point):
|
def context_menu(self, point):
|
||||||
"""
|
"""
|
||||||
Build the Right Click Context menu and set state depending on
|
Build the Right Click Context menu and set state depending on
|
||||||
the type of theme.
|
the type of theme.
|
||||||
"""
|
"""
|
||||||
item = self.themeListWidget.itemAt(point)
|
item = self.theme_list_widget.itemAt(point)
|
||||||
if item is None:
|
if item is None:
|
||||||
return
|
return
|
||||||
real_theme_name = item.data(QtCore.Qt.UserRole)
|
real_theme_name = item.data(QtCore.Qt.UserRole)
|
||||||
theme_name = unicode(item.text())
|
theme_name = unicode(item.text())
|
||||||
visible = real_theme_name == theme_name
|
visible = real_theme_name == theme_name
|
||||||
self.deleteAction.setVisible(visible)
|
self.delete_action.setVisible(visible)
|
||||||
self.renameAction.setVisible(visible)
|
self.rename_action.setVisible(visible)
|
||||||
self.globalAction.setVisible(visible)
|
self.global_action.setVisible(visible)
|
||||||
self.menu.exec_(self.themeListWidget.mapToGlobal(point))
|
self.menu.exec_(self.theme_list_widget.mapToGlobal(point))
|
||||||
|
|
||||||
def changeGlobalFromTab(self, theme_name):
|
def change_global_from_tab(self, theme_name):
|
||||||
"""
|
"""
|
||||||
Change the global theme when it is changed through the Themes settings
|
Change the global theme when it is changed through the Themes settings
|
||||||
tab
|
tab
|
||||||
"""
|
"""
|
||||||
log.debug(u'changeGlobalFromTab %s', theme_name)
|
log.debug(u'change_global_from_tab %s', theme_name)
|
||||||
for count in range (0, self.themeListWidget.count()):
|
for count in range (0, self.theme_list_widget.count()):
|
||||||
# reset the old name
|
# reset the old name
|
||||||
item = self.themeListWidget.item(count)
|
item = self.theme_list_widget.item(count)
|
||||||
old_name = item.text()
|
old_name = item.text()
|
||||||
new_name = item.data(QtCore.Qt.UserRole)
|
new_name = item.data(QtCore.Qt.UserRole)
|
||||||
if old_name != new_name:
|
if old_name != new_name:
|
||||||
self.themeListWidget.item(count).setText(new_name)
|
self.theme_list_widget.item(count).setText(new_name)
|
||||||
# Set the new name
|
# Set the new name
|
||||||
if theme_name == new_name:
|
if theme_name == new_name:
|
||||||
name = translate('OpenLP.ThemeManager', '%s (default)') % new_name
|
name = translate('OpenLP.ThemeManager', '%s (default)') % new_name
|
||||||
self.themeListWidget.item(count).setText(name)
|
self.theme_list_widget.item(count).setText(name)
|
||||||
self.deleteToolbarAction.setVisible(
|
self.deleteToolbarAction.setVisible(
|
||||||
item not in self.themeListWidget.selectedItems())
|
item not in self.theme_list_widget.selectedItems())
|
||||||
|
|
||||||
def changeGlobalFromScreen(self, index=-1):
|
def changeGlobalFromScreen(self, index=-1):
|
||||||
"""
|
"""
|
||||||
@ -217,21 +217,21 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
Theme Manager list
|
Theme Manager list
|
||||||
"""
|
"""
|
||||||
log.debug(u'changeGlobalFromScreen %s', index)
|
log.debug(u'changeGlobalFromScreen %s', index)
|
||||||
selected_row = self.themeListWidget.currentRow()
|
selected_row = self.theme_list_widget.currentRow()
|
||||||
for count in range (0, self.themeListWidget.count()):
|
for count in range (0, self.theme_list_widget.count()):
|
||||||
item = self.themeListWidget.item(count)
|
item = self.theme_list_widget.item(count)
|
||||||
old_name = item.text()
|
old_name = item.text()
|
||||||
# reset the old name
|
# reset the old name
|
||||||
if old_name != item.data(QtCore.Qt.UserRole):
|
if old_name != item.data(QtCore.Qt.UserRole):
|
||||||
self.themeListWidget.item(count).setText(item.data(QtCore.Qt.UserRole))
|
self.theme_list_widget.item(count).setText(item.data(QtCore.Qt.UserRole))
|
||||||
# Set the new name
|
# Set the new name
|
||||||
if count == selected_row:
|
if count == selected_row:
|
||||||
self.global_theme = self.themeListWidget.item(count).text()
|
self.global_theme = self.theme_list_widget.item(count).text()
|
||||||
name = translate('OpenLP.ThemeManager', '%s (default)') % self.global_theme
|
name = translate('OpenLP.ThemeManager', '%s (default)') % self.global_theme
|
||||||
self.themeListWidget.item(count).setText(name)
|
self.theme_list_widget.item(count).setText(name)
|
||||||
Settings().setValue(self.settingsSection + u'/global theme', self.global_theme)
|
Settings().setValue(self.settingsSection + u'/global theme', self.global_theme)
|
||||||
Receiver.send_message(u'theme_update_global', self.global_theme)
|
Receiver.send_message(u'theme_update_global', self.global_theme)
|
||||||
self._pushThemes()
|
self._push_themes()
|
||||||
|
|
||||||
def onAddTheme(self):
|
def onAddTheme(self):
|
||||||
"""
|
"""
|
||||||
@ -242,44 +242,44 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
theme.set_default_header_footer()
|
theme.set_default_header_footer()
|
||||||
self.themeForm.theme = theme
|
self.themeForm.theme = theme
|
||||||
self.themeForm.exec_()
|
self.themeForm.exec_()
|
||||||
self.loadThemes()
|
self.load_themes()
|
||||||
|
|
||||||
def onRenameTheme(self):
|
def on_rename_theme(self):
|
||||||
"""
|
"""
|
||||||
Renames an existing theme to a new name
|
Renames an existing theme to a new name
|
||||||
"""
|
"""
|
||||||
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to rename.'),
|
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to rename.'),
|
||||||
translate('OpenLP.ThemeManager', 'Rename Confirmation'),
|
translate('OpenLP.ThemeManager', 'Rename Confirmation'),
|
||||||
translate('OpenLP.ThemeManager', 'Rename %s theme?'), False, False):
|
translate('OpenLP.ThemeManager', 'Rename %s theme?'), False, False):
|
||||||
item = self.themeListWidget.currentItem()
|
item = self.theme_list_widget.currentItem()
|
||||||
old_theme_name = item.data(QtCore.Qt.UserRole)
|
old_theme_name = item.data(QtCore.Qt.UserRole)
|
||||||
self.fileRenameForm.fileNameEdit.setText(old_theme_name)
|
self.fileRenameForm.fileNameEdit.setText(old_theme_name)
|
||||||
if self.fileRenameForm.exec_():
|
if self.fileRenameForm.exec_():
|
||||||
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
||||||
if old_theme_name == new_theme_name:
|
if old_theme_name == new_theme_name:
|
||||||
return
|
return
|
||||||
if self.checkIfThemeExists(new_theme_name):
|
if self.check_if_theme_exists(new_theme_name):
|
||||||
old_theme_data = self.getThemeData(old_theme_name)
|
old_theme_data = self.get_theme_data(old_theme_name)
|
||||||
self.cloneThemeData(old_theme_data, new_theme_name)
|
self.cloneThemeData(old_theme_data, new_theme_name)
|
||||||
self.deleteTheme(old_theme_name)
|
self.delete_theme(old_theme_name)
|
||||||
for plugin in self.plugin_manager.plugins:
|
for plugin in self.plugin_manager.plugins:
|
||||||
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.renderer.update_theme(new_theme_name, old_theme_name)
|
self.renderer.update_theme(new_theme_name, old_theme_name)
|
||||||
self.loadThemes()
|
self.load_themes()
|
||||||
|
|
||||||
def onCopyTheme(self):
|
def on_copy_theme(self):
|
||||||
"""
|
"""
|
||||||
Copies an existing theme to a new name
|
Copies an existing theme to a new name
|
||||||
"""
|
"""
|
||||||
item = self.themeListWidget.currentItem()
|
item = self.theme_list_widget.currentItem()
|
||||||
old_theme_name = item.data(QtCore.Qt.UserRole)
|
old_theme_name = item.data(QtCore.Qt.UserRole)
|
||||||
self.fileRenameForm.fileNameEdit.setText(translate('OpenLP.ThemeManager',
|
self.fileRenameForm.fileNameEdit.setText(translate('OpenLP.ThemeManager',
|
||||||
'Copy of %s', 'Copy of <theme name>') % old_theme_name)
|
'Copy of %s', 'Copy of <theme name>') % old_theme_name)
|
||||||
if self.fileRenameForm.exec_(True):
|
if self.fileRenameForm.exec_(True):
|
||||||
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
||||||
if self.checkIfThemeExists(new_theme_name):
|
if self.check_if_theme_exists(new_theme_name):
|
||||||
theme_data = self.getThemeData(old_theme_name)
|
theme_data = self.get_theme_data(old_theme_name)
|
||||||
self.cloneThemeData(theme_data, new_theme_name)
|
self.cloneThemeData(theme_data, new_theme_name)
|
||||||
|
|
||||||
def cloneThemeData(self, theme_data, new_theme_name):
|
def cloneThemeData(self, theme_data, new_theme_name):
|
||||||
@ -295,51 +295,51 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
save_from = theme_data.background_filename
|
save_from = theme_data.background_filename
|
||||||
theme_data.theme_name = new_theme_name
|
theme_data.theme_name = new_theme_name
|
||||||
theme_data.extend_image_filename(self.path)
|
theme_data.extend_image_filename(self.path)
|
||||||
self.saveTheme(theme_data, save_from, save_to)
|
self.save_theme(theme_data, save_from, save_to)
|
||||||
self.loadThemes()
|
self.load_themes()
|
||||||
|
|
||||||
def onEditTheme(self):
|
def on_edit_theme(self):
|
||||||
"""
|
"""
|
||||||
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.theme_list_widget,
|
||||||
translate('OpenLP.ThemeManager', 'You must select a theme to edit.')):
|
translate('OpenLP.ThemeManager', 'You must select a theme to edit.')):
|
||||||
item = self.themeListWidget.currentItem()
|
item = self.theme_list_widget.currentItem()
|
||||||
theme = self.getThemeData(item.data(QtCore.Qt.UserRole))
|
theme = self.get_theme_data(item.data(QtCore.Qt.UserRole))
|
||||||
if theme.background_type == u'image':
|
if theme.background_type == u'image':
|
||||||
self.oldBackgroundImage = theme.background_filename
|
self.oldBackgroundImage = theme.background_filename
|
||||||
self.themeForm.theme = theme
|
self.themeForm.theme = theme
|
||||||
self.themeForm.exec_(True)
|
self.themeForm.exec_(True)
|
||||||
self.oldBackgroundImage = None
|
self.oldBackgroundImage = None
|
||||||
self.renderer.update_theme(theme.theme_name)
|
self.renderer.update_theme(theme.theme_name)
|
||||||
self.loadThemes()
|
self.load_themes()
|
||||||
|
|
||||||
def onDeleteTheme(self):
|
def on_delete_theme(self):
|
||||||
"""
|
"""
|
||||||
Delete a theme
|
Delete a theme
|
||||||
"""
|
"""
|
||||||
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'),
|
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'),
|
||||||
translate('OpenLP.ThemeManager', 'Delete Confirmation'),
|
translate('OpenLP.ThemeManager', 'Delete Confirmation'),
|
||||||
translate('OpenLP.ThemeManager', 'Delete %s theme?')):
|
translate('OpenLP.ThemeManager', 'Delete %s theme?')):
|
||||||
item = self.themeListWidget.currentItem()
|
item = self.theme_list_widget.currentItem()
|
||||||
theme = item.text()
|
theme = item.text()
|
||||||
row = self.themeListWidget.row(item)
|
row = self.theme_list_widget.row(item)
|
||||||
self.themeListWidget.takeItem(row)
|
self.theme_list_widget.takeItem(row)
|
||||||
self.deleteTheme(theme)
|
self.delete_theme(theme)
|
||||||
self.renderer.update_theme(theme, only_delete=True)
|
self.renderer.update_theme(theme, only_delete=True)
|
||||||
# As we do not reload the themes, push out the change. Reload the
|
# As we do not reload the themes, push out the change. Reload the
|
||||||
# list as the internal lists and events need to be triggered.
|
# list as the internal lists and events need to be triggered.
|
||||||
self._pushThemes()
|
self._push_themes()
|
||||||
|
|
||||||
def deleteTheme(self, theme):
|
def delete_theme(self, theme):
|
||||||
"""
|
"""
|
||||||
Delete a theme.
|
Delete a theme.
|
||||||
|
|
||||||
``theme``
|
``theme``
|
||||||
The theme to delete.
|
The theme to delete.
|
||||||
"""
|
"""
|
||||||
self.themeList.remove(theme)
|
self.theme_list.remove(theme)
|
||||||
thumb = u'%s.png' % theme
|
thumb = u'%s.png' % theme
|
||||||
delete_file(os.path.join(self.path, thumb))
|
delete_file(os.path.join(self.path, thumb))
|
||||||
delete_file(os.path.join(self.thumbPath, thumb))
|
delete_file(os.path.join(self.thumbPath, thumb))
|
||||||
@ -349,11 +349,11 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
except OSError, shutil.Error:
|
except OSError, shutil.Error:
|
||||||
log.exception(u'Error deleting theme %s', theme)
|
log.exception(u'Error deleting theme %s', theme)
|
||||||
|
|
||||||
def onExportTheme(self):
|
def on_export_theme(self):
|
||||||
"""
|
"""
|
||||||
Export the theme in a zip file
|
Export the theme in a zip file
|
||||||
"""
|
"""
|
||||||
item = self.themeListWidget.currentItem()
|
item = self.theme_list_widget.currentItem()
|
||||||
if item is None:
|
if item is None:
|
||||||
critical_error_message_box(message=translate('OpenLP.ThemeManager', 'You have not selected a theme.'))
|
critical_error_message_box(message=translate('OpenLP.ThemeManager', 'You have not selected a theme.'))
|
||||||
return
|
return
|
||||||
@ -366,29 +366,26 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
Settings().setValue(self.settingsSection + u'/last directory export', path)
|
Settings().setValue(self.settingsSection + u'/last directory export', path)
|
||||||
theme_path = os.path.join(path, theme + u'.otz')
|
theme_path = os.path.join(path, theme + u'.otz')
|
||||||
# FIXME: Do not overwrite build-in.
|
# FIXME: Do not overwrite build-in.
|
||||||
zip = None
|
zip_file = None
|
||||||
try:
|
try:
|
||||||
zip = zipfile.ZipFile(theme_path, u'w')
|
zip_file = zipfile.ZipFile(theme_path, u'w')
|
||||||
source = os.path.join(self.path, theme)
|
source = os.path.join(self.path, theme)
|
||||||
for files in os.walk(source):
|
for files in os.walk(source):
|
||||||
for name in files[2]:
|
for name in files[2]:
|
||||||
zip.write(
|
zip_file.write(os.path.join(source, name).encode(u'utf-8'),
|
||||||
os.path.join(source, name).encode(u'utf-8'),
|
|
||||||
os.path.join(theme, name).encode(u'utf-8'))
|
os.path.join(theme, name).encode(u'utf-8'))
|
||||||
QtGui.QMessageBox.information(self,
|
QtGui.QMessageBox.information(self, translate('OpenLP.ThemeManager', 'Theme Exported'),
|
||||||
translate('OpenLP.ThemeManager', 'Theme Exported'),
|
|
||||||
translate('OpenLP.ThemeManager', 'Your theme has been successfully exported.'))
|
translate('OpenLP.ThemeManager', 'Your theme has been successfully exported.'))
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
log.exception(u'Export Theme Failed')
|
log.exception(u'Export Theme Failed')
|
||||||
critical_error_message_box(
|
critical_error_message_box(translate('OpenLP.ThemeManager', 'Theme Export Failed'),
|
||||||
translate('OpenLP.ThemeManager', 'Theme Export Failed'),
|
|
||||||
translate('OpenLP.ThemeManager', 'Your theme could not be exported due to an error.'))
|
translate('OpenLP.ThemeManager', 'Your theme could not be exported due to an error.'))
|
||||||
finally:
|
finally:
|
||||||
if zip:
|
if zip_file:
|
||||||
zip.close()
|
zip_file.close()
|
||||||
Receiver.send_message(u'cursor_normal')
|
Receiver.send_message(u'cursor_normal')
|
||||||
|
|
||||||
def onImportTheme(self):
|
def on_import_theme(self):
|
||||||
"""
|
"""
|
||||||
Opens a file dialog to select the theme file(s) to import before
|
Opens a file dialog to select the theme file(s) to import before
|
||||||
attempting to extract OpenLP themes from those files. This process
|
attempting to extract OpenLP themes from those files. This process
|
||||||
@ -402,36 +399,35 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
if not files:
|
if not files:
|
||||||
return
|
return
|
||||||
Receiver.send_message(u'cursor_busy')
|
Receiver.send_message(u'cursor_busy')
|
||||||
for file in files:
|
for file_name in files:
|
||||||
Settings().setValue(self.settingsSection + u'/last directory import', unicode(file))
|
Settings().setValue(self.settingsSection + u'/last directory import', unicode(file_name))
|
||||||
self.unzipTheme(file, self.path)
|
self.unzip_theme(file_name, self.path)
|
||||||
self.loadThemes()
|
self.load_themes()
|
||||||
Receiver.send_message(u'cursor_normal')
|
Receiver.send_message(u'cursor_normal')
|
||||||
|
|
||||||
def loadThemes(self, firstTime=False):
|
def load_themes(self, first_time=False):
|
||||||
"""
|
"""
|
||||||
Loads the theme lists and triggers updates accross the whole system
|
Loads the theme lists and triggers updates accross the whole system
|
||||||
using direct calls or core functions and events for the plugins.
|
using direct calls or core functions and events for the plugins.
|
||||||
The plugins will call back in to get the real list if they want it.
|
The plugins will call back in to get the real list if they want it.
|
||||||
"""
|
"""
|
||||||
log.debug(u'Load themes from dir')
|
log.debug(u'Load themes from dir')
|
||||||
self.themeList = []
|
self.theme_list = []
|
||||||
self.themeListWidget.clear()
|
self.theme_list_widget.clear()
|
||||||
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
||||||
if firstTime:
|
if first_time:
|
||||||
self.firstTime()
|
self.first_time()
|
||||||
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
||||||
# No themes have been found so create one
|
# No themes have been found so create one
|
||||||
if not files:
|
if not files:
|
||||||
theme = ThemeXML()
|
theme = ThemeXML()
|
||||||
theme.theme_name = UiStrings().Default
|
theme.theme_name = UiStrings().Default
|
||||||
self._writeTheme(theme, None, None)
|
self._write_theme(theme, None, None)
|
||||||
Settings().setValue(self.settingsSection + u'/global theme', theme.theme_name)
|
Settings().setValue(self.settingsSection + u'/global theme', theme.theme_name)
|
||||||
self.configUpdated()
|
self.config_updated()
|
||||||
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
||||||
# Sort the themes by its name considering language specific
|
# Sort the themes by its name considering language specific
|
||||||
files.sort(key=lambda file_name: unicode(file_name),
|
files.sort(key=lambda file_name: unicode(file_name), cmp=locale_compare)
|
||||||
cmp=locale_compare)
|
|
||||||
# now process the file list of png files
|
# now process the file list of png files
|
||||||
for name in files:
|
for name in files:
|
||||||
# check to see file is in theme root directory
|
# check to see file is in theme root directory
|
||||||
@ -450,23 +446,23 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
icon = create_thumb(theme, thumb)
|
icon = create_thumb(theme, thumb)
|
||||||
item_name.setIcon(icon)
|
item_name.setIcon(icon)
|
||||||
item_name.setData(QtCore.Qt.UserRole, text_name)
|
item_name.setData(QtCore.Qt.UserRole, text_name)
|
||||||
self.themeListWidget.addItem(item_name)
|
self.theme_list_widget.addItem(item_name)
|
||||||
self.themeList.append(text_name)
|
self.theme_list.append(text_name)
|
||||||
self._pushThemes()
|
self._push_themes()
|
||||||
|
|
||||||
def _pushThemes(self):
|
def _push_themes(self):
|
||||||
"""
|
"""
|
||||||
Notify listeners that the theme list has been updated
|
Notify listeners that the theme list has been updated
|
||||||
"""
|
"""
|
||||||
Receiver.send_message(u'theme_update_list', self.getThemes())
|
Receiver.send_message(u'theme_update_list', self.get_themes())
|
||||||
|
|
||||||
def getThemes(self):
|
def get_themes(self):
|
||||||
"""
|
"""
|
||||||
Return the list of loaded themes
|
Return the list of loaded themes
|
||||||
"""
|
"""
|
||||||
return self.themeList
|
return self.theme_list
|
||||||
|
|
||||||
def getThemeData(self, theme_name):
|
def get_theme_data(self, theme_name):
|
||||||
"""
|
"""
|
||||||
Returns a theme object from an XML file
|
Returns a theme object from an XML file
|
||||||
|
|
||||||
@ -480,18 +476,20 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
log.debug(u'No theme data - using default theme')
|
log.debug(u'No theme data - using default theme')
|
||||||
return ThemeXML()
|
return ThemeXML()
|
||||||
else:
|
else:
|
||||||
return self._createThemeFromXml(xml, self.path)
|
return self._create_theme_fom_Xml(xml, self.path)
|
||||||
|
|
||||||
def overWriteMessageBox(self, theme_name):
|
def over_write_message_box(self, theme_name):
|
||||||
ret = QtGui.QMessageBox.question(self,
|
"""
|
||||||
translate('OpenLP.ThemeManager', 'Theme Already Exists'),
|
Check before overwriting the theme
|
||||||
|
"""
|
||||||
|
ret = QtGui.QMessageBox.question(self, translate('OpenLP.ThemeManager', 'Theme Already Exists'),
|
||||||
translate('OpenLP.ThemeManager',
|
translate('OpenLP.ThemeManager',
|
||||||
'Theme %s already exists. Do you want to replace it?').replace('%s', theme_name),
|
'Theme %s already exists. Do you want to replace it?').replace('%s', theme_name),
|
||||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
|
||||||
QtGui.QMessageBox.No)
|
QtGui.QMessageBox.No)
|
||||||
return ret == QtGui.QMessageBox.Yes
|
return ret == QtGui.QMessageBox.Yes
|
||||||
|
|
||||||
def unzipTheme(self, file_name, dir):
|
def unzip_theme(self, file_name, dir):
|
||||||
"""
|
"""
|
||||||
Unzip the theme, remove the preview file if stored
|
Unzip the theme, remove the preview file if stored
|
||||||
Generate a new preview file. Check the XML theme version and upgrade if
|
Generate a new preview file. Check the XML theme version and upgrade if
|
||||||
@ -499,32 +497,32 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
log.debug(u'Unzipping theme %s', file_name)
|
log.debug(u'Unzipping theme %s', file_name)
|
||||||
file_name = unicode(file_name)
|
file_name = unicode(file_name)
|
||||||
zip = None
|
zip_file = None
|
||||||
out_file = None
|
out_file = None
|
||||||
file_xml = None
|
file_xml = None
|
||||||
abort_import = True
|
abort_import = True
|
||||||
try:
|
try:
|
||||||
zip = zipfile.ZipFile(file_name)
|
zip_file = zipfile.ZipFile(file_name)
|
||||||
xml_file = filter(lambda name:
|
xml_file = filter(lambda name:
|
||||||
os.path.splitext(name)[1].lower() == u'.xml', zip.namelist())
|
os.path.splitext(name)[1].lower() == u'.xml', zip_file.namelist())
|
||||||
if len(xml_file) != 1:
|
if len(xml_file) != 1:
|
||||||
log.exception(u'Theme contains "%s" XML files' % len(xml_file))
|
log.exception(u'Theme contains "%s" XML files' % len(xml_file))
|
||||||
raise Exception(u'validation')
|
raise Exception('validation')
|
||||||
xml_tree = ElementTree(element=XML(zip.read(xml_file[0]))).getroot()
|
xml_tree = ElementTree(element=XML(zip_file.read(xml_file[0]))).getroot()
|
||||||
v1_background = xml_tree.find(u'BackgroundType')
|
v1_background = xml_tree.find(u'BackgroundType')
|
||||||
if v1_background is not None:
|
if v1_background is not None:
|
||||||
theme_name, file_xml, out_file, abort_import = self.unzipVersion122(
|
theme_name, file_xml, out_file, abort_import = self.unzip_version_122(
|
||||||
dir, zip, xml_file[0], xml_tree, v1_background, out_file)
|
dir, zip_file, xml_file[0], xml_tree, v1_background, out_file)
|
||||||
else:
|
else:
|
||||||
theme_name = xml_tree.find(u'name').text.strip()
|
theme_name = xml_tree.find(u'name').text.strip()
|
||||||
theme_folder = os.path.join(dir, theme_name)
|
theme_folder = os.path.join(dir, theme_name)
|
||||||
theme_exists = os.path.exists(theme_folder)
|
theme_exists = os.path.exists(theme_folder)
|
||||||
if theme_exists and not self.overWriteMessageBox(theme_name):
|
if theme_exists and not self.over_write_message_box(theme_name):
|
||||||
abort_import = True
|
abort_import = True
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
abort_import = False
|
abort_import = False
|
||||||
for name in zip.namelist():
|
for name in zip_file.namelist():
|
||||||
try:
|
try:
|
||||||
uname = unicode(name, u'utf-8')
|
uname = unicode(name, u'utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
@ -539,12 +537,12 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
full_name = os.path.join(dir, uname)
|
full_name = os.path.join(dir, uname)
|
||||||
check_directory_exists(os.path.dirname(full_name))
|
check_directory_exists(os.path.dirname(full_name))
|
||||||
if os.path.splitext(uname)[1].lower() == u'.xml':
|
if os.path.splitext(uname)[1].lower() == u'.xml':
|
||||||
file_xml = unicode(zip.read(name), u'utf-8')
|
file_xml = unicode(zip_file.read(name), u'utf-8')
|
||||||
out_file = open(full_name, u'w')
|
out_file = open(full_name, u'w')
|
||||||
out_file.write(file_xml.encode(u'utf-8'))
|
out_file.write(file_xml.encode(u'utf-8'))
|
||||||
else:
|
else:
|
||||||
out_file = open(full_name, u'wb')
|
out_file = open(full_name, u'wb')
|
||||||
out_file.write(zip.read(name))
|
out_file.write(zip_file.read(name))
|
||||||
out_file.close()
|
out_file.close()
|
||||||
except (IOError, zipfile.BadZipfile):
|
except (IOError, zipfile.BadZipfile):
|
||||||
log.exception(u'Importing theme from zip failed %s' % file_name)
|
log.exception(u'Importing theme from zip failed %s' % file_name)
|
||||||
@ -557,15 +555,15 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
# Close the files, to be able to continue creating the theme.
|
# Close the files, to be able to continue creating the theme.
|
||||||
if zip:
|
if zip_file:
|
||||||
zip.close()
|
zip_file.close()
|
||||||
if out_file:
|
if out_file:
|
||||||
out_file.close()
|
out_file.close()
|
||||||
if not abort_import:
|
if not abort_import:
|
||||||
# As all files are closed, we can create the Theme.
|
# As all files are closed, we can create the Theme.
|
||||||
if file_xml:
|
if file_xml:
|
||||||
theme = self._createThemeFromXml(file_xml, self.path)
|
theme = self._create_theme_fom_Xml(file_xml, self.path)
|
||||||
self.generateAndSaveImage(dir, theme_name, theme)
|
self.generate_and_save_image(dir, theme_name, theme)
|
||||||
# Only show the error message, when IOError was not raised (in
|
# Only show the error message, when IOError was not raised (in
|
||||||
# this case the error message has already been shown).
|
# this case the error message has already been shown).
|
||||||
elif zip is not None:
|
elif zip is not None:
|
||||||
@ -574,22 +572,21 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
translate('OpenLP.ThemeManager', 'File is not a valid theme.'))
|
translate('OpenLP.ThemeManager', 'File is not a valid theme.'))
|
||||||
log.exception(u'Theme file does not contain XML data %s' % file_name)
|
log.exception(u'Theme file does not contain XML data %s' % file_name)
|
||||||
|
|
||||||
def unzipVersion122(self, dir, zip, xml_file, xml_tree, background,
|
def unzip_version_122(self, dir_name, zip_file, xml_file, xml_tree, background, out_file):
|
||||||
out_file):
|
|
||||||
"""
|
"""
|
||||||
Unzip openlp.org 1.2x theme file and upgrade the theme xml. When calling
|
Unzip openlp.org 1.2x theme file and upgrade the theme xml. When calling
|
||||||
this method, please keep in mind, that some parameters are redundant.
|
this method, please keep in mind, that some parameters are redundant.
|
||||||
"""
|
"""
|
||||||
theme_name = xml_tree.find(u'Name').text.strip()
|
theme_name = xml_tree.find(u'Name').text.strip()
|
||||||
theme_name = self.badV1NameChars.sub(u'', theme_name)
|
theme_name = self.badV1NameChars.sub(u'', theme_name)
|
||||||
theme_folder = os.path.join(dir, theme_name)
|
theme_folder = os.path.join(dir_name, theme_name)
|
||||||
theme_exists = os.path.exists(theme_folder)
|
theme_exists = os.path.exists(theme_folder)
|
||||||
if theme_exists and not self.overWriteMessageBox(theme_name):
|
if theme_exists and not self.over_write_message_box(theme_name):
|
||||||
return '', '', '', True
|
return '', '', '', True
|
||||||
themedir = os.path.join(dir, theme_name)
|
themedir = os.path.join(dir_name, theme_name)
|
||||||
check_directory_exists(themedir)
|
check_directory_exists(themedir)
|
||||||
file_xml = unicode(zip.read(xml_file), u'utf-8')
|
file_xml = unicode(zip_file.read(xml_file), u'utf-8')
|
||||||
file_xml = self._migrateVersion122(file_xml)
|
file_xml = self._migrate_version_122(file_xml)
|
||||||
out_file = open(os.path.join(themedir, theme_name + u'.xml'), u'w')
|
out_file = open(os.path.join(themedir, theme_name + u'.xml'), u'w')
|
||||||
out_file.write(file_xml.encode(u'utf-8'))
|
out_file.write(file_xml.encode(u'utf-8'))
|
||||||
out_file.close()
|
out_file.close()
|
||||||
@ -597,18 +594,17 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
image_name = xml_tree.find(u'BackgroundParameter1').text.strip()
|
image_name = xml_tree.find(u'BackgroundParameter1').text.strip()
|
||||||
# image file has same extension and is in subfolder
|
# image file has same extension and is in subfolder
|
||||||
image_file = filter(lambda name: os.path.splitext(name)[1].lower()
|
image_file = filter(lambda name: os.path.splitext(name)[1].lower()
|
||||||
== os.path.splitext(image_name)[1].lower() and name.find(r'/'),
|
== os.path.splitext(image_name)[1].lower() and name.find(r'/'), zip_file.namelist())
|
||||||
zip.namelist())
|
|
||||||
if len(image_file) >= 1:
|
if len(image_file) >= 1:
|
||||||
out_file = open(os.path.join(themedir, image_name), u'wb')
|
out_file = open(os.path.join(themedir, image_name), u'wb')
|
||||||
out_file.write(zip.read(image_file[0]))
|
out_file.write(zip_file.read(image_file[0]))
|
||||||
out_file.close()
|
out_file.close()
|
||||||
else:
|
else:
|
||||||
log.exception(u'Theme file does not contain image file "%s"' % image_name.decode(u'utf-8', u'replace'))
|
log.exception(u'Theme file does not contain image file "%s"' % image_name.decode(u'utf-8', u'replace'))
|
||||||
raise Exception(u'validation')
|
raise Exception(u'validation')
|
||||||
return theme_name, file_xml, out_file, False
|
return theme_name, file_xml, out_file, False
|
||||||
|
|
||||||
def checkIfThemeExists(self, theme_name):
|
def check_if_theme_exists(self, theme_name):
|
||||||
"""
|
"""
|
||||||
Check if theme already exists and displays error message
|
Check if theme already exists and displays error message
|
||||||
|
|
||||||
@ -623,25 +619,25 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def saveTheme(self, theme, image_from, image_to):
|
def save_theme(self, theme, image_from, image_to):
|
||||||
"""
|
"""
|
||||||
Called by thememaintenance Dialog to save the theme
|
Called by thememaintenance Dialog to save the theme
|
||||||
and to trigger the reload of the theme list
|
and to trigger the reload of the theme list
|
||||||
"""
|
"""
|
||||||
self._writeTheme(theme, image_from, image_to)
|
self._write_theme(theme, image_from, image_to)
|
||||||
if theme.background_type == BackgroundType.to_string(BackgroundType.Image):
|
if theme.background_type == BackgroundType.to_string(BackgroundType.Image):
|
||||||
self.image_manager.updateImageBorder(theme.background_filename,
|
self.image_manager.updateImageBorder(theme.background_filename,
|
||||||
ImageSource.Theme, QtGui.QColor(theme.background_border_color))
|
ImageSource.Theme, QtGui.QColor(theme.background_border_color))
|
||||||
self.image_manager.processUpdates()
|
self.image_manager.processUpdates()
|
||||||
|
|
||||||
def _writeTheme(self, theme, image_from, image_to):
|
def _write_theme(self, theme, image_from, image_to):
|
||||||
"""
|
"""
|
||||||
Writes the theme to the disk and handles the background image if
|
Writes the theme to the disk and handles the background image if
|
||||||
necessary
|
necessary
|
||||||
"""
|
"""
|
||||||
name = theme.theme_name
|
name = theme.theme_name
|
||||||
theme_pretty_xml = theme.extract_formatted_xml()
|
theme_pretty_xml = theme.extract_formatted_xml()
|
||||||
log.debug(u'saveTheme %s %s', name, theme_pretty_xml.decode(u'utf-8'))
|
log.debug(u'save_theme %s %s', name, theme_pretty_xml.decode(u'utf-8'))
|
||||||
theme_dir = os.path.join(self.path, name)
|
theme_dir = os.path.join(self.path, name)
|
||||||
check_directory_exists(theme_dir)
|
check_directory_exists(theme_dir)
|
||||||
theme_file = os.path.join(theme_dir, name + u'.xml')
|
theme_file = os.path.join(theme_dir, name + u'.xml')
|
||||||
@ -662,11 +658,14 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
shutil.copyfile(unicode(image_from).encode(encoding), unicode(image_to).encode(encoding))
|
shutil.copyfile(unicode(image_from).encode(encoding), unicode(image_to).encode(encoding))
|
||||||
except IOError, shutil.Error:
|
except IOError, shutil.Error:
|
||||||
log.exception(u'Failed to save theme image')
|
log.exception(u'Failed to save theme image')
|
||||||
self.generateAndSaveImage(self.path, name, theme)
|
self.generate_and_save_image(self.path, name, theme)
|
||||||
|
|
||||||
def generateAndSaveImage(self, dir, name, theme):
|
def generate_and_save_image(self, dir, name, theme):
|
||||||
log.debug(u'generateAndSaveImage %s %s', dir, name)
|
"""
|
||||||
frame = self.generateImage(theme)
|
Generate and Save the theme image.
|
||||||
|
"""
|
||||||
|
log.debug(u'generate_and_save_image %s %s', dir, name)
|
||||||
|
frame = self.generate_image(theme)
|
||||||
sample_path_name = os.path.join(self.path, name + u'.png')
|
sample_path_name = os.path.join(self.path, name + u'.png')
|
||||||
if os.path.exists(sample_path_name):
|
if os.path.exists(sample_path_name):
|
||||||
os.unlink(sample_path_name)
|
os.unlink(sample_path_name)
|
||||||
@ -675,18 +674,18 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
create_thumb(sample_path_name, thumb, False)
|
create_thumb(sample_path_name, thumb, False)
|
||||||
log.debug(u'Theme image written to %s', sample_path_name)
|
log.debug(u'Theme image written to %s', sample_path_name)
|
||||||
|
|
||||||
def updatePreviewImages(self):
|
def update_preview_images(self):
|
||||||
"""
|
"""
|
||||||
Called to update the themes' preview images.
|
Called to update the themes' preview images.
|
||||||
"""
|
"""
|
||||||
self.main_window.displayProgressBar(len(self.themeList))
|
self.main_window.displayProgressBar(len(self.theme_list))
|
||||||
for theme in self.themeList:
|
for theme in self.theme_list:
|
||||||
self.main_window.incrementProgressBar()
|
self.main_window.incrementProgressBar()
|
||||||
self.generateAndSaveImage(self.path, theme, self.getThemeData(theme))
|
self.generate_and_save_image(self.path, theme, self.get_theme_data(theme))
|
||||||
self.main_window.finishedProgressBar()
|
self.main_window.finishedProgressBar()
|
||||||
self.loadThemes()
|
self.load_themes()
|
||||||
|
|
||||||
def generateImage(self, theme_data, forcePage=False):
|
def generate_image(self, theme_data, forcePage=False):
|
||||||
"""
|
"""
|
||||||
Call the renderer to build a Sample Image
|
Call the renderer to build a Sample Image
|
||||||
|
|
||||||
@ -696,21 +695,21 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
``forcePage``
|
``forcePage``
|
||||||
Flag to tell message lines per page need to be generated.
|
Flag to tell message lines per page need to be generated.
|
||||||
"""
|
"""
|
||||||
log.debug(u'generateImage \n%s ', theme_data)
|
log.debug(u'generate_image \n%s ', theme_data)
|
||||||
return self.renderer.generate_preview(theme_data, forcePage)
|
return self.renderer.generate_preview(theme_data, forcePage)
|
||||||
|
|
||||||
def getPreviewImage(self, theme):
|
def get_preview_image(self, theme):
|
||||||
"""
|
"""
|
||||||
Return an image representing the look of the theme
|
Return an image representing the look of the theme
|
||||||
|
|
||||||
``theme``
|
``theme``
|
||||||
The theme to return the image for
|
The theme to return the image for
|
||||||
"""
|
"""
|
||||||
log.debug(u'getPreviewImage %s ', theme)
|
log.debug(u'get_preview_image %s ', theme)
|
||||||
image = os.path.join(self.path, theme + u'.png')
|
image = os.path.join(self.path, theme + u'.png')
|
||||||
return image
|
return image
|
||||||
|
|
||||||
def _createThemeFromXml(self, theme_xml, path):
|
def _create_theme_fom_Xml(self, theme_xml, path):
|
||||||
"""
|
"""
|
||||||
Return a theme object using information parsed from XML
|
Return a theme object using information parsed from XML
|
||||||
|
|
||||||
@ -722,15 +721,14 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
theme.extend_image_filename(path)
|
theme.extend_image_filename(path)
|
||||||
return theme
|
return theme
|
||||||
|
|
||||||
def _validate_theme_action(self, select_text, confirm_title, confirm_text,
|
def _validate_theme_action(self, select_text, confirm_title, confirm_text, testPlugin=True, confirm=True):
|
||||||
testPlugin=True, confirm=True):
|
|
||||||
"""
|
"""
|
||||||
Check to see if theme has been selected and the destructive action
|
Check to see if theme has been selected and the destructive action
|
||||||
is allowed.
|
is allowed.
|
||||||
"""
|
"""
|
||||||
self.global_theme = Settings().value(self.settingsSection + u'/global theme')
|
self.global_theme = Settings().value(self.settingsSection + u'/global theme')
|
||||||
if check_item_selected(self.themeListWidget, select_text):
|
if check_item_selected(self.theme_list_widget, select_text):
|
||||||
item = self.themeListWidget.currentItem()
|
item = self.theme_list_widget.currentItem()
|
||||||
theme = item.text()
|
theme = item.text()
|
||||||
# confirm deletion
|
# confirm deletion
|
||||||
if confirm:
|
if confirm:
|
||||||
@ -755,7 +753,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _migrateVersion122(self, xml_data):
|
def _migrate_version_122(self, xml_data):
|
||||||
"""
|
"""
|
||||||
Convert the xml data from version 1 format to the current format.
|
Convert the xml data from version 1 format to the current format.
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ class ThemesTab(SettingsTab):
|
|||||||
"""
|
"""
|
||||||
Utility method to update the global theme preview image.
|
Utility method to update the global theme preview image.
|
||||||
"""
|
"""
|
||||||
image = self.main_window.themeManagerContents.getPreviewImage(self.global_theme)
|
image = self.main_window.themeManagerContents.get_preview_image(self.global_theme)
|
||||||
preview = QtGui.QPixmap(unicode(image))
|
preview = QtGui.QPixmap(unicode(image))
|
||||||
if not preview.isNull():
|
if not preview.isNull():
|
||||||
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||||
|
@ -62,7 +62,7 @@ class OpenLP1SongImport(SongImport):
|
|||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.availableThemes = \
|
self.availableThemes = \
|
||||||
kwargs[u'plugin'].formParent.themeManagerContents.getThemes()
|
kwargs[u'plugin'].formParent.themeManagerContents.get_themes()
|
||||||
|
|
||||||
def doImport(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user