Standardize row hight in renderer

Various theme fixes and cleanups
This commit is contained in:
Tim Bentley 2009-08-06 18:43:53 +01:00
parent cf56b14383
commit 9b5f844afa
4 changed files with 63 additions and 103 deletions

View File

@ -154,11 +154,6 @@ class Renderer(object):
text.append(line) text.append(line)
#print text #print text
split_text = self.pre_render_text(text) split_text = self.pre_render_text(text)
# print "-----------------------------"
# print split_text
# split_text = self._split_set_of_lines(text, False)
# print "-----------------------------"
# print split_text
log.debug(u'format_slide - End') log.debug(u'format_slide - End')
return split_text return split_text
@ -168,7 +163,7 @@ class Renderer(object):
line_width = self._rect.width() - self._right_margin line_width = self._rect.width() - self._right_margin
#number of lines on a page - adjust for rounding up. #number of lines on a page - adjust for rounding up.
#print self._rect.height() , metrics.height(), int(self._rect.height() / metrics.height()) #print self._rect.height() , metrics.height(), int(self._rect.height() / metrics.height())
page_length = int(self._rect.height() / metrics.height()) - 1 page_length = int(self._rect.height() / metrics.height() - 2 ) - 1
ave_line_width = line_width / metrics.averageCharWidth() ave_line_width = line_width / metrics.averageCharWidth()
# print "A", ave_line_width # print "A", ave_line_width
ave_line_width = int(ave_line_width + (ave_line_width * 0.5)) ave_line_width = int(ave_line_width + (ave_line_width * 0.5))
@ -312,73 +307,6 @@ class Renderer(object):
QtCore.Qt.SmoothTransformation) QtCore.Qt.SmoothTransformation)
log.debug(u'render background End') log.debug(u'render background End')
# def _split_set_of_lines(self, lines, footer):
# """
# Given a list of lines, decide how to split them best if they don't all
# fit on the screen. This is done by splitting at 1/2, 1/3 or 1/4 of the
# set. If it doesn't fit, even at this size, just split at each
# opportunity. We'll do this by getting the bounding box of each line,
# and then summing them appropriately.
#
# Returns a list of [lists of lines], one set for each screenful.
#
# ``lines``
# The lines of text to split.
#
# ``footer``
# The footer text.
# """
# bboxes = []
# for line in lines:
# bboxes.append(self._render_and_wrap_single_line(line, footer))
# numlines = len(lines)
# bottom = self._rect.bottom()
# for ratio in (numlines, numlines/2, numlines/3, numlines/4):
# good = 1
# startline = 0
# endline = startline + ratio
# while (endline <= numlines and endline != 0):
# by = 0
# for (x,y) in bboxes[startline:endline]:
# by += y
# if by > bottom:
# good = 0
# break
# startline += ratio
# endline = startline + ratio
# if good == 1:
# break
# retval = []
# numlines_per_page = ratio
# if good:
# c = 0
# thislines = []
# while c < numlines:
# thislines.append(lines[c])
# c += 1
# if len(thislines) == numlines_per_page:
# retval.append(thislines)
# thislines = []
# if len(thislines) > 0:
# retval.append(thislines)
# else:
# # print "Just split where you can"
# retval = []
# startline = 0
# endline = startline + 1
# while (endline <= numlines):
# by = 0
# for (x,y) in bboxes[startline:endline]:
# by += y
# if by > bottom:
# retval.append(lines[startline:endline-1])
# startline = endline-1
# # gets incremented below
# endline = startline
# by = 0
# endline += 1
# return retval
def _correctAlignment(self, rect, bbox): def _correctAlignment(self, rect, bbox):
""" """
Corrects the vertical alignment of text. Corrects the vertical alignment of text.

View File

@ -161,7 +161,7 @@ class ServiceManager(QtGui.QWidget):
# Last little bits of setting up # Last little bits of setting up
self.config = PluginConfig(u'ServiceManager') self.config = PluginConfig(u'ServiceManager')
self.servicePath = self.config.get_data_path() self.servicePath = self.config.get_data_path()
self.service_theme = self.config.get_config(u'theme service theme', u'') self.service_theme = unicode(self.config.get_config(u'theme service theme', u''))
def onMoveSelectionUp(self): def onMoveSelectionUp(self):
""" """
@ -412,7 +412,11 @@ class ServiceManager(QtGui.QWidget):
def addServiceItem(self, item): def addServiceItem(self, item):
""" """
Add an item to the list Add a Service item to the list
``item``
Service Item to be added
""" """
self.serviceItems.append({u'data': item, u'order': len(self.serviceItems)+1, u'expanded':True}) self.serviceItems.append({u'data': item, u'order': len(self.serviceItems)+1, u'expanded':True})
treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList) treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList)
@ -465,13 +469,21 @@ class ServiceManager(QtGui.QWidget):
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
""" """
Accept Drag events Accept Drag events
``event``
Handle of the event pint passed
""" """
event.accept() event.accept()
def dropEvent(self, event): def dropEvent(self, event):
""" """
Handle the release of the event and trigger the plugin Receive drop event and trigger an internal event to get the
to add the data plugins to build and push the correct service item
The drag event payload carries the plugin name
``event``
Handle of the event pint passed
""" """
link = event.mimeData() link = event.mimeData()
if link.hasText(): if link.hasText():
@ -481,12 +493,16 @@ class ServiceManager(QtGui.QWidget):
def updateThemeList(self, theme_list): def updateThemeList(self, theme_list):
""" """
Called from ThemeManager when the Themes have changed Called from ThemeManager when the Themes have changed
``theme_list``
A list of current themes to be displayed
""" """
self.ThemeComboBox.clear() self.ThemeComboBox.clear()
self.ThemeComboBox.addItem(u'') self.ThemeComboBox.addItem(u'')
for theme in theme_list: for theme in theme_list:
self.ThemeComboBox.addItem(theme) self.ThemeComboBox.addItem(theme)
id = self.ThemeComboBox.findText(unicode(self.service_theme), QtCore.Qt.MatchExactly) id = self.ThemeComboBox.findText(self.service_theme, QtCore.Qt.MatchExactly)
# Not Found # Not Found
if id == -1: if id == -1:
id = 0 id = 0

View File

@ -28,7 +28,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.ui import AmendThemeForm, ServiceManager from openlp.core.ui import AmendThemeForm, ServiceManager
from openlp.core.theme import Theme from openlp.core.theme import Theme
from openlp.core.lib import Event, EventType, EventManager, OpenLPToolbar, ThemeXML, Renderer, translate, file_to_xml, buildIcon from openlp.core.lib import PluginConfig, Event, EventType, EventManager, OpenLPToolbar, ThemeXML, Renderer, translate, file_to_xml, buildIcon
from openlp.core.utils import ConfigHelper from openlp.core.utils import ConfigHelper
class ThemeManager(QtGui.QWidget): class ThemeManager(QtGui.QWidget):
@ -72,6 +72,10 @@ class ThemeManager(QtGui.QWidget):
self.path = os.path.join(ConfigHelper.get_data_path(), u'themes') self.path = os.path.join(ConfigHelper.get_data_path(), u'themes')
self.checkThemesExists(self.path) self.checkThemesExists(self.path)
self.amendThemeForm.path = self.path self.amendThemeForm.path = self.path
# Last little bits of setting up
self.config = PluginConfig(u'themes')
self.servicePath = self.config.get_data_path()
self.global_theme = unicode(self.config.get_config(u'theme global theme', u''))
def onAddTheme(self): def onAddTheme(self):
self.amendThemeForm.loadTheme(None) self.amendThemeForm.loadTheme(None)
@ -84,26 +88,32 @@ class ThemeManager(QtGui.QWidget):
self.amendThemeForm.exec_() self.amendThemeForm.exec_()
def onDeleteTheme(self): def onDeleteTheme(self):
self.global_theme = unicode(self.config.get_config(u'theme global theme', u''))
item = self.ThemeListWidget.currentItem() item = self.ThemeListWidget.currentItem()
if item is not None: if item is not None:
theme = unicode(item.text()) theme = unicode(item.text())
th = theme + u'.png' if theme == self.global_theme:
row = self.ThemeListWidget.row(item) QtGui.QMessageBox.critical(self,
self.ThemeListWidget.takeItem(row) translate(u'ThemeManager', u'Error'),
try: translate(u'ThemeManager', u'You are unable to delete the default theme!'),
os.remove(os.path.join(self.path, th)) QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
except: else:
#if not present do not worry th = theme + u'.png'
pass row = self.ThemeListWidget.row(item)
try: self.ThemeListWidget.takeItem(row)
shutil.rmtree(os.path.join(self.path, theme)) try:
except: os.remove(os.path.join(self.path, th))
#if not present do not worry except:
pass #if not present do not worry
#As we do not reload the themes push out the change pass
self.parent.EventManager.post_event(Event(EventType.ThemeListChanged)) try:
self.parent.ServiceManagerContents.updateThemeList(self.getThemes()) shutil.rmtree(os.path.join(self.path, theme))
self.parent.settingsForm.ThemesTab.updateThemeList(self.getThemes()) except:
#if not present do not worry
pass
#As we do not reload the themes push out the change
#Reaload the list as the internal lists and events need to be triggered
self.loadThemes()
def onExportTheme(self): def onExportTheme(self):
pass pass
@ -211,6 +221,9 @@ class ThemeManager(QtGui.QWidget):
self.generateAndSaveImage(dir, themename, filexml) self.generateAndSaveImage(dir, themename, filexml)
def checkVersion1(self, xmlfile): def checkVersion1(self, xmlfile):
"""
Am I a version 1 theme
"""
log.debug(u'checkVersion1 ') log.debug(u'checkVersion1 ')
theme = xmlfile theme = xmlfile
tree = ElementTree(element=XML(theme)).getroot() tree = ElementTree(element=XML(theme)).getroot()
@ -220,6 +233,11 @@ class ThemeManager(QtGui.QWidget):
return True return True
def migrateVersion122(self, filename, fullpath, xml_data): def migrateVersion122(self, filename, fullpath, xml_data):
"""
Called by convert the xml data from version 1 format
to the current format.
New fields are defaulted but the new theme is useable
"""
log.debug(u'migrateVersion122 %s %s', filename, fullpath) log.debug(u'migrateVersion122 %s %s', filename, fullpath)
theme = Theme(xml_data) theme = Theme(xml_data)
newtheme = ThemeXML() newtheme = ThemeXML()

View File

@ -99,8 +99,6 @@ class ThemesTab(SettingsTab):
QtCore.QObject.connect(self.DefaultComboBox, QtCore.QObject.connect(self.DefaultComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onDefaultComboBoxChanged) QtCore.SIGNAL(u'activated(int)'), self.onDefaultComboBoxChanged)
#self.DefaultListView.setScaledContents(True)
def retranslateUi(self): def retranslateUi(self):
self.GlobalGroupBox.setTitle(translate(u'ThemesTab', u'Global theme')) self.GlobalGroupBox.setTitle(translate(u'ThemesTab', u'Global theme'))
self.LevelGroupBox.setTitle(translate(u'ThemesTab', u'Theme level')) self.LevelGroupBox.setTitle(translate(u'ThemesTab', u'Theme level'))
@ -138,9 +136,9 @@ class ThemesTab(SettingsTab):
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style) self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
def onDefaultComboBoxChanged(self, value): def onDefaultComboBoxChanged(self, value):
self.global_theme = self.DefaultComboBox.currentText() self.global_theme = unicode(self.DefaultComboBox.currentText())
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style) self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
image = self.parent.ThemeManagerContents.getPreviewImage(unicode(self.global_theme)) image = self.parent.ThemeManagerContents.getPreviewImage(self.global_theme)
preview = QtGui.QPixmap(unicode(image)) preview = QtGui.QPixmap(unicode(image))
display = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) display = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
self.DefaultListView.setPixmap(display) self.DefaultListView.setPixmap(display)
@ -152,14 +150,14 @@ class ThemesTab(SettingsTab):
self.DefaultComboBox.clear() self.DefaultComboBox.clear()
for theme in theme_list: for theme in theme_list:
self.DefaultComboBox.addItem(theme) self.DefaultComboBox.addItem(theme)
id = self.DefaultComboBox.findText(unicode(self.global_theme), QtCore.Qt.MatchExactly) id = self.DefaultComboBox.findText(self.global_theme, QtCore.Qt.MatchExactly)
if id == -1: if id == -1:
id = 0 # Not Found id = 0 # Not Found
self.global_theme = u'' self.global_theme = u''
self.DefaultComboBox.setCurrentIndex(id) self.DefaultComboBox.setCurrentIndex(id)
self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style) self.parent.RenderManager.set_global_theme(self.global_theme, self.global_style)
if self.global_theme is not u'': if self.global_theme is not u'':
image = self.parent.ThemeManagerContents.getPreviewImage(unicode(self.global_theme)) image = self.parent.ThemeManagerContents.getPreviewImage(self.global_theme)
preview = QtGui.QPixmap(unicode(image)) preview = QtGui.QPixmap(unicode(image))
display = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) display = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
self.DefaultListView.setPixmap(display) self.DefaultListView.setPixmap(display)