fix ups requested by Raoul

This commit is contained in:
Tim Bentley 2010-12-31 08:34:53 +00:00
parent 0ce3848d0f
commit 0a1118266b
3 changed files with 39 additions and 19 deletions

View File

@ -291,7 +291,7 @@ def clean_tags(text):
Remove Tags from text for display Remove Tags from text for display
""" """
text = text.replace(u'<br>', u'\n') text = text.replace(u'<br>', u'\n')
for tag in DisplayTags.get_html_tags().html_expands: for tag in DisplayTags.get_html_tags():
text = text.replace(tag[u'start tag'], u'') text = text.replace(tag[u'start tag'], u'')
text = text.replace(tag[u'end tag'], u'') text = text.replace(tag[u'end tag'], u'')
return text return text
@ -300,7 +300,7 @@ def expand_tags(text):
""" """
Expand tags HTML for display Expand tags HTML for display
""" """
for tag in DisplayTags.get_html_tags().html_expands: for tag in DisplayTags.get_html_tags():
text = text.replace(tag[u'start tag'], tag[u'start html']) text = text.replace(tag[u'start tag'], tag[u'start html'])
text = text.replace(tag[u'end tag'], tag[u'end html']) text = text.replace(tag[u'end tag'], tag[u'end html'])
return text return text

View File

@ -59,6 +59,27 @@ class DisplayTags(object):
@staticmethod @staticmethod
def get_html_tags(): def get_html_tags():
""" """
Provide access to the HtmlTags object. Provide access to the html_expands list.
""" """
return DisplayTags.html_tags return DisplayTags.html_tags.html_expands
@staticmethod
def reset_html_tags():
"""
Resets the html_expands list.
"""
return DisplayTags.html_tags.reset_list()
@staticmethod
def add_html_tag(tag):
"""
Add a new tag to the list
"""
return DisplayTags.html_tags.add_tag(tag)
@staticmethod
def remove_html_tag(id):
"""
Removes amd individual html_expands list.
"""
return DisplayTags.html_tags.html_expands.pop(id)

View File

@ -50,14 +50,14 @@ class DisplayTagTab(SettingsTab):
Initialise values before the Load takes place Initialise values before the Load takes place
""" """
# Create initial copy from master # Create initial copy from master
DisplayTags.get_html_tags().reset_list() DisplayTags.reset_html_tags()
user_expands = QtCore.QSettings().value(u'displayTags/html_tags', user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
QtCore.QVariant(u'')).toString() QtCore.QVariant(u'')).toString()
# cPickle only accepts str not unicode strings # cPickle only accepts str not unicode strings
user_tags = cPickle.loads(str(user_expands)) user_tags = cPickle.loads(str(user_expands))
# If we have some user ones added them as well # If we have some user ones added them as well
for t in user_tags: for t in user_tags:
DisplayTags.get_html_tags().add_tag(t) DisplayTags.add_html_tag(t)
self.selected = -1 self.selected = -1
def setupUi(self): def setupUi(self):
@ -194,8 +194,7 @@ class DisplayTagTab(SettingsTab):
self.newPushButton.setEnabled(True) self.newPushButton.setEnabled(True)
self.updatePushButton.setEnabled(False) self.updatePushButton.setEnabled(False)
self.deletePushButton.setEnabled(False) self.deletePushButton.setEnabled(False)
for linenumber, html in enumerate( for linenumber, html in enumerate(DisplayTags.get_html_tags()):
DisplayTags.get_html_tags().html_expands):
self.tagTableWidget.setRowCount( self.tagTableWidget.setRowCount(
self.tagTableWidget.rowCount() + 1) self.tagTableWidget.rowCount() + 1)
self.tagTableWidget.setItem(linenumber, 0, self.tagTableWidget.setItem(linenumber, 0,
@ -221,7 +220,7 @@ class DisplayTagTab(SettingsTab):
Save Custom tags in a pickle . Save Custom tags in a pickle .
""" """
temp = [] temp = []
for tag in DisplayTags.get_html_tags().html_expands: for tag in DisplayTags.get_html_tags():
if not tag[u'protected']: if not tag[u'protected']:
temp.append(tag) temp.append(tag)
if temp: if temp:
@ -244,7 +243,7 @@ class DisplayTagTab(SettingsTab):
Table Row selected so display items and set field state. Table Row selected so display items and set field state.
""" """
row = self.tagTableWidget.currentRow() row = self.tagTableWidget.currentRow()
html = DisplayTags.get_html_tags().html_expands[row] html = DisplayTags.get_html_tags()[row]
self.selected = row self.selected = row
self.descriptionLineEdit.setText(html[u'desc']) self.descriptionLineEdit.setText(html[u'desc'])
self.tagLineEdit.setText(self._strip(html[u'start tag'])) self.tagLineEdit.setText(self._strip(html[u'start tag']))
@ -269,7 +268,7 @@ class DisplayTagTab(SettingsTab):
""" """
Add a new tag to list only if it is not a duplicate. Add a new tag to list only if it is not a duplicate.
""" """
for html in DisplayTags.get_html_tags().html_expands: for html in DisplayTags.get_html_tags():
if self._strip(html[u'start tag']) == u'n': if self._strip(html[u'start tag']) == u'n':
QtGui.QMessageBox.critical(self, QtGui.QMessageBox.critical(self,
translate('OpenLP.DisplayTagTab', 'Update Error'), translate('OpenLP.DisplayTagTab', 'Update Error'),
@ -279,17 +278,17 @@ class DisplayTagTab(SettingsTab):
QtGui.QMessageBox.Ok) QtGui.QMessageBox.Ok)
return return
# Add new tag to list # Add new tag to list
DisplayTags.get_html_tags().html_expands.append( tag = {u'desc': u'New Item', u'start tag': u'{n}',
{u'desc': u'New Item', u'start tag': u'{n}',
u'start html': u'<Html_here>', u'end tag': u'{/n}', u'start html': u'<Html_here>', u'end tag': u'{/n}',
u'end html': u'</and here>', u'protected': False}) u'end html': u'</and here>', u'protected': False}
DisplayTags.add_html_tag(tag)
self._resetTable() self._resetTable()
def onDefaultPushed(self): def onDefaultPushed(self):
""" """
Remove all Custom Tags and reset to base set only. Remove all Custom Tags and reset to base set only.
""" """
DisplayTags.get_html_tags().reset_list() DisplayTags.reset_html_tags()
self._resetTable() self._resetTable()
def onDeletePushed(self): def onDeletePushed(self):
@ -297,7 +296,7 @@ class DisplayTagTab(SettingsTab):
Delete selected custom tag. Delete selected custom tag.
""" """
if self.selected != -1: if self.selected != -1:
DisplayTags.get_html_tags().html_expands.pop(self.selected) DisplayTags.remove_html_tag(self.selected)
self.selected = -1 self.selected = -1
self._resetTable() self._resetTable()
@ -305,7 +304,7 @@ class DisplayTagTab(SettingsTab):
""" """
Update Custom Tag details if not duplicate. Update Custom Tag details if not duplicate.
""" """
html_expands = DisplayTags.get_html_tags().html_expands html_expands = DisplayTags.get_html_tags()
if self.selected != -1: if self.selected != -1:
html = html_expands[self.selected] html = html_expands[self.selected]
tag = unicode(self.tagLineEdit.text()) tag = unicode(self.tagLineEdit.text())