Jon Tibble has proposed merging lp:~meths/openlp/trivialfixes into lp:openlp.
Requested reviews: OpenLP Core (openlp-core) For more details, see: https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/47571 Refactors and cleanups -- https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/47571 Your team OpenLP Core is requested to review the proposed merge of lp:~meths/openlp/trivialfixes into lp:openlp.
=== modified file 'openlp/core/lib/spelltextedit.py' --- openlp/core/lib/spelltextedit.py 2011-01-18 04:32:24 +0000 +++ openlp/core/lib/spelltextedit.py 2011-01-26 18:41:37 +0000 @@ -47,13 +47,16 @@ # 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 @@ 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 @@ # 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 @@ cursor.insertText(html[u'start tag']) cursor.insertText(html[u'end tag']) + 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): """ === modified file 'openlp/core/ui/mainwindow.py' --- openlp/core/ui/mainwindow.py 2011-01-21 19:09:56 +0000 +++ openlp/core/ui/mainwindow.py 2011-01-26 18:41:37 +0000 @@ -563,10 +563,10 @@ 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 @@ 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 @@ self.cleanUp() event.accept() - def cleanUp(self): """ Runs all the cleanup code before OpenLP shuts down === modified file 'openlp/core/ui/servicemanager.py' --- openlp/core/ui/servicemanager.py 2011-01-23 06:56:58 +0000 +++ openlp/core/ui/servicemanager.py 2011-01-26 18:41:37 +0000 @@ -108,7 +108,7 @@ 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 @@ 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 @@ 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 @@ 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() === modified file 'openlp/plugins/bibles/lib/manager.py' --- openlp/plugins/bibles/lib/manager.py 2011-01-08 02:44:12 +0000 +++ openlp/plugins/bibles/lib/manager.py 2011-01-26 18:41:37 +0000 @@ -92,7 +92,7 @@ return None @staticmethod - def list(): + def get_formats_list(): """ Return a list of the supported Bible formats. """ === modified file 'openlp/plugins/custom/lib/mediaitem.py' --- openlp/plugins/custom/lib/mediaitem.py 2010-12-26 11:04:47 +0000 +++ openlp/plugins/custom/lib/mediaitem.py 2011-01-26 18:41:37 +0000 @@ -68,9 +68,6 @@ 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 @@ else: raw_footer.append(u'') service_item.raw_footer = raw_footer - return True \ No newline at end of file + return True === modified file 'openlp/plugins/images/lib/mediaitem.py' --- openlp/plugins/images/lib/mediaitem.py 2011-01-23 15:36:15 +0000 +++ openlp/plugins/images/lib/mediaitem.py 2011-01-26 18:41:37 +0000 @@ -220,6 +220,3 @@ 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) === modified file 'openlp/plugins/songs/lib/easislidesimport.py' --- openlp/plugins/songs/lib/easislidesimport.py 2011-01-21 22:28:34 +0000 +++ openlp/plugins/songs/lib/easislidesimport.py 2011-01-26 18:41:37 +0000 @@ -314,11 +314,11 @@ 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 === modified file 'openlp/plugins/songs/lib/importer.py' --- openlp/plugins/songs/lib/importer.py 2011-01-18 17:26:57 +0000 +++ openlp/plugins/songs/lib/importer.py 2011-01-26 18:41:37 +0000 @@ -105,7 +105,7 @@ return None @staticmethod - def list(): + def get_formats_list(): """ Return a list of the supported song formats. """ === modified file 'openlp/plugins/songs/lib/mediaitem.py' --- openlp/plugins/songs/lib/mediaitem.py 2011-01-20 02:31:20 +0000 +++ openlp/plugins/songs/lib/mediaitem.py 2011-01-26 18:41:37 +0000 @@ -68,9 +68,6 @@ 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 ## === modified file 'openlp/plugins/songs/lib/oooimport.py' --- openlp/plugins/songs/lib/oooimport.py 2011-01-21 22:28:34 +0000 +++ openlp/plugins/songs/lib/oooimport.py 2011-01-26 18:41:37 +0000 @@ -66,31 +66,34 @@ 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 @@ 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) === modified file 'openlp/plugins/songs/lib/sofimport.py' --- openlp/plugins/songs/lib/sofimport.py 2011-01-13 17:55:29 +0000 +++ openlp/plugins/songs/lib/sofimport.py 2011-01-26 18:41:37 +0000 @@ -75,23 +75,11 @@ """ 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: - 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): """ @@ -101,7 +89,7 @@ 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()
_______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp