fixed Verse Tag' column; clean up

This commit is contained in:
Andreas Preikschat 2011-03-17 13:32:45 +01:00
parent 84175d232b
commit e9bcab13de

View File

@ -297,7 +297,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.verseOrderEdit.setText(u' '.join(translated)) self.verseOrderEdit.setText(u' '.join(translated))
else: else:
self.verseOrderEdit.setText(u'') self.verseOrderEdit.setText(u'')
self.verseListWidget.resizeRowsToContents()
self.tagRows() self.tagRows()
# clear the results # clear the results
self.authorsListView.clear() self.authorsListView.clear()
@ -312,10 +311,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id)) topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
self.topicsListView.addItem(topic_name) self.topicsListView.addItem(topic_name)
self.titleEdit.setFocus(QtCore.Qt.OtherFocusReason) self.titleEdit.setFocus(QtCore.Qt.OtherFocusReason)
# if not preview hide the preview button # Hide or show the preview button.
self.previewButton.setVisible(False) self.previewButton.setVisible(preview)
if preview:
self.previewButton.setVisible(True)
def tagRows(self): def tagRows(self):
""" """
@ -329,6 +326,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
row_def = u'%s%s' % (verse_tag, verse_def[1:]) row_def = u'%s%s' % (verse_tag, verse_def[1:])
row_label.append(row_def) row_label.append(row_def)
self.verseListWidget.setVerticalHeaderLabels(row_label) self.verseListWidget.setVerticalHeaderLabels(row_label)
self.verseListWidget.setColumnWidth(0, self.width)
self.verseListWidget.resizeRowsToContents()
self.verseListWidget.repaint()
def onAuthorAddButtonClicked(self): def onAuthorAddButtonClicked(self):
item = int(self.authorsComboBox.currentIndex()) item = int(self.authorsComboBox.currentIndex())
@ -453,9 +453,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.verseListWidget.setRowCount( self.verseListWidget.setRowCount(
self.verseListWidget.rowCount() + 1) self.verseListWidget.rowCount() + 1)
self.verseListWidget.setItem( self.verseListWidget.setItem(
int(self.verseListWidget.rowCount() - 1), 0, item) self.verseListWidget.rowCount() - 1, 0, item)
self.verseListWidget.setColumnWidth(0, self.width)
self.verseListWidget.resizeRowsToContents()
self.tagRows() self.tagRows()
def onVerseEditButtonClicked(self): def onVerseEditButtonClicked(self):
@ -482,8 +480,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
item = QtGui.QTableWidgetItem(tempList[row], 0) item = QtGui.QTableWidgetItem(tempList[row], 0)
item.setData(QtCore.Qt.UserRole, tempId[row]) item.setData(QtCore.Qt.UserRole, tempId[row])
self.verseListWidget.setItem(row, 0, item) self.verseListWidget.setItem(row, 0, item)
self.verseListWidget.resizeRowsToContents()
self.verseListWidget.repaint()
self.tagRows() self.tagRows()
def onVerseEditAllButtonClicked(self): def onVerseEditAllButtonClicked(self):
@ -500,53 +496,50 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.verse_form.setVerse(verse_list) self.verse_form.setVerse(verse_list)
else: else:
self.verse_form.setVerse(u'') self.verse_form.setVerse(u'')
if self.verse_form.exec_(): if not self.verse_form.exec_():
verse_list = self.verse_form.getVerseAll() return
verse_list = unicode(verse_list.replace(u'\r\n', u'\n')) verse_list = self.verse_form.getVerseAll()
self.verseListWidget.clear() verse_list = unicode(verse_list.replace(u'\r\n', u'\n'))
self.verseListWidget.setRowCount(0) self.verseListWidget.clear()
for row in self.findVerseSplit.split(verse_list): self.verseListWidget.setRowCount(0)
for match in row.split(u'---['): for row in self.findVerseSplit.split(verse_list):
for count, parts in enumerate(match.split(u']---\n')): for match in row.split(u'---['):
if len(parts) > 1: for count, parts in enumerate(match.split(u']---\n')):
if count == 0: if len(parts) <= 1:
# handling carefully user inputted versetags continue
separator = parts.find(u':') if count == 0:
if separator >= 0: # handling carefully user inputted versetags
verse_name = parts[0:separator].strip() separator = parts.find(u':')
verse_num = parts[separator+1:].strip() if separator >= 0:
else: verse_name = parts[0:separator].strip()
verse_name = parts verse_num = parts[separator+1:].strip()
verse_num = u'1' else:
verse_index = \ verse_name = parts
VerseType.from_loose_input(verse_name) verse_num = u'1'
verse_tag = VerseType.Tags[verse_index] verse_index = VerseType.from_loose_input(verse_name)
# Later we need to handle v1a as well. verse_tag = VerseType.Tags[verse_index]
#regex = re.compile(r'(\d+\w.)') # Later we need to handle v1a as well.
regex = re.compile(r'\D*(\d+)\D*') #regex = re.compile(r'(\d+\w.)')
match = regex.match(verse_num) regex = re.compile(r'\D*(\d+)\D*')
if match: match = regex.match(verse_num)
verse_num = match.group(1) if match:
else: verse_num = match.group(1)
verse_num = u'1' else:
verse_def = u'%s%s' % (verse_tag, verse_num) verse_num = u'1'
else: verse_def = u'%s%s' % (verse_tag, verse_num)
if parts.endswith(u'\n'): else:
parts = parts.rstrip(u'\n') if parts.endswith(u'\n'):
item = QtGui.QTableWidgetItem(parts) parts = parts.rstrip(u'\n')
item.setData(QtCore.Qt.UserRole, item = QtGui.QTableWidgetItem(parts)
QtCore.QVariant(verse_def)) item.setData(QtCore.Qt.UserRole,
self.verseListWidget.setRowCount( QtCore.QVariant(verse_def))
self.verseListWidget.rowCount() + 1) self.verseListWidget.setRowCount(
self.verseListWidget.setItem( self.verseListWidget.rowCount() + 1)
int(self.verseListWidget.rowCount() - 1), self.verseListWidget.setItem(
0, item) self.verseListWidget.rowCount() - 1, 0, item)
self.verseListWidget.setColumnWidth(0, self.width) self.tagRows()
self.verseListWidget.resizeRowsToContents() self.verseEditButton.setEnabled(False)
self.verseListWidget.repaint() self.verseDeleteButton.setEnabled(False)
self.tagRows()
self.verseEditButton.setEnabled(False)
self.verseDeleteButton.setEnabled(False)
def onVerseDeleteButtonClicked(self): def onVerseDeleteButtonClicked(self):
self.verseListWidget.removeRow(self.verseListWidget.currentRow()) self.verseListWidget.removeRow(self.verseListWidget.currentRow())
@ -728,7 +721,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song.title = unicode(self.titleEdit.text()) self.song.title = unicode(self.titleEdit.text())
self.song.alternate_title = unicode(self.alternativeEdit.text()) self.song.alternate_title = unicode(self.alternativeEdit.text())
self.song.copyright = unicode(self.copyrightEdit.text()) self.song.copyright = unicode(self.copyrightEdit.text())
# Values will be set when cleaning the song. # Values will be set when cleaning the song.
self.song.search_title = u'' self.song.search_title = u''
self.song.search_lyrics = u'' self.song.search_lyrics = u''
self.song.verse_order = u'' self.song.verse_order = u''
@ -753,7 +746,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song.theme_name = theme_name self.song.theme_name = theme_name
else: else:
self.song.theme_name = None self.song.theme_name = None
self.processLyrics() self._processLyrics()
self.song.authors = [] self.song.authors = []
for row in range(self.authorsListView.count()): for row in range(self.authorsListView.count()):
item = self.authorsListView.item(row) item = self.authorsListView.item(row)
@ -769,12 +762,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
if not preview: if not preview:
self.song = None self.song = None
def processLyrics(self): def _processLyrics(self):
""" """
Process the lyric data entered by the user into the OpenLP XML format. Process the lyric data entered by the user into the OpenLP XML format.
""" """
# This method must only be run after the self.song = Song() assignment. # This method must only be run after the self.song = Song() assignment.
log.debug(u'processLyrics') log.debug(u'_processLyrics')
try: try:
sxml = SongXML() sxml = SongXML()
multiple = [] multiple = []