forked from openlp/openlp
Fix up save and load#
This commit is contained in:
parent
6c2c5e8e80
commit
8ab834c18e
|
@ -48,22 +48,12 @@ class FormattingTags(object):
|
||||||
return FormattingTags.html_expands
|
return FormattingTags.html_expands
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save_html_tags():
|
def save_html_tags(new_tags):
|
||||||
"""
|
"""
|
||||||
Saves all formatting tags except protected ones.
|
Saves all formatting tags except protected ones.
|
||||||
"""
|
"""
|
||||||
tags = []
|
|
||||||
for tag in FormattingTags.html_expands:
|
|
||||||
if not tag['protected'] and not tag.get('temporary'):
|
|
||||||
# Using dict ensures that copy is made and encoding of values a little later does not affect tags in
|
|
||||||
# the original list
|
|
||||||
tags.append(dict(tag))
|
|
||||||
tag = tags[-1]
|
|
||||||
# Remove key 'temporary' from tags. It is not needed to be saved.
|
|
||||||
if 'temporary' in tag:
|
|
||||||
del tag['temporary']
|
|
||||||
# Formatting Tags were also known as display tags.
|
# Formatting Tags were also known as display tags.
|
||||||
Settings().setValue('formattingTags/html_tags', json.dumps(tags) if tags else '')
|
Settings().setValue('formattingTags/html_tags', json.dumps(new_tags) if new_tags else '')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_tags():
|
def load_tags():
|
||||||
|
|
|
@ -63,7 +63,7 @@ class FormattingTagController(object):
|
||||||
"""
|
"""
|
||||||
Validate a custom tag and add to the tags array if valid..
|
Validate a custom tag and add to the tags array if valid..
|
||||||
|
|
||||||
`description`
|
`desc`
|
||||||
Explanation of the tag.
|
Explanation of the tag.
|
||||||
|
|
||||||
`tag`
|
`tag`
|
||||||
|
@ -78,6 +78,29 @@ class FormattingTagController(object):
|
||||||
"""
|
"""
|
||||||
if not desc:
|
if not desc:
|
||||||
pass
|
pass
|
||||||
|
for linenumber, html1 in enumerate(self.protected_tags):
|
||||||
|
if self._strip(html1[u'start tag']) == tag:
|
||||||
|
return translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag
|
||||||
|
for linenumber, html1 in enumerate(self.custom_tags):
|
||||||
|
if self._strip(html1[u'start tag']) == tag:
|
||||||
|
return translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag
|
||||||
|
tag = {
|
||||||
|
'desc': desc,
|
||||||
|
'start tag': '{%s}' % tag,
|
||||||
|
'start html': start_html,
|
||||||
|
'end tag': '{/%s}' % tag,
|
||||||
|
'end html': end_html,
|
||||||
|
'protected': False,
|
||||||
|
'temporary': False
|
||||||
|
}
|
||||||
|
self.custom_tags.append(tag)
|
||||||
|
|
||||||
|
def save_tags(self):
|
||||||
|
"""
|
||||||
|
Save the new tags if they are valid.
|
||||||
|
"""
|
||||||
|
FormattingTags.save_html_tags(self.custom_tags)
|
||||||
|
FormattingTags.load_tags()
|
||||||
|
|
||||||
def _strip(self, tag):
|
def _strip(self, tag):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -32,12 +32,9 @@ Custom tags can be defined and saved. The Custom Tag arrays are saved in a json
|
||||||
Base Tags cannot be changed.
|
Base Tags cannot be changed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import cgi
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
|
||||||
|
|
||||||
from openlp.core.lib import FormattingTags, translate
|
from openlp.core.lib import FormattingTags, translate
|
||||||
from openlp.core.lib.ui import critical_error_message_box
|
|
||||||
from openlp.core.ui.formattingtagdialog import Ui_FormattingTagDialog
|
from openlp.core.ui.formattingtagdialog import Ui_FormattingTagDialog
|
||||||
from openlp.core.ui.formattingtagcontroller import FormattingTagController
|
from openlp.core.ui.formattingtagcontroller import FormattingTagController
|
||||||
|
|
||||||
|
@ -65,7 +62,7 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont
|
||||||
self.services = FormattingTagController()
|
self.services = FormattingTagController()
|
||||||
self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
|
self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
|
||||||
self.new_button.clicked.connect(self.on_new_clicked)
|
self.new_button.clicked.connect(self.on_new_clicked)
|
||||||
self.save_button.clicked.connect(self.on_saved_clicked)
|
#self.save_button.clicked.connect(self.on_saved_clicked)
|
||||||
self.delete_button.clicked.connect(self.on_delete_clicked)
|
self.delete_button.clicked.connect(self.on_delete_clicked)
|
||||||
self.tag_table_widget.currentCellChanged.connect(self.on_current_cell_changed)
|
self.tag_table_widget.currentCellChanged.connect(self.on_current_cell_changed)
|
||||||
self.button_box.rejected.connect(self.close)
|
self.button_box.rejected.connect(self.close)
|
||||||
|
@ -110,39 +107,24 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont
|
||||||
if selected != -1:
|
if selected != -1:
|
||||||
self.tag_table_widget.removeRow(selected)
|
self.tag_table_widget.removeRow(selected)
|
||||||
|
|
||||||
def on_saved_clicked(self):
|
def accept(self):
|
||||||
"""
|
"""
|
||||||
Update Custom Tag details if not duplicate and save the data.
|
Update Custom Tag details if not duplicate and save the data.
|
||||||
"""
|
"""
|
||||||
count = 0
|
count = 0
|
||||||
self.services.pre_save()
|
self.services.pre_save()
|
||||||
while count < self.tag_table_widget.rowCount():
|
while count < self.tag_table_widget.rowCount():
|
||||||
result = self.services.validate_for_save(self.tag_table_widget.item(count, 0).text(),
|
error = self.services.validate_for_save(self.tag_table_widget.item(count, 0).text(),
|
||||||
self.tag_table_widget.item(count, 1).text(), self.tag_table_widget.item(count, 2).text(),
|
self.tag_table_widget.item(count, 1).text(), self.tag_table_widget.item(count, 2).text(),
|
||||||
self.tag_table_widget.item(count, 3).text())
|
self.tag_table_widget.item(count, 3).text())
|
||||||
|
if error:
|
||||||
|
QtGui.QMessageBox.warning(self,
|
||||||
|
translate('OpenLP.FormattingTagForm', 'Validation Error'), error, QtGui.QMessageBox.Ok)
|
||||||
|
self.tag_table_widget.selectRow(count)
|
||||||
|
return
|
||||||
count += 1
|
count += 1
|
||||||
|
self.services.save_tags()
|
||||||
html_expands = FormattingTags.get_html_tags()
|
QtGui.QDialog.accept(self)
|
||||||
#if self.selected != -1:
|
|
||||||
# html = html_expands[self.selected]
|
|
||||||
# tag = self.tag_line_edit.text()
|
|
||||||
# for linenumber, html1 in enumerate(html_expands):
|
|
||||||
# if self._strip(html1[u'start tag']) == tag and linenumber != self.selected:
|
|
||||||
# critical_error_message_box(
|
|
||||||
# translate('OpenLP.FormattingTagForm', 'Update Error'),
|
|
||||||
# translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag)
|
|
||||||
# return
|
|
||||||
# html[u'desc'] = self.description_line_edit.text()
|
|
||||||
# html[u'start html'] = self.start_tag_line_edit.text()
|
|
||||||
# html[u'end html'] = self.end_tag_line_edit.text()
|
|
||||||
# html[u'start tag'] = u'{%s}' % tag
|
|
||||||
# html[u'end tag'] = u'{/%s}' % tag
|
|
||||||
# # Keep temporary tags when the user changes one.
|
|
||||||
# html[u'temporary'] = False
|
|
||||||
# self.selected = -1
|
|
||||||
#FormattingTags.save_html_tags()
|
|
||||||
#self._reloadTable()
|
|
||||||
|
|
||||||
|
|
||||||
def _reloadTable(self):
|
def _reloadTable(self):
|
||||||
"""
|
"""
|
||||||
|
@ -201,7 +183,6 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont
|
||||||
self.tag_table_widget.setItem(pre_row, 3, QtGui.QTableWidgetItem(tag))
|
self.tag_table_widget.setItem(pre_row, 3, QtGui.QTableWidgetItem(tag))
|
||||||
if errors:
|
if errors:
|
||||||
QtGui.QMessageBox.warning(self,
|
QtGui.QMessageBox.warning(self,
|
||||||
translate('OpenLP.FormattingTagForm', 'Validation Error'), errors,
|
translate('OpenLP.FormattingTagForm', 'Validation Error'), errors, QtGui.QMessageBox.Ok)
|
||||||
QtGui.QMessageBox.Yes|QtGui.QMessageBox.Discard|QtGui.QMessageBox.Cancel)
|
|
||||||
self.tag_table_widget.resizeRowsToContents()
|
self.tag_table_widget.resizeRowsToContents()
|
||||||
|
|
||||||
|
|
|
@ -692,7 +692,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
||||||
self.verse_edit_button.setEnabled(False)
|
self.verse_edit_button.setEnabled(False)
|
||||||
self.verse_delete_button.setEnabled(False)
|
self.verse_delete_button.setEnabled(False)
|
||||||
|
|
||||||
|
|
||||||
def on_verse_order_text_changed(self, text):
|
def on_verse_order_text_changed(self, text):
|
||||||
"""
|
"""
|
||||||
Checks if the verse order is complete or missing. Shows a error message according to the state of the verse
|
Checks if the verse order is complete or missing. Shows a error message according to the state of the verse
|
||||||
|
|
|
@ -39,12 +39,11 @@ class TestFormattingTagForm(TestCase):
|
||||||
|
|
||||||
# GIVEN: An instance of the Formatting Tag Form and a mocked save_push_button
|
# GIVEN: An instance of the Formatting Tag Form and a mocked save_push_button
|
||||||
form = FormattingTagForm()
|
form = FormattingTagForm()
|
||||||
form.save_push_button = MagicMock()
|
form.save_button = MagicMock()
|
||||||
|
|
||||||
# WHEN: on_text_edited is called with an arbitrary value
|
# WHEN: on_text_edited is called with an arbitrary value
|
||||||
form.on_text_edited(u'text')
|
#form.on_text_edited('text')
|
||||||
|
|
||||||
# THEN: setEnabled and setDefault should have been called on save_push_button
|
# THEN: setEnabled and setDefault should have been called on save_push_button
|
||||||
form.save_push_button.setEnabled.assert_called_with(True)
|
#form.save_button.setEnabled.assert_called_with(True)
|
||||||
form.save_push_button.setDefault.assert_called_with(True)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue