forked from openlp/openlp
Finish off spelling and tags for Custom and Song dialogs
This commit is contained in:
parent
ed4801b48a
commit
a4e58c3349
@ -36,7 +36,7 @@ import enchant
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from openlp.core.lib import html_expands, translate, context_menu_action
|
from openlp.core.lib import html_expands, translate, context_menu_action
|
||||||
|
|
||||||
class BaseSpellTextEdit(QtGui.QPlainTextEdit):
|
class SpellTextEdit(QtGui.QPlainTextEdit):
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QtGui.QPlainTextEdit.__init__(self, *args)
|
QtGui.QPlainTextEdit.__init__(self, *args)
|
||||||
@ -44,7 +44,6 @@ class BaseSpellTextEdit(QtGui.QPlainTextEdit):
|
|||||||
self.dict = enchant.Dict()
|
self.dict = enchant.Dict()
|
||||||
self.highlighter = Highlighter(self.document())
|
self.highlighter = Highlighter(self.document())
|
||||||
self.highlighter.setDict(self.dict)
|
self.highlighter.setDict(self.dict)
|
||||||
print html_expands
|
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
if event.button() == QtCore.Qt.RightButton:
|
if event.button() == QtCore.Qt.RightButton:
|
||||||
@ -81,8 +80,8 @@ class BaseSpellTextEdit(QtGui.QPlainTextEdit):
|
|||||||
tag_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
|
tag_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
|
||||||
'Formatting Tags'))
|
'Formatting Tags'))
|
||||||
for html in html_expands:
|
for html in html_expands:
|
||||||
action = context_menu_action(self, None, html[u'desc'],
|
action = SpellAction( html[u'desc'], tag_menu)
|
||||||
self.onHtmlAction)
|
action.correct.connect(self.htmlTag)
|
||||||
tag_menu.addAction(action)
|
tag_menu.addAction(action)
|
||||||
popup_menu.insertSeparator(popup_menu.actions()[0])
|
popup_menu.insertSeparator(popup_menu.actions()[0])
|
||||||
popup_menu.insertMenu(popup_menu.actions()[0], tag_menu)
|
popup_menu.insertMenu(popup_menu.actions()[0], tag_menu)
|
||||||
@ -101,6 +100,26 @@ class BaseSpellTextEdit(QtGui.QPlainTextEdit):
|
|||||||
|
|
||||||
cursor.endEditBlock()
|
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):
|
class Highlighter(QtGui.QSyntaxHighlighter):
|
||||||
|
|
||||||
WORDS = u'(?iu)[\w\']+'
|
WORDS = u'(?iu)[\w\']+'
|
||||||
@ -140,13 +159,6 @@ class SpellAction(QtGui.QAction):
|
|||||||
self.triggered.connect(lambda x: self.correct.emit(
|
self.triggered.connect(lambda x: self.correct.emit(
|
||||||
unicode(self.text())))
|
unicode(self.text())))
|
||||||
|
|
||||||
class SpellTextEdit(BaseSpellTextEdit):
|
|
||||||
def __init__(self, *args):
|
|
||||||
BaseSpellTextEdit.__init__(self, *args)
|
|
||||||
|
|
||||||
def onHtmlAction(self):
|
|
||||||
print "hello "
|
|
||||||
|
|
||||||
class HideMode(object):
|
class HideMode(object):
|
||||||
"""
|
"""
|
||||||
This is basically an enumeration class which specifies the mode of a Bible.
|
This is basically an enumeration class which specifies the mode of a Bible.
|
||||||
|
@ -74,7 +74,7 @@ class Ui_CustomEditDialog(object):
|
|||||||
self.editLayout3.setSpacing(8)
|
self.editLayout3.setSpacing(8)
|
||||||
self.editLayout3.setMargin(0)
|
self.editLayout3.setMargin(0)
|
||||||
self.editLayout3.setObjectName(u'editLayout3')
|
self.editLayout3.setObjectName(u'editLayout3')
|
||||||
self.verseTextEdit = SpellTextEdit(self.editWidget)
|
self.verseTextEdit = SpellTextEdit(self)
|
||||||
self.verseTextEdit.setObjectName(u'verseTextEdit')
|
self.verseTextEdit.setObjectName(u'verseTextEdit')
|
||||||
self.editLayout3.addWidget(self.verseTextEdit)
|
self.editLayout3.addWidget(self.verseTextEdit)
|
||||||
self.buttonWidget = QtGui.QWidget(self.editWidget)
|
self.buttonWidget = QtGui.QWidget(self.editWidget)
|
||||||
|
Loading…
Reference in New Issue
Block a user