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