Change xml handling to work with Normal/Bold and True

This commit is contained in:
Tim Bentley 2009-08-03 20:49:21 +01:00
parent 13f016cf5f
commit 5ccf0581de
3 changed files with 44 additions and 37 deletions

View File

@ -556,17 +556,21 @@ class Renderer(object):
""" """
Set the fonts from the current theme settings. Set the fonts from the current theme settings.
""" """
footer_weight = 50
if self._theme.font_footer_weight == u'Bold':
footer_weight = 75
self.footerFont = QtGui.QFont(self._theme.font_footer_name, self.footerFont = QtGui.QFont(self._theme.font_footer_name,
int(self._theme.font_footer_proportion), # size int(self._theme.font_footer_proportion), # size
int(self._theme.font_footer_weight), # weight int(footer_weight), # weight
0)# italic self._theme.font_footer_italics)# italic
self.footerFont.setItalic(int(self._theme.font_footer_italics))
self.footerFont.setPixelSize(int(self._theme.font_footer_proportion)) self.footerFont.setPixelSize(int(self._theme.font_footer_proportion))
main_weight = 50
if self._theme.font_main_weight == u'Bold':
main_weight = 75
self.mainFont = QtGui.QFont(self._theme.font_main_name, self.mainFont = QtGui.QFont(self._theme.font_main_name,
int(self._theme.font_main_proportion), # size int(self._theme.font_main_proportion), # size
int(self._theme.font_main_weight), # weight int(main_weight), # weight
0)# italic self._theme.font_main_italics)# italic
self.mainFont.setItalic(int(self._theme.font_main_italics))
self.mainFont.setPixelSize(int(self._theme.font_main_proportion)) self.mainFont.setPixelSize(int(self._theme.font_main_proportion))
def _get_extent_and_render(self, line, footer, tlcorner=(0, 0), draw=False, color=None): def _get_extent_and_render(self, line, footer, tlcorner=(0, 0), draw=False, color=None):

View File

@ -46,16 +46,16 @@ blankthemexml=\
<name>Arial</name> <name>Arial</name>
<color>#000000</color> <color>#000000</color>
<proportion>30</proportion> <proportion>30</proportion>
<weight>50</weight> <weight>Normal</weight>
<italics>0</italics> <italics>False</italics>
<location override="False" x="0" y="0" width="0" height="0"/> <location override="False" x="0" y="0" width="0" height="0"/>
</font> </font>
<font type="footer"> <font type="footer">
<name>Arial</name> <name>Arial</name>
<color>#000000</color> <color>#000000</color>
<proportion>12</proportion> <proportion>12</proportion>
<weight>50</weight> <weight>Normal</weight>
<italics>0</italics> <italics>False</italics>
<location override="False" x="0" y="0" width="0" height="0"/> <location override="False" x="0" y="0" width="0" height="0"/>
</font> </font>
<display> <display>
@ -161,7 +161,7 @@ class ThemeXML(object):
#Create Filename element #Create Filename element
self.child_element(background, u'filename', filename) self.child_element(background, u'filename', filename)
def add_font(self, name, color, proportion, override, fonttype=u'main', weight=u'50', italics=u'0', def add_font(self, name, color, proportion, override, fonttype=u'main', weight=u'Bold', italics=False,
xpos=0, ypos=0, width=0, height=0): xpos=0, ypos=0, width=0, height=0):
""" """
Add a Font. Add a Font.
@ -341,14 +341,17 @@ class ThemeXML(object):
setattr(self, master + element.tag + u'_'+ e[0], e[1]) setattr(self, master + element.tag + u'_'+ e[0], e[1])
else: else:
field = master + e[0] field = master + e[0]
e1 = e[1]
if e[1] == u'True' or e[1] == u'False': if e[1] == u'True' or e[1] == u'False':
e1 = str_to_bool(e[1]) setattr(self, field, str_to_bool(e[1]))
setattr(self, field, e1) else:
setattr(self, field, e[1])
else: else:
if element.tag is not None: if element.tag is not None:
field = master + element.tag field = master + element.tag
setattr(self, field, element.text) if element.text == u'True' or element.text == u'False':
setattr(self, field, str_to_bool(element.text))
else:
setattr(self, field, element.text)
def __str__(self): def __str__(self):
""" """

View File

@ -166,17 +166,17 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
def onFontMainWeightComboBoxSelected(self, value): def onFontMainWeightComboBoxSelected(self, value):
if value ==0: if value ==0:
self.theme.font_main_weight = 50 self.theme.font_main_weight = u'Normal'
self.theme.font_main_italics = 0 self.theme.font_main_italics = False
elif value == 1: elif value == 1:
self.theme.font_main_weight = 75 self.theme.font_main_weight = u'Bold'
self.theme.font_main_italics = 0 self.theme.font_main_italics = False
elif value == 2: elif value == 2:
self.theme.font_main_weight = 50 self.theme.font_main_weight = u'Normal'
self.theme.font_main_italics = 1 self.theme.font_main_italics = True
else: else:
self.theme.font_main_weight = 75 self.theme.font_main_weight = u'Bold'
self.theme.font_main_italics = 1 self.theme.font_main_italics = True
self.previewTheme(self.theme) self.previewTheme(self.theme)
def onFontMainColorPushButtonClicked(self): def onFontMainColorPushButtonClicked(self):
@ -239,17 +239,17 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
def onFontFooterWeightComboBoxSelected(self, value): def onFontFooterWeightComboBoxSelected(self, value):
if value == 0: if value == 0:
self.theme.font_footer_weight = 50 self.theme.font_footer_weight = u'Normal'
self.theme.font_footer_italics = 0 self.theme.font_footer_italics = False
elif value == 1: elif value == 1:
self.theme.font_footer_weight = 75 self.theme.font_footer_weight = u'Bold'
self.theme.font_footer_italics = 0 self.theme.font_footer_italics = False
elif value == 2: elif value == 2:
self.theme.font_footer_weight = 50 self.theme.font_footer_weight = u'Normal'
self.theme.font_footer_italics = 1 self.theme.font_footer_italics = True
else: else:
self.theme.font_footer_weight = 75 self.theme.font_footer_weight = u'Bold'
self.theme.font_footer_italics = 1 self.theme.font_footer_italics = True
self.previewTheme(self.theme) self.previewTheme(self.theme)
def onFontFooterColorPushButtonClicked(self): def onFontFooterColorPushButtonClicked(self):
@ -445,11 +445,11 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.GradientComboBox.setCurrentIndex(2) self.GradientComboBox.setCurrentIndex(2)
self.FontMainSizeSpinBox.setValue(int(self.theme.font_main_proportion)) self.FontMainSizeSpinBox.setValue(int(self.theme.font_main_proportion))
if int(self.theme.font_main_italics) == 0 and int(self.theme.font_main_weight) == 50: if not self.theme.font_main_italics and self.theme.font_main_weight == u'Normal':
self.FontMainWeightComboBox.setCurrentIndex(0) self.FontMainWeightComboBox.setCurrentIndex(0)
elif int(self.theme.font_main_italics) == 0 and int(self.theme.font_main_weight) == 75: elif not self.theme.font_main_italics and self.theme.font_main_weight == u'Bold':
self.FontMainWeightComboBox.setCurrentIndex(1) self.FontMainWeightComboBox.setCurrentIndex(1)
elif int(self.theme.font_main_italics) == 1 and int(self.theme.font_main_weight) == 50: elif self.theme.font_main_italics and self.theme.font_main_weight == u'Normal':
self.FontMainWeightComboBox.setCurrentIndex(2) self.FontMainWeightComboBox.setCurrentIndex(2)
else: else:
self.FontMainWeightComboBox.setCurrentIndex(3) self.FontMainWeightComboBox.setCurrentIndex(3)
@ -459,11 +459,11 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.FontMainWidthSpinBox.setValue(int(self.theme.font_main_width)) self.FontMainWidthSpinBox.setValue(int(self.theme.font_main_width))
self.FontMainHeightSpinBox.setValue(int(self.theme.font_main_height)) self.FontMainHeightSpinBox.setValue(int(self.theme.font_main_height))
self.FontFooterSizeSpinBox.setValue(int(self.theme.font_footer_proportion)) self.FontFooterSizeSpinBox.setValue(int(self.theme.font_footer_proportion))
if int(self.theme.font_footer_italics) == 0 and int(self.theme.font_footer_weight) == 50: if not self.theme.font_footer_italics and self.theme.font_footer_weight == u'Normal':
self.FontFooterWeightComboBox.setCurrentIndex(0) self.FontFooterWeightComboBox.setCurrentIndex(0)
elif int(self.theme.font_footer_italics) == 0 and int(self.theme.font_footer_weight) == 75: elif not self.theme.font_footer_italics and self.theme.font_footer_weight == u'Bold':
self.FontFooterWeightComboBox.setCurrentIndex(1) self.FontFooterWeightComboBox.setCurrentIndex(1)
elif int(self.theme.font_footer_italics) == 1 and int(self.theme.font_footer_weight) == 50: elif self.theme.font_footer_italics and self.theme.font_footer_weight == u'Normal':
self.FontFooterWeightComboBox.setCurrentIndex(2) self.FontFooterWeightComboBox.setCurrentIndex(2)
else: else:
self.FontFooterWeightComboBox.setCurrentIndex(3) self.FontFooterWeightComboBox.setCurrentIndex(3)