forked from openlp/openlp
Lots of cleanups and refactors
bzr-revno: 1249
This commit is contained in:
commit
5ae99a25ad
@ -47,13 +47,16 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
|
||||
# Default dictionary based on the current locale.
|
||||
if ENCHANT_AVAILABLE:
|
||||
try:
|
||||
self.dict = enchant.Dict()
|
||||
self.dictionary = enchant.Dict()
|
||||
except DictNotFoundError:
|
||||
self.dict = enchant.Dict(u'en_US')
|
||||
self.dictionary = enchant.Dict(u'en_US')
|
||||
self.highlighter = Highlighter(self.document())
|
||||
self.highlighter.setDict(self.dict)
|
||||
self.highlighter.spellingDictionary = self.dictionary
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
"""
|
||||
Handle mouse clicks within the text edit region.
|
||||
"""
|
||||
if event.button() == QtCore.Qt.RightButton:
|
||||
# Rewrite the mouse event to a left button event so the cursor is
|
||||
# moved to the location of the pointer.
|
||||
@ -63,6 +66,9 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
|
||||
QtGui.QPlainTextEdit.mousePressEvent(self, event)
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
"""
|
||||
Provide the context menu for the text edit region.
|
||||
"""
|
||||
popupMenu = self.createStandardContextMenu()
|
||||
# Select the word under the cursor.
|
||||
cursor = self.textCursor()
|
||||
@ -74,10 +80,10 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
|
||||
# suggestions if it is.
|
||||
if ENCHANT_AVAILABLE and self.textCursor().hasSelection():
|
||||
text = unicode(self.textCursor().selectedText())
|
||||
if not self.dict.check(text):
|
||||
if not self.dictionary.check(text):
|
||||
spell_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
|
||||
'Spelling Suggestions'))
|
||||
for word in self.dict.suggest(text):
|
||||
for word in self.dictionary.suggest(text):
|
||||
action = SpellAction(word, spell_menu)
|
||||
action.correct.connect(self.correctWord)
|
||||
spell_menu.addAction(action)
|
||||
@ -126,28 +132,32 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
|
||||
cursor.insertText(html[u'start tag'])
|
||||
cursor.insertText(html[u'end tag'])
|
||||
|
||||
class Highlighter(QtGui.QSyntaxHighlighter):
|
||||
|
||||
class Highlighter(QtGui.QSyntaxHighlighter):
|
||||
"""
|
||||
Provides a text highlighter for pointing out spelling errors in text.
|
||||
"""
|
||||
WORDS = u'(?iu)[\w\']+'
|
||||
|
||||
def __init__(self, *args):
|
||||
QtGui.QSyntaxHighlighter.__init__(self, *args)
|
||||
self.dict = None
|
||||
|
||||
def setDict(self, dict):
|
||||
self.dict = dict
|
||||
self.spellingDictionary = None
|
||||
|
||||
def highlightBlock(self, text):
|
||||
if not self.dict:
|
||||
"""
|
||||
Highlight misspelt words in a block of text
|
||||
"""
|
||||
if not self.spellingDictionary:
|
||||
return
|
||||
text = unicode(text)
|
||||
format = QtGui.QTextCharFormat()
|
||||
format.setUnderlineColor(QtCore.Qt.red)
|
||||
format.setUnderlineStyle(QtGui.QTextCharFormat.SpellCheckUnderline)
|
||||
charFormat = QtGui.QTextCharFormat()
|
||||
charFormat.setUnderlineColor(QtCore.Qt.red)
|
||||
charFormat.setUnderlineStyle(QtGui.QTextCharFormat.SpellCheckUnderline)
|
||||
for word_object in re.finditer(self.WORDS, text):
|
||||
if not self.dict.check(word_object.group()):
|
||||
if not self.spellingDictionary.check(word_object.group()):
|
||||
self.setFormat(word_object.start(),
|
||||
word_object.end() - word_object.start(), format)
|
||||
word_object.end() - word_object.start(), charFormat)
|
||||
|
||||
|
||||
class SpellAction(QtGui.QAction):
|
||||
"""
|
||||
|
@ -563,10 +563,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
self.ServiceManagerContents.onLoadServiceClicked)
|
||||
QtCore.QObject.connect(self.FileSaveItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
self.ServiceManagerContents.onSaveServiceClicked)
|
||||
self.ServiceManagerContents.saveFile)
|
||||
QtCore.QObject.connect(self.FileSaveAsItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
self.ServiceManagerContents.onSaveServiceAsClicked)
|
||||
self.ServiceManagerContents.saveFileAs)
|
||||
# i18n set signals for languages
|
||||
QtCore.QObject.connect(self.AutoLanguageItem,
|
||||
QtCore.SIGNAL(u'toggled(bool)'), self.setAutoLanguage)
|
||||
@ -807,15 +807,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
Hook to close the main window and display windows on exit
|
||||
"""
|
||||
if self.ServiceManagerContents.isModified():
|
||||
ret = QtGui.QMessageBox.question(self,
|
||||
translate('OpenLP.MainWindow', 'Save Changes to Service?'),
|
||||
translate('OpenLP.MainWindow', 'Your service has changed. '
|
||||
'Do you want to save those changes?'),
|
||||
QtGui.QMessageBox.StandardButtons(
|
||||
QtGui.QMessageBox.Cancel |
|
||||
QtGui.QMessageBox.Discard |
|
||||
QtGui.QMessageBox.Save),
|
||||
QtGui.QMessageBox.Save)
|
||||
ret = self.ServiceManagerContents.saveModifiedService()
|
||||
if ret == QtGui.QMessageBox.Save:
|
||||
if self.ServiceManagerContents.saveFile():
|
||||
self.cleanUp()
|
||||
@ -847,7 +839,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
self.cleanUp()
|
||||
event.accept()
|
||||
|
||||
|
||||
def cleanUp(self):
|
||||
"""
|
||||
Runs all the cleanup code before OpenLP shuts down
|
||||
|
@ -108,7 +108,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
translate('OpenLP.ServiceManager', 'Save Service'),
|
||||
u':/general/general_save.png',
|
||||
translate('OpenLP.ServiceManager', 'Save this service'),
|
||||
self.onSaveServiceClicked)
|
||||
self.saveFile)
|
||||
self.toolbar.addSeparator()
|
||||
self.themeLabel = QtGui.QLabel(translate('OpenLP.ServiceManager',
|
||||
'Theme:'), self)
|
||||
@ -361,12 +361,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
Create a new service.
|
||||
"""
|
||||
if self.isModified():
|
||||
result = QtGui.QMessageBox.question(self.mainwindow,
|
||||
translate('OpenLP.ServiceManager', 'Save Changes'),
|
||||
translate('OpenLP.ServiceManager', 'The current service has '
|
||||
'been modified, would you like to save it?'),
|
||||
QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
|
||||
QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save)
|
||||
result = self.saveModifiedService()
|
||||
if result == QtGui.QMessageBox.Cancel:
|
||||
return False
|
||||
elif result == QtGui.QMessageBox.Save:
|
||||
@ -376,12 +371,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
|
||||
def onLoadServiceClicked(self):
|
||||
if self.isModified():
|
||||
result = QtGui.QMessageBox.question(self.mainwindow,
|
||||
translate('OpenLP.ServiceManager', 'Save Changes'),
|
||||
translate('OpenLP.ServiceManager', 'The current service has '
|
||||
'been modified, would you like to save it?'),
|
||||
QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
|
||||
QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save)
|
||||
result = self.saveModifiedService()
|
||||
if result == QtGui.QMessageBox.Cancel:
|
||||
return False
|
||||
elif result == QtGui.QMessageBox.Save:
|
||||
@ -397,11 +387,13 @@ class ServiceManager(QtGui.QWidget):
|
||||
split_filename(fileName)[0])
|
||||
self.loadFile(fileName)
|
||||
|
||||
def onSaveServiceClicked(self):
|
||||
self.saveFile()
|
||||
|
||||
def onSaveServiceAsClicked(self):
|
||||
self.saveFileAs()
|
||||
def saveModifiedService(self):
|
||||
return QtGui.QMessageBox.question(self.mainwindow,
|
||||
translate('OpenLP.ServiceManager', 'Modified Service'),
|
||||
translate('OpenLP.ServiceManager', 'The current service has '
|
||||
'been modified. Would you like to save this service?'),
|
||||
QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
|
||||
QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save)
|
||||
|
||||
def onRecentServiceClicked(self):
|
||||
sender = self.sender()
|
||||
|
@ -92,7 +92,7 @@ class BibleFormat(object):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def list():
|
||||
def get_formats_list():
|
||||
"""
|
||||
Return a list of the supported Bible formats.
|
||||
"""
|
||||
|
@ -68,9 +68,6 @@ class CustomMediaItem(MediaManagerItem):
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick)
|
||||
|
||||
def requiredIcons(self):
|
||||
MediaManagerItem.requiredIcons(self)
|
||||
|
||||
def initialise(self):
|
||||
self.loadCustomListView(self.manager.get_all_objects(
|
||||
CustomSlide, order_by_ref=CustomSlide.title))
|
||||
|
@ -220,6 +220,3 @@ class ImageMediaItem(MediaManagerItem):
|
||||
unicode(translate('ImagePlugin.MediaItem',
|
||||
'There was a problem replacing your background, '
|
||||
'the image file "%s" no longer exists.')) % filename)
|
||||
|
||||
def onPreviewClick(self):
|
||||
MediaManagerItem.onPreviewClick(self)
|
||||
|
@ -314,11 +314,11 @@ class EasiSlidesImport(SongImport):
|
||||
pass
|
||||
|
||||
def _listHas(self, lst, subitems):
|
||||
for i in subitems:
|
||||
if type(lst) == type({}) and lst.has_key(i):
|
||||
lst = lst[i]
|
||||
elif type(lst) == type([]) and i in lst:
|
||||
lst = lst[i]
|
||||
for subitem in subitems:
|
||||
if isinstance(lst, dict) and lst.has_key(subitem):
|
||||
lst = lst[subitem]
|
||||
elif isinstance(lst, list) and subitem in lst:
|
||||
lst = lst[subitem]
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
@ -105,7 +105,7 @@ class SongFormat(object):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def list():
|
||||
def get_formats_list():
|
||||
"""
|
||||
Return a list of the supported song formats.
|
||||
"""
|
||||
|
@ -68,9 +68,6 @@ class SongMediaItem(MediaManagerItem):
|
||||
self.editItem = None
|
||||
self.whitespace = re.compile(r'\W+', re.UNICODE)
|
||||
|
||||
def requiredIcons(self):
|
||||
MediaManagerItem.requiredIcons(self)
|
||||
|
||||
def addEndHeaderBar(self):
|
||||
self.addToolbarSeparator()
|
||||
## Song Maintenance Button ##
|
||||
|
@ -66,31 +66,34 @@ class OooImport(SongImport):
|
||||
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
|
||||
|
||||
def do_import(self):
|
||||
self.abort = False
|
||||
self.stop_import_flag = False
|
||||
self.import_wizard.progressBar.setMaximum(0)
|
||||
self.start_ooo()
|
||||
for filename in self.filenames:
|
||||
if self.abort:
|
||||
if self.stop_import_flag:
|
||||
self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
|
||||
return
|
||||
filename = unicode(filename)
|
||||
if os.path.isfile(filename):
|
||||
self.open_ooo_file(filename)
|
||||
if self.document:
|
||||
if self.document.supportsService(
|
||||
"com.sun.star.presentation.PresentationDocument"):
|
||||
self.process_pres()
|
||||
if self.document.supportsService(
|
||||
"com.sun.star.text.TextDocument"):
|
||||
self.process_doc()
|
||||
self.process_ooo_document()
|
||||
self.close_ooo_file()
|
||||
self.close_ooo()
|
||||
self.import_wizard.progressBar.setMaximum(1)
|
||||
self.import_wizard.incrementProgressBar(u'', 1)
|
||||
return True
|
||||
|
||||
def stop_import(self):
|
||||
self.abort = True
|
||||
def process_ooo_document(self):
|
||||
"""
|
||||
Handle the import process for OpenOffice files. This method facilitates
|
||||
allowing subclasses to handle specific types of OpenOffice files.
|
||||
"""
|
||||
if self.document.supportsService(
|
||||
"com.sun.star.presentation.PresentationDocument"):
|
||||
self.process_pres()
|
||||
if self.document.supportsService("com.sun.star.text.TextDocument"):
|
||||
self.process_doc()
|
||||
|
||||
def start_ooo(self):
|
||||
"""
|
||||
@ -180,7 +183,7 @@ class OooImport(SongImport):
|
||||
slides = doc.getDrawPages()
|
||||
text = u''
|
||||
for slide_no in range(slides.getCount()):
|
||||
if self.abort:
|
||||
if self.stop_import_flag:
|
||||
self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
|
||||
return
|
||||
slide = slides.getByIndex(slide_no)
|
||||
|
@ -75,23 +75,11 @@ class SofImport(OooImport):
|
||||
"""
|
||||
OooImport.__init__(self, master_manager, **kwargs)
|
||||
|
||||
def do_import(self):
|
||||
self.abort = False
|
||||
self.start_ooo()
|
||||
for filename in self.filenames:
|
||||
if self.abort:
|
||||
self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
|
||||
return
|
||||
filename = unicode(filename)
|
||||
if os.path.isfile(filename):
|
||||
self.open_ooo_file(filename)
|
||||
if self.document:
|
||||
def process_ooo_document(self):
|
||||
"""
|
||||
Handle the import process for SoF files.
|
||||
"""
|
||||
self.process_sof_file()
|
||||
self.close_ooo_file()
|
||||
self.close_ooo()
|
||||
self.import_wizard.progressBar.setMaximum(1)
|
||||
self.import_wizard.incrementProgressBar(u'', 1)
|
||||
return True
|
||||
|
||||
def process_sof_file(self):
|
||||
"""
|
||||
@ -101,7 +89,7 @@ class SofImport(OooImport):
|
||||
self.new_song()
|
||||
paragraphs = self.document.getText().createEnumeration()
|
||||
while paragraphs.hasMoreElements():
|
||||
if self.abort:
|
||||
if self.stop_import_flag:
|
||||
self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
|
||||
return
|
||||
paragraph = paragraphs.nextElement()
|
||||
|
Loading…
Reference in New Issue
Block a user