More refactoring

This commit is contained in:
Tim Bentley 2010-10-11 17:14:36 +01:00
parent 216f044883
commit 562a27e8ca
6 changed files with 219 additions and 67 deletions

View File

@ -460,7 +460,7 @@ def build_lyrics_css(item, webkitvers):
shadow += build_lyrics_outline_css(theme, True)
else:
lyricsmain += u' text-shadow: %s %spx %spx;' % \
(theme.font_mainy_shadow_color, theme.font_main_shadow_size,
(theme.font_main_shadow_color, theme.font_main_shadow_size,
theme.font_main_shadow_size)
lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow)
return lyrics_css
@ -524,7 +524,7 @@ def build_lyrics_format_css(theme, width, height):
'text-align: %s; vertical-align: %s; font-family: %s; ' \
'font-size: %spt; color: %s; line-height: %d%%; margin:0;' \
'padding:0; padding-left:%spx; width: %spx; height: %spx; ' % \
(align, valign, theme.font_main_name, theme.font_main_proportion,
(align, valign, theme.font_main_name, theme.font_main_size,
theme.font_main_color, 100 + int(theme.font_main_line_adjustment),
left_margin, width, height)
if theme.font_main_outline:
@ -588,7 +588,7 @@ def build_footer_css(item, height):
bottom = height - int(item.footer.y()) - int(item.footer.height())
lyrics_html = style % (item.footer.x(), bottom,
item.footer.width(), theme.font_footer_name,
theme.font_footer_proportion, theme.font_footer_color)
theme.font_footer_size, theme.font_footer_color)
return lyrics_html
def build_alert_css(alertTab, width):

View File

@ -42,7 +42,6 @@ BLANK_THEME_XML = \
'''<?xml version="1.0" encoding="utf-8"?>
<theme version="1.0">
<name>BlankStyle</name>
<background mode="transparent"/>
<background type="solid" mode="opaque">
<color>#000000</color>
</background>
@ -56,8 +55,8 @@ BLANK_THEME_XML = \
</background>
<font type="main">
<name>Arial</name>
<color>#000000</color>
<proportion>30</proportion>
<color>#FFFFFF</color>
<size>30</size>
<bold>False</bold>
<italics>False</italics>
<line_adjustment>0</line_adjustment>
@ -67,8 +66,8 @@ BLANK_THEME_XML = \
</font>
<font type="footer">
<name>Arial</name>
<color>#000000</color>
<proportion>12</proportion>
<color>#FFFFFF</color>
<size>12</size>
<bold>False</bold>
<italics>False</italics>
<shadow shadowColor="#000000" shadowSize="5">True</shadow>
@ -95,9 +94,9 @@ class ThemeLevel(object):
boolean_list = [u'bold', u'italics', u'override', u'outline', u'shadow', \
u'slide_transition']
integer_list =[u'proportion', u'line_adjustment', u'x', u'height', u'y', \
integer_list =[u'size', u'line_adjustment', u'x', u'height', u'y', \
u'width', u'shadow_size', u'outline_size', u'horizontal_align', \
u'vertical_align', u'wrap_style' ]
u'vertical_align']
class ThemeXML(object):
"""
@ -109,6 +108,7 @@ class ThemeXML(object):
"""
# Create the minidom document
self.theme_xml = Document()
self.parse_xml(BLANK_THEME_XML)
def extend_image_filename(self, path):
"""
@ -129,7 +129,7 @@ class ThemeXML(object):
"""
self.theme = self.theme_xml.createElement(u'theme')
self.theme_xml.appendChild(self.theme)
self.theme.setAttribute(u'version', u'1.0')
self.theme.setAttribute(u'version', u'2.0')
self.name = self.theme_xml.createElement(u'name')
text_node = self.theme_xml.createTextNode(name)
self.name.appendChild(text_node)
@ -262,7 +262,7 @@ class ThemeXML(object):
# Create Font color element
self.child_element(background, u'color', color)
# Create Proportion name element
self.child_element(background, u'proportion', proportion)
self.child_element(background, u'size', proportion)
# Create weight name element
self.child_element(background, u'bold', bold)
# Create italics name element
@ -361,8 +361,8 @@ class ThemeXML(object):
``xml``
The XML string to parse.
"""
self.parse_xml(BLANK_THEME_XML)
self.parse_xml(unicode(xml))
print self
def parse_xml(self, xml):
"""
@ -388,7 +388,9 @@ class ThemeXML(object):
if parent is not None:
if element.getparent().tag == u'font':
master = element.getparent().tag + u'_' + element.getparent().attrib[u'type']
# set up Outline and Shadow Tags and move to font_main
if element.getparent().tag == u'display':
self._create_attr(u'font_main', element.tag, element.text)
master = element.getparent().tag
if element.getparent().tag == u'background':
master = element.getparent().tag
@ -396,26 +398,13 @@ class ThemeXML(object):
for attr in element.getparent().attrib:
self._create_attr(master, attr, element.getparent().attrib[attr])
if master:
# the next few lines fix up errors in the XML to the current standard.
# move the fields from display to font_main
if master == u'display' and (element.tag == u'shadow' or element.tag == u'outline'):
master = u'font_main'
# fix bold font
if element.tag == u'weight':
if element.text.strip().lstrip() == u'Normal':
self._create_attr(master, u'bold', False)
else:
self._create_attr(master, u'bold', True)
else:
# normal service happens here!
self._create_attr(master, element.tag, element.text)
if element.attrib:
for attr in element.attrib:
base_element = attr
# correction for the shadow and outline tags
if element.tag == u'shadow' or element.tag == u'outline':
if not attr.startswith(element.tag):
elembase_elementent = element.tag + u'_' + attr
base_element = element.tag + u'_' + attr
self._create_attr(master, base_element,
element.attrib[attr])
else:
@ -424,10 +413,39 @@ class ThemeXML(object):
if element.tag == u'name':
self._create_attr(u'theme', element.tag, element.text)
def _translate_tags(self, master, element, value):
"""
Clean up XML removing and redefining tags
"""
master = master.strip().lstrip()
element = element.strip().lstrip()
value = unicode(value).strip().lstrip()
print "start", master, element, value
if master == u'display':
if element == u'wrapStyle':
return True, None, None, None
if element == u'shadow' or element == u'outline':
master = u'font_main'
# fix bold font
if element == u'weight':
element = u'bold'
if value == u'Normal':
value = False
else:
value = True
if element == u'proportion':
element = u'size'
print "end", master, element, value
return False, master, element, value
def _create_attr(self, master , element, value):
"""
Create the attributes with the correct data types and name format
"""
reject, master, element, value = \
self._translate_tags(master, element, value)
if reject:
return
field = self._de_hump(element)
tag = master + u'_' + field
if element in boolean_list:

View File

@ -476,8 +476,9 @@ class ThemeManager(QtGui.QWidget):
unicode(themename) + u'.xml')
xml = get_text_file_string(xml_file)
if not xml:
xml = self.baseTheme()
return self.createThemeFromXml(xml, self.path)
return self.baseTheme()
else:
return self.createThemeFromXml(xml, self.path)
def checkThemesExists(self, dir):
"""
@ -755,15 +756,14 @@ class ThemeManager(QtGui.QWidget):
"""
log.debug(u'base theme created')
newtheme = ThemeXML()
newtheme.new_document(
unicode(translate('OpenLP.ThemeManager', 'New Theme')))
newtheme.add_background_solid(u'#000000')
newtheme.add_font(unicode(QtGui.QFont().family()), u'#FFFFFF',
u'30', u'False')
newtheme.add_font(unicode(QtGui.QFont().family()), u'#FFFFFF',
u'12', u'False', u'footer')
newtheme.add_display(u'0', u'0', u'0')
print newtheme.extract_xml()
# newtheme.new_document(
# unicode(translate('OpenLP.ThemeManager', 'New Theme')))
# newtheme.add_background_solid(u'#000000')
# newtheme.add_font(unicode(QtGui.QFont().family()), u'#FFFFFF',
# u'30', u'False')
# newtheme.add_font(unicode(QtGui.QFont().family()), u'#FFFFFF',
# u'12', u'False', u'footer')
# newtheme.add_display(u'0', u'0', u'0')
return newtheme.extract_xml()
def createThemeFromXml(self, theme_xml, path):

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'themewizard.ui'
#
# Created: Sat Oct 9 08:32:36 2010
# Created: Sat Oct 9 19:28:22 2010
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
@ -194,6 +194,12 @@ class Ui_ThemeWizard(object):
self.shadowSizeSpinBox.setObjectName("shadowSizeSpinBox")
self.shadowLayout.addWidget(self.shadowSizeSpinBox)
self.formLayout.setLayout(5, QtGui.QFormLayout.FieldRole, self.shadowLayout)
self.boldCheckBox = QtGui.QCheckBox(self.mainAreaPage)
self.boldCheckBox.setObjectName("boldCheckBox")
self.formLayout.setWidget(6, QtGui.QFormLayout.FieldRole, self.boldCheckBox)
self.italicsCheckBox = QtGui.QCheckBox(self.mainAreaPage)
self.italicsCheckBox.setObjectName("italicsCheckBox")
self.formLayout.setWidget(7, QtGui.QFormLayout.FieldRole, self.italicsCheckBox)
ThemeWizard.addPage(self.mainAreaPage)
self.footerAreaPage = QtGui.QWizardPage()
self.footerAreaPage.setObjectName("footerAreaPage")
@ -232,6 +238,31 @@ class Ui_ThemeWizard(object):
ThemeWizard.addPage(self.footerAreaPage)
self.alignmentPage = QtGui.QWizardPage()
self.alignmentPage.setObjectName("alignmentPage")
self.formLayout_2 = QtGui.QFormLayout(self.alignmentPage)
self.formLayout_2.setMargin(20)
self.formLayout_2.setObjectName("formLayout_2")
self.HorizontalLabel = QtGui.QLabel(self.alignmentPage)
self.HorizontalLabel.setObjectName("HorizontalLabel")
self.formLayout_2.setWidget(0, QtGui.QFormLayout.LabelRole, self.HorizontalLabel)
self.horizontalComboBox = QtGui.QComboBox(self.alignmentPage)
self.horizontalComboBox.setEditable(False)
self.horizontalComboBox.setObjectName("horizontalComboBox")
self.horizontalComboBox.addItem("")
self.horizontalComboBox.addItem("")
self.horizontalComboBox.addItem("")
self.formLayout_2.setWidget(0, QtGui.QFormLayout.FieldRole, self.horizontalComboBox)
self.Verticallabe = QtGui.QLabel(self.alignmentPage)
self.Verticallabe.setObjectName("Verticallabe")
self.formLayout_2.setWidget(1, QtGui.QFormLayout.LabelRole, self.Verticallabe)
self.verticalComboBox = QtGui.QComboBox(self.alignmentPage)
self.verticalComboBox.setObjectName("verticalComboBox")
self.verticalComboBox.addItem("")
self.verticalComboBox.addItem("")
self.verticalComboBox.addItem("")
self.formLayout_2.setWidget(1, QtGui.QFormLayout.FieldRole, self.verticalComboBox)
self.TransitionsCheckBox = QtGui.QCheckBox(self.alignmentPage)
self.TransitionsCheckBox.setObjectName("TransitionsCheckBox")
self.formLayout_2.setWidget(2, QtGui.QFormLayout.FieldRole, self.TransitionsCheckBox)
ThemeWizard.addPage(self.alignmentPage)
self.areaPositionPage = QtGui.QWizardPage()
self.areaPositionPage.setObjectName("areaPositionPage")
@ -454,6 +485,8 @@ class Ui_ThemeWizard(object):
self.shadowCheckBox.setText(QtGui.QApplication.translate("ThemeWizard", "&Shadow:", None, QtGui.QApplication.UnicodeUTF8))
self.shadowSizeLabel.setText(QtGui.QApplication.translate("ThemeWizard", "Size:", None, QtGui.QApplication.UnicodeUTF8))
self.shadowSizeSpinBox.setSuffix(QtGui.QApplication.translate("ThemeWizard", "pt", None, QtGui.QApplication.UnicodeUTF8))
self.boldCheckBox.setText(QtGui.QApplication.translate("ThemeWizard", "Bold Display", None, QtGui.QApplication.UnicodeUTF8))
self.italicsCheckBox.setText(QtGui.QApplication.translate("ThemeWizard", "Italic Display", None, QtGui.QApplication.UnicodeUTF8))
self.footerAreaPage.setTitle(QtGui.QApplication.translate("ThemeWizard", "Footer Area Font Details", None, QtGui.QApplication.UnicodeUTF8))
self.footerAreaPage.setSubTitle(QtGui.QApplication.translate("ThemeWizard", "Define the font and display characteristics for the Footer text", None, QtGui.QApplication.UnicodeUTF8))
self.footerFontLabel.setText(QtGui.QApplication.translate("ThemeWizard", "Font:", None, QtGui.QApplication.UnicodeUTF8))
@ -462,6 +495,15 @@ class Ui_ThemeWizard(object):
self.footerSizeSpinBox.setSuffix(QtGui.QApplication.translate("ThemeWizard", "pt", None, QtGui.QApplication.UnicodeUTF8))
self.alignmentPage.setTitle(QtGui.QApplication.translate("ThemeWizard", "Text Formatting Details", None, QtGui.QApplication.UnicodeUTF8))
self.alignmentPage.setSubTitle(QtGui.QApplication.translate("ThemeWizard", "Allows additional display formatting information to be defined", None, QtGui.QApplication.UnicodeUTF8))
self.HorizontalLabel.setText(QtGui.QApplication.translate("ThemeWizard", "Horizontal Align:", None, QtGui.QApplication.UnicodeUTF8))
self.horizontalComboBox.setItemText(0, QtGui.QApplication.translate("ThemeWizard", "Left", None, QtGui.QApplication.UnicodeUTF8))
self.horizontalComboBox.setItemText(1, QtGui.QApplication.translate("ThemeWizard", "Center", None, QtGui.QApplication.UnicodeUTF8))
self.horizontalComboBox.setItemText(2, QtGui.QApplication.translate("ThemeWizard", "Right", None, QtGui.QApplication.UnicodeUTF8))
self.Verticallabe.setText(QtGui.QApplication.translate("ThemeWizard", "Vertcal Align:", None, QtGui.QApplication.UnicodeUTF8))
self.verticalComboBox.setItemText(0, QtGui.QApplication.translate("ThemeWizard", "Top", None, QtGui.QApplication.UnicodeUTF8))
self.verticalComboBox.setItemText(1, QtGui.QApplication.translate("ThemeWizard", "Middle", None, QtGui.QApplication.UnicodeUTF8))
self.verticalComboBox.setItemText(2, QtGui.QApplication.translate("ThemeWizard", "Bottom", None, QtGui.QApplication.UnicodeUTF8))
self.TransitionsCheckBox.setText(QtGui.QApplication.translate("ThemeWizard", "Transitions", None, QtGui.QApplication.UnicodeUTF8))
self.areaPositionPage.setTitle(QtGui.QApplication.translate("ThemeWizard", "Output Area Locations", None, QtGui.QApplication.UnicodeUTF8))
self.areaPositionPage.setSubTitle(QtGui.QApplication.translate("ThemeWizard", "Allows you to change and move the Main and Footer areas.", None, QtGui.QApplication.UnicodeUTF8))
self.mainPositionGroupBox.setTitle(QtGui.QApplication.translate("ThemeWizard", "&Main Area", None, QtGui.QApplication.UnicodeUTF8))
@ -488,4 +530,3 @@ class Ui_ThemeWizard(object):
self.previewPage.setSubTitle(QtGui.QApplication.translate("ThemeWizard", "View the theme and save it replacing the current one or change the name to create a new theme", None, QtGui.QApplication.UnicodeUTF8))
self.themeNameLabel.setText(QtGui.QApplication.translate("ThemeWizard", "Theme name:", None, QtGui.QApplication.UnicodeUTF8))
self.previewLabel.setText(QtGui.QApplication.translate("ThemeWizard", "Preview", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -139,18 +139,23 @@ class ThemeWizardForm(QtGui.QWizard, Ui_ThemeWizard):
QtCore.QObject.connect(self.shadowColorPushButton,
QtCore.SIGNAL(u'pressed()'),
self.onShadowColourPushButtonClicked)
QtCore.QObject.connect(self.mainSizeSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onMainSizeSpinBoxFinished)
QtCore.QObject.connect(self.lineSpacingSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onLineSpacingSpinBoxFinished)
QtCore.QObject.connect(self.outlineSizeSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onOutlineSizeSpinBoxFinished)
QtCore.QObject.connect(self.shadowSizeSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onShadowSizeSpinBoxFinished)
QtCore.QObject.connect(self.outlineCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onOutlineCheckCheckBoxChanged)
QtCore.QObject.connect(self.shadowCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onShadowCheckCheckBoxChanged)
QtCore.QObject.connect(self.footerColorPushButton,
QtCore.SIGNAL(u'pressed()'),
self.onFooterColourPushButtonClicked)
def onOutlineCheckCheckBoxChanged(self, state):
self.outlineColorPushButton.setEnabled(state)
self.outlineSizeSpinBox.setEnabled(state)
def onShadowCheckCheckBoxChanged(self, state):
self.shadowColorPushButton.setEnabled(state)
self.shadowSizeSpinBox.setEnabled(state)
def exec_(self):
"""
@ -237,11 +242,10 @@ class ThemeWizardForm(QtGui.QWizard, Ui_ThemeWizard):
self.setField(u'gradient', QtCore.QVariant(4))
def setMainAreaTabValues(self):
#self.setField(u'mainFontComboBox', QtCore.QVariant(self.theme.font_main_name))
self.mainColorPushButton.setStyleSheet(u'background-color: %s' %
self.theme.font_main_color)
self.setField(u'mainSizeSpinBox', \
QtCore.QVariant(self.theme.font_main_proportion))
QtCore.QVariant(self.theme.font_main_size))
self.setField(u'lineSpacingSpinBox', \
QtCore.QVariant(self.theme.font_main_line_adjustment))
self.setField(u'outlineCheckBox', \
@ -256,9 +260,17 @@ class ThemeWizardForm(QtGui.QWizard, Ui_ThemeWizard):
self.theme.font_main_shadow_color)
self.setField(u'shadowSizeSpinBox', \
QtCore.QVariant(self.theme.font_main_shadow_size))
self.setField(u'boldCheckBox', \
QtCore.QVariant(self.theme.font_main_bold))
self.setField(u'italicsCheckBox', \
QtCore.QVariant(self.theme.font_main_italics))
def setFooterAreaTabValues(self):
pass
self.footerColorPushButton.setStyleSheet(u'background-color: %s' %
self.theme.font_footer_color)
self.setField(u'footerSizeSpinBox', \
QtCore.QVariant(self.theme.font_footer_size))
def setAlignmentTabValues(self):
pass
def setPositionTabValues(self):
@ -303,6 +315,8 @@ class ThemeWizardForm(QtGui.QWizard, Ui_ThemeWizard):
u'shadowColorPushButton', self.shadowColorPushButton)
self.mainAreaPage.registerField(
u'shadowSizeSpinBox', self.shadowSizeSpinBox)
self.mainAreaPage.registerField(
u'footerSizeSpinBox', self.footerSizeSpinBox)
def onBackgroundComboBox(self, index):
self.theme.background_type = BackgroundType.to_string(index)
@ -341,40 +355,38 @@ class ThemeWizardForm(QtGui.QWizard, Ui_ThemeWizard):
def onMainFontComboBox(self, index):
#self.theme.background_type = BackgroundType.to_string(index)
self.setBackgroundTabValues()
self.setMainAreaTabValues()
def onMainColourPushButtonClicked(self):
self.theme.font_main_color = \
self._colorButton(self.theme.font_main_color)
self.setBackgroundTabValues()
self.setMainAreaTabValues()
def onOutlineColourPushButtonClicked(self):
self.theme.font_main_outline_color = \
self._colorButton(self.theme.font_main_outline_color)
self.setBackgroundTabValues()
self.setMainAreaTabValues()
def onShadowColourPushButtonClicked(self):
self.theme.font_main_shadow_color = \
self._colorButton(self.theme.font_main_shadow_color)
self.setBackgroundTabValues()
self.setMainAreaTabValues()
def onMainSizeSpinBoxFinished(self):
def onFooterColourPushButtonClicked(self):
self.theme.font_footer_color = \
self._colorButton(self.theme.font_footer_color)
self.setFooterAreaTabValues()
def updateTheme(self):
self.theme.font_main_proportion = \
self.field(u'mainSizeSpinBox').toInt()[0]
def onLineSpacingSpinBoxFinished(self):
self.theme.font_main_line_adjustment = \
self.field(u'lineSpacingSpinBox').toInt()[0]
def onOutlineSizeSpinBoxFinished(self):
self.theme.font_main_outline = \
self.field(u'outlineSizeSpinBox').toInt()[0]
def onShadowSizeSpinBoxFinished(self):
self.theme.font_main_shadow_size = \
self.field(u'shadowSizeSpinBox').toInt()[0]
def _colorButton(self, field):
print field
new_color = QtGui.QColorDialog.getColor(

View File

@ -458,6 +458,20 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="boldCheckBox">
<property name="text">
<string>Bold Display</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="italicsCheckBox">
<property name="text">
<string>Italic Display</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWizardPage" name="footerAreaPage">
@ -554,6 +568,73 @@ p, li { white-space: pre-wrap; }
<property name="subTitle">
<string>Allows additional display formatting information to be defined</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="margin">
<number>20</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="HorizontalLabel">
<property name="text">
<string>Horizontal Align:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="horizontalComboBox">
<property name="editable">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>Center</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="Verticallabe">
<property name="text">
<string>Vertcal Align:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="verticalComboBox">
<item>
<property name="text">
<string>Top</string>
</property>
</item>
<item>
<property name="text">
<string>Middle</string>
</property>
</item>
<item>
<property name="text">
<string>Bottom</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="TransitionsCheckBox">
<property name="text">
<string>Transitions</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWizardPage" name="areaPositionPage">
<property name="title">