Make the "Song Maintenance" button on the SongEdit form to work; Include a merge from trunk.

This commit is contained in:
Raoul Snyman 2009-08-06 16:51:38 +02:00
commit 2fb7ff511e
6 changed files with 126 additions and 94 deletions

View File

@ -167,32 +167,37 @@ class Renderer(object):
#take the width work out approx how many characters and add 50% #take the width work out approx how many characters and add 50%
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())
page_length = int(self._rect.height() / metrics.height()) - 1 page_length = int(self._rect.height() / metrics.height()) - 1
ave_line_width = line_width / metrics.averageCharWidth() ave_line_width = line_width / metrics.averageCharWidth()
#print 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))
#print ave_line_width # print "B", ave_line_width
split_pages = [] split_pages = []
page = [] page = []
split_lines = [] split_lines = []
count = 0 count = 0
for line in text: for line in text:
#print line , len(line) # print "C", line , len(line)
if len(line) > ave_line_width: if len(line) > ave_line_width:
while len(line) > 0: while len(line) > 0:
pos = line.find(u' ', ave_line_width) pos = line.find(u' ', ave_line_width)
#print ave_line_width, pos, line[:pos] # print "D2", len(line), ave_line_width, pos, line[:pos]
split_text = line[:pos] split_text = line[:pos]
#print metrics.width(split_text, -1), line_width # print "E", metrics.width(split_text, -1), line_width
while metrics.width(split_text, -1) > line_width: while metrics.width(split_text, -1) > line_width:
#Find the next space to the left #Find the next space to the left
pos = line[:pos].rfind(u' ') pos = line[:pos].rfind(u' ')
#print ave_line_width, pos, line[:pos] # print "F", ave_line_width, pos, line[:pos]
#no more spaces found #no more spaces found
if pos == -1: if pos == 0:
split_text = line split_text = line
while metrics.width(split_text, -1) > line_width:
split_text = split_text[:-1]
pos = len(split_text)
else: else:
split_text = line[:pos] split_text = line[:pos]
# print "F1", split_text, line, pos
split_lines.append(split_text) split_lines.append(split_text)
line = line[pos:] line = line[pos:]
#Text fits in a line now #Text fits in a line now
@ -200,13 +205,14 @@ class Renderer(object):
split_lines.append(line) split_lines.append(line)
line = u'' line = u''
# count += 1 # count += 1
# if count == 50: # if count == 15:
# a = c # a = c
#print split_lines # print "G", split_lines
#print line # print "H", line
else: else:
split_lines.append(line) split_lines.append(line)
line = u'' line = u''
#print "I", split_lines, page_length
for line in split_lines: for line in split_lines:
page.append(line) page.append(line)
if len(page) == page_length: if len(page) == page_length:
@ -306,72 +312,72 @@ 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): # def _split_set_of_lines(self, lines, footer):
""" # """
Given a list of lines, decide how to split them best if they don't all # 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 # 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 # 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, # opportunity. We'll do this by getting the bounding box of each line,
and then summing them appropriately. # and then summing them appropriately.
#
Returns a list of [lists of lines], one set for each screenful. # Returns a list of [lists of lines], one set for each screenful.
#
``lines`` # ``lines``
The lines of text to split. # The lines of text to split.
#
``footer`` # ``footer``
The footer text. # The footer text.
""" # """
bboxes = [] # bboxes = []
for line in lines: # for line in lines:
bboxes.append(self._render_and_wrap_single_line(line, footer)) # bboxes.append(self._render_and_wrap_single_line(line, footer))
numlines = len(lines) # numlines = len(lines)
bottom = self._rect.bottom() # bottom = self._rect.bottom()
for ratio in (numlines, numlines/2, numlines/3, numlines/4): # for ratio in (numlines, numlines/2, numlines/3, numlines/4):
good = 1 # good = 1
startline = 0 # startline = 0
endline = startline + ratio # endline = startline + ratio
while (endline <= numlines and endline != 0): # while (endline <= numlines and endline != 0):
by = 0 # by = 0
for (x,y) in bboxes[startline:endline]: # for (x,y) in bboxes[startline:endline]:
by += y # by += y
if by > bottom: # if by > bottom:
good = 0 # good = 0
break # break
startline += ratio # startline += ratio
endline = startline + ratio # endline = startline + ratio
if good == 1: # if good == 1:
break # break
retval = [] # retval = []
numlines_per_page = ratio # numlines_per_page = ratio
if good: # if good:
c = 0 # c = 0
thislines = [] # thislines = []
while c < numlines: # while c < numlines:
thislines.append(lines[c]) # thislines.append(lines[c])
c += 1 # c += 1
if len(thislines) == numlines_per_page: # if len(thislines) == numlines_per_page:
retval.append(thislines) # retval.append(thislines)
thislines = [] # thislines = []
if len(thislines) > 0: # if len(thislines) > 0:
retval.append(thislines) # retval.append(thislines)
else: # else:
# print "Just split where you can" # # print "Just split where you can"
retval = [] # retval = []
startline = 0 # startline = 0
endline = startline + 1 # endline = startline + 1
while (endline <= numlines): # while (endline <= numlines):
by = 0 # by = 0
for (x,y) in bboxes[startline:endline]: # for (x,y) in bboxes[startline:endline]:
by += y # by += y
if by > bottom: # if by > bottom:
retval.append(lines[startline:endline-1]) # retval.append(lines[startline:endline-1])
startline = endline-1 # startline = endline-1
# gets incremented below # # gets incremented below
endline = startline # endline = startline
by = 0 # by = 0
endline += 1 # endline += 1
return retval # return retval
def _correctAlignment(self, rect, bbox): def _correctAlignment(self, rect, bbox):
""" """

View File

@ -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'Bold', italics=False, def add_font(self, name, color, proportion, override, fonttype=u'main', weight=u'Normal', italics=u'False',
xpos=0, ypos=0, width=0, height=0): xpos=0, ypos=0, width=0, height=0):
""" """
Add a Font. Add a Font.

View File

@ -60,6 +60,10 @@ class MainDisplay(QtGui.QWidget):
Sets up the screen on a particular screen. Sets up the screen on a particular screen.
@param (integer) screen This is the screen number. @param (integer) screen This is the screen number.
""" """
# Temporary fix until I can speak to Tim Bentley.
if screenNumber not in self.screens:
screenNumber = 0
# /Temporary fix
screen = self.screens[screenNumber] screen = self.screens[screenNumber]
if screen[u'number'] != screenNumber: if screen[u'number'] != screenNumber:
# We will most probably never actually hit this bit, but just in # We will most probably never actually hit this bit, but just in
@ -82,7 +86,8 @@ class MainDisplay(QtGui.QWidget):
painter_image.begin(self.InitialFrame) painter_image.begin(self.InitialFrame)
painter_image.fillRect(self.InitialFrame.rect(), QtCore.Qt.white) painter_image.fillRect(self.InitialFrame.rect(), QtCore.Qt.white)
painter_image.drawImage((screen[u'size'].width() - splash_image.width()) / 2, painter_image.drawImage((screen[u'size'].width() - splash_image.width()) / 2,
(screen[u'size'].height() - splash_image.height()) / 2 , splash_image) (screen[u'size'].height() - splash_image.height()) / 2,
splash_image)
self.frameView(self.InitialFrame) self.frameView(self.InitialFrame)
#Build a Black screen #Build a Black screen
painter = QtGui.QPainter() painter = QtGui.QPainter()
@ -98,7 +103,6 @@ class MainDisplay(QtGui.QWidget):
``frame`` ``frame``
Image frame to be rendered Image frame to be rendered
""" """
self.frame = frame self.frame = frame
if self.timer_id != 0 : if self.timer_id != 0 :
self.displayAlert() self.displayAlert()
@ -131,7 +135,9 @@ class MainDisplay(QtGui.QWidget):
alertframe = QtGui.QPixmap.fromImage(self.frame) alertframe = QtGui.QPixmap.fromImage(self.frame)
painter = QtGui.QPainter(alertframe) painter = QtGui.QPainter(alertframe)
top = alertframe.rect().height() * 0.9 top = alertframe.rect().height() * 0.9
painter.fillRect(QtCore.QRect(0, top , alertframe.rect().width(), alertframe.rect().height() - top), QtGui.QColor(self.alertTab.bg_color)) painter.fillRect(
QtCore.QRect(0, top, alertframe.rect().width(), alertframe.rect().height() - top),
QtGui.QColor(self.alertTab.bg_color))
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily(self.alertTab.font_face) font.setFamily(self.alertTab.font_face)
font.setBold(True) font.setBold(True)
@ -140,7 +146,8 @@ class MainDisplay(QtGui.QWidget):
painter.setPen(QtGui.QColor(self.alertTab.font_color)) painter.setPen(QtGui.QColor(self.alertTab.font_color))
x, y = (0, top) x, y = (0, top)
metrics=QtGui.QFontMetrics(font) metrics=QtGui.QFontMetrics(font)
painter.drawText(x, y+metrics.height()-metrics.descent()-1, self.alerttext) painter.drawText(
x, y + metrics.height() - metrics.descent() - 1, self.alerttext)
painter.end() painter.end()
self.display.setPixmap(alertframe) self.display.setPixmap(alertframe)
# check to see if we have a timer running # check to see if we have a timer running

View File

@ -20,6 +20,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import logging import logging
import time
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -268,6 +269,8 @@ class BibleMediaItem(MediaManagerItem):
def setQuickMsg2(self, text): def setQuickMsg2(self, text):
self.QuickMsg2.setText(translate(u'BibleMediaItem', unicode(text))) self.QuickMsg2.setText(translate(u'BibleMediaItem', unicode(text)))
Receiver().send_message(u'openlpprocessevents') Receiver().send_message(u'openlpprocessevents')
#minor delay to get the events processed
time.sleep(0.5)
def loadBibles(self): def loadBibles(self):
log.debug(u'Loading Bibles') log.debug(u'Loading Bibles')

View File

@ -68,9 +68,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
QtCore.SIGNAL(u'activated(int)'), self.onSongBookComboChanged) QtCore.SIGNAL(u'activated(int)'), self.onSongBookComboChanged)
QtCore.QObject.connect(self.ThemeSelectionComboItem, QtCore.QObject.connect(self.ThemeSelectionComboItem,
QtCore.SIGNAL(u'activated(int)'), self.onThemeComboChanged) QtCore.SIGNAL(u'activated(int)'), self.onThemeComboChanged)
QtCore.QObject.connect(self.MaintenanceButton,
QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked)
# Create other objects and forms # Create other objects and forms
self.songmanager = songmanager self.songmanager = songmanager
self.eventmanager = eventmanager self.eventmanager = eventmanager
self.parent = parent
self.verse_form = EditVerseForm() self.verse_form = EditVerseForm()
self.initialise() self.initialise()
self.AuthorsListView.setSortingEnabled(False) self.AuthorsListView.setSortingEnabled(False)
@ -228,8 +231,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
item = int(self.SongTopicCombo.currentIndex()) item = int(self.SongTopicCombo.currentIndex())
if item > -1: if item > -1:
item_id = (self.SongTopicCombo.itemData(item)).toInt()[0] item_id = (self.SongTopicCombo.itemData(item)).toInt()[0]
print item_id
print self.TopicsListView
topic = self.songmanager.get_topic(item_id) topic = self.songmanager.get_topic(item_id)
self.song.topics.append(topic) self.song.topics.append(topic)
topic_item = QtGui.QListWidgetItem(unicode(topic.name)) topic_item = QtGui.QListWidgetItem(unicode(topic.name))
@ -333,6 +334,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.CopyrightEditItem.setFocus() self.CopyrightEditItem.setFocus()
self.CopyrightEditItem.setCursorPosition(pos + 1) self.CopyrightEditItem.setCursorPosition(pos + 1)
def onMaintenanceButtonClicked(self):
self.parent.song_maintenance_form.exec_()
self.loadAuthors()
self.loadBooks()
self.loadTopics()
def onAccept(self): def onAccept(self):
log.debug(u'OnAccept') log.debug(u'OnAccept')
if not self._validate_song(): if not self._validate_song():

View File

@ -71,15 +71,22 @@ class SongsPlugin(Plugin):
self.ImportSongMenu.setTitle(translate(u'main_window', u'&Song')) self.ImportSongMenu.setTitle(translate(u'main_window', u'&Song'))
self.ImportOpenSongItem.setText(translate(u'main_window', u'OpenSong')) self.ImportOpenSongItem.setText(translate(u'main_window', u'OpenSong'))
self.ImportOpenlp1Item.setText(translate(u'main_window', u'openlp.org 1.0')) self.ImportOpenlp1Item.setText(translate(u'main_window', u'openlp.org 1.0'))
self.ImportOpenlp1Item.setToolTip(translate(u'main_window', u'Export songs in openlp.org 1.0 format')) self.ImportOpenlp1Item.setToolTip(
self.ImportOpenlp1Item.setStatusTip(translate(u'main_window', u'Export songs in openlp.org 1.0 format')) translate(u'main_window', u'Export songs in openlp.org 1.0 format'))
self.ImportOpenlp1Item.setStatusTip(
translate(u'main_window', u'Export songs in openlp.org 1.0 format'))
self.ImportOpenlp2Item.setText(translate(u'main_window', u'OpenLP 2.0')) self.ImportOpenlp2Item.setText(translate(u'main_window', u'OpenLP 2.0'))
self.ImportOpenlp2Item.setToolTip(translate(u'main_window', u'Export songs in OpenLP 2.0 format')) self.ImportOpenlp2Item.setToolTip(
self.ImportOpenlp2Item.setStatusTip(translate(u'main_window', u'Export songs in OpenLP 2.0 format')) translate(u'main_window', u'Export songs in OpenLP 2.0 format'))
self.ImportOpenlp2Item.setStatusTip(
translate(u'main_window', u'Export songs in OpenLP 2.0 format'))
# Signals and slots # Signals and slots
QtCore.QObject.connect(self.ImportOpenlp1Item, QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick) QtCore.QObject.connect(self.ImportOpenlp1Item,
QtCore.QObject.connect(self.ImportOpenlp2Item, QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick) QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenSongItem, QtCore.SIGNAL(u'triggered()'), self.onImportOpenSongItemClick) QtCore.QObject.connect(self.ImportOpenlp2Item,
QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenSongItem,
QtCore.SIGNAL(u'triggered()'), self.onImportOpenSongItemClick)
def add_export_menu_item(self, export_menu): def add_export_menu_item(self, export_menu):
self.ExportSongMenu = QtGui.QMenu(export_menu) self.ExportSongMenu = QtGui.QMenu(export_menu)
@ -101,8 +108,10 @@ class SongsPlugin(Plugin):
self.ExportOpenlp1Item.setText(translate(u'main_window', u'openlp.org 1.0')) self.ExportOpenlp1Item.setText(translate(u'main_window', u'openlp.org 1.0'))
self.ExportOpenlp2Item.setText(translate(u'main_window', u'OpenLP 2.0')) self.ExportOpenlp2Item.setText(translate(u'main_window', u'OpenLP 2.0'))
# Signals and slots # Signals and slots
QtCore.QObject.connect(self.ExportOpenlp1Item, QtCore.SIGNAL(u'triggered()'), self.onExportOpenlp1ItemClicked) QtCore.QObject.connect(self.ExportOpenlp1Item,
QtCore.QObject.connect(self.ExportOpenSongItem, QtCore.SIGNAL(u'triggered()'), self.onExportOpenSongItemClicked) QtCore.SIGNAL(u'triggered()'), self.onExportOpenlp1ItemClicked)
QtCore.QObject.connect(self.ExportOpenSongItem,
QtCore.SIGNAL(u'triggered()'), self.onExportOpenSongItemClicked)
def initialise(self): def initialise(self):
self.media_item.displayResultsSong(self.songmanager.get_songs()) self.media_item.displayResultsSong(self.songmanager.get_songs())