forked from openlp/openlp
HEAD
This commit is contained in:
commit
327711d0ef
|
@ -708,3 +708,13 @@ class MediaManagerItem(QtGui.QWidget):
|
|||
return self._service_manager
|
||||
|
||||
service_manager = property(_get_service_manager)
|
||||
|
||||
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)
|
||||
|
|
|
@ -128,7 +128,7 @@ class Renderer(object):
|
|||
The theme name.
|
||||
"""
|
||||
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)
|
||||
footer_rect = self.get_footer_rectangle(theme_data)
|
||||
self._theme_dimensions[theme_name] = [theme_data, main_rect, footer_rect]
|
||||
|
@ -662,3 +662,4 @@ class Renderer(object):
|
|||
return self._theme_manager
|
||||
|
||||
theme_manager = property(_get_theme_manager)
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ own tab to the settings dialog.
|
|||
from PyQt4 import QtGui
|
||||
|
||||
|
||||
from openlp.core.lib import Registry
|
||||
|
||||
class SettingsTab(QtGui.QWidget):
|
||||
"""
|
||||
SettingsTab is a helper widget for plugins to define Tabs for the settings
|
||||
|
@ -136,3 +138,54 @@ class SettingsTab(QtGui.QWidget):
|
|||
Tab has just been made visible to the user
|
||||
"""
|
||||
pass
|
||||
|
||||
def _get_service_manager(self):
|
||||
"""
|
||||
Adds the service manager to the class dynamically
|
||||
"""
|
||||
if not hasattr(self, u'_service_manager'):
|
||||
self._service_manager = Registry().get(u'service_manager')
|
||||
return self._service_manager
|
||||
|
||||
service_manager = property(_get_service_manager)
|
||||
|
||||
def _get_main_window(self):
|
||||
"""
|
||||
Adds the main window to the class dynamically
|
||||
"""
|
||||
if not hasattr(self, u'_main_window'):
|
||||
self._main_window = Registry().get(u'main_window')
|
||||
return self._main_window
|
||||
|
||||
main_window = property(_get_main_window)
|
||||
|
||||
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)
|
||||
|
||||
def _get_media_controller(self):
|
||||
"""
|
||||
Adds the media controller to the class dynamically
|
||||
"""
|
||||
if not hasattr(self, u'_media_controller'):
|
||||
self._media_controller = Registry().get(u'media_controller')
|
||||
return self._media_controller
|
||||
|
||||
media_controller = property(_get_media_controller)
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ class Theme(object):
|
|||
* ``0`` - normal
|
||||
* ``1`` - lyrics
|
||||
"""
|
||||
|
||||
def __init__(self, xml):
|
||||
"""
|
||||
Initialise a theme with data from xml
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -41,7 +41,7 @@ from ConfigParser import SafeConfigParser
|
|||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import translate, PluginStatus, Receiver, build_icon, check_directory_exists, Settings
|
||||
from openlp.core.lib import translate, PluginStatus, Receiver, build_icon, check_directory_exists, Settings, Registry
|
||||
from openlp.core.utils import get_web_page, AppLocation, get_filesystem_encoding
|
||||
from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
|
||||
|
||||
|
@ -204,7 +204,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||
self.themeComboBox.addItem(item.text())
|
||||
if self.hasRunWizard:
|
||||
# Add any existing themes to list.
|
||||
for theme in self.parent().themeManagerContents.getThemes():
|
||||
for theme in self.theme_manager.get_themes():
|
||||
index = self.themeComboBox.findText(theme)
|
||||
if index == -1:
|
||||
self.themeComboBox.addItem(theme)
|
||||
|
@ -479,3 +479,13 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||
"""
|
||||
status = PluginStatus.Active if field.checkState() == QtCore.Qt.Checked else PluginStatus.Inactive
|
||||
Settings().setValue(tag, status)
|
||||
|
||||
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)
|
||||
|
|
|
@ -502,9 +502,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||
self.copyData = False
|
||||
# Set up signals and slots
|
||||
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()'),
|
||||
self.themeManagerContents.onExportTheme)
|
||||
self.themeManagerContents.on_export_theme)
|
||||
QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||
self.viewMediaManagerItem.setChecked)
|
||||
QtCore.QObject.connect(self.serviceManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||
|
@ -583,9 +583,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||
self.settingsForm.postSetUp()
|
||||
# Once all components are initialised load the Themes
|
||||
log.info(u'Load Themes')
|
||||
self.themeManagerContents.loadThemes(True)
|
||||
self.themeManagerContents.load_themes(True)
|
||||
# Hide/show the theme combobox on the service manager
|
||||
self.serviceManagerContents.themeChange()
|
||||
self.serviceManagerContents.theme_change()
|
||||
# Reset the cursor
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
|
||||
|
@ -702,7 +702,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||
else:
|
||||
self.activePlugin.toggleStatus(PluginStatus.Inactive)
|
||||
self.themeManagerContents.configUpdated()
|
||||
self.themeManagerContents.loadThemes(True)
|
||||
self.themeManagerContents.load_themes(True)
|
||||
Receiver.send_message(u'theme_update_global', self.themeManagerContents.global_theme)
|
||||
# Check if any Bibles downloaded. If there are, they will be
|
||||
# processed.
|
||||
|
@ -784,7 +784,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||
"""
|
||||
Updates the new theme preview images.
|
||||
"""
|
||||
self.themeManagerContents.updatePreviewImages()
|
||||
self.themeManagerContents.update_preview_images()
|
||||
|
||||
def onFormattingTagItemClicked(self):
|
||||
"""
|
||||
|
@ -1064,7 +1064,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||
while self.imageManager.image_thread.isRunning():
|
||||
time.sleep(0.1)
|
||||
# Clean temporary files used by services
|
||||
self.serviceManagerContents.cleanUp()
|
||||
self.serviceManagerContents.clean_up()
|
||||
if save_settings:
|
||||
if Settings().value(u'advanced/save current plugin'):
|
||||
Settings().setValue(u'advanced/current media plugin', self.mediaToolBox.currentIndex())
|
||||
|
|
|
@ -51,13 +51,11 @@ class PlayerTab(SettingsTab):
|
|||
"""
|
||||
MediaTab is the Media settings tab in the settings dialog.
|
||||
"""
|
||||
def __init__(self, parent, mainWindow):
|
||||
def __init__(self, parent):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
self.parent = parent
|
||||
self.mainWindow = mainWindow
|
||||
self.mediaPlayers = mainWindow.mediaController.mediaPlayers
|
||||
self.mediaPlayers = self.media_controller.mediaPlayers
|
||||
self.savedUsedPlayers = None
|
||||
self.iconPath = u':/media/multimedia-player.png'
|
||||
player_translated = translate('OpenLP.PlayerTab', 'Players')
|
||||
|
@ -230,7 +228,7 @@ class PlayerTab(SettingsTab):
|
|||
set_media_players(self.usedPlayers, override_player)
|
||||
player_string_changed = True
|
||||
if player_string_changed:
|
||||
self.parent.reset_supported_suffixes()
|
||||
self.service_manager.reset_supported_suffixes()
|
||||
Receiver.send_message(u'mediaitem_media_rebuild')
|
||||
Receiver.send_message(u'config_screen_changed')
|
||||
|
||||
|
|
|
@ -103,11 +103,11 @@ class ServiceManagerList(QtGui.QTreeWidget):
|
|||
|
||||
class ServiceManagerDialog(object):
|
||||
"""
|
||||
The UI for the service manager.
|
||||
UI part of the Service Manager
|
||||
"""
|
||||
def setup_ui(self, widget):
|
||||
"""
|
||||
Set up the UI for the service manager
|
||||
Define the UI
|
||||
"""
|
||||
# Create the top toolbar
|
||||
self.toolbar = OpenLPToolbar(self)
|
||||
|
@ -220,8 +220,9 @@ class ServiceManagerDialog(object):
|
|||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'),
|
||||
self.regenerate_service_Items)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_global'), self.themeChange)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'service_item_update'), self.serviceItemUpdate)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_global'), self.theme_change)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'service_item_update'),
|
||||
self.service_item_update)
|
||||
# Last little bits of setting up
|
||||
self.service_theme = Settings().value(self.main_window.serviceManagerSettingsSection + u'/service theme')
|
||||
self.servicePath = AppLocation.get_section_data_path(u'servicemanager')
|
||||
|
@ -574,7 +575,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
if success:
|
||||
try:
|
||||
shutil.copy(temp_file_name, path_file_name)
|
||||
except:
|
||||
except shutil.Error:
|
||||
return self.save_file_as()
|
||||
self.main_window.addRecentFile(path_file_name)
|
||||
self.set_modified(False)
|
||||
|
@ -632,7 +633,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
if success:
|
||||
try:
|
||||
shutil.copy(temp_file_name, path_file_name)
|
||||
except:
|
||||
except shutil.Error:
|
||||
return self.save_file_as()
|
||||
self.main_window.addRecentFile(path_file_name)
|
||||
self.set_modified(False)
|
||||
|
@ -711,7 +712,8 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
try:
|
||||
ucsfile = zip_info.filename.decode(u'utf-8')
|
||||
except UnicodeDecodeError:
|
||||
log.exception(u'file_name "%s" is not valid UTF-8', zip_info.file_name.decode(u'utf-8', u'replace'))
|
||||
log.exception(u'file_name "%s" is not valid UTF-8' %
|
||||
zip_info.file_name.decode(u'utf-8', u'replace'))
|
||||
critical_error_message_box(message=translate('OpenLP.ServiceManager',
|
||||
'File is not a valid service.\n The content encoding is not UTF-8.'))
|
||||
continue
|
||||
|
@ -1214,13 +1216,13 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
self.service_manager_list.setCurrentItem(treewidgetitem)
|
||||
treewidgetitem.setExpanded(item[u'expanded'])
|
||||
|
||||
def cleanUp(self):
|
||||
def clean_up(self):
|
||||
"""
|
||||
Empties the servicePath of temporary files on system exit.
|
||||
"""
|
||||
log.debug(u'Cleaning up servicePath')
|
||||
for file in os.listdir(self.servicePath):
|
||||
file_path = os.path.join(self.servicePath, file)
|
||||
for file_name in os.listdir(self.servicePath):
|
||||
file_path = os.path.join(self.servicePath, file_name)
|
||||
delete_file(file_path)
|
||||
if os.path.exists(os.path.join(self.servicePath, u'audio')):
|
||||
shutil.rmtree(os.path.join(self.servicePath, u'audio'), True)
|
||||
|
@ -1235,12 +1237,12 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/service theme', self.service_theme)
|
||||
self.regenerate_service_Items(True)
|
||||
|
||||
def themeChange(self):
|
||||
def theme_change(self):
|
||||
"""
|
||||
The theme may have changed in the settings dialog so make
|
||||
sure the theme combo box is in the correct state.
|
||||
"""
|
||||
log.debug(u'themeChange')
|
||||
log.debug(u'theme_change')
|
||||
visible = self.renderer.theme_level == ThemeLevel.Global
|
||||
self.theme_label.setVisible(visible)
|
||||
self.theme_combo_box.setVisible(visible)
|
||||
|
@ -1284,7 +1286,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
self.repaint_service_list(-1, -1)
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
|
||||
def serviceItemUpdate(self, message):
|
||||
def service_item_update(self, message):
|
||||
"""
|
||||
Triggered from plugins to update service items.
|
||||
Save the values as they will be used as part of the service load
|
||||
|
@ -1419,7 +1421,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
|||
"""
|
||||
Triggers a remote edit to a plugin to allow item to be edited.
|
||||
"""
|
||||
item, child = self.find_service_item()
|
||||
item = self.find_service_item()[0]
|
||||
if self.service_items[item][u'service_item'].is_capable(ItemCapabilities.CanEdit):
|
||||
new_item = Registry().get(self.service_items[item][u'service_item'].name). \
|
||||
onRemoteEdit(self.service_items[item][u'service_item'].edit_id)
|
||||
|
|
|
@ -55,11 +55,11 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
|
|||
# General tab
|
||||
self.generalTab = GeneralTab(self)
|
||||
# Themes tab
|
||||
self.themesTab = ThemesTab(self, self.main_window)
|
||||
self.themesTab = ThemesTab(self)
|
||||
# Advanced tab
|
||||
self.advancedTab = AdvancedTab(self)
|
||||
# Advanced tab
|
||||
self.playerTab = PlayerTab(self, self.main_window)
|
||||
self.playerTab = PlayerTab(self)
|
||||
|
||||
def exec_(self):
|
||||
"""
|
||||
|
|
|
@ -34,7 +34,7 @@ import os
|
|||
|
||||
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.ui import critical_error_message_box
|
||||
from openlp.core.ui import ThemeLayoutForm
|
||||
|
@ -59,7 +59,6 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||
The QWidget-derived parent of the wizard.
|
||||
"""
|
||||
QtGui.QWizard.__init__(self, parent)
|
||||
self.thememanager = parent
|
||||
self.setupUi(self)
|
||||
self.registerFields()
|
||||
self.updateThemeAllowed = True
|
||||
|
@ -152,7 +151,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||
# Do not trigger on start up
|
||||
if self.currentPage != self.welcomePage:
|
||||
self.updateTheme()
|
||||
self.thememanager.generateImage(self.theme, True)
|
||||
self.theme_manager.generate_image(self.theme, True)
|
||||
|
||||
def updateLinesText(self, lines):
|
||||
"""
|
||||
|
@ -202,7 +201,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||
self.setOption(QtGui.QWizard.HaveCustomButton1, enabled)
|
||||
if self.page(pageId) == self.previewPage:
|
||||
self.updateTheme()
|
||||
frame = self.thememanager.generateImage(self.theme)
|
||||
frame = self.theme_manager.generate_image(self.theme)
|
||||
self.previewBoxLabel.setPixmap(frame)
|
||||
self.displayAspectRatio = float(frame.width()) / frame.height()
|
||||
self.resizeEvent()
|
||||
|
@ -212,15 +211,15 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||
Generate layout preview and display the form.
|
||||
"""
|
||||
self.updateTheme()
|
||||
width = self.thememanager.mainwindow.renderer.width
|
||||
height = self.thememanager.mainwindow.renderer.height
|
||||
width = self.renderer.width
|
||||
height = self.renderer.height
|
||||
pixmap = QtGui.QPixmap(width, height)
|
||||
pixmap.fill(QtCore.Qt.white)
|
||||
paint = QtGui.QPainter(pixmap)
|
||||
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.drawRect(self.thememanager.mainwindow.renderer.get_footer_rectangle(self.theme))
|
||||
paint.drawRect(self.renderer.get_footer_rectangle(self.theme))
|
||||
paint.end()
|
||||
self.themeLayoutForm.exec_(pixmap)
|
||||
|
||||
|
@ -532,9 +531,9 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||
filename = os.path.split(unicode(self.theme.background_filename))[1]
|
||||
saveTo = os.path.join(self.path, self.theme.theme_name, 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
|
||||
self.thememanager.saveTheme(self.theme, saveFrom, saveTo)
|
||||
self.theme_manager.save_theme(self.theme, saveFrom, saveTo)
|
||||
return QtGui.QDialog.accept(self)
|
||||
|
||||
def _colorButton(self, field):
|
||||
|
@ -545,3 +544,23 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
|
|||
if new_color.isValid():
|
||||
field = new_color.name()
|
||||
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)
|
||||
|
|
|
@ -78,67 +78,67 @@ class ThemeManager(QtGui.QWidget):
|
|||
text=translate('OpenLP.ThemeManager', 'Edit Theme'),
|
||||
icon=u':/themes/theme_edit.png',
|
||||
tooltip=translate('OpenLP.ThemeManager', 'Edit a theme.'),
|
||||
triggers=self.onEditTheme)
|
||||
self.deleteToolbarAction = self.toolbar.addToolbarAction(u'deleteTheme',
|
||||
triggers=self.on_edit_theme)
|
||||
self.deleteToolbarAction = self.toolbar.addToolbarAction(u'delete_theme',
|
||||
text=translate('OpenLP.ThemeManager', 'Delete Theme'),
|
||||
icon=u':/general/general_delete.png',
|
||||
tooltip=translate('OpenLP.ThemeManager', 'Delete a theme.'),
|
||||
triggers=self.onDeleteTheme)
|
||||
triggers=self.on_delete_theme)
|
||||
self.toolbar.addSeparator()
|
||||
self.toolbar.addToolbarAction(u'importTheme',
|
||||
text=translate('OpenLP.ThemeManager', 'Import Theme'),
|
||||
icon=u':/general/general_import.png',
|
||||
tooltip=translate('OpenLP.ThemeManager', 'Import a theme.'),
|
||||
triggers=self.onImportTheme)
|
||||
triggers=self.on_import_theme)
|
||||
self.toolbar.addToolbarAction(u'exportTheme',
|
||||
text=translate('OpenLP.ThemeManager', 'Export Theme'),
|
||||
icon=u':/general/general_export.png',
|
||||
tooltip=translate('OpenLP.ThemeManager', 'Export a theme.'),
|
||||
triggers=self.onExportTheme)
|
||||
triggers=self.on_export_theme)
|
||||
self.layout.addWidget(self.toolbar)
|
||||
self.themeWidget = QtGui.QWidgetAction(self.toolbar)
|
||||
self.themeWidget.setObjectName(u'themeWidget')
|
||||
self.theme_widget = QtGui.QWidgetAction(self.toolbar)
|
||||
self.theme_widget.setObjectName(u'theme_widget')
|
||||
# create theme manager list
|
||||
self.themeListWidget = QtGui.QListWidget(self)
|
||||
self.themeListWidget.setAlternatingRowColors(True)
|
||||
self.themeListWidget.setIconSize(QtCore.QSize(88, 50))
|
||||
self.themeListWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||
self.themeListWidget.setObjectName(u'themeListWidget')
|
||||
self.layout.addWidget(self.themeListWidget)
|
||||
QtCore.QObject.connect(self.themeListWidget, QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
|
||||
self.contextMenu)
|
||||
self.theme_list_widget = QtGui.QListWidget(self)
|
||||
self.theme_list_widget.setAlternatingRowColors(True)
|
||||
self.theme_list_widget.setIconSize(QtCore.QSize(88, 50))
|
||||
self.theme_list_widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||
self.theme_list_widget.setObjectName(u'theme_list_widget')
|
||||
self.layout.addWidget(self.theme_list_widget)
|
||||
QtCore.QObject.connect(self.theme_list_widget, QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
|
||||
self.context_menu)
|
||||
# build the context menu
|
||||
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'),
|
||||
icon=u':/themes/theme_edit.png', triggers=self.onEditTheme)
|
||||
self.copyAction = create_widget_action(self.menu,
|
||||
icon=u':/themes/theme_edit.png', triggers=self.on_edit_theme)
|
||||
self.copy_action = create_widget_action(self.menu,
|
||||
text=translate('OpenLP.ThemeManager', '&Copy Theme'),
|
||||
icon=u':/themes/theme_edit.png', triggers=self.onCopyTheme)
|
||||
self.renameAction = create_widget_action(self.menu,
|
||||
icon=u':/themes/theme_edit.png', triggers=self.on_copy_theme)
|
||||
self.rename_action = create_widget_action(self.menu,
|
||||
text=translate('OpenLP.ThemeManager', '&Rename Theme'),
|
||||
icon=u':/themes/theme_edit.png', triggers=self.onRenameTheme)
|
||||
self.deleteAction = create_widget_action(self.menu,
|
||||
icon=u':/themes/theme_edit.png', triggers=self.on_rename_theme)
|
||||
self.delete_action = create_widget_action(self.menu,
|
||||
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.globalAction = create_widget_action(self.menu,
|
||||
self.global_action = create_widget_action(self.menu,
|
||||
text=translate('OpenLP.ThemeManager', 'Set As &Global Default'),
|
||||
icon=u':/general/general_export.png',
|
||||
triggers=self.changeGlobalFromScreen)
|
||||
self.exportAction = create_widget_action(self.menu,
|
||||
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
|
||||
QtCore.QObject.connect(self.themeListWidget,
|
||||
QtCore.QObject.connect(self.theme_list_widget,
|
||||
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.changeGlobalFromScreen)
|
||||
QtCore.QObject.connect(self.themeListWidget,
|
||||
QtCore.SIGNAL(u'currentItemChanged(QListWidgetItem *, QListWidgetItem *)'), self.checkListState)
|
||||
QtCore.QObject.connect(self.theme_list_widget,
|
||||
QtCore.SIGNAL(u'currentItemChanged(QListWidgetItem *, QListWidgetItem *)'), self.check_list_state)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'theme_update_global'), self.changeGlobalFromTab)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated)
|
||||
QtCore.SIGNAL(u'theme_update_global'), self.change_global_from_tab)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated)
|
||||
# Variables
|
||||
self.themeList = []
|
||||
self.theme_list = []
|
||||
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
||||
check_directory_exists(self.path)
|
||||
self.thumbPath = os.path.join(self.path, u'thumbnails')
|
||||
|
@ -147,9 +147,9 @@ class ThemeManager(QtGui.QWidget):
|
|||
self.oldBackgroundImage = None
|
||||
self.badV1NameChars = re.compile(r'[%+\[\]]')
|
||||
# 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
|
||||
"""
|
||||
|
@ -161,13 +161,13 @@ class ThemeManager(QtGui.QWidget):
|
|||
delete_file(theme_file)
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
|
||||
def configUpdated(self):
|
||||
def config_updated(self):
|
||||
"""
|
||||
Triggered when Config dialog is updated.
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
@ -181,41 +181,41 @@ class ThemeManager(QtGui.QWidget):
|
|||
else:
|
||||
self.deleteToolbarAction.setVisible(False)
|
||||
|
||||
def contextMenu(self, point):
|
||||
def context_menu(self, point):
|
||||
"""
|
||||
Build the Right Click Context menu and set state depending on
|
||||
the type of theme.
|
||||
"""
|
||||
item = self.themeListWidget.itemAt(point)
|
||||
item = self.theme_list_widget.itemAt(point)
|
||||
if item is None:
|
||||
return
|
||||
real_theme_name = item.data(QtCore.Qt.UserRole)
|
||||
theme_name = unicode(item.text())
|
||||
visible = real_theme_name == theme_name
|
||||
self.deleteAction.setVisible(visible)
|
||||
self.renameAction.setVisible(visible)
|
||||
self.globalAction.setVisible(visible)
|
||||
self.menu.exec_(self.themeListWidget.mapToGlobal(point))
|
||||
self.delete_action.setVisible(visible)
|
||||
self.rename_action.setVisible(visible)
|
||||
self.global_action.setVisible(visible)
|
||||
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
|
||||
tab
|
||||
"""
|
||||
log.debug(u'changeGlobalFromTab %s', theme_name)
|
||||
for count in range(0, self.themeListWidget.count()):
|
||||
log.debug(u'change_global_from_tab %s', theme_name)
|
||||
for count in range(0, self.theme_list_widget.count()):
|
||||
# reset the old name
|
||||
item = self.themeListWidget.item(count)
|
||||
item = self.theme_list_widget.item(count)
|
||||
old_name = item.text()
|
||||
new_name = item.data(QtCore.Qt.UserRole)
|
||||
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
|
||||
if theme_name == 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(
|
||||
item not in self.themeListWidget.selectedItems())
|
||||
item not in self.theme_list_widget.selectedItems())
|
||||
|
||||
def changeGlobalFromScreen(self, index=-1):
|
||||
"""
|
||||
|
@ -223,21 +223,21 @@ class ThemeManager(QtGui.QWidget):
|
|||
Theme Manager list
|
||||
"""
|
||||
log.debug(u'changeGlobalFromScreen %s', index)
|
||||
selected_row = self.themeListWidget.currentRow()
|
||||
for count in range(0, self.themeListWidget.count()):
|
||||
item = self.themeListWidget.item(count)
|
||||
selected_row = self.theme_list_widget.currentRow()
|
||||
for count in range(0, self.theme_list_widget.count()):
|
||||
item = self.theme_list_widget.item(count)
|
||||
old_name = item.text()
|
||||
# reset the old name
|
||||
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
|
||||
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
|
||||
self.themeListWidget.item(count).setText(name)
|
||||
self.theme_list_widget.item(count).setText(name)
|
||||
Settings().setValue(self.settingsSection + u'/global theme', self.global_theme)
|
||||
Receiver.send_message(u'theme_update_global', self.global_theme)
|
||||
self._pushThemes()
|
||||
self._push_themes()
|
||||
|
||||
def onAddTheme(self):
|
||||
"""
|
||||
|
@ -248,44 +248,44 @@ class ThemeManager(QtGui.QWidget):
|
|||
theme.set_default_header_footer()
|
||||
self.themeForm.theme = theme
|
||||
self.themeForm.exec_()
|
||||
self.loadThemes()
|
||||
self.load_themes()
|
||||
|
||||
def onRenameTheme(self):
|
||||
def on_rename_theme(self):
|
||||
"""
|
||||
Renames an existing theme to a new name
|
||||
"""
|
||||
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to rename.'),
|
||||
translate('OpenLP.ThemeManager', 'Rename Confirmation'),
|
||||
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)
|
||||
self.fileRenameForm.fileNameEdit.setText(old_theme_name)
|
||||
if self.fileRenameForm.exec_():
|
||||
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
||||
if old_theme_name == new_theme_name:
|
||||
return
|
||||
if self.checkIfThemeExists(new_theme_name):
|
||||
old_theme_data = self.getThemeData(old_theme_name)
|
||||
if self.check_if_theme_exists(new_theme_name):
|
||||
old_theme_data = self.get_theme_data(old_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:
|
||||
if plugin.usesTheme(old_theme_name):
|
||||
plugin.renameTheme(old_theme_name, new_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
|
||||
"""
|
||||
item = self.themeListWidget.currentItem()
|
||||
item = self.theme_list_widget.currentItem()
|
||||
old_theme_name = item.data(QtCore.Qt.UserRole)
|
||||
self.fileRenameForm.fileNameEdit.setText(translate('OpenLP.ThemeManager',
|
||||
'Copy of %s', 'Copy of <theme name>') % old_theme_name)
|
||||
if self.fileRenameForm.exec_(True):
|
||||
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
||||
if self.checkIfThemeExists(new_theme_name):
|
||||
theme_data = self.getThemeData(old_theme_name)
|
||||
if self.check_if_theme_exists(new_theme_name):
|
||||
theme_data = self.get_theme_data(old_theme_name)
|
||||
self.cloneThemeData(theme_data, new_theme_name)
|
||||
|
||||
def cloneThemeData(self, theme_data, new_theme_name):
|
||||
|
@ -301,65 +301,65 @@ class ThemeManager(QtGui.QWidget):
|
|||
save_from = theme_data.background_filename
|
||||
theme_data.theme_name = new_theme_name
|
||||
theme_data.extend_image_filename(self.path)
|
||||
self.saveTheme(theme_data, save_from, save_to)
|
||||
self.loadThemes()
|
||||
self.save_theme(theme_data, save_from, save_to)
|
||||
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
|
||||
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.')):
|
||||
item = self.themeListWidget.currentItem()
|
||||
theme = self.getThemeData(item.data(QtCore.Qt.UserRole))
|
||||
item = self.theme_list_widget.currentItem()
|
||||
theme = self.get_theme_data(item.data(QtCore.Qt.UserRole))
|
||||
if theme.background_type == u'image':
|
||||
self.oldBackgroundImage = theme.background_filename
|
||||
self.themeForm.theme = theme
|
||||
self.themeForm.exec_(True)
|
||||
self.oldBackgroundImage = None
|
||||
self.renderer.update_theme(theme.theme_name)
|
||||
self.loadThemes()
|
||||
self.load_themes()
|
||||
|
||||
def onDeleteTheme(self):
|
||||
def on_delete_theme(self):
|
||||
"""
|
||||
Delete a theme
|
||||
"""
|
||||
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'),
|
||||
translate('OpenLP.ThemeManager', 'Delete Confirmation'),
|
||||
translate('OpenLP.ThemeManager', 'Delete %s theme?')):
|
||||
item = self.themeListWidget.currentItem()
|
||||
item = self.theme_list_widget.currentItem()
|
||||
theme = item.text()
|
||||
row = self.themeListWidget.row(item)
|
||||
self.themeListWidget.takeItem(row)
|
||||
self.deleteTheme(theme)
|
||||
row = self.theme_list_widget.row(item)
|
||||
self.theme_list_widget.takeItem(row)
|
||||
self.delete_theme(theme)
|
||||
self.renderer.update_theme(theme, only_delete=True)
|
||||
# As we do not reload the themes, push out the change. Reload the
|
||||
# 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.
|
||||
|
||||
``theme``
|
||||
The theme to delete.
|
||||
"""
|
||||
self.themeList.remove(theme)
|
||||
self.theme_list.remove(theme)
|
||||
thumb = u'%s.png' % theme
|
||||
delete_file(os.path.join(self.path, thumb))
|
||||
delete_file(os.path.join(self.thumbPath, thumb))
|
||||
try:
|
||||
encoding = get_filesystem_encoding()
|
||||
shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
|
||||
except OSError:
|
||||
except OSError, shutil.Error:
|
||||
log.exception(u'Error deleting theme %s', theme)
|
||||
|
||||
def onExportTheme(self):
|
||||
def on_export_theme(self):
|
||||
"""
|
||||
Export the theme in a zip file
|
||||
"""
|
||||
item = self.themeListWidget.currentItem()
|
||||
item = self.theme_list_widget.currentItem()
|
||||
if item is None:
|
||||
critical_error_message_box(message=translate('OpenLP.ThemeManager', 'You have not selected a theme.'))
|
||||
return
|
||||
|
@ -386,15 +386,14 @@ class ThemeManager(QtGui.QWidget):
|
|||
translate('OpenLP.ThemeManager', 'Your theme has been successfully exported.'))
|
||||
except (IOError, OSError):
|
||||
log.exception(u'Export Theme Failed')
|
||||
critical_error_message_box(
|
||||
translate('OpenLP.ThemeManager', 'Theme Export Failed'),
|
||||
critical_error_message_box(translate('OpenLP.ThemeManager', 'Theme Export Failed'),
|
||||
translate('OpenLP.ThemeManager', 'Your theme could not be exported due to an error.'))
|
||||
finally:
|
||||
if theme_zip:
|
||||
theme_zip.close()
|
||||
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
|
||||
attempting to extract OpenLP themes from those files. This process
|
||||
|
@ -408,36 +407,35 @@ class ThemeManager(QtGui.QWidget):
|
|||
if not files:
|
||||
return
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
for file in files:
|
||||
Settings().setValue(self.settingsSection + u'/last directory import', unicode(file))
|
||||
self.unzipTheme(file, self.path)
|
||||
self.loadThemes()
|
||||
for file_name in files:
|
||||
Settings().setValue(self.settingsSection + u'/last directory import', unicode(file_name))
|
||||
self.unzip_theme(file_name, self.path)
|
||||
self.load_themes()
|
||||
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
|
||||
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.
|
||||
"""
|
||||
log.debug(u'Load themes from dir')
|
||||
self.themeList = []
|
||||
self.themeListWidget.clear()
|
||||
self.theme_list = []
|
||||
self.theme_list_widget.clear()
|
||||
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
||||
if firstTime:
|
||||
self.firstTime()
|
||||
if first_time:
|
||||
self.first_time()
|
||||
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
||||
# No themes have been found so create one
|
||||
if not files:
|
||||
theme = ThemeXML()
|
||||
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)
|
||||
self.configUpdated()
|
||||
self.config_updated()
|
||||
files = SettingsManager.get_files(self.settingsSection, u'.png')
|
||||
# Sort the themes by its name considering language specific
|
||||
files.sort(key=lambda file_name: unicode(file_name),
|
||||
cmp=locale_compare)
|
||||
files.sort(key=lambda file_name: unicode(file_name), cmp=locale_compare)
|
||||
# now process the file list of png files
|
||||
for name in files:
|
||||
# check to see file is in theme root directory
|
||||
|
@ -456,23 +454,23 @@ class ThemeManager(QtGui.QWidget):
|
|||
icon = create_thumb(theme, thumb)
|
||||
item_name.setIcon(icon)
|
||||
item_name.setData(QtCore.Qt.UserRole, text_name)
|
||||
self.themeListWidget.addItem(item_name)
|
||||
self.themeList.append(text_name)
|
||||
self._pushThemes()
|
||||
self.theme_list_widget.addItem(item_name)
|
||||
self.theme_list.append(text_name)
|
||||
self._push_themes()
|
||||
|
||||
def _pushThemes(self):
|
||||
def _push_themes(self):
|
||||
"""
|
||||
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 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
|
||||
|
||||
|
@ -486,21 +484,20 @@ class ThemeManager(QtGui.QWidget):
|
|||
log.debug(u'No theme data - using default theme')
|
||||
return ThemeXML()
|
||||
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):
|
||||
"""
|
||||
Display a warning box to the user that a theme already exists
|
||||
"""
|
||||
ret = QtGui.QMessageBox.question(self,
|
||||
translate('OpenLP.ThemeManager', 'Theme Already Exists'),
|
||||
ret = QtGui.QMessageBox.question(self, translate('OpenLP.ThemeManager', 'Theme Already Exists'),
|
||||
translate('OpenLP.ThemeManager',
|
||||
'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.No)
|
||||
return ret == QtGui.QMessageBox.Yes
|
||||
|
||||
def unzipTheme(self, file_name, directory):
|
||||
def unzip_theme(self, file_name, directory):
|
||||
"""
|
||||
Unzip the theme, remove the preview file if stored
|
||||
Generate a new preview file. Check the XML theme version and upgrade if
|
||||
|
@ -517,17 +514,17 @@ class ThemeManager(QtGui.QWidget):
|
|||
xml_file = filter(lambda name: os.path.splitext(name)[1].lower() == u'.xml', theme_zip.namelist())
|
||||
if len(xml_file) != 1:
|
||||
log.exception(u'Theme contains "%s" XML files' % len(xml_file))
|
||||
raise Exception(u'validation')
|
||||
raise Exception('validation')
|
||||
xml_tree = ElementTree(element=XML(theme_zip.read(xml_file[0]))).getroot()
|
||||
v1_background = xml_tree.find(u'BackgroundType')
|
||||
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(
|
||||
directory, theme_zip, xml_file[0], xml_tree, v1_background, out_file)
|
||||
else:
|
||||
theme_name = xml_tree.find(u'name').text.strip()
|
||||
theme_folder = os.path.join(directory, theme_name)
|
||||
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
|
||||
return
|
||||
else:
|
||||
|
@ -572,8 +569,8 @@ class ThemeManager(QtGui.QWidget):
|
|||
if not abort_import:
|
||||
# As all files are closed, we can create the Theme.
|
||||
if file_xml:
|
||||
theme = self._createThemeFromXml(file_xml, self.path)
|
||||
self.generateAndSaveImage(directory, theme_name, theme)
|
||||
theme = self._create_theme_fom_Xml(file_xml, self.path)
|
||||
self.generate_and_save_image(directory, theme_name, theme)
|
||||
# Only show the error message, when IOError was not raised (in
|
||||
# this case the error message has already been shown).
|
||||
elif theme_zip is not None:
|
||||
|
@ -582,22 +579,21 @@ class ThemeManager(QtGui.QWidget):
|
|||
translate('OpenLP.ThemeManager', 'File is not a valid theme.'))
|
||||
log.exception(u'Theme file does not contain XML data %s' % file_name)
|
||||
|
||||
def unzipVersion122(self, directory, theme_zip, xml_file, xml_tree, background,
|
||||
out_file):
|
||||
def unzip_version_122(self, dir_name, zip_file, xml_file, xml_tree, background, out_file):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
theme_name = xml_tree.find(u'Name').text.strip()
|
||||
theme_name = self.badV1NameChars.sub(u'', theme_name)
|
||||
theme_folder = os.path.join(directory, theme_name)
|
||||
theme_folder = os.path.join(dir_name, theme_name)
|
||||
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
|
||||
themedir = os.path.join(directory, theme_name)
|
||||
themedir = os.path.join(dir_name, theme_name)
|
||||
check_directory_exists(themedir)
|
||||
file_xml = unicode(theme_zip.read(xml_file), u'utf-8')
|
||||
file_xml = self._migrateVersion122(file_xml)
|
||||
file_xml = unicode(zip_file.read(xml_file), u'utf-8')
|
||||
file_xml = self._migrate_version_122(file_xml)
|
||||
out_file = open(os.path.join(themedir, theme_name + u'.xml'), u'w')
|
||||
out_file.write(file_xml.encode(u'utf-8'))
|
||||
out_file.close()
|
||||
|
@ -605,18 +601,17 @@ class ThemeManager(QtGui.QWidget):
|
|||
image_name = xml_tree.find(u'BackgroundParameter1').text.strip()
|
||||
# image file has same extension and is in subfolder
|
||||
image_file = filter(lambda name: os.path.splitext(name)[1].lower()
|
||||
== os.path.splitext(image_name)[1].lower() and name.find(r'/'),
|
||||
theme_zip.namelist())
|
||||
== os.path.splitext(image_name)[1].lower() and name.find(r'/'), zip_file.namelist())
|
||||
if len(image_file) >= 1:
|
||||
out_file = open(os.path.join(themedir, image_name), u'wb')
|
||||
out_file.write(theme_zip.read(image_file[0]))
|
||||
out_file.write(zip_file.read(image_file[0]))
|
||||
out_file.close()
|
||||
else:
|
||||
log.exception(u'Theme file does not contain image file "%s"' % image_name.decode(u'utf-8', u'replace'))
|
||||
raise Exception(u'validation')
|
||||
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
|
||||
|
||||
|
@ -631,25 +626,25 @@ class ThemeManager(QtGui.QWidget):
|
|||
return False
|
||||
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
|
||||
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):
|
||||
self.image_manager.update_image_border(theme.background_filename,
|
||||
ImageSource.Theme, QtGui.QColor(theme.background_border_color))
|
||||
self.image_manager.process_updates()
|
||||
|
||||
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
|
||||
necessary
|
||||
"""
|
||||
name = theme.theme_name
|
||||
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)
|
||||
check_directory_exists(theme_dir)
|
||||
theme_file = os.path.join(theme_dir, name + u'.xml')
|
||||
|
@ -668,16 +663,16 @@ class ThemeManager(QtGui.QWidget):
|
|||
try:
|
||||
encoding = get_filesystem_encoding()
|
||||
shutil.copyfile(unicode(image_from).encode(encoding), unicode(image_to).encode(encoding))
|
||||
except IOError:
|
||||
except IOError, shutil.Error:
|
||||
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, directory, name, theme):
|
||||
def generate_and_save_image(self, directory, name, theme):
|
||||
"""
|
||||
Generate and save a preview image
|
||||
"""
|
||||
log.debug(u'generateAndSaveImage %s %s', directory, name)
|
||||
frame = self.generateImage(theme)
|
||||
log.debug(u'generate_and_save_image %s %s', directory, name)
|
||||
frame = self.generate_image(theme)
|
||||
sample_path_name = os.path.join(self.path, name + u'.png')
|
||||
if os.path.exists(sample_path_name):
|
||||
os.unlink(sample_path_name)
|
||||
|
@ -686,18 +681,18 @@ class ThemeManager(QtGui.QWidget):
|
|||
create_thumb(sample_path_name, thumb, False)
|
||||
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.
|
||||
"""
|
||||
self.main_window.displayProgressBar(len(self.themeList))
|
||||
for theme in self.themeList:
|
||||
self.main_window.displayProgressBar(len(self.theme_list))
|
||||
for theme in self.theme_list:
|
||||
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.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
|
||||
|
||||
|
@ -707,21 +702,21 @@ class ThemeManager(QtGui.QWidget):
|
|||
``forcePage``
|
||||
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)
|
||||
|
||||
def getPreviewImage(self, theme):
|
||||
def get_preview_image(self, theme):
|
||||
"""
|
||||
Return an image representing the look of the theme
|
||||
|
||||
``theme``
|
||||
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')
|
||||
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
|
||||
|
||||
|
@ -733,15 +728,14 @@ class ThemeManager(QtGui.QWidget):
|
|||
theme.extend_image_filename(path)
|
||||
return theme
|
||||
|
||||
def _validate_theme_action(self, select_text, confirm_title, confirm_text,
|
||||
testPlugin=True, confirm=True):
|
||||
def _validate_theme_action(self, select_text, confirm_title, confirm_text, testPlugin=True, confirm=True):
|
||||
"""
|
||||
Check to see if theme has been selected and the destructive action
|
||||
is allowed.
|
||||
"""
|
||||
self.global_theme = Settings().value(self.settingsSection + u'/global theme')
|
||||
if check_item_selected(self.themeListWidget, select_text):
|
||||
item = self.themeListWidget.currentItem()
|
||||
if check_item_selected(self.theme_list_widget, select_text):
|
||||
item = self.theme_list_widget.currentItem()
|
||||
theme = item.text()
|
||||
# confirm deletion
|
||||
if confirm:
|
||||
|
@ -766,7 +760,7 @@ class ThemeManager(QtGui.QWidget):
|
|||
return True
|
||||
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.
|
||||
|
||||
|
|
|
@ -40,11 +40,10 @@ class ThemesTab(SettingsTab):
|
|||
"""
|
||||
ThemesTab is the theme settings tab in the settings dialog.
|
||||
"""
|
||||
def __init__(self, parent, mainwindow):
|
||||
def __init__(self, parent):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
self.mainwindow = mainwindow
|
||||
generalTranslated = translate('OpenLP.ThemesTab', 'Themes')
|
||||
SettingsTab.__init__(self, parent, u'Themes', generalTranslated)
|
||||
self.iconPath = u':/themes/theme_new.png'
|
||||
|
@ -152,8 +151,8 @@ class ThemesTab(SettingsTab):
|
|||
settings.setValue(u'theme level', self.theme_level)
|
||||
settings.setValue(u'global theme', self.global_theme)
|
||||
settings.endGroup()
|
||||
self.mainwindow.renderer.set_global_theme(self.global_theme)
|
||||
self.mainwindow.renderer.set_theme_level(self.theme_level)
|
||||
self.renderer.set_global_theme(self.global_theme)
|
||||
self.renderer.set_theme_level(self.theme_level)
|
||||
Receiver.send_message(u'theme_update_global', self.global_theme)
|
||||
|
||||
def postSetUp(self):
|
||||
|
@ -185,7 +184,7 @@ class ThemesTab(SettingsTab):
|
|||
Set the global default theme
|
||||
"""
|
||||
self.global_theme = self.DefaultComboBox.currentText()
|
||||
self.mainwindow.renderer.set_global_theme(self.global_theme)
|
||||
self.renderer.set_global_theme(self.global_theme)
|
||||
self.__previewGlobalTheme()
|
||||
|
||||
def updateThemeList(self, theme_list):
|
||||
|
@ -202,8 +201,8 @@ class ThemesTab(SettingsTab):
|
|||
self.DefaultComboBox.clear()
|
||||
self.DefaultComboBox.addItems(theme_list)
|
||||
find_and_set_in_combo_box(self.DefaultComboBox, self.global_theme)
|
||||
self.mainwindow.renderer.set_global_theme(self.global_theme)
|
||||
self.mainwindow.renderer.set_theme_level(self.theme_level)
|
||||
self.renderer.set_global_theme(self.global_theme)
|
||||
self.renderer.set_theme_level(self.theme_level)
|
||||
if self.global_theme is not u'':
|
||||
self.__previewGlobalTheme()
|
||||
|
||||
|
@ -211,7 +210,7 @@ class ThemesTab(SettingsTab):
|
|||
"""
|
||||
Utility method to update the global theme preview image.
|
||||
"""
|
||||
image = self.mainwindow.themeManagerContents.getPreviewImage(self.global_theme)
|
||||
image = self.theme_manager.get_preview_image(self.global_theme)
|
||||
preview = QtGui.QPixmap(unicode(image))
|
||||
if not preview.isNull():
|
||||
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||
|
|
|
@ -83,7 +83,7 @@ class PptviewController(PresentationController):
|
|||
if self.process:
|
||||
return
|
||||
log.debug(u'start PPTView')
|
||||
dllpath = os.path.join(self.plugin.pluginManager.basepath, u'presentations', u'lib', u'pptviewlib',
|
||||
dllpath = os.path.join(self.plugin_manager.basepath, u'presentations', u'lib', u'pptviewlib',
|
||||
u'pptviewlib.dll')
|
||||
self.process = cdll.LoadLibrary(dllpath)
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
|
|
|
@ -33,7 +33,7 @@ import shutil
|
|||
|
||||
from PyQt4 import QtCore
|
||||
|
||||
from openlp.core.lib import Receiver, check_directory_exists, create_thumb, validate_thumb, Settings
|
||||
from openlp.core.lib import Receiver, Registry, check_directory_exists, create_thumb, validate_thumb, Settings
|
||||
from openlp.core.utils import AppLocation
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -438,3 +438,13 @@ class PresentationController(object):
|
|||
|
||||
def close_presentation(self):
|
||||
pass
|
||||
|
||||
def _get_plugin_manager(self):
|
||||
"""
|
||||
Adds the plugin manager to the class dynamically
|
||||
"""
|
||||
if not hasattr(self, u'_plugin_manager'):
|
||||
self._plugin_manager = Registry().get(u'plugin_manager')
|
||||
return self._plugin_manager
|
||||
|
||||
plugin_manager = property(_get_plugin_manager)
|
||||
|
|
|
@ -61,8 +61,7 @@ class OpenLP1SongImport(SongImport):
|
|||
The database providing the data to import.
|
||||
"""
|
||||
SongImport.__init__(self, manager, **kwargs)
|
||||
self.availableThemes = \
|
||||
kwargs[u'plugin'].formParent.themeManagerContents.getThemes()
|
||||
self.availableThemes = kwargs[u'plugin'].theme_manager.get_themes()
|
||||
|
||||
def doImport(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue