diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 3171730ea..d9d094949 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -86,10 +86,10 @@ class BaseModel(object): """ Creates an instance of a class and populates it, returning the instance """ - me = cls() + instance = cls() for key in kwargs: - me.__setattr__(key, kwargs[key]) - return me + instance.__setattr__(key, kwargs[key]) + return instance class Manager(object): """ diff --git a/openlp/core/lib/displaytags.py b/openlp/core/lib/displaytags.py index dd7276a7d..d414f80bb 100644 --- a/openlp/core/lib/displaytags.py +++ b/openlp/core/lib/displaytags.py @@ -60,8 +60,8 @@ class DisplayTags(object): DisplayTags.html_expands.append(tag) @staticmethod - def remove_html_tag(id): + def remove_html_tag(tag_id): """ - Removes amd individual html_expands list. + Removes an individual html_expands tag. """ - DisplayTags.html_expands.pop(id) + DisplayTags.html_expands.pop(tag_id) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 02d7010be..fb242602a 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -61,10 +61,10 @@ class Image(object): image = None image_bytes = None + class ImageManager(QtCore.QObject): """ Image Manager handles the conversion and sizing of images. - """ log.info(u'Image Manager loaded') diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index fb31006b5..476df79b0 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -44,6 +44,9 @@ class PluginStatus(object): class StringContent(object): + """ + Provide standard strings for objects to use. + """ Name = u'name' Import = u'import' Load = u'load' diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index d119f19ff..dca226069 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -583,8 +583,7 @@ class ThemeXML(object): self.background_end_color, self.background_direction) else: - filename = \ - os.path.split(self.background_filename)[1] + filename = os.path.split(self.background_filename)[1] self.add_background_image(filename) self.add_font(self.font_main_name, self.font_main_color, diff --git a/openlp/core/theme/theme.py b/openlp/core/theme/theme.py index e506fc2c2..8a57c3ae7 100644 --- a/openlp/core/theme/theme.py +++ b/openlp/core/theme/theme.py @@ -33,11 +33,14 @@ processing version 1 themes in OpenLP version 2. from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtGui -DELPHI_COLORS = {u'clRed': 0xFF0000, - u'clBlue': 0x0000FF, - u'clYellow': 0xFFFF00, - u'clBlack': 0x000000, - u'clWhite': 0xFFFFFF} +DELPHI_COLORS = { + u'clAqua': 0x00FFFF, u'clBlack': 0x000000, u'clBlue': 0x0000FF, + u'clFuchsia': 0xFF00FF, u'clGray': 0x808080, u'clGreen': 0x008000, + u'clLime': 0x00FF00, u'clMaroon': 0x800000, u'clNavy': 0x000080, + u'clOlive': 0x808000, u'clPurple': 0x800080, u'clRed': 0xFF0000, + u'clSilver': 0xC0C0C0, u'clTeal': 0x008080, u'clWhite': 0xFFFFFF, + u'clYellow': 0xFFFF00 +} BLANK_STYLE_XML = \ ''' @@ -184,7 +187,6 @@ class Theme(object): if element.tag != u'Theme': element_text = element.text val = 0 - # easy! if element_text is None: val = element_text # strings need special handling to sort the colours out diff --git a/openlp/core/ui/displaytagtab.py b/openlp/core/ui/displaytagtab.py index 983bc17a8..54d021913 100644 --- a/openlp/core/ui/displaytagtab.py +++ b/openlp/core/ui/displaytagtab.py @@ -23,27 +23,27 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -''' +""" The :mod:`DisplayTagTab` provides an Tag Edit facility. The Base set are protected and included each time loaded. Custom tags can be defined and saved. The Custom Tag arrays are saved in a pickle so QSettings works on them. Base Tags cannot be changed. - -''' +""" import cPickle + from PyQt4 import QtCore, QtGui from openlp.core.lib import SettingsTab, translate, DisplayTags from openlp.core.lib.ui import critical_error_message_box class DisplayTagTab(SettingsTab): - ''' + """ The :class:`DisplayTagTab` manages the settings tab . - ''' + """ def __init__(self): - ''' + """ Initialise the settings tab - ''' + """ SettingsTab.__init__(self, u'Display Tags') def resizeEvent(self, event=None): @@ -67,9 +67,9 @@ class DisplayTagTab(SettingsTab): self.selected = -1 def setupUi(self): - ''' + """ Configure the UI elements for the tab. - ''' + """ self.setObjectName(u'DisplayTagTab') self.tabTitleVisible = \ translate(u'OpenLP.DisplayTagTab', 'Display Tags') diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index bae00c2da..c4ab75aac 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -326,8 +326,7 @@ class MainDisplay(DisplayWidget): vol = float(volume)/float(10) if isBackground or not self.usePhonon: js = u'show_video("init", "%s", %s, true); show_video("play");' % \ - (videoPath.replace(u'\\', u'\\\\'), \ - str(vol)) + (videoPath.replace(u'\\', u'\\\\'), str(vol)) self.frame.evaluateJavaScript(js) else: self.phononActive = True @@ -398,8 +397,7 @@ class MainDisplay(DisplayWidget): if u'video' in self.override: Receiver.send_message(u'video_background_replaced') self.override = {} - elif self.override[u'theme'] != \ - serviceItem.themedata.theme_name: + elif self.override[u'theme'] != serviceItem.themedata.theme_name: Receiver.send_message(u'live_theme_changed') self.override = {} else: diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 9af4931fb..e489d7b5d 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -77,10 +77,10 @@ class Ui_MainWindow(object): self.MainContentLayout.setMargin(0) self.MainContentLayout.setObjectName(u'MainContentLayout') mainWindow.setCentralWidget(self.MainContent) - self.ControlSplitter = QtGui.QSplitter(self.MainContent) - self.ControlSplitter.setOrientation(QtCore.Qt.Horizontal) - self.ControlSplitter.setObjectName(u'ControlSplitter') - self.MainContentLayout.addWidget(self.ControlSplitter) + self.controlSplitter = QtGui.QSplitter(self.MainContent) + self.controlSplitter.setOrientation(QtCore.Qt.Horizontal) + self.controlSplitter.setObjectName(u'controlSplitter') + self.MainContentLayout.addWidget(self.controlSplitter) # Create slide controllers self.previewController = SlideController(self, self.settingsmanager, self.screens) @@ -102,9 +102,9 @@ class Ui_MainWindow(object): self.FileExportMenu = QtGui.QMenu(self.FileMenu) self.FileExportMenu.setObjectName(u'FileExportMenu') # View Menu - self.ViewMenu = QtGui.QMenu(self.MenuBar) - self.ViewMenu.setObjectName(u'ViewMenu') - self.ViewModeMenu = QtGui.QMenu(self.ViewMenu) + self.viewMenu = QtGui.QMenu(self.MenuBar) + self.viewMenu.setObjectName(u'viewMenu') + self.ViewModeMenu = QtGui.QMenu(self.viewMenu) self.ViewModeMenu.setObjectName(u'ViewModeMenu') # Tools Menu self.ToolsMenu = QtGui.QMenu(self.MenuBar) @@ -125,38 +125,38 @@ class Ui_MainWindow(object): self.DefaultThemeLabel.setObjectName(u'DefaultThemeLabel') self.StatusBar.addPermanentWidget(self.DefaultThemeLabel) # Create the MediaManager - self.MediaManagerDock = OpenLPDockWidget(mainWindow, - u'MediaManagerDock', u':/system/system_mediamanager.png') - self.MediaManagerDock.setStyleSheet(MEDIA_MANAGER_STYLE) - self.MediaManagerDock.setMinimumWidth( + self.mediaManagerDock = OpenLPDockWidget(mainWindow, + u'mediaManagerDock', u':/system/system_mediamanager.png') + self.mediaManagerDock.setStyleSheet(MEDIA_MANAGER_STYLE) + self.mediaManagerDock.setMinimumWidth( self.settingsmanager.mainwindow_left) # Create the media toolbox - self.MediaToolBox = QtGui.QToolBox(self.MediaManagerDock) + self.MediaToolBox = QtGui.QToolBox(self.mediaManagerDock) self.MediaToolBox.setObjectName(u'MediaToolBox') - self.MediaManagerDock.setWidget(self.MediaToolBox) + self.mediaManagerDock.setWidget(self.MediaToolBox) mainWindow.addDockWidget(QtCore.Qt.LeftDockWidgetArea, - self.MediaManagerDock) + self.mediaManagerDock) # Create the service manager - self.ServiceManagerDock = OpenLPDockWidget(mainWindow, - u'ServiceManagerDock', u':/system/system_servicemanager.png') - self.ServiceManagerDock.setMinimumWidth( + self.serviceManagerDock = OpenLPDockWidget(mainWindow, + u'serviceManagerDock', u':/system/system_servicemanager.png') + self.serviceManagerDock.setMinimumWidth( self.settingsmanager.mainwindow_right) self.ServiceManagerContents = ServiceManager(mainWindow, - self.ServiceManagerDock) - self.ServiceManagerDock.setWidget(self.ServiceManagerContents) + self.serviceManagerDock) + self.serviceManagerDock.setWidget(self.ServiceManagerContents) mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, - self.ServiceManagerDock) + self.serviceManagerDock) # Create the theme manager - self.ThemeManagerDock = OpenLPDockWidget(mainWindow, - u'ThemeManagerDock', u':/system/system_thememanager.png') - self.ThemeManagerDock.setMinimumWidth( + self.themeManagerDock = OpenLPDockWidget(mainWindow, + u'themeManagerDock', u':/system/system_thememanager.png') + self.themeManagerDock.setMinimumWidth( self.settingsmanager.mainwindow_right) self.ThemeManagerContents = ThemeManager(mainWindow, - self.ThemeManagerDock) + self.themeManagerDock) self.ThemeManagerContents.setObjectName(u'ThemeManagerContents') - self.ThemeManagerDock.setWidget(self.ThemeManagerContents) + self.themeManagerDock.setWidget(self.ThemeManagerContents) mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, - self.ThemeManagerDock) + self.themeManagerDock) # Create the menu items self.FileNewItem = icon_action(mainWindow, u'FileNewItem', u':/general/general_new.png') @@ -186,14 +186,14 @@ class Ui_MainWindow(object): mainWindow.actionList.add_action(self.ExportLanguageItem, u'Export') self.ViewMediaManagerItem = icon_action(mainWindow, u'ViewMediaManagerItem', u':/system/system_mediamanager.png', - self.MediaManagerDock.isVisible()) + self.mediaManagerDock.isVisible()) self.ViewThemeManagerItem = icon_action(mainWindow, u'ViewThemeManagerItem', u':/system/system_thememanager.png', - self.ThemeManagerDock.isVisible()) + self.themeManagerDock.isVisible()) mainWindow.actionList.add_action(self.ViewMediaManagerItem, u'View') self.ViewServiceManagerItem = icon_action(mainWindow, u'ViewServiceManagerItem', u':/system/system_servicemanager.png', - self.ServiceManagerDock.isVisible()) + self.serviceManagerDock.isVisible()) mainWindow.actionList.add_action(self.ViewServiceManagerItem, u'View') self.ViewPreviewPanel = checkable_action(mainWindow, u'ViewPreviewPanel', previewVisible) @@ -215,9 +215,9 @@ class Ui_MainWindow(object): self.ToolsAddToolItem = icon_action(mainWindow, u'ToolsAddToolItem', u':/tools/tools_add.png') mainWindow.actionList.add_action(self.ToolsAddToolItem, u'Tools') - self.SettingsPluginListItem = icon_action(mainWindow, - u'SettingsPluginListItem', u':/system/settings_plugin_list.png') - mainWindow.actionList.add_action(self.SettingsPluginListItem, + self.settingsPluginListItem = icon_action(mainWindow, + u'settingsPluginListItem', u':/system/settings_plugin_list.png') + mainWindow.actionList.add_action(self.settingsPluginListItem, u'Settings') # i18n Language Items self.AutoLanguageItem = checkable_action(mainWindow, @@ -264,14 +264,14 @@ class Ui_MainWindow(object): self.FileExportMenu.menuAction(), self.FileExitItem) add_actions(self.ViewModeMenu, (self.ModeDefaultItem, self.ModeSetupItem, self.ModeLiveItem)) - add_actions(self.ViewMenu, (self.ViewModeMenu.menuAction(), + add_actions(self.viewMenu, (self.ViewModeMenu.menuAction(), None, self.ViewMediaManagerItem, self.ViewServiceManagerItem, self.ViewThemeManagerItem, None, self.ViewPreviewPanel, self.ViewLivePanel)) # i18n add Language Actions add_actions(self.SettingsLanguageMenu, (self.AutoLanguageItem, None)) add_actions(self.SettingsLanguageMenu, self.LanguageGroup.actions()) - add_actions(self.SettingsMenu, (self.SettingsPluginListItem, + add_actions(self.SettingsMenu, (self.settingsPluginListItem, self.SettingsLanguageMenu.menuAction(), None, self.SettingsShortcutsItem, self.SettingsConfigureItem)) add_actions(self.ToolsMenu, (self.ToolsAddToolItem, None)) @@ -279,7 +279,7 @@ class Ui_MainWindow(object): self.HelpOnlineHelpItem, None, self.HelpWebSiteItem, self.HelpAboutItem)) add_actions(self.MenuBar, (self.FileMenu.menuAction(), - self.ViewMenu.menuAction(), self.ToolsMenu.menuAction(), + self.viewMenu.menuAction(), self.ToolsMenu.menuAction(), self.SettingsMenu.menuAction(), self.HelpMenu.menuAction())) # Initialise the translation self.retranslateUi(mainWindow) @@ -300,18 +300,18 @@ class Ui_MainWindow(object): self.FileMenu.setTitle(translate('OpenLP.MainWindow', '&File')) self.FileImportMenu.setTitle(translate('OpenLP.MainWindow', '&Import')) self.FileExportMenu.setTitle(translate('OpenLP.MainWindow', '&Export')) - self.ViewMenu.setTitle(translate('OpenLP.MainWindow', '&View')) + self.viewMenu.setTitle(translate('OpenLP.MainWindow', '&View')) self.ViewModeMenu.setTitle(translate('OpenLP.MainWindow', 'M&ode')) self.ToolsMenu.setTitle(translate('OpenLP.MainWindow', '&Tools')) self.SettingsMenu.setTitle(translate('OpenLP.MainWindow', '&Settings')) self.SettingsLanguageMenu.setTitle(translate('OpenLP.MainWindow', '&Language')) self.HelpMenu.setTitle(translate('OpenLP.MainWindow', '&Help')) - self.MediaManagerDock.setWindowTitle( + self.mediaManagerDock.setWindowTitle( translate('OpenLP.MainWindow', 'Media Manager')) - self.ServiceManagerDock.setWindowTitle( + self.serviceManagerDock.setWindowTitle( translate('OpenLP.MainWindow', 'Service Manager')) - self.ThemeManagerDock.setWindowTitle( + self.themeManagerDock.setWindowTitle( translate('OpenLP.MainWindow', 'Theme Manager')) self.FileNewItem.setText(translate('OpenLP.MainWindow', '&New')) self.FileNewItem.setToolTip( @@ -403,11 +403,11 @@ class Ui_MainWindow(object): 'Toggle the visibility of the live panel.')) self.ViewLivePanel.setShortcut( translate('OpenLP.MainWindow', 'F12')) - self.SettingsPluginListItem.setText(translate('OpenLP.MainWindow', + self.settingsPluginListItem.setText(translate('OpenLP.MainWindow', '&Plugin List')) - self.SettingsPluginListItem.setStatusTip( + self.settingsPluginListItem.setStatusTip( translate('OpenLP.MainWindow', 'List the Plugins')) - self.SettingsPluginListItem.setShortcut( + self.settingsPluginListItem.setShortcut( translate('OpenLP.MainWindow', 'Alt+F7')) self.HelpDocumentationItem.setText( translate('OpenLP.MainWindow', '&User Guide')) @@ -501,20 +501,20 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.SIGNAL(u'toggled(bool)'), self.setPreviewPanelVisibility) QtCore.QObject.connect(self.ViewLivePanel, QtCore.SIGNAL(u'toggled(bool)'), self.setLivePanelVisibility) - QtCore.QObject.connect(self.MediaManagerDock, + QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewMediaManagerItem.setChecked) - QtCore.QObject.connect(self.ServiceManagerDock, + QtCore.QObject.connect(self.serviceManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewServiceManagerItem.setChecked) - QtCore.QObject.connect(self.ThemeManagerDock, + QtCore.QObject.connect(self.themeManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewThemeManagerItem.setChecked) QtCore.QObject.connect(self.HelpWebSiteItem, QtCore.SIGNAL(u'triggered()'), self.onHelpWebSiteClicked) QtCore.QObject.connect(self.HelpAboutItem, QtCore.SIGNAL(u'triggered()'), self.onHelpAboutItemClicked) - QtCore.QObject.connect(self.SettingsPluginListItem, + QtCore.QObject.connect(self.settingsPluginListItem, QtCore.SIGNAL(u'triggered()'), self.onPluginItemClicked) QtCore.QObject.connect(self.SettingsConfigureItem, QtCore.SIGNAL(u'triggered()'), self.onSettingsConfigureItemClicked) @@ -748,9 +748,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): settings = QtCore.QSettings() settings.setValue(u'%s/view mode' % self.generalSettingsSection, mode) - self.MediaManagerDock.setVisible(media) - self.ServiceManagerDock.setVisible(service) - self.ThemeManagerDock.setVisible(theme) + self.mediaManagerDock.setVisible(media) + self.serviceManagerDock.setVisible(service) + self.themeManagerDock.setVisible(theme) self.setPreviewPanelVisibility(preview) self.setLivePanelVisibility(live) @@ -867,16 +867,16 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): theme) def toggleMediaManager(self, visible): - if self.MediaManagerDock.isVisible() != visible: - self.MediaManagerDock.setVisible(visible) + if self.mediaManagerDock.isVisible() != visible: + self.mediaManagerDock.setVisible(visible) def toggleServiceManager(self, visible): - if self.ServiceManagerDock.isVisible() != visible: - self.ServiceManagerDock.setVisible(visible) + if self.serviceManagerDock.isVisible() != visible: + self.serviceManagerDock.setVisible(visible) def toggleThemeManager(self, visible): - if self.ThemeManagerDock.isVisible() != visible: - self.ThemeManagerDock.setVisible(visible) + if self.themeManagerDock.isVisible() != visible: + self.themeManagerDock.setVisible(visible) def setPreviewPanelVisibility(self, visible): """ diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index 3b41d76a3..6318a44a5 100644 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -34,7 +34,9 @@ from plugindialog import Ui_PluginViewDialog log = logging.getLogger(__name__) class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): - + """ + The plugin form provides user control over the plugins OpenLP uses. + """ def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.parent = parent diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index bf0453e05..3445c63a1 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -78,7 +78,7 @@ class SlideController(QtGui.QWidget): self.selectedRow = 0 self.serviceItem = None self.alertTab = None - self.panel = QtGui.QWidget(parent.ControlSplitter) + self.panel = QtGui.QWidget(parent.controlSplitter) self.slideList = {} # Layout for holding panel self.panelLayout = QtGui.QVBoxLayout(self.panel) @@ -455,7 +455,7 @@ class SlideController(QtGui.QWidget): self.previewListWidget.resizeRowsToContents() else: # Sort out image heights. - width = self.parent.ControlSplitter.sizes()[self.split] + width = self.parent.controlSplitter.sizes()[self.split] for framenumber in range(len(self.serviceItem.get_frames())): self.previewListWidget.setRowHeight( framenumber, width / self.ratio) @@ -584,7 +584,7 @@ class SlideController(QtGui.QWidget): Receiver.send_message(u'%s_start' % serviceItem.name.lower(), [serviceItem, self.isLive, blanked, slideno]) self.slideList = {} - width = self.parent.ControlSplitter.sizes()[self.split] + width = self.parent.controlSplitter.sizes()[self.split] self.serviceItem = serviceItem self.previewListWidget.clear() self.previewListWidget.setRowCount(0) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index e6fff1cc8..7de4e82c3 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -33,6 +33,13 @@ import re log = logging.getLogger(__name__) def get_reference_match(match_type): + """ + Provides the regexes and matches to use while parsing strings for bible + references. + + ``match_type`` + The type of reference information trying to be extracted in this call. + """ local_separator = unicode(u':;;\s*[:vV]\s*;;-;;\s*-\s*;;,;;\s*,\s*;;end' ).split(u';;') # English # local_separator = unicode(u',;;\s*,\s*;;-;;\s*-\s*;;.;;\.;;[Ee]nde' diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 71027881c..6e720fa0b 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -84,8 +84,6 @@ class ImageMediaItem(MediaManagerItem): def initialise(self): log.debug(u'initialise') self.listView.clear() - self.listView.setSelectionMode( - QtGui.QAbstractItemView.ExtendedSelection) self.listView.setIconSize(QtCore.QSize(88, 50)) self.servicePath = os.path.join( AppLocation.get_section_data_path(self.settingsSection), diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index ea1b679b4..f0549a960 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -151,8 +151,6 @@ class MediaMediaItem(MediaManagerItem): return False def initialise(self): - self.listView.setSelectionMode( - QtGui.QAbstractItemView.ExtendedSelection) self.listView.setIconSize(QtCore.QSize(88, 50)) self.loadList(SettingsManager.load_list(self.settingsSection, self.settingsSection)) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index f12d36dc8..79e7d0ea8 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -69,7 +69,8 @@ class ImpressController(PresentationController): Initialise the class """ log.debug(u'Initialising') - PresentationController.__init__(self, plugin, u'Impress') + PresentationController.__init__(self, plugin, u'Impress', + ImpressDocument) self.supports = [u'odp'] self.alsosupports = [u'ppt', u'pps', u'pptx', u'ppsx'] self.process = None @@ -183,14 +184,6 @@ class ImpressController(PresentationController): except: log.exception(u'Failed to terminate OpenOffice') - def add_doc(self, name): - """ - Called when a new Impress document is opened - """ - log.debug(u'Add Doc OpenOffice') - doc = ImpressDocument(self, name) - self.docs.append(doc) - return doc class ImpressDocument(PresentationDocument): """ @@ -431,35 +424,36 @@ class ImpressDocument(PresentationDocument): def get_slide_text(self, slide_no): """ - Returns the text on the slide + Returns the text on the slide. ``slide_no`` - The slide the text is required for, starting at 1 + The slide the text is required for, starting at 1 + """ + return __get_text_from_slide(slide_no) + + def get_slide_notes(self, slide_no): + """ + Returns the text in the slide notes. + + ``slide_no`` + The slide the notes are required for, starting at 1 + """ + return __get_text_from_page(slide_no, True) + + def __get_text_from_page(self, slide_no, notes=False): + """ + Return any text extracted from the presentation page. + + ``notes`` + A boolean. If set the method searches the notes of the slide. """ - doc = self.document - pages = doc.getDrawPages() text = '' + pages = self.document.getDrawPages() page = pages.getByIndex(slide_no - 1) + if notes: + page = page.getNotesPage() for idx in range(page.getCount()): shape = page.getByIndex(idx) if shape.supportsService("com.sun.star.drawing.Text"): text += shape.getString() + '\n' return text - - def get_slide_notes(self, slide_no): - """ - Returns the text on the slide - - ``slide_no`` - The slide the notes are required for, starting at 1 - """ - doc = self.document - pages = doc.getDrawPages() - text = '' - page = pages.getByIndex(slide_no - 1) - notes = page.getNotesPage() - for idx in range(notes.getCount()): - shape = notes.getByIndex(idx) - if shape.supportsService("com.sun.star.drawing.Text"): - text += shape.getString() + '\n' - return text diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index a0173cb27..09020692a 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -186,7 +186,7 @@ class PresentationMediaItem(MediaManagerItem): controller_name = self.findControllerByType(filename) if controller_name: controller = self.controllers[controller_name] - doc = controller.add_doc(unicode(file)) + doc = controller.add_document(unicode(file)) thumb = os.path.join(doc.get_thumbnail_folder(), u'icon.png') preview = doc.get_thumbnail_path(1, True) if not preview and not initialLoad: @@ -226,7 +226,7 @@ class PresentationMediaItem(MediaManagerItem): filepath = unicode(item.data( QtCore.Qt.UserRole).toString()) for cidx in self.controllers: - doc = self.controllers[cidx].add_doc(filepath) + doc = self.controllers[cidx].add_document(filepath) doc.presentation_deleted() doc.close_presentation() for row in row_list: @@ -260,7 +260,7 @@ class PresentationMediaItem(MediaManagerItem): return False controller = self.controllers[service_item.shortname] (path, name) = os.path.split(filename) - doc = controller.add_doc(filename) + doc = controller.add_document(filename) if doc.get_thumbnail_path(1, True) is None: doc.load_presentation() i = 1 diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 4d926ad3d..b7c64ccee 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -59,7 +59,7 @@ class Controller(object): self.controller = controller if self.doc is not None: self.shutdown() - self.doc = self.controller.add_doc(file) + self.doc = self.controller.add_document(file) if not self.doc.load_presentation(): # Display error message to user # Inform slidecontroller that the action failed? diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index 012f8534a..65e9f35ff 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -53,7 +53,8 @@ class PowerpointController(PresentationController): Initialise the class """ log.debug(u'Initialising') - PresentationController.__init__(self, plugin, u'Powerpoint') + PresentationController.__init__(self, plugin, u'Powerpoint', + PowerpointDocument) self.supports = [u'ppt', u'pps', u'pptx', u'ppsx'] self.process = None @@ -97,14 +98,6 @@ class PowerpointController(PresentationController): pass self.process = None - def add_doc(self, name): - """ - Called when a new powerpoint document is opened - """ - log.debug(u'Add Doc PowerPoint') - doc = PowerpointDocument(self, name) - self.docs.append(doc) - return doc class PowerpointDocument(PresentationDocument): """ @@ -291,13 +284,7 @@ class PowerpointDocument(PresentationDocument): ``slide_no`` The slide the text is required for, starting at 1. """ - text = '' - shapes = self.presentation.Slides(slide_no).Shapes - for idx in range(shapes.Count): - shape = shapes(idx + 1) - if shape.HasTextFrame: - text += shape.TextFrame.TextRange.Text + '\n' - return text + return _get_text_from_shapes(self.presentation.Slides(slide_no).Shapes) def get_slide_notes(self, slide_no): """ @@ -306,10 +293,19 @@ class PowerpointDocument(PresentationDocument): ``slide_no`` The slide the notes are required for, starting at 1. """ - text = '' - shapes = self.presentation.Slides(slide_no).NotesPage.Shapes - for idx in range(shapes.Count): - shape = shapes(idx + 1) - if shape.HasTextFrame: - text += shape.TextFrame.TextRange.Text + '\n' - return text \ No newline at end of file + return _get_text_from_shapes( + self.presentation.Slides(slide_no).NotesPage.Shapes) + +def _get_text_from_shapes(shapes): + """ + Returns any text extracted from the shapes on a presentation slide. + + ``shapes`` + A set of shapes to search for text. + """ + text = '' + for idx in range(shapes.Count): + shape = shapes(idx + 1) + if shape.HasTextFrame: + text += shape.TextFrame.TextRange.Text + '\n' + return text diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 4c8e7bf95..a64cd31dd 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -49,7 +49,8 @@ class PptviewController(PresentationController): """ log.debug(u'Initialising') self.process = None - PresentationController.__init__(self, plugin, u'Powerpoint Viewer') + PresentationController.__init__(self, plugin, u'Powerpoint Viewer', + PptviewDocument) self.supports = [u'ppt', u'pps', u'pptx', u'ppsx'] def check_available(self): @@ -93,14 +94,6 @@ class PptviewController(PresentationController): while self.docs: self.docs[0].close_presentation() - def add_doc(self, name): - """ - Called when a new powerpoint document is opened - """ - log.debug(u'Add Doc PPTView') - doc = PptviewDocument(self, name) - self.docs.append(doc) - return doc class PptviewDocument(PresentationDocument): """ @@ -247,4 +240,4 @@ class PptviewDocument(PresentationDocument): """ Triggers the previous slide on the running presentation """ - self.controller.process.PrevStep(self.pptid) \ No newline at end of file + self.controller.process.PrevStep(self.pptid) diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index 42f7b654a..8b282e0f4 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -35,151 +35,6 @@ from openlp.core.utils import AppLocation log = logging.getLogger(__name__) -class PresentationController(object): - """ - This class is used to control interactions with presentation applications - by creating a runtime environment. This is a base class for presentation - controllers to inherit from. - - To create a new controller, take a copy of this file and name it so it ends - with ``controller.py``, i.e. ``foobarcontroller.py``. Make sure it inherits - :class:`~openlp.plugins.presentations.lib.presentationcontroller.PresentationController`, - and then fill in the blanks. If possible try to make sure it loads on all - platforms, usually by using :mod:``os.name`` checks, although - ``__init__``, ``check_available`` and ``presentation_deleted`` should - always be implemented. - - See :class:`~openlp.plugins.presentations.lib.impresscontroller.ImpressController`, - :class:`~openlp.plugins.presentations.lib.powerpointcontroller.PowerpointController` or - :class:`~openlp.plugins.presentations.lib.pptviewcontroller.PptviewController` - for examples. - - **Basic Attributes** - - ``name`` - The name that appears in the options and the media manager - - ``enabled`` - The controller is enabled - - ``available`` - The controller is available on this machine. Set by init via - call to check_available - - ``plugin`` - The presentationplugin object - - ``supports`` - The primary native file types this application supports - - ``alsosupports`` - Other file types the application can import, although not necessarily - the first choice due to potential incompatibilities - - **Hook Functions** - - ``kill()`` - Called at system exit to clean up any running presentations - - ``check_available()`` - Returns True if presentation application is installed/can run on this - machine - - ``presentation_deleted()`` - Deletes presentation specific files, e.g. thumbnails - - """ - log.info(u'PresentationController loaded') - - def __init__(self, plugin=None, name=u'PresentationController'): - """ - This is the constructor for the presentationcontroller object. This - provides an easy way for descendent plugins to populate common data. - This method *must* be overridden, like so:: - - class MyPresentationController(PresentationController): - def __init__(self, plugin): - PresentationController.__init( - self, plugin, u'My Presenter App') - - ``plugin`` - Defaults to *None*. The presentationplugin object - - ``name`` - Name of the application, to appear in the application - """ - self.supports = [] - self.alsosupports = [] - self.docs = [] - self.plugin = plugin - self.name = name - self.settings_section = self.plugin.settingsSection - self.available = self.check_available() - self.temp_folder = os.path.join( - AppLocation.get_section_data_path(self.settings_section), name) - self.thumbnail_folder = os.path.join( - AppLocation.get_section_data_path(self.settings_section), - u'thumbnails') - self.thumbnail_prefix = u'slide' - if not os.path.isdir(self.thumbnail_folder): - os.makedirs(self.thumbnail_folder) - if not os.path.isdir(self.temp_folder): - os.makedirs(self.temp_folder) - - def enabled(self): - """ - Return whether the controller is currently enabled - """ - if self.available: - return QtCore.QSettings().value( - self.settings_section + u'/' + self.name, - QtCore.QVariant(QtCore.Qt.Checked)).toInt()[0] == \ - QtCore.Qt.Checked - else: - return False - - def check_available(self): - """ - Presentation app is able to run on this machine - """ - return False - - def start_process(self): - """ - Loads a running version of the presentation application in the - background. - """ - pass - - def kill(self): - """ - Called at system exit to clean up any running presentations and - close the application - """ - log.debug(u'Kill') - self.close_presentation() - - def add_doc(self, name): - """ - Called when a new presentation document is opened - """ - doc = PresentationDocument(self, name) - self.docs.append(doc) - return doc - - def remove_doc(self, doc=None): - """ - Called to remove an open document from the collection - """ - log.debug(u'remove_doc Presentation') - if doc is None: - return - if doc in self.docs: - self.docs.remove(doc) - - def close_presentation(self): - pass - class PresentationDocument(object): """ Base class for presentation documents to inherit from. @@ -440,4 +295,152 @@ class PresentationDocument(object): ``slide_no`` The slide the notes are required for, starting at 1 """ - return '' \ No newline at end of file + return '' + + +class PresentationController(object): + """ + This class is used to control interactions with presentation applications + by creating a runtime environment. This is a base class for presentation + controllers to inherit from. + + To create a new controller, take a copy of this file and name it so it ends + with ``controller.py``, i.e. ``foobarcontroller.py``. Make sure it inherits + :class:`~openlp.plugins.presentations.lib.presentationcontroller.PresentationController`, + and then fill in the blanks. If possible try to make sure it loads on all + platforms, usually by using :mod:``os.name`` checks, although + ``__init__``, ``check_available`` and ``presentation_deleted`` should + always be implemented. + + See :class:`~openlp.plugins.presentations.lib.impresscontroller.ImpressController`, + :class:`~openlp.plugins.presentations.lib.powerpointcontroller.PowerpointController` or + :class:`~openlp.plugins.presentations.lib.pptviewcontroller.PptviewController` + for examples. + + **Basic Attributes** + + ``name`` + The name that appears in the options and the media manager + + ``enabled`` + The controller is enabled + + ``available`` + The controller is available on this machine. Set by init via + call to check_available + + ``plugin`` + The presentationplugin object + + ``supports`` + The primary native file types this application supports + + ``alsosupports`` + Other file types the application can import, although not necessarily + the first choice due to potential incompatibilities + + **Hook Functions** + + ``kill()`` + Called at system exit to clean up any running presentations + + ``check_available()`` + Returns True if presentation application is installed/can run on this + machine + + ``presentation_deleted()`` + Deletes presentation specific files, e.g. thumbnails + + """ + log.info(u'PresentationController loaded') + + def __init__(self, plugin=None, name=u'PresentationController', + document_class=PresentationDocument): + """ + This is the constructor for the presentationcontroller object. This + provides an easy way for descendent plugins to populate common data. + This method *must* be overridden, like so:: + + class MyPresentationController(PresentationController): + def __init__(self, plugin): + PresentationController.__init( + self, plugin, u'My Presenter App') + + ``plugin`` + Defaults to *None*. The presentationplugin object + + ``name`` + Name of the application, to appear in the application + """ + self.supports = [] + self.alsosupports = [] + self.docs = [] + self.plugin = plugin + self.name = name + self.document_class = document_class + self.settings_section = self.plugin.settingsSection + self.available = self.check_available() + self.temp_folder = os.path.join( + AppLocation.get_section_data_path(self.settings_section), name) + self.thumbnail_folder = os.path.join( + AppLocation.get_section_data_path(self.settings_section), + u'thumbnails') + self.thumbnail_prefix = u'slide' + if not os.path.isdir(self.thumbnail_folder): + os.makedirs(self.thumbnail_folder) + if not os.path.isdir(self.temp_folder): + os.makedirs(self.temp_folder) + + def enabled(self): + """ + Return whether the controller is currently enabled + """ + if self.available: + return QtCore.QSettings().value( + self.settings_section + u'/' + self.name, + QtCore.QVariant(QtCore.Qt.Checked)).toInt()[0] == \ + QtCore.Qt.Checked + else: + return False + + def check_available(self): + """ + Presentation app is able to run on this machine + """ + return False + + def start_process(self): + """ + Loads a running version of the presentation application in the + background. + """ + pass + + def kill(self): + """ + Called at system exit to clean up any running presentations and + close the application + """ + log.debug(u'Kill') + self.close_presentation() + + def add_document(self, name): + """ + Called when a new presentation document is opened + """ + document = self.document_class(self, name) + self.docs.append(document) + return document + + def remove_doc(self, doc=None): + """ + Called to remove an open document from the collection + """ + log.debug(u'remove_doc Presentation') + if doc is None: + return + if doc in self.docs: + self.docs.remove(doc) + + def close_presentation(self): + pass diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index af8b71795..c763d70b9 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -104,6 +104,15 @@ class VerseType(object): def retrieve_windows_encoding(recommendation=None): + """ + Determines which encoding to use on an information source. The process uses + both automated detection, which is passed to this method as a + recommendation, and user confirmation to return an encoding. + + ``recommendation`` + A recommended encoding discovered programmatically for the user to + confirm. + """ # map chardet result to compatible windows standard code page codepage_mapping = {'IBM866': u'cp866', 'TIS-620': u'cp874', 'SHIFT_JIS': u'cp932', 'GB2312': u'cp936', 'HZ-GB-2312': u'cp936', diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index 2bbf818b3..d9a3202b5 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -71,7 +71,6 @@ class Topic(BaseModel): def init_schema(url): - """ Setup the songs database connection and initialise the database schema. diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index eb16f4ba4..e7557f952 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -36,9 +36,6 @@ from openlp.plugins.songs.lib.songimport import SongImport log = logging.getLogger(__name__) -class OpenSongImportError(Exception): - pass - class OpenSongImport(SongImport): """ Import songs exported from OpenSong