From a4e58c3349a947faa3375a749e907ba51e3a9fc7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 22 Aug 2010 09:27:08 +0100 Subject: [PATCH] Finish off spelling and tags for Custom and Song dialogs --- openlp/core/ui/__init__.py | 34 +++++++++++++------ .../plugins/custom/forms/editcustomdialog.py | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index fa694f6ed..da2155559 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -36,7 +36,7 @@ import enchant from PyQt4 import QtCore, QtGui from openlp.core.lib import html_expands, translate, context_menu_action -class BaseSpellTextEdit(QtGui.QPlainTextEdit): +class SpellTextEdit(QtGui.QPlainTextEdit): def __init__(self, *args): QtGui.QPlainTextEdit.__init__(self, *args) @@ -44,7 +44,6 @@ class BaseSpellTextEdit(QtGui.QPlainTextEdit): self.dict = enchant.Dict() self.highlighter = Highlighter(self.document()) self.highlighter.setDict(self.dict) - print html_expands def mousePressEvent(self, event): if event.button() == QtCore.Qt.RightButton: @@ -81,8 +80,8 @@ class BaseSpellTextEdit(QtGui.QPlainTextEdit): tag_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit', 'Formatting Tags')) for html in html_expands: - action = context_menu_action(self, None, html[u'desc'], - self.onHtmlAction) + action = SpellAction( html[u'desc'], tag_menu) + action.correct.connect(self.htmlTag) tag_menu.addAction(action) popup_menu.insertSeparator(popup_menu.actions()[0]) popup_menu.insertMenu(popup_menu.actions()[0], tag_menu) @@ -101,6 +100,26 @@ class BaseSpellTextEdit(QtGui.QPlainTextEdit): cursor.endEditBlock() + def htmlTag(self, tag): + ''' + Replaces the selected text with word. + ''' + for html in html_expands: + if tag == html[u'desc']: + cursor = self.textCursor() + if self.textCursor().hasSelection(): + text = cursor.selectedText() + cursor.beginEditBlock() + cursor.removeSelectedText() + cursor.insertText(html[u'start tag']) + cursor.insertText(text) + cursor.insertText(html[u'end tag']) + cursor.endEditBlock() + else: + cursor = self.textCursor() + cursor.insertText(html[u'start tag']) + cursor.insertText(html[u'end tag']) + class Highlighter(QtGui.QSyntaxHighlighter): WORDS = u'(?iu)[\w\']+' @@ -140,13 +159,6 @@ class SpellAction(QtGui.QAction): self.triggered.connect(lambda x: self.correct.emit( unicode(self.text()))) -class SpellTextEdit(BaseSpellTextEdit): - def __init__(self, *args): - BaseSpellTextEdit.__init__(self, *args) - - def onHtmlAction(self): - print "hello " - class HideMode(object): """ This is basically an enumeration class which specifies the mode of a Bible. diff --git a/openlp/plugins/custom/forms/editcustomdialog.py b/openlp/plugins/custom/forms/editcustomdialog.py index ac58789fa..17de883cf 100644 --- a/openlp/plugins/custom/forms/editcustomdialog.py +++ b/openlp/plugins/custom/forms/editcustomdialog.py @@ -74,7 +74,7 @@ class Ui_CustomEditDialog(object): self.editLayout3.setSpacing(8) self.editLayout3.setMargin(0) self.editLayout3.setObjectName(u'editLayout3') - self.verseTextEdit = SpellTextEdit(self.editWidget) + self.verseTextEdit = SpellTextEdit(self) self.verseTextEdit.setObjectName(u'verseTextEdit') self.editLayout3.addWidget(self.verseTextEdit) self.buttonWidget = QtGui.QWidget(self.editWidget)