openlp/openlp/core/ui/themeform.py

604 lines
26 KiB
Python
Raw Normal View History

2010-10-03 07:42:02 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
2011-03-24 19:04:02 +00:00
# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, #
# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
2010-10-03 07:42:02 +00:00
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import logging
2010-11-05 19:20:41 +00:00
import os
2010-10-03 07:42:02 +00:00
from PyQt4 import QtCore, QtGui
2011-02-18 03:15:09 +00:00
from openlp.core.lib import Receiver, translate
from openlp.core.lib.theme import BackgroundType, BackgroundGradientType
2011-02-09 05:04:12 +00:00
from openlp.core.lib.ui import UiStrings, critical_error_message_box
2010-11-05 19:20:41 +00:00
from openlp.core.utils import get_images_filter
2010-11-19 18:05:49 +00:00
from themewizard import Ui_ThemeWizard
2010-10-03 07:42:02 +00:00
log = logging.getLogger(__name__)
2010-11-19 18:05:49 +00:00
class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
2010-10-03 07:42:02 +00:00
"""
This is the Theme Import Wizard, which allows easy creation and editing of
OpenLP themes.
2010-10-03 07:42:02 +00:00
"""
log.info(u'ThemeWizardForm loaded')
def __init__(self, parent):
"""
Instantiate the wizard, and run any extra setup we need to.
``parent``
The QWidget-derived parent of the wizard.
"""
QtGui.QWizard.__init__(self, parent)
2010-10-13 19:40:01 +00:00
self.thememanager = parent
2010-10-03 07:42:02 +00:00
self.setupUi(self)
self.registerFields()
self.updateThemeAllowed = True
QtCore.QObject.connect(self.backgroundComboBox,
2010-10-03 07:42:02 +00:00
QtCore.SIGNAL(u'currentIndexChanged(int)'),
self.onBackgroundComboBoxCurrentIndexChanged)
2010-10-03 07:42:02 +00:00
QtCore.QObject.connect(self.gradientComboBox,
QtCore.SIGNAL(u'currentIndexChanged(int)'),
self.onGradientComboBoxCurrentIndexChanged)
QtCore.QObject.connect(self.colorButton,
QtCore.SIGNAL(u'clicked()'),
self.onColorButtonClicked)
QtCore.QObject.connect(self.gradientStartButton,
QtCore.SIGNAL(u'clicked()'),
self.onGradientStartButtonClicked)
QtCore.QObject.connect(self.gradientEndButton,
QtCore.SIGNAL(u'clicked()'),
self.onGradientEndButtonClicked)
2010-10-03 07:42:02 +00:00
QtCore.QObject.connect(self.imageBrowseButton,
QtCore.SIGNAL(u'clicked()'),
self.onImageBrowseButtonClicked)
QtCore.QObject.connect(self.mainColorButton,
QtCore.SIGNAL(u'clicked()'),
self.onMainColorButtonClicked)
QtCore.QObject.connect(self.outlineColorButton,
QtCore.SIGNAL(u'clicked()'),
self.onOutlineColorButtonClicked)
QtCore.QObject.connect(self.shadowColorButton,
QtCore.SIGNAL(u'clicked()'),
self.onShadowColorButtonClicked)
2010-10-11 16:14:36 +00:00
QtCore.QObject.connect(self.outlineCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onOutlineCheckCheckBoxStateChanged)
2010-10-11 16:14:36 +00:00
QtCore.QObject.connect(self.shadowCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onShadowCheckCheckBoxStateChanged)
QtCore.QObject.connect(self.footerColorButton,
QtCore.SIGNAL(u'clicked()'),
self.onFooterColorButtonClicked)
QtCore.QObject.connect(self.mainPositionCheckBox,
2010-10-13 19:40:01 +00:00
QtCore.SIGNAL(u'stateChanged(int)'),
self.onMainPositionCheckBoxStateChanged)
QtCore.QObject.connect(self.footerPositionCheckBox,
2010-10-13 19:40:01 +00:00
QtCore.SIGNAL(u'stateChanged(int)'),
self.onFooterPositionCheckBoxStateChanged)
2010-11-08 06:11:04 +00:00
QtCore.QObject.connect(self,
QtCore.SIGNAL(u'currentIdChanged(int)'),
self.onCurrentIdChanged)
2010-11-23 20:48:55 +00:00
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_line_count'),
self.updateLinesText)
2010-11-24 19:41:14 +00:00
QtCore.QObject.connect(self.mainSizeSpinBox,
QtCore.SIGNAL(u'valueChanged(int)'),
self.calculateLines)
QtCore.QObject.connect(self.lineSpacingSpinBox,
QtCore.SIGNAL(u'valueChanged(int)'),
self.calculateLines)
QtCore.QObject.connect(self.outlineSizeSpinBox,
QtCore.SIGNAL(u'valueChanged(int)'),
self.calculateLines)
QtCore.QObject.connect(self.shadowSizeSpinBox,
QtCore.SIGNAL(u'valueChanged(int)'),
self.calculateLines)
QtCore.QObject.connect(self.mainFontComboBox,
QtCore.SIGNAL(u'activated(int)'),
self.calculateLines)
2010-11-08 06:11:04 +00:00
2010-11-05 19:20:41 +00:00
def setDefaults(self):
"""
Set up display at start of theme edit.
"""
self.restart()
self.setBackgroundPageValues()
self.setMainAreaPageValues()
self.setFooterAreaPageValues()
self.setAlignmentPageValues()
self.setPositionPageValues()
self.setPreviewPageValues()
2010-11-05 19:20:41 +00:00
def registerFields(self):
"""
Map field names to screen names,
"""
self.backgroundPage.registerField(
u'background_type', self.backgroundComboBox)
2010-11-05 19:20:41 +00:00
self.backgroundPage.registerField(
u'color', self.colorButton)
self.backgroundPage.registerField(
u'grandient_start', self.gradientStartButton)
2010-11-05 19:20:41 +00:00
self.backgroundPage.registerField(
u'grandient_end', self.gradientEndButton)
2010-11-05 19:20:41 +00:00
self.backgroundPage.registerField(
u'background_image', self.imageFileEdit)
2010-11-05 19:20:41 +00:00
self.backgroundPage.registerField(
u'gradient', self.gradientComboBox)
self.mainAreaPage.registerField(
u'mainColorButton', self.mainColorButton)
2010-11-05 19:20:41 +00:00
self.mainAreaPage.registerField(
u'mainSizeSpinBox', self.mainSizeSpinBox)
self.mainAreaPage.registerField(
u'lineSpacingSpinBox', self.lineSpacingSpinBox)
self.mainAreaPage.registerField(
u'outlineCheckBox', self.outlineCheckBox)
self.mainAreaPage.registerField(
u'outlineColorButton', self.outlineColorButton)
2010-11-05 19:20:41 +00:00
self.mainAreaPage.registerField(
u'outlineSizeSpinBox', self.outlineSizeSpinBox)
self.mainAreaPage.registerField(
u'shadowCheckBox', self.shadowCheckBox)
self.mainAreaPage.registerField(
u'mainBoldCheckBox', self.mainBoldCheckBox)
2010-11-05 19:20:41 +00:00
self.mainAreaPage.registerField(
u'mainItalicsCheckBox', self.mainItalicsCheckBox)
2010-11-05 19:20:41 +00:00
self.mainAreaPage.registerField(
u'shadowColorButton', self.shadowColorButton)
2010-11-05 19:20:41 +00:00
self.mainAreaPage.registerField(
u'shadowSizeSpinBox', self.shadowSizeSpinBox)
self.mainAreaPage.registerField(
u'footerSizeSpinBox', self.footerSizeSpinBox)
self.areaPositionPage.registerField(
u'mainPositionX', self.mainXSpinBox)
self.areaPositionPage.registerField(
u'mainPositionY', self.mainYSpinBox)
self.areaPositionPage.registerField(
u'mainPositionWidth', self.mainWidthSpinBox)
self.areaPositionPage.registerField(
u'mainPositionHeight', self.mainHeightSpinBox)
self.areaPositionPage.registerField(
u'footerPositionX', self.footerXSpinBox)
self.areaPositionPage.registerField(
u'footerPositionY', self.footerYSpinBox)
self.areaPositionPage.registerField(
u'footerPositionWidth', self.footerWidthSpinBox)
self.areaPositionPage.registerField(
u'footerPositionHeight', self.footerHeightSpinBox)
self.backgroundPage.registerField(
u'horizontal', self.horizontalComboBox)
self.backgroundPage.registerField(
u'vertical', self.verticalComboBox)
self.backgroundPage.registerField(
u'slideTransition', self.transitionsCheckBox)
self.backgroundPage.registerField(
u'name', self.themeNameEdit)
2010-11-23 20:48:55 +00:00
def calculateLines(self):
"""
Calculate the number of lines on a page by rendering text
"""
# Do not trigger on start up
if self.currentPage != self.welcomePage:
2010-11-23 20:48:55 +00:00
self.updateTheme()
2011-02-14 16:08:17 +00:00
self.thememanager.generateImage(self.theme, True)
2010-11-23 20:48:55 +00:00
def updateLinesText(self, lines):
"""
Updates the lines on a page on the wizard
"""
self.mainLineCountLabel.setText(unicode(translate('OpenLP.ThemeForm',
'(%d lines per slide)')) % int(lines))
2010-11-23 20:48:55 +00:00
def resizeEvent(self, event=None):
"""
Rescale the theme preview thumbnail on resize events.
"""
if not event:
event = QtGui.QResizeEvent(self.size(), self.size())
QtGui.QWizard.resizeEvent(self, event)
if self.currentPage() == self.previewPage:
frameWidth = self.previewBoxLabel.lineWidth()
pixmapWidth = self.previewArea.width() - 2 * frameWidth
pixmapHeight = self.previewArea.height() - 2 * frameWidth
aspectRatio = float(pixmapWidth) / pixmapHeight
if aspectRatio < self.displayAspectRatio:
pixmapHeight = int(pixmapWidth / self.displayAspectRatio + 0.5)
else:
pixmapWidth = int(pixmapHeight * self.displayAspectRatio + 0.5)
self.previewBoxLabel.setFixedSize(pixmapWidth + 2 * frameWidth,
pixmapHeight + 2 * frameWidth)
def onCurrentIdChanged(self, pageId):
"""
Detects Page changes and updates as approprate.
"""
if self.page(pageId) == self.previewPage:
self.updateTheme()
frame = self.thememanager.generateImage(self.theme)
self.previewBoxLabel.setPixmap(QtGui.QPixmap.fromImage(frame))
self.displayAspectRatio = float(frame.width()) / frame.height()
self.resizeEvent()
def onOutlineCheckCheckBoxStateChanged(self, state):
2010-10-16 07:21:24 +00:00
"""
2010-10-16 13:54:57 +00:00
Change state as Outline check box changed
2010-10-16 07:21:24 +00:00
"""
2011-01-23 08:25:21 +00:00
if self.updateThemeAllowed:
if state == QtCore.Qt.Checked:
self.theme.font_main_outline = True
else:
self.theme.font_main_outline = False
self.outlineColorButton.setEnabled(self.theme.font_main_outline)
self.outlineSizeSpinBox.setEnabled(self.theme.font_main_outline)
self.calculateLines()
2010-10-11 16:14:36 +00:00
def onShadowCheckCheckBoxStateChanged(self, state):
2010-10-16 07:21:24 +00:00
"""
Change state as Shadow check box changed
"""
2011-01-23 08:25:21 +00:00
if self.updateThemeAllowed:
if state == QtCore.Qt.Checked:
self.theme.font_main_shadow = True
else:
self.theme.font_main_shadow = False
self.shadowColorButton.setEnabled(self.theme.font_main_shadow)
self.shadowSizeSpinBox.setEnabled(self.theme.font_main_shadow)
self.calculateLines()
2010-10-03 07:42:02 +00:00
def onMainPositionCheckBoxStateChanged(self, value):
2010-10-16 07:21:24 +00:00
"""
Change state as Main Area Position check box changed
NOTE the font_main_override is the inverse of the check box value
2010-10-16 07:21:24 +00:00
"""
if self.updateThemeAllowed:
self.theme.font_main_override = not (value == QtCore.Qt.Checked)
2010-10-16 07:21:24 +00:00
def onFooterPositionCheckBoxStateChanged(self, value):
2010-10-16 07:21:24 +00:00
"""
Change state as Footer Area Position check box changed
NOTE the font_footer_override is the inverse of the check box value
2010-10-16 07:21:24 +00:00
"""
if self.updateThemeAllowed:
self.theme.font_footer_override = not (value == QtCore.Qt.Checked)
2010-10-13 19:40:01 +00:00
def exec_(self, edit=False):
2010-10-03 07:42:02 +00:00
"""
Run the wizard.
"""
2010-12-21 11:09:00 +00:00
log.debug(u'Editing theme %s' % self.theme.theme_name)
self.updateThemeAllowed = False
2010-10-03 07:42:02 +00:00
self.setDefaults()
self.updateThemeAllowed = True
self.themeNameLabel.setVisible(not edit)
self.themeNameEdit.setVisible(not edit)
2011-01-09 18:51:06 +00:00
self.edit_mode = edit
if edit:
self.setWindowTitle(unicode(translate('OpenLP.ThemeWizard',
2011-01-03 19:47:14 +00:00
'Edit Theme - %s')) % self.theme.theme_name)
self.next()
else:
2011-02-18 01:07:55 +00:00
self.setWindowTitle(UiStrings.NewTheme)
2010-10-03 07:42:02 +00:00
return QtGui.QWizard.exec_(self)
2010-10-24 19:23:12 +00:00
def initializePage(self, id):
2010-11-08 06:11:04 +00:00
"""
Set up the pages for Initial run through dialog
"""
log.debug(u'initializePage %s' % id)
wizardPage = self.page(id)
if wizardPage == self.backgroundPage:
self.setBackgroundPageValues()
elif wizardPage == self.mainAreaPage:
self.setMainAreaPageValues()
elif wizardPage == self.footerAreaPage:
self.setFooterAreaPageValues()
elif wizardPage == self.alignmentPage:
self.setAlignmentPageValues()
elif wizardPage == self.areaPositionPage:
self.setPositionPageValues()
2010-10-03 07:42:02 +00:00
def setBackgroundPageValues(self):
2010-10-16 07:21:24 +00:00
"""
Handle the display and state of the Background page.
2010-10-16 07:21:24 +00:00
"""
2010-10-09 06:48:54 +00:00
if self.theme.background_type == \
BackgroundType.to_string(BackgroundType.Solid):
self.colorButton.setStyleSheet(u'background-color: %s' %
2010-10-03 07:42:02 +00:00
self.theme.background_color)
self.setField(u'background_type', QtCore.QVariant(0))
2010-10-09 06:48:54 +00:00
elif self.theme.background_type == \
BackgroundType.to_string(BackgroundType.Gradient):
self.gradientStartButton.setStyleSheet(u'background-color: %s' %
2010-10-03 07:42:02 +00:00
self.theme.background_start_color)
self.gradientEndButton.setStyleSheet(u'background-color: %s' %
2010-10-03 07:42:02 +00:00
self.theme.background_end_color)
self.setField(u'background_type', QtCore.QVariant(1))
2010-10-03 07:42:02 +00:00
else:
self.imageFileEdit.setText(self.theme.background_filename)
self.setField(u'background_type', QtCore.QVariant(2))
2010-10-09 06:48:54 +00:00
if self.theme.background_direction == \
BackgroundGradientType.to_string(BackgroundGradientType.Horizontal):
2010-11-18 17:46:47 +00:00
self.setField(u'gradient', QtCore.QVariant(0))
2010-10-09 06:48:54 +00:00
elif self.theme.background_direction == \
BackgroundGradientType.to_string(BackgroundGradientType.Vertical):
2010-11-18 17:46:47 +00:00
self.setField(u'gradient', QtCore.QVariant(1))
2010-10-09 06:48:54 +00:00
elif self.theme.background_direction == \
BackgroundGradientType.to_string(BackgroundGradientType.Circular):
2010-11-18 17:46:47 +00:00
self.setField(u'gradient', QtCore.QVariant(2))
2010-10-09 06:48:54 +00:00
elif self.theme.background_direction == \
BackgroundGradientType.to_string(BackgroundGradientType.LeftTop):
2010-11-18 17:46:47 +00:00
self.setField(u'gradient', QtCore.QVariant(3))
2010-10-09 06:48:54 +00:00
else:
2010-11-18 17:46:47 +00:00
self.setField(u'gradient', QtCore.QVariant(4))
2010-10-03 07:42:02 +00:00
def setMainAreaPageValues(self):
2010-10-16 07:21:24 +00:00
"""
Handle the display and state of the Main Area page.
2010-10-16 07:21:24 +00:00
"""
2010-10-13 19:40:01 +00:00
self.mainFontComboBox.setCurrentFont(
QtGui.QFont(self.theme.font_main_name))
self.mainColorButton.setStyleSheet(u'background-color: %s' %
2010-10-09 11:20:47 +00:00
self.theme.font_main_color)
self.setField(u'mainSizeSpinBox',
2010-10-11 16:14:36 +00:00
QtCore.QVariant(self.theme.font_main_size))
self.setField(u'lineSpacingSpinBox',
2010-10-09 11:20:47 +00:00
QtCore.QVariant(self.theme.font_main_line_adjustment))
self.setField(u'outlineCheckBox',
2010-10-09 11:20:47 +00:00
QtCore.QVariant(self.theme.font_main_outline))
self.outlineColorButton.setStyleSheet(u'background-color: %s' %
2010-10-09 11:20:47 +00:00
self.theme.font_main_outline_color)
self.setField(u'outlineSizeSpinBox',
2010-10-09 11:20:47 +00:00
QtCore.QVariant(self.theme.font_main_outline_size))
self.setField(u'shadowCheckBox',
2010-10-09 11:20:47 +00:00
QtCore.QVariant(self.theme.font_main_shadow))
self.shadowColorButton.setStyleSheet(u'background-color: %s' %
2010-10-09 11:20:47 +00:00
self.theme.font_main_shadow_color)
self.setField(u'shadowSizeSpinBox',
2010-10-09 11:20:47 +00:00
QtCore.QVariant(self.theme.font_main_shadow_size))
self.setField(u'mainBoldCheckBox',
2010-10-11 16:14:36 +00:00
QtCore.QVariant(self.theme.font_main_bold))
self.setField(u'mainItalicsCheckBox',
2010-10-11 16:14:36 +00:00
QtCore.QVariant(self.theme.font_main_italics))
2010-10-09 10:59:49 +00:00
def setFooterAreaPageValues(self):
2010-10-16 07:21:24 +00:00
"""
Handle the display and state of the Footer Area page.
2010-10-16 07:21:24 +00:00
"""
2010-10-13 19:40:01 +00:00
self.footerFontComboBox.setCurrentFont(
QtGui.QFont(self.theme.font_main_name))
self.footerColorButton.setStyleSheet(u'background-color: %s' %
2010-10-11 16:14:36 +00:00
self.theme.font_footer_color)
self.setField(u'footerSizeSpinBox',
2010-10-11 16:14:36 +00:00
QtCore.QVariant(self.theme.font_footer_size))
def setPositionPageValues(self):
2010-10-16 13:54:57 +00:00
"""
Handle the display and state of the Position page.
2010-10-16 13:54:57 +00:00
"""
2010-11-16 17:33:41 +00:00
# Main Area
self.mainPositionCheckBox.setChecked(not self.theme.font_main_override)
self.setField(u'mainPositionX', QtCore.QVariant(self.theme.font_main_x))
self.setField(u'mainPositionY', QtCore.QVariant(self.theme.font_main_y))
self.setField(u'mainPositionHeight',
2010-10-13 20:19:38 +00:00
QtCore.QVariant(self.theme.font_main_height))
self.setField(u'mainPositionWidth',
2010-10-13 20:19:38 +00:00
QtCore.QVariant(self.theme.font_main_width))
2010-11-16 17:33:41 +00:00
# Footer
self.footerPositionCheckBox.setChecked(
not self.theme.font_footer_override)
self.setField(u'footerPositionX',
2010-10-13 20:19:38 +00:00
QtCore.QVariant(self.theme.font_footer_x))
self.setField(u'footerPositionY',
2010-10-13 20:19:38 +00:00
QtCore.QVariant(self.theme.font_footer_y))
self.setField(u'footerPositionHeight',
2010-10-13 20:19:38 +00:00
QtCore.QVariant(self.theme.font_footer_height))
self.setField(u'footerPositionWidth',
2010-10-13 20:19:38 +00:00
QtCore.QVariant(self.theme.font_footer_width))
2010-10-09 10:59:49 +00:00
def setAlignmentPageValues(self):
2010-11-08 06:11:04 +00:00
"""
Handle the display and state of the Alignments page.
2010-11-08 06:11:04 +00:00
"""
self.setField(u'horizontal',
2010-10-17 18:58:42 +00:00
QtCore.QVariant(self.theme.display_horizontal_align))
self.setField(u'vertical',
2010-10-17 18:58:42 +00:00
QtCore.QVariant(self.theme.display_vertical_align))
self.setField(u'slideTransition',
2010-11-16 17:33:41 +00:00
QtCore.QVariant(self.theme.display_slide_transition))
2010-10-17 18:58:42 +00:00
def setPreviewPageValues(self):
"""
Handle the display and state of the Preview page.
"""
2010-10-17 18:58:42 +00:00
self.setField(u'name', QtCore.QVariant(self.theme.theme_name))
2010-10-13 19:40:01 +00:00
def onBackgroundComboBoxCurrentIndexChanged(self, index):
2010-10-16 07:21:24 +00:00
"""
Background style Combo box has changed.
"""
# do not allow updates when screen is building for the first time.
if self.updateThemeAllowed:
self.theme.background_type = BackgroundType.to_string(index)
self.setBackgroundPageValues()
2010-10-03 07:42:02 +00:00
def onGradientComboBoxCurrentIndexChanged(self, index):
2010-10-16 07:21:24 +00:00
"""
Background gradient Combo box has changed.
"""
2011-01-25 04:42:15 +00:00
if self.updateThemeAllowed:
self.theme.background_direction = \
BackgroundGradientType.to_string(index)
self.setBackgroundPageValues()
2010-10-03 07:42:02 +00:00
def onColorButtonClicked(self):
2010-11-08 06:11:04 +00:00
"""
Background / Gradient 1 Color button pushed.
"""
self.theme.background_color = \
self._colorButton(self.theme.background_color)
self.setBackgroundPageValues()
def onGradientStartButtonClicked(self):
"""
Gradient 2 Color button pushed.
"""
self.theme.background_start_color = \
self._colorButton(self.theme.background_start_color)
self.setBackgroundPageValues()
2010-10-03 07:42:02 +00:00
def onGradientEndButtonClicked(self):
2010-11-08 06:11:04 +00:00
"""
Gradient 2 Color button pushed.
"""
2010-10-03 07:42:02 +00:00
self.theme.background_end_color = \
self._colorButton(self.theme.background_end_color)
self.setBackgroundPageValues()
2010-10-03 07:42:02 +00:00
def onImageBrowseButtonClicked(self):
2010-11-08 06:11:04 +00:00
"""
Background Image button pushed.
"""
2010-10-03 07:42:02 +00:00
images_filter = get_images_filter()
2011-02-14 18:20:59 +00:00
images_filter = u'%s;;%s (*.*) (*)' % (
images_filter, UiStrings.AllFiles)
2010-10-03 07:42:02 +00:00
filename = QtGui.QFileDialog.getOpenFileName(self,
2010-11-04 17:03:52 +00:00
translate('OpenLP.ThemeForm', 'Select Image'), u'',
2010-10-03 07:42:02 +00:00
images_filter)
if filename:
2010-11-05 19:20:41 +00:00
self.theme.background_filename = unicode(filename)
self.setBackgroundPageValues()
2010-10-03 07:42:02 +00:00
def onMainColorButtonClicked(self):
2010-10-09 10:59:49 +00:00
self.theme.font_main_color = \
self._colorButton(self.theme.font_main_color)
self.setMainAreaPageValues()
2010-10-09 10:59:49 +00:00
def onOutlineColorButtonClicked(self):
2010-10-09 10:59:49 +00:00
self.theme.font_main_outline_color = \
self._colorButton(self.theme.font_main_outline_color)
self.setMainAreaPageValues()
2010-10-09 10:59:49 +00:00
def onShadowColorButtonClicked(self):
2010-10-09 10:59:49 +00:00
self.theme.font_main_shadow_color = \
self._colorButton(self.theme.font_main_shadow_color)
self.setMainAreaPageValues()
2010-10-11 16:14:36 +00:00
def onFooterColorButtonClicked(self):
2010-10-11 16:14:36 +00:00
self.theme.font_footer_color = \
self._colorButton(self.theme.font_footer_color)
self.setFooterAreaPageValues()
2010-10-09 10:59:49 +00:00
2010-10-11 16:14:36 +00:00
def updateTheme(self):
2010-10-16 07:21:24 +00:00
"""
Update the theme object from the UI for fields not already updated
when the are changed.
"""
if not self.updateThemeAllowed:
return
2010-11-08 06:11:04 +00:00
log.debug(u'updateTheme')
2010-10-13 19:40:01 +00:00
# main page
self.theme.font_main_name = \
2010-10-17 19:34:10 +00:00
unicode(self.mainFontComboBox.currentFont().family())
2010-10-13 19:40:01 +00:00
self.theme.font_main_size = \
2010-10-09 11:20:47 +00:00
self.field(u'mainSizeSpinBox').toInt()[0]
self.theme.font_main_line_adjustment = \
self.field(u'lineSpacingSpinBox').toInt()[0]
2010-11-05 19:20:41 +00:00
self.theme.font_main_outline_size = \
2010-10-09 11:20:47 +00:00
self.field(u'outlineSizeSpinBox').toInt()[0]
self.theme.font_main_shadow_size = \
self.field(u'shadowSizeSpinBox').toInt()[0]
2010-11-05 19:20:41 +00:00
self.theme.font_main_bold = \
self.field(u'mainBoldCheckBox').toBool()
2010-11-05 19:20:41 +00:00
self.theme.font_main_italics = \
self.field(u'mainItalicsCheckBox').toBool()
2010-10-13 19:40:01 +00:00
# footer page
self.theme.font_footer_name = \
2010-10-17 19:34:10 +00:00
unicode(self.footerFontComboBox.currentFont().family())
2010-10-13 19:40:01 +00:00
self.theme.font_footer_size = \
self.field(u'footerSizeSpinBox').toInt()[0]
2010-10-16 07:21:24 +00:00
# position page
self.theme.font_main_x = self.field(u'mainPositionX').toInt()[0]
self.theme.font_main_y = self.field(u'mainPositionY').toInt()[0]
self.theme.font_main_height = \
self.field(u'mainPositionHeight').toInt()[0]
self.theme.font_main_width = self.field(u'mainPositionWidth').toInt()[0]
self.theme.font_footer_x = self.field(u'footerPositionX').toInt()[0]
self.theme.font_footer_y = self.field(u'footerPositionY').toInt()[0]
self.theme.font_footer_height = \
self.field(u'footerPositionHeight').toInt()[0]
self.theme.font_footer_width = \
self.field(u'footerPositionWidth').toInt()[0]
2010-10-17 19:34:10 +00:00
# position page
self.theme.display_horizontal_align = \
self.horizontalComboBox.currentIndex()
self.theme.display_vertical_align = \
self.verticalComboBox.currentIndex()
self.theme.display_slide_transition = \
self.field(u'slideTransition').toBool()
2010-10-09 11:20:47 +00:00
2010-11-05 19:20:41 +00:00
def accept(self):
"""
Lets save the them as Finish has been pressed
"""
2010-11-08 06:11:04 +00:00
# Save the theme name
2011-01-25 04:42:15 +00:00
self.theme.theme_name = unicode(self.field(u'name').toString())
2010-11-18 17:40:20 +00:00
if not self.theme.theme_name:
critical_error_message_box(
2010-11-18 17:40:20 +00:00
translate('OpenLP.ThemeForm', 'Theme Name Missing'),
translate('OpenLP.ThemeForm',
2011-01-15 19:24:50 +00:00
'There is no name for this theme. Please enter one.'))
2010-11-05 19:20:41 +00:00
return
2010-11-21 20:46:44 +00:00
if self.theme.theme_name == u'-1' or self.theme.theme_name == u'None':
critical_error_message_box(
2010-11-21 20:46:44 +00:00
translate('OpenLP.ThemeForm', 'Theme Name Invalid'),
2010-11-21 20:45:22 +00:00
translate('OpenLP.ThemeForm',
2011-01-15 19:24:50 +00:00
'Invalid theme name. Please enter one.'))
2010-11-21 20:45:22 +00:00
return
saveFrom = None
saveTo = None
2010-11-05 19:20:41 +00:00
if self.theme.background_type == \
BackgroundType.to_string(BackgroundType.Image):
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
2011-01-09 18:51:06 +00:00
if not self.edit_mode and \
not self.thememanager.checkIfThemeExists(self.theme.theme_name):
2011-01-09 19:15:40 +00:00
return
2011-01-03 19:47:14 +00:00
self.thememanager.saveTheme(self.theme, saveFrom, saveTo)
return QtGui.QDialog.accept(self)
2010-11-05 19:20:41 +00:00
def _colorButton(self, field):
2010-10-16 07:21:24 +00:00
"""
Handle Color buttons
"""
2010-10-03 07:42:02 +00:00
new_color = QtGui.QColorDialog.getColor(
QtGui.QColor(field), self)
if new_color.isValid():
2010-11-24 01:51:08 +00:00
field = new_color.name()
return field