Amend theme XML to handle missing data

Add some value management on Theme dialog
This commit is contained in:
Tim Bentley 2009-04-11 08:33:45 +01:00
parent 192088165e
commit 61dbab1899
3 changed files with 154 additions and 19 deletions

View File

@ -52,23 +52,30 @@ class ThemeXML():
background.setAttribute(u'type', u'solid')
self.theme.appendChild(background)
color = self.theme_xml.createElement(u'color')
color = self.theme_xml.createElement(u'color1')
bkc = self.theme_xml.createTextNode(bkcolor)
color.appendChild(bkc)
background.appendChild(color)
color = self.theme_xml.createElement(u'color2')
background.appendChild(color)
color = self.theme_xml.createElement(u'direction')
background.appendChild(color)
def add_background_gradient(self, startcolor, endcolor, direction):
background = self.theme_xml.createElement(u'background')
background.setAttribute(u'mode', u'opaque')
background.setAttribute(u'type', u'Gradient')
background.setAttribute(u'type', u'gradient')
self.theme.appendChild(background)
color = self.theme_xml.createElement(u'startColor')
color = self.theme_xml.createElement(u'color1')
bkc = self.theme_xml.createTextNode(startcolor)
color.appendChild(bkc)
background.appendChild(color)
color = self.theme_xml.createElement(u'endColor')
color = self.theme_xml.createElement(u'color2')
bkc = self.theme_xml.createTextNode(endcolor)
color.appendChild(bkc)
background.appendChild(color)
@ -111,11 +118,10 @@ class ThemeXML():
name = self.theme_xml.createElement(u'location')
name.setAttribute(u'override',override)
if override == u'True':
name.setAttribute(u'x',str(xpos))
name.setAttribute(u'y',str(ypos))
name.setAttribute(u'width',str(width))
name.setAttribute(u'height',str(height))
name.setAttribute(u'x',str(xpos))
name.setAttribute(u'y',str(ypos))
name.setAttribute(u'width',str(width))
name.setAttribute(u'height',str(height))
background.appendChild(name)
def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap):

View File

@ -128,8 +128,8 @@ class Renderer:
p=QtGui.QPainter()
p.begin(self._paint)
if self._theme.background_type == u'solid':
p.fillRect(self._paint.rect(), QtGui.QColor(self._theme.background_color))
elif self._theme.background_type == u'Gradient' : # gradient
p.fillRect(self._paint.rect(), QtGui.QColor(self._theme.background_color1))
elif self._theme.background_type == u'gradient' : # gradient
gradient = None
if self._theme.background_direction == u'vertical':
w = int(self._paint.width())/2
@ -142,8 +142,8 @@ class Renderer:
h = int(self._paint.height())/2
gradient = QtGui.QRadialGradient(w, h, w) # Circular
gradient.setColorAt(0, QtGui.QColor(self._theme.background_startColor))
gradient.setColorAt(1, QtGui.QColor(self._theme.background_endColor))
gradient.setColorAt(0, QtGui.QColor(self._theme.background_color1))
gradient.setColorAt(1, QtGui.QColor(self._theme.background_color2))
p.setBrush(QtGui.QBrush(gradient))
rectPath = QtGui.QPainterPath()

View File

@ -23,6 +23,7 @@ from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QColor, QFont
from openlp.core.lib import ThemeXML
from openlp.core import Renderer
from openlp.core import translate
from amendthemedialog import Ui_AmendThemeDialog
@ -34,12 +35,102 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
#define signals
#Exits
QtCore.QObject.connect(self.ThemeButtonBox, QtCore.SIGNAL("accepted()"), self.accept)
QtCore.QObject.connect(self.ThemeButtonBox, QtCore.SIGNAL("rejected()"), self.close)
#Buttons
QtCore.QObject.connect(self.Color1PushButton ,
QtCore.SIGNAL("pressed()"), self.onColor1PushButtonClicked)
QtCore.QObject.connect(self.Color2PushButton ,
QtCore.SIGNAL("pressed()"), self.onColor2PushButtonClicked)
QtCore.QObject.connect(self.MainFontColorPushButton,
QtCore.SIGNAL("pressed()"), self.onMainFontColorPushButtonClicked)
QtCore.QObject.connect(self.FontFooterColorPushButton,
QtCore.SIGNAL("pressed()"), self.onFontFooterColorPushButtonClicked)
#Combo boxes
QtCore.QObject.connect(self.BackgroundComboBox,
QtCore.SIGNAL("activated(int)"), self.onBackgroundComboBoxSelected)
QtCore.QObject.connect(self.BackgroundTypeComboBox,
QtCore.SIGNAL("activated(int)"), self.onBackgroundTypeComboBoxSelected)
QtCore.QObject.connect(self.GradientComboBox,
QtCore.SIGNAL("activated(int)"), self.onGradientComboBoxSelected)
def accept(self):
return QtGui.QDialog.accept(self)
def loadTheme(self, theme):
if theme == None:
theme = self.baseTheme()
self.theme = ThemeXML()
self.theme.parse(self.baseTheme())
else:
pass
self.generateImage(theme)
self.paintUi(self.theme)
self.generateImage(self.theme)
def onGradientComboBoxSelected(self):
if self.GradientComboBox.currentIndex() == 0: # Horizontal
self.theme.background_direction = u'horizontal'
elif self.GradientComboBox.currentIndex() == 1: # vertical
self.theme.background_direction = u'vertical'
else:
self.theme.background_direction = u'circular'
self.stateChanging(self.theme)
self.generateImage(self.theme)
def onBackgroundComboBoxSelected(self):
if self.BackgroundComboBox.currentIndex() == 0: # Opaque
self.theme.background_mode = u'opaque'
else:
self.theme.background_mode = u'transparent'
self.stateChanging(self.theme)
self.generateImage(self.theme)
def onBackgroundTypeComboBoxSelected(self):
if self.BackgroundTypeComboBox.currentIndex() == 0: # Solid
self.theme.background_type = u'solid'
elif self.BackgroundTypeComboBox.currentIndex() == 1: # Gradient
self.theme.background_type = u'gradient'
if self.theme.background_direction == None: # never defined
self.theme.background_direction = u'horizontal'
self.theme.background_color2 = u'#000000'
else:
self.theme.background_type = u'image'
self.stateChanging(self.theme)
self.generateImage(self.theme)
def onColor1PushButtonClicked(self):
self.theme.background_color1 = QtGui.QColorDialog.getColor(
QColor(self.theme.background_color1), self).name()
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(self.theme.background_color1))
self.generateImage(self.theme)
def onColor2PushButtonClicked(self):
self.theme.background_color2 = QtGui.QColorDialog.getColor(
QColor(self.theme.background_color2), self).name()
self.Color2PushButton.setStyleSheet(
'background-color: %s' % str(self.theme.background_color2))
self.generateImage(self.theme)
def onMainFontColorPushButtonClicked(self):
self.theme.font_main_color = QtGui.QColorDialog.getColor(
QColor(self.theme.font_main_color), self).name()
self.MainFontColorPushButton.setStyleSheet(
'background-color: %s' % str(self.theme.font_main_color))
self.generateImage(self.theme)
def onFontFooterColorPushButtonClicked(self):
self.theme.font_footer_color = QtGui.QColorDialog.getColor(
QColor(self.theme.font_footer_color), self).name()
self.FontFooterColorPushButton.setStyleSheet(
'background-color: %s' % str(self.theme.font_footer_color))
self.generateImage(self.theme)
def baseTheme(self):
log.debug(u'base Theme')
@ -50,12 +141,50 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
newtheme.add_font(str(QFont().family()), str(u'#FFFFFF'), str(12), u'False', u'footer')
newtheme.add_display(str(False), str(u'#FFFFFF'), str(False), str(u'#FFFFFF'),
str(0), str(0), str(0))
return newtheme.extract_xml()
def generateImage(self, theme_xml):
log.debug(u'generateImage %s ', theme_xml)
theme = ThemeXML()
theme.parse(theme_xml)
def paintUi(self, theme):
print theme # leave as helpful for initial development
self.stateChanging(theme)
self.BackgroundTypeComboBox.setCurrentIndex(0)
self.BackgroundComboBox.setCurrentIndex(0)
self.GradientComboBox.setCurrentIndex(0)
self.MainFontColorPushButton.setStyleSheet(
'background-color: %s' % str(theme.font_main_color))
self.FontFooterColorPushButton.setStyleSheet(
'background-color: %s' % str(theme.font_footer_color))
def stateChanging(self, theme):
if theme.background_type == u'solid':
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(theme.background_color1))
self.Color1Label.setText(translate(u'ThemeManager', u'Background Font:'))
self.Color1Label.setVisible(True)
self.Color1PushButton.setVisible(True)
self.Color2Label.setVisible(False)
self.Color2PushButton.setVisible(False)
elif theme.background_type == u'gradient':
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(theme.background_color1))
self.Color2PushButton.setStyleSheet(
'background-color: %s' % str(theme.background_color2))
self.Color1Label.setText(translate(u'ThemeManager', u'First Color:'))
self.Color2Label.setText(translate(u'ThemeManager', u'Second Color:'))
self.Color1Label.setVisible(True)
self.Color1PushButton.setVisible(True)
self.Color2Label.setVisible(True)
self.Color2PushButton.setVisible(True)
else: # must be image
self.Color1Label.setVisible(False)
self.Color1PushButton.setVisible(False)
self.Color2Label.setVisible(False)
self.Color2PushButton.setVisible(False)
def generateImage(self, theme):
log.debug(u'generateImage %s ', theme)
#theme = ThemeXML()
#theme.parse(theme_xml)
#print theme
size=QtCore.QSize(800,600)
frame=TstFrame(size)