forked from openlp/openlp
formatting tags
This commit is contained in:
commit
676b9133d1
@ -308,11 +308,11 @@ class Plugin(QtCore.QObject):
|
||||
Perform tasks on application startup
|
||||
"""
|
||||
# FIXME: Remove after 2.2 release.
|
||||
# This is needed to load the list of images/media/presentation from the config saved
|
||||
# before the settings rewrite.
|
||||
# This is needed to load the list of media/presentation from the config saved before the settings rewrite.
|
||||
if self.media_item_class is not None and self.name != u'images':
|
||||
loaded_list = Settings().get_files_from_config(self)
|
||||
# Now save the list to the config using our Settings class.
|
||||
if loaded_list:
|
||||
Settings().setValue(u'%s/%s files' % (self.settings_section, self.name), loaded_list)
|
||||
|
||||
def uses_theme(self, theme):
|
||||
|
@ -31,7 +31,7 @@ The UI widgets for the formatting tags window.
|
||||
"""
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import UiStrings, translate
|
||||
from openlp.core.lib import UiStrings, translate, build_icon
|
||||
from openlp.core.lib.ui import create_button_box
|
||||
|
||||
|
||||
@ -45,12 +45,34 @@ class Ui_FormattingTagDialog(object):
|
||||
"""
|
||||
formatting_tag_dialog.setObjectName(u'formatting_tag_dialog')
|
||||
formatting_tag_dialog.resize(725, 548)
|
||||
self.list_data_grid_layout = QtGui.QGridLayout(formatting_tag_dialog)
|
||||
self.list_data_grid_layout = QtGui.QVBoxLayout(formatting_tag_dialog)
|
||||
self.list_data_grid_layout.setMargin(8)
|
||||
self.list_data_grid_layout.setObjectName(u'list_data_grid_layout')
|
||||
self.tag_table_widget_read_label = QtGui.QLabel()
|
||||
self.list_data_grid_layout.addWidget(self.tag_table_widget_read_label)
|
||||
self.tag_table_widget_read = QtGui.QTableWidget(formatting_tag_dialog)
|
||||
self.tag_table_widget_read.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.tag_table_widget_read.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
||||
self.tag_table_widget_read.setAlternatingRowColors(True)
|
||||
self.tag_table_widget_read.setCornerButtonEnabled(False)
|
||||
self.tag_table_widget_read.setObjectName(u'tag_table_widget_read')
|
||||
self.tag_table_widget_read.setColumnCount(4)
|
||||
self.tag_table_widget_read.setRowCount(0)
|
||||
self.tag_table_widget_read.horizontalHeader().setStretchLastSection(True)
|
||||
item = QtGui.QTableWidgetItem()
|
||||
self.tag_table_widget_read.setHorizontalHeaderItem(0, item)
|
||||
item = QtGui.QTableWidgetItem()
|
||||
self.tag_table_widget_read.setHorizontalHeaderItem(1, item)
|
||||
item = QtGui.QTableWidgetItem()
|
||||
self.tag_table_widget_read.setHorizontalHeaderItem(2, item)
|
||||
item = QtGui.QTableWidgetItem()
|
||||
self.tag_table_widget_read.setHorizontalHeaderItem(3, item)
|
||||
self.list_data_grid_layout.addWidget(self.tag_table_widget_read)
|
||||
self.tag_table_widget_label = QtGui.QLabel()
|
||||
self.list_data_grid_layout.addWidget(self.tag_table_widget_label)
|
||||
self.tag_table_widget = QtGui.QTableWidget(formatting_tag_dialog)
|
||||
self.tag_table_widget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.tag_table_widget.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
||||
self.tag_table_widget.setEditTriggers(QtGui.QAbstractItemView.AllEditTriggers)
|
||||
self.tag_table_widget.setAlternatingRowColors(True)
|
||||
self.tag_table_widget.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
||||
self.tag_table_widget.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
||||
@ -67,58 +89,85 @@ class Ui_FormattingTagDialog(object):
|
||||
self.tag_table_widget.setHorizontalHeaderItem(2, item)
|
||||
item = QtGui.QTableWidgetItem()
|
||||
self.tag_table_widget.setHorizontalHeaderItem(3, item)
|
||||
self.list_data_grid_layout.addWidget(self.tag_table_widget, 0, 0, 1, 1)
|
||||
self.horizontal_layout = QtGui.QHBoxLayout()
|
||||
self.horizontal_layout.setObjectName(u'horizontal_layout')
|
||||
spacer_item = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||
self.horizontal_layout.addItem(spacer_item)
|
||||
self.delete_push_button = QtGui.QPushButton(formatting_tag_dialog)
|
||||
self.delete_push_button.setObjectName(u'delete_push_button')
|
||||
self.horizontal_layout.addWidget(self.delete_push_button)
|
||||
self.list_data_grid_layout.addLayout(self.horizontal_layout, 1, 0, 1, 1)
|
||||
self.edit_group_box = QtGui.QGroupBox(formatting_tag_dialog)
|
||||
self.edit_group_box.setObjectName(u'edit_group_box')
|
||||
self.data_grid_layout = QtGui.QGridLayout(self.edit_group_box)
|
||||
self.data_grid_layout.setObjectName(u'data_grid_layout')
|
||||
self.description_label = QtGui.QLabel(self.edit_group_box)
|
||||
self.description_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.description_label.setObjectName(u'description_label')
|
||||
self.data_grid_layout.addWidget(self.description_label, 0, 0, 1, 1)
|
||||
self.description_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
self.description_line_edit.setObjectName(u'description_line_edit')
|
||||
self.data_grid_layout.addWidget(self.description_line_edit, 0, 1, 2, 1)
|
||||
self.new_push_button = QtGui.QPushButton(self.edit_group_box)
|
||||
self.new_push_button.setObjectName(u'new_push_button')
|
||||
self.data_grid_layout.addWidget(self.new_push_button, 0, 2, 2, 1)
|
||||
self.tag_label = QtGui.QLabel(self.edit_group_box)
|
||||
self.tag_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.tag_label.setObjectName(u'tag_label')
|
||||
self.data_grid_layout.addWidget(self.tag_label, 2, 0, 1, 1)
|
||||
self.tag_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
self.tag_line_edit.setMaximumSize(QtCore.QSize(50, 16777215))
|
||||
self.tag_line_edit.setMaxLength(5)
|
||||
self.tag_line_edit.setObjectName(u'tag_line_edit')
|
||||
self.data_grid_layout.addWidget(self.tag_line_edit, 2, 1, 1, 1)
|
||||
self.start_tag_label = QtGui.QLabel(self.edit_group_box)
|
||||
self.start_tag_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.start_tag_label.setObjectName(u'start_tag_label')
|
||||
self.data_grid_layout.addWidget(self.start_tag_label, 3, 0, 1, 1)
|
||||
self.start_tag_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
self.start_tag_line_edit.setObjectName(u'start_tag_line_edit')
|
||||
self.data_grid_layout.addWidget(self.start_tag_line_edit, 3, 1, 1, 1)
|
||||
self.end_tag_label = QtGui.QLabel(self.edit_group_box)
|
||||
self.end_tag_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.end_tag_label.setObjectName(u'end_tag_label')
|
||||
self.data_grid_layout.addWidget(self.end_tag_label, 4, 0, 1, 1)
|
||||
self.end_tag_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
self.end_tag_line_edit.setObjectName(u'end_tag_line_edit')
|
||||
self.data_grid_layout.addWidget(self.end_tag_line_edit, 4, 1, 1, 1)
|
||||
self.save_push_button = QtGui.QPushButton(self.edit_group_box)
|
||||
self.save_push_button.setObjectName(u'save_push_button')
|
||||
self.data_grid_layout.addWidget(self.save_push_button, 4, 2, 1, 1)
|
||||
self.list_data_grid_layout.addWidget(self.edit_group_box, 2, 0, 1, 1)
|
||||
self.button_box = create_button_box(formatting_tag_dialog, u'button_box', [u'close'])
|
||||
self.list_data_grid_layout.addWidget(self.button_box, 3, 0, 1, 1)
|
||||
self.list_data_grid_layout.addWidget(self.tag_table_widget)
|
||||
|
||||
|
||||
#self.horizontal_layout = QtGui.QHBoxLayout()
|
||||
#self.horizontal_layout.setObjectName(u'horizontal_layout')
|
||||
#spacer_item = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||
#self.horizontal_layout.addItem(spacer_item)
|
||||
#self.delete_push_button = QtGui.QPushButton(formatting_tag_dialog)
|
||||
#self.delete_push_button.setObjectName(u'delete_push_button')
|
||||
#self.horizontal_layout.addWidget(self.delete_push_button)
|
||||
#self.list_data_grid_layout.addLayout(self.horizontal_layout, 1, 0, 1, 1)
|
||||
#self.edit_group_box = QtGui.QGroupBox(formatting_tag_dialog)
|
||||
#self.edit_group_box.setObjectName(u'edit_group_box')
|
||||
#self.data_grid_layout = QtGui.QGridLayout(self.edit_group_box)
|
||||
#self.data_grid_layout.setObjectName(u'data_grid_layout')
|
||||
#self.description_label = QtGui.QLabel(self.edit_group_box)
|
||||
#self.description_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
#self.description_label.setObjectName(u'description_label')
|
||||
#self.data_grid_layout.addWidget(self.description_label, 0, 0, 1, 1)
|
||||
#self.description_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
#self.description_line_edit.setObjectName(u'description_line_edit')
|
||||
#self.data_grid_layout.addWidget(self.description_line_edit, 0, 1, 2, 1)
|
||||
#self.new_push_button = QtGui.QPushButton(self.edit_group_box)
|
||||
#self.new_push_button.setObjectName(u'new_push_button')
|
||||
#self.data_grid_layout.addWidget(self.new_push_button, 0, 2, 2, 1)
|
||||
#self.tag_label = QtGui.QLabel(self.edit_group_box)
|
||||
#self.tag_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
#self.tag_label.setObjectName(u'tag_label')
|
||||
#self.data_grid_layout.addWidget(self.tag_label, 2, 0, 1, 1)
|
||||
#self.tag_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
#self.tag_line_edit.setMaximumSize(QtCore.QSize(50, 16777215))
|
||||
#self.tag_line_edit.setMaxLength(5)
|
||||
#self.tag_line_edit.setObjectName(u'tag_line_edit')
|
||||
#self.data_grid_layout.addWidget(self.tag_line_edit, 2, 1, 1, 1)
|
||||
#self.start_tag_label = QtGui.QLabel(self.edit_group_box)
|
||||
#self.start_tag_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
#self.start_tag_label.setObjectName(u'start_tag_label')
|
||||
#self.data_grid_layout.addWidget(self.start_tag_label, 3, 0, 1, 1)
|
||||
#self.start_tag_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
#self.start_tag_line_edit.setObjectName(u'start_tag_line_edit')
|
||||
#self.data_grid_layout.addWidget(self.start_tag_line_edit, 3, 1, 1, 1)
|
||||
#self.end_tag_label = QtGui.QLabel(self.edit_group_box)
|
||||
#self.end_tag_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
#self.end_tag_label.setObjectName(u'end_tag_label')
|
||||
#self.data_grid_layout.addWidget(self.end_tag_label, 4, 0, 1, 1)
|
||||
#self.end_tag_line_edit = QtGui.QLineEdit(self.edit_group_box)
|
||||
#self.end_tag_line_edit.setObjectName(u'end_tag_line_edit')
|
||||
#self.data_grid_layout.addWidget(self.end_tag_line_edit, 4, 1, 1, 1)
|
||||
#self.save_push_button = QtGui.QPushButton(self.edit_group_box)
|
||||
#self.save_push_button.setObjectName(u'save_push_button')
|
||||
#self.data_grid_layout.addWidget(self.save_push_button, 4, 2, 1, 1)
|
||||
#self.list_data_grid_layout.addWidget(self.edit_group_box, 2, 0, 1, 1)
|
||||
|
||||
|
||||
self.edit_button_layout = QtGui.QHBoxLayout()
|
||||
self.new_button = QtGui.QPushButton(formatting_tag_dialog)
|
||||
self.new_button.setIcon(build_icon(u':/general/general_new.png'))
|
||||
self.new_button.setObjectName(u'new_button')
|
||||
self.edit_button_layout.addWidget(self.new_button)
|
||||
self.delete_button = QtGui.QPushButton(formatting_tag_dialog)
|
||||
self.delete_button.setIcon(build_icon(u':/general/general_delete.png'))
|
||||
self.delete_button.setObjectName(u'delete_button')
|
||||
self.edit_button_layout.addWidget(self.delete_button)
|
||||
self.edit_button_layout.addStretch()
|
||||
self.list_data_grid_layout.addLayout(self.edit_button_layout)
|
||||
self.button_box = create_button_box(formatting_tag_dialog, 'button_box',
|
||||
[u'cancel', u'save', u'defaults'])
|
||||
self.save_button = self.button_box.button(QtGui.QDialogButtonBox.Save)
|
||||
self.save_button.setObjectName(u'save_button')
|
||||
self.restore_button = self.button_box.button(QtGui.QDialogButtonBox.RestoreDefaults)
|
||||
self.restore_button.setIcon(build_icon(u':/general/general_revert.png'))
|
||||
self.restore_button.setObjectName(u'restore_button')
|
||||
self.list_data_grid_layout.addWidget(self.button_box)
|
||||
|
||||
#self.button_box = create_button_box(formatting_tag_dialog, u'button_box', [u'close'])
|
||||
#self.list_data_grid_layout.addWidget(self.button_box, 5, 0, 1, 1)
|
||||
#self.delete_push_button = QtGui.QPushButton(formatting_tag_dialog)
|
||||
#self.delete_push_button.setObjectName(u'delete_push_button')
|
||||
#self.list_data_grid_layout.addWidget(self.delete_push_button, 5, 0, 1, 1)
|
||||
|
||||
self.retranslateUi(formatting_tag_dialog)
|
||||
|
||||
@ -127,14 +176,25 @@ class Ui_FormattingTagDialog(object):
|
||||
Translate the UI on the fly
|
||||
"""
|
||||
formatting_tag_dialog.setWindowTitle(translate('OpenLP.FormattingTagDialog', 'Configure Formatting Tags'))
|
||||
self.edit_group_box.setTitle(translate('OpenLP.FormattingTagDialog', 'Edit Selection'))
|
||||
self.save_push_button.setText(translate('OpenLP.FormattingTagDialog', 'Save'))
|
||||
self.description_label.setText(translate('OpenLP.FormattingTagDialog', 'Description'))
|
||||
self.tag_label.setText(translate('OpenLP.FormattingTagDialog', 'Tag'))
|
||||
self.start_tag_label.setText(translate('OpenLP.FormattingTagDialog', 'Start HTML'))
|
||||
self.end_tag_label.setText(translate('OpenLP.FormattingTagDialog', 'End HTML'))
|
||||
self.delete_push_button.setText(UiStrings().Delete)
|
||||
self.new_push_button.setText(UiStrings().New)
|
||||
#self.edit_group_box.setTitle(translate('OpenLP.FormattingTagDialog', 'Edit Selection'))
|
||||
#self.save_push_button.setText(translate('OpenLP.FormattingTagDialog', 'Save'))
|
||||
#self.description_label.setText(translate('OpenLP.FormattingTagDialog', 'Description'))
|
||||
#self.tag_label.setText(translate('OpenLP.FormattingTagDialog', 'Tag'))
|
||||
#self.start_tag_label.setText(translate('OpenLP.FormattingTagDialog', 'Start HTML'))
|
||||
#self.end_tag_label.setText(translate('OpenLP.FormattingTagDialog', 'End HTML'))
|
||||
self.delete_button.setText(UiStrings().Delete)
|
||||
self.new_button.setText(UiStrings().New)
|
||||
self.tag_table_widget_read_label.setText(translate('OpenLP.FormattingTagDialog', 'Static Formatting'))
|
||||
self.tag_table_widget_read.horizontalHeaderItem(0).\
|
||||
setText(translate('OpenLP.FormattingTagDialog', 'Description'))
|
||||
self.tag_table_widget_read.horizontalHeaderItem(1).setText(translate('OpenLP.FormattingTagDialog', 'Tag'))
|
||||
self.tag_table_widget_read.horizontalHeaderItem(2).\
|
||||
setText(translate('OpenLP.FormattingTagDialog', 'Start HTML'))
|
||||
self.tag_table_widget_read.horizontalHeaderItem(3).setText(translate('OpenLP.FormattingTagDialog', 'End HTML'))
|
||||
self.tag_table_widget_read.setColumnWidth(0, 120)
|
||||
self.tag_table_widget_read.setColumnWidth(1, 80)
|
||||
self.tag_table_widget_read.setColumnWidth(2, 330)
|
||||
self.tag_table_widget_label.setText(translate('OpenLP.FormattingTagDialog', 'Custom Formatting'))
|
||||
self.tag_table_widget.horizontalHeaderItem(0).setText(translate('OpenLP.FormattingTagDialog', 'Description'))
|
||||
self.tag_table_widget.horizontalHeaderItem(1).setText(translate('OpenLP.FormattingTagDialog', 'Tag'))
|
||||
self.tag_table_widget.horizontalHeaderItem(2).setText(translate('OpenLP.FormattingTagDialog', 'Start HTML'))
|
||||
|
@ -31,7 +31,11 @@ The :mod:`formattingtagform` provides an Tag Edit facility. The Base set are pro
|
||||
Custom tags can be defined and saved. The Custom Tag arrays are saved in a pickle so QSettings works on them. Base Tags
|
||||
cannot be changed.
|
||||
"""
|
||||
from PyQt4 import QtGui
|
||||
|
||||
import re
|
||||
import cgi
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
|
||||
from openlp.core.lib import FormattingTags, translate
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
@ -48,17 +52,21 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog):
|
||||
"""
|
||||
QtGui.QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
|
||||
self.new_push_button.clicked.connect(self.on_new_clicked)
|
||||
self.save_push_button.clicked.connect(self.on_saved_clicked)
|
||||
self.delete_push_button.clicked.connect(self.on_delete_clicked)
|
||||
self.html_tag_regex = re.compile(r'<(?:(?P<close>/(?=[^\s/>]+>))?'
|
||||
r'(?P<tag>[^\s/!\?>]+)(?:\s+[^\s=]+="[^"]*")*\s*(?P<empty>/)?'
|
||||
r'|(?P<cdata>!\[CDATA\[(?:(?!\]\]>).)*\]\])'
|
||||
r'|(?P<procinst>\?(?:(?!\?>).)*\?)'
|
||||
r'|(?P<comment>!--(?:(?!-->).)*--))>', re.UNICODE)
|
||||
self.html_regex = re.compile(r'^(?:[^<>]*%s)*[^<>]*$' % self.html_tag_regex.pattern)
|
||||
#self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
|
||||
self.new_button.clicked.connect(self.on_new_clicked)
|
||||
#self.save_push_button.clicked.connect(self.on_saved_clicked)
|
||||
self.delete_button.clicked.connect(self.on_delete_clicked)
|
||||
self.tag_table_widget.currentCellChanged.connect(self.on_current_cell_changed)
|
||||
self.button_box.rejected.connect(self.close)
|
||||
self.description_line_edit.textEdited.connect(self.on_text_edited)
|
||||
self.tag_line_edit.textEdited.connect(self.on_text_edited)
|
||||
self.start_tag_line_edit.textEdited.connect(self.on_text_edited)
|
||||
self.end_tag_line_edit.textEdited.connect(self.on_text_edited)
|
||||
# Forces reloading of tags from openlp configuration.
|
||||
FormattingTags.load_tags()
|
||||
self.pause_validation = False
|
||||
|
||||
def exec_(self):
|
||||
"""
|
||||
@ -66,14 +74,13 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog):
|
||||
"""
|
||||
# Create initial copy from master
|
||||
self._reloadTable()
|
||||
self.selected = -1
|
||||
return QtGui.QDialog.exec_(self)
|
||||
|
||||
def on_row_selected(self):
|
||||
"""
|
||||
Table Row selected so display items and set field state.
|
||||
"""
|
||||
self.save_push_button.setEnabled(False)
|
||||
#self.save_push_button.setEnabled(False)
|
||||
self.selected = self.tag_table_widget.currentRow()
|
||||
html = FormattingTags.get_html_tags()[self.selected]
|
||||
self.description_line_edit.setText(html[u'desc'])
|
||||
@ -104,6 +111,9 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog):
|
||||
"""
|
||||
Add a new tag to list only if it is not a duplicate.
|
||||
"""
|
||||
last_row = self.tag_table_widget.rowCount() - 1
|
||||
self.tag_table_widget.selectRow(last_row)
|
||||
self.tag_table_widget.setCurrentCell(last_row, 0)
|
||||
for html in FormattingTags.get_html_tags():
|
||||
if self._strip(html[u'start tag']) == u'n':
|
||||
critical_error_message_box(
|
||||
@ -113,19 +123,19 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog):
|
||||
# Add new tag to list
|
||||
tag = {
|
||||
u'desc': translate('OpenLP.FormattingTagForm', 'New Tag'),
|
||||
u'start tag': u'{n}',
|
||||
u'start tag': u'{n%s}' % unicode(last_row + 1),
|
||||
u'start html': translate('OpenLP.FormattingTagForm', '<HTML here>'),
|
||||
u'end tag': u'{/n}',
|
||||
u'end tag': u'{/n%s}' % unicode(last_row + 1),
|
||||
u'end html': translate('OpenLP.FormattingTagForm', '</and here>'),
|
||||
u'protected': False,
|
||||
u'temporary': False
|
||||
}
|
||||
FormattingTags.add_html_tags([tag])
|
||||
FormattingTags.save_html_tags()
|
||||
self._reloadTable()
|
||||
#FormattingTags.add_html_tags([tag])
|
||||
#FormattingTags.save_html_tags()
|
||||
#self._reloadTable()
|
||||
# Highlight new row
|
||||
self.tag_table_widget.selectRow(self.tag_table_widget.rowCount() - 1)
|
||||
self.on_row_selected()
|
||||
#self.tag_table_widget.selectRow(self.tag_table_widget.rowCount() - 1)
|
||||
#self.on_row_selected()
|
||||
self.tag_table_widget.scrollToBottom()
|
||||
|
||||
def on_delete_clicked(self):
|
||||
@ -170,29 +180,137 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog):
|
||||
"""
|
||||
Reset List for loading.
|
||||
"""
|
||||
self.tag_table_widget_read.clearContents()
|
||||
self.tag_table_widget_read.setRowCount(0)
|
||||
self.tag_table_widget.clearContents()
|
||||
self.tag_table_widget.setRowCount(0)
|
||||
self.new_push_button.setEnabled(True)
|
||||
self.save_push_button.setEnabled(False)
|
||||
self.delete_push_button.setEnabled(False)
|
||||
self.new_button.setEnabled(True)
|
||||
self.delete_button.setEnabled(False)
|
||||
for linenumber, html in enumerate(FormattingTags.get_html_tags()):
|
||||
if html[u'protected']:
|
||||
line = self.tag_table_widget_read.rowCount()
|
||||
self.tag_table_widget_read.setRowCount(line + 1)
|
||||
print linenumber, self.tag_table_widget_read.rowCount()
|
||||
self.tag_table_widget_read.setItem(line, 0, QtGui.QTableWidgetItem(html[u'desc']))
|
||||
self.tag_table_widget_read.setItem(line, 1, QtGui.QTableWidgetItem(self._strip(html[u'start tag'])))
|
||||
self.tag_table_widget_read.setItem(line, 2, QtGui.QTableWidgetItem(html[u'start html']))
|
||||
self.tag_table_widget_read.setItem(line, 3, QtGui.QTableWidgetItem(html[u'end html']))
|
||||
self.tag_table_widget_read.resizeRowsToContents()
|
||||
else:
|
||||
print self.tag_table_widget.rowCount(), html
|
||||
line = self.tag_table_widget.rowCount()
|
||||
self.tag_table_widget.setRowCount(line + 1)
|
||||
self.tag_table_widget.setRowCount(self.tag_table_widget.rowCount() + 1)
|
||||
self.tag_table_widget.setItem(linenumber, 0, QtGui.QTableWidgetItem(html[u'desc']))
|
||||
self.tag_table_widget.setItem(linenumber, 1, QtGui.QTableWidgetItem(self._strip(html[u'start tag'])))
|
||||
self.tag_table_widget.setItem(linenumber, 2, QtGui.QTableWidgetItem(html[u'start html']))
|
||||
self.tag_table_widget.setItem(linenumber, 3, QtGui.QTableWidgetItem(html[u'end html']))
|
||||
# Permanent (persistent) tags do not have this key.
|
||||
if u'temporary' not in html:
|
||||
html[u'temporary'] = False
|
||||
self.tag_table_widget.setItem(line, 0, QtGui.QTableWidgetItem(html[u'desc']))
|
||||
self.tag_table_widget.setItem(line, 1, QtGui.QTableWidgetItem(self._strip(html[u'start tag'])))
|
||||
self.tag_table_widget.setItem(line, 2, QtGui.QTableWidgetItem(html[u'start html']))
|
||||
self.tag_table_widget.setItem(line, 3, QtGui.QTableWidgetItem(html[u'end html']))
|
||||
self.tag_table_widget.resizeRowsToContents()
|
||||
self.description_line_edit.setText(u'')
|
||||
self.tag_line_edit.setText(u'')
|
||||
self.start_tag_line_edit.setText(u'')
|
||||
self.end_tag_line_edit.setText(u'')
|
||||
self.description_line_edit.setEnabled(False)
|
||||
self.tag_line_edit.setEnabled(False)
|
||||
self.start_tag_line_edit.setEnabled(False)
|
||||
self.end_tag_line_edit.setEnabled(False)
|
||||
# Permanent (persistent) tags do not have this key
|
||||
html[u'temporary'] = False
|
||||
|
||||
def on_current_cell_changed(self, cur_row, cur_col, pre_row, pre_col):
|
||||
"""
|
||||
This function processes all user edits in the table. It is called on each cell change.
|
||||
"""
|
||||
print cur_row, cur_col, pre_col, pre_col
|
||||
# only process for editable rows
|
||||
pre_row_item = self.tag_table_widget.item(pre_row, 0)
|
||||
edit_item = None
|
||||
if pre_row_item and (pre_row_item.flags() & QtCore.Qt.ItemIsEditable) and not self.pause_validation:
|
||||
data = self.item_to_data_dict(pre_row_item)
|
||||
item = self.tag_table_widget.item(pre_row, pre_col)
|
||||
text = unicode(item.text())
|
||||
if pre_col is 0:
|
||||
# Tag name edited
|
||||
if text:
|
||||
for row in range(self.tag_table_widget.rowCount()):
|
||||
counting_item = self.tag_table_widget.item(row, 0)
|
||||
if row != pre_row and counting_item and counting_item.text() == text:
|
||||
answer = QtGui.QMessageBox.warning(self,
|
||||
translate('OpenLP.FormattingTagForm', 'Validation Error'),
|
||||
translate('OpenLP.FormattingTagForm',
|
||||
'Tag %s is already defined. Please pick a different one.' % text),
|
||||
QtGui.QMessageBox.Discard|QtGui.QMessageBox.Ok)
|
||||
if answer == QtGui.QMessageBox.Discard:
|
||||
item.setText(data.get(u'tag'))
|
||||
else:
|
||||
edit_item = item
|
||||
break
|
||||
if not edit_item:
|
||||
data[u'tag'] = text
|
||||
data.setdefault(u'description', u'')
|
||||
data.setdefault(u'html', u'')
|
||||
pre_row_item.setData(QtCore.Qt.UserRole, data)
|
||||
flags = self.tag_table_widget.item(pre_row, 1).flags()
|
||||
if not (flags & QtCore.Qt.ItemIsEditable):
|
||||
# if description cell is read only, the user is adding a new tag.
|
||||
# So we add another empty row and enable editing for description and html.
|
||||
new_row = self.tag_table_widget.rowCount()
|
||||
self.tag_table_widget.insertRow(new_row)
|
||||
for column in range(4):
|
||||
new_item = QtGui.QTableWidgetItem(u'')
|
||||
if column != 0:
|
||||
new_item.setFlags(flags)
|
||||
self.tag_table_widget.setItem(new_row, column, new_item)
|
||||
for column in [1, 2]:
|
||||
self.tag_table_widget.item(pre_row, column).setFlags(item.flags())
|
||||
# trigger edit as editing might have been enabled after selecting
|
||||
if cur_row == pre_row and cur_col in [1, 2]:
|
||||
cur_item = self.tag_table_widget.item(cur_row, cur_col)
|
||||
self.tag_table_widget.editItem(cur_item)
|
||||
self.tag_table_widget.resizeRowsToContents()
|
||||
else:
|
||||
answer = None
|
||||
if self.tag_table_widget.item(pre_row, 1).text() or self.tag_table_widget.item(pre_row, 2).text():
|
||||
answer = QtGui.QMessageBox.warning(self,
|
||||
translate('OpenLP.FormattingTagForm', 'Validation Error'),
|
||||
translate('OpenLP.FormattingTagForm',
|
||||
'No tag name defined. Do you want to delete the whole tag?'),
|
||||
QtGui.QMessageBox.Yes|QtGui.QMessageBox.Discard|QtGui.QMessageBox.Cancel)
|
||||
if answer == QtGui.QMessageBox.Discard:
|
||||
item.setText(data.get(u'tag'))
|
||||
if answer == QtGui.QMessageBox.Cancel:
|
||||
edit_item = item
|
||||
elif pre_row < self.tag_table_widget.rowCount() - 1:
|
||||
self.tag_table_widget.removeRow(pre_row)
|
||||
elif pre_col is 1:
|
||||
# Description edited
|
||||
data[u'description'] = text
|
||||
pre_row_item.setData(QtCore.Qt.UserRole, data)
|
||||
elif pre_col is 2:
|
||||
# HTML edited
|
||||
end_html = self.start_html_to_end_html(text)
|
||||
if end_html is not None:
|
||||
item.setToolTip(cgi.escape(text))
|
||||
if self.tag_table_widget.item(pre_row, 3) is None:
|
||||
self.tag_table_widget.setItem(pre_row, 3, QtGui.QTableWidgetItem(end_html))
|
||||
else:
|
||||
self.tag_table_widget.item(pre_row, 3).setText(end_html)
|
||||
self.tag_table_widget.item(pre_row, 3).setToolTip(cgi.escape(end_html))
|
||||
data[u'html'] = text
|
||||
pre_row_item.setData(QtCore.Qt.UserRole, data)
|
||||
self.tag_table_widget.resizeRowsToContents()
|
||||
elif QtGui.QMessageBox.question(self,
|
||||
translate('OpenLP.FormattingTagForm', 'Validation Error'),
|
||||
translate('OpenLP.FormattingTagForm', 'The entered HTML is not valid. Please enter valid HTML.'),
|
||||
QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) == QtGui.QMessageBox.Cancel:
|
||||
item.setText(data.get(u'html'))
|
||||
else:
|
||||
edit_item = item
|
||||
if not edit_item:
|
||||
# select the tag cell in a empty row
|
||||
cur_row_item = self.tag_table_widget.item(cur_row, 0)
|
||||
if cur_row_item and (cur_row_item.flags() & QtCore.Qt.ItemIsEditable) and cur_row_item.text().isEmpty():
|
||||
edit_item = cur_row_item
|
||||
if edit_item:
|
||||
self.tag_table_widget.setCurrentItem(edit_item)
|
||||
# enable delete_button for editable rows
|
||||
cur_row = self.tag_table_widget.currentRow()
|
||||
cur_row_item = self.tag_table_widget.item(cur_row, 0)
|
||||
delete_enabled = bool(cur_row_item) and bool(cur_row_item.flags() & QtCore.Qt.ItemIsEditable)
|
||||
delete_enabled &= cur_row < self.tag_table_widget.rowCount() - 1
|
||||
self.delete_button.setEnabled(delete_enabled)
|
||||
|
||||
def _strip(self, tag):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user