From f484286f8a0eff4a63793ed474ae5c1304579bbb Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 26 Jan 2011 02:43:16 +0000 Subject: [PATCH 1/5] Few cleanups --- openlp/plugins/bibles/lib/manager.py | 2 +- openlp/plugins/songs/lib/easislidesimport.py | 10 +++++----- openlp/plugins/songs/lib/importer.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 63c6954fb..85204ac7a 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -92,7 +92,7 @@ class BibleFormat(object): return None @staticmethod - def list(): + def get_formats_list(): """ Return a list of the supported Bible formats. """ diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 64523fd3a..84e7a3841 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -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 diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 91d3d7e6f..6f566ff4f 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -105,7 +105,7 @@ class SongFormat(object): return None @staticmethod - def list(): + def get_formats_list(): """ Return a list of the supported song formats. """ From df9bd3b3a2cf37cdd7cca32f4111ec820e23fdba Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 26 Jan 2011 16:05:55 +0000 Subject: [PATCH 2/5] Cleanup modified service messages --- openlp/core/ui/mainwindow.py | 15 +++------------ openlp/core/ui/servicemanager.py | 28 ++++++++++------------------ 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index db9d4f9d5..d8bedade3 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -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 diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index d1a3e6762..7f1d6493e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -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() From 51812f21de24aae47772c927a0b8c9643fd4fb57 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 26 Jan 2011 17:13:26 +0000 Subject: [PATCH 3/5] Stop redefining builtins and docstrings --- openlp/core/lib/spelltextedit.py | 42 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/openlp/core/lib/spelltextedit.py b/openlp/core/lib/spelltextedit.py index 82391a0b3..44180a25c 100644 --- a/openlp/core/lib/spelltextedit.py +++ b/openlp/core/lib/spelltextedit.py @@ -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): """ From 934d26bd0adbee3cfdf6fe0c86c569e5fd3d814a Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 26 Jan 2011 18:14:46 +0000 Subject: [PATCH 4/5] Cleanup superfluous functions and import halting --- openlp/plugins/custom/lib/mediaitem.py | 5 +---- openlp/plugins/images/lib/mediaitem.py | 3 --- openlp/plugins/songs/lib/mediaitem.py | 3 --- openlp/plugins/songs/lib/oooimport.py | 9 +++------ openlp/plugins/songs/lib/sofimport.py | 6 +++--- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 304773ea5..9b8115956 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -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)) @@ -182,4 +179,4 @@ class CustomMediaItem(MediaManagerItem): else: raw_footer.append(u'') service_item.raw_footer = raw_footer - return True \ No newline at end of file + return True diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 4f976bd51..d55735188 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -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) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 625f99f18..dc51f97f5 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -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 ## diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 45d1ce5b9..819a62d1e 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -66,11 +66,11 @@ 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) @@ -89,9 +89,6 @@ class OooImport(SongImport): self.import_wizard.incrementProgressBar(u'', 1) return True - def stop_import(self): - self.abort = True - def start_ooo(self): """ Start OpenOffice.org process @@ -180,7 +177,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) diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index 8475b0824..82b89141f 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -76,10 +76,10 @@ class SofImport(OooImport): OooImport.__init__(self, master_manager, **kwargs) def do_import(self): - self.abort = False + self.stop_import_flag = False 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) @@ -101,7 +101,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() From 0a52af1869cb20bad6eb339c1506e6f7261f93c8 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 26 Jan 2011 18:35:11 +0000 Subject: [PATCH 5/5] Refactor OOo song imports --- openlp/plugins/songs/lib/oooimport.py | 18 ++++++++++++------ openlp/plugins/songs/lib/sofimport.py | 22 +++++----------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 819a62d1e..32315130a 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -77,18 +77,24 @@ class OooImport(SongImport): 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 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): """ Start OpenOffice.org process diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index 82b89141f..96a514f85 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -75,23 +75,11 @@ class SofImport(OooImport): """ OooImport.__init__(self, master_manager, **kwargs) - def do_import(self): - self.stop_import_flag = False - self.start_ooo() - for filename in self.filenames: - 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: - 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_ooo_document(self): + """ + Handle the import process for SoF files. + """ + self.process_sof_file() def process_sof_file(self): """