From 84ce96f989d074a0ae027d9c8939f199fce8f47a Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 3 Nov 2009 18:14:25 +0000 Subject: [PATCH] More truth testing cleanup - core --- openlp/core/lib/__init__.py | 2 +- openlp/core/lib/dockwidget.py | 2 +- openlp/core/lib/mediamanageritem.py | 10 +++++----- openlp/core/lib/plugin.py | 8 ++++---- openlp/core/lib/pluginconfig.py | 10 +++++----- openlp/core/lib/pluginmanager.py | 5 +++-- openlp/core/lib/renderer.py | 22 +++++++++++----------- openlp/core/lib/rendermanager.py | 12 +++++++----- openlp/core/lib/serviceitem.py | 2 +- openlp/core/lib/themexmlhandler.py | 4 ++-- openlp/core/lib/toolbar.py | 6 +++--- openlp/core/ui/maindisplay.py | 2 +- openlp/core/ui/mediadockmanager.py | 4 ++-- openlp/core/ui/pluginform.py | 4 ++-- openlp/core/ui/servicemanager.py | 2 +- openlp/core/ui/settingsform.py | 5 +++-- openlp/core/ui/slidecontroller.py | 20 ++++++++++---------- openlp/core/ui/thememanager.py | 9 +++++---- openlp/core/utils/confighelper.py | 2 +- 19 files changed, 68 insertions(+), 63 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 189718d47..a7223e938 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -110,7 +110,7 @@ def contextMenuAction(base, icon, text, slot): Utility method to help build context menus for plugins """ action = QtGui.QAction(text, base) - if icon is not None: + if icon: action.setIcon(buildIcon(icon)) QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), slot) return action diff --git a/openlp/core/lib/dockwidget.py b/openlp/core/lib/dockwidget.py index 0b788d1a3..0f10b3c52 100644 --- a/openlp/core/lib/dockwidget.py +++ b/openlp/core/lib/dockwidget.py @@ -36,7 +36,7 @@ class OpenLPDockWidget(QtGui.QDockWidget): """ QtGui.QDockWidget.__init__(self, parent) self.parent = parent - if name is not None: + if name: self.setObjectName(name) self.setFloating(False) self.log = logging.getLogger(u'OpenLPDockWidget') diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 196edc616..f5930944b 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -110,7 +110,7 @@ class MediaManagerItem(QtGui.QWidget): QtGui.QIcon.Normal, QtGui.QIcon.Off) else: self.icon = None - if title is not None: + if title: self.title = title self.Toolbar = None self.ServiceItemIconName = None @@ -364,7 +364,7 @@ class MediaManagerItem(QtGui.QWidget): self.trUtf8(u'You must select one or more items')) log.debug(self.PluginNameShort + u' Preview Requested') service_item = self.buildServiceItem() - if service_item is not None: + if service_item: service_item.fromPlugin = True self.parent.preview_controller.addServiceItem(service_item) @@ -375,7 +375,7 @@ class MediaManagerItem(QtGui.QWidget): self.trUtf8(u'You must select one or more items')) log.debug(self.PluginNameShort + u' Live Requested') service_item = self.buildServiceItem() - if service_item is not None: + if service_item: service_item.fromPlugin = True service_item.uuid = unicode(uuid.uuid1()) self.parent.live_controller.addServiceItem(service_item) @@ -387,7 +387,7 @@ class MediaManagerItem(QtGui.QWidget): self.trUtf8(u'You must select one or more items')) log.debug(self.PluginNameShort + u' Add Requested') service_item = self.buildServiceItem() - if service_item is not None: + if service_item: service_item.fromPlugin = False service_item.uuid = unicode(uuid.uuid1()) self.parent.service_manager.addServiceItem(service_item) @@ -397,7 +397,7 @@ class MediaManagerItem(QtGui.QWidget): Common method for generating a service item """ service_item = ServiceItem(self.parent) - if self.ServiceItemIconName is not None: + if self.ServiceItemIconName: service_item.addIcon(self.ServiceItemIconName) else: service_item.addIcon( diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index f7aba44b9..dba8666e3 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -112,7 +112,7 @@ class Plugin(QtCore.QObject): """ QtCore.QObject.__init__(self) self.name = name - if version is not None: + if version: self.version = version self.icon = None self.config = PluginConfig(self.name) @@ -236,7 +236,7 @@ class Plugin(QtCore.QObject): """ Called by the plugin Manager to initialise anything it needs. """ - if self.media_item is not None: + if self.media_item: self.media_item.initialise() def finalise(self): @@ -256,7 +256,7 @@ class Plugin(QtCore.QObject): """ Called by plugin to replace toolbar """ - if self.media_item is not None: + if self.media_item: self.mediadock.insert_dock(self.media_item, self.icon, self.weight) - if self.settings_tab is not None: + if self.settings_tab: self.settings.insertTab(self.settings_tab, self.weight) diff --git a/openlp/core/lib/pluginconfig.py b/openlp/core/lib/pluginconfig.py index 7aed81f78..7b534a73c 100644 --- a/openlp/core/lib/pluginconfig.py +++ b/openlp/core/lib/pluginconfig.py @@ -107,7 +107,7 @@ class PluginConfig(object): files = os.listdir(self.get_data_path()) except: return [] - if suffix is not None: + if suffix: return_files = [] for file in files: if file.find(u'.') != -1: @@ -131,7 +131,7 @@ class PluginConfig(object): The name of the list. """ list_count = self.get_config(u'%s count' % name) - if list_count is not None: + if list_count: list_count = int(list_count) else: list_count = 0 @@ -169,12 +169,12 @@ class PluginConfig(object): ``num`` Defaults to *None*. A further qualifier. """ - if num is not None: + if num: name = u'last directory %d' % num else: name = u'last directory' last_dir = self.get_config(name) - if last_dir is None: + if not last_dir: last_dir = u'' return last_dir @@ -185,7 +185,7 @@ class PluginConfig(object): ``num`` Defaults to *None*. A further qualifier. """ - if num is not None: + if num: name = u'last directory %d' % num else: name = u'last directory' diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 8a9fb216a..4ac23e6a2 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -149,8 +149,9 @@ class PluginManager(object): for plugin in self.plugins: if plugin.status is not PluginStatus.Disabled: plugin.settings_tab = plugin.get_settings_tab() - if plugin.settings_tab is not None: - log.debug(u'Inserting settings tab item from %s' % plugin.name) + if plugin.settings_tab: + log.debug(u'Inserting settings tab item from %s' % + plugin.name) settingsform.addTab(plugin.name, plugin.settings_tab) else: log.debug(u'No tab settings in %s' % plugin.name) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c3274ec32..f7e59c099 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -59,7 +59,7 @@ class Renderer(object): ``debug`` The debug mode. """ - self._debug=debug + self._debug = debug def set_theme(self, theme): """ @@ -76,7 +76,7 @@ class Renderer(object): self.theme_name = theme.theme_name self._set_theme_font() if theme.background_type == u'image': - if theme.background_filename is not None: + if theme.background_filename: self.set_bg_image(theme.background_filename) def set_bg_image(self, filename): @@ -88,7 +88,7 @@ class Renderer(object): """ log.debug(u'set bg image %s', filename) self._bg_image_filename = unicode(filename) - if self._frame is not None: + if self._frame: self.scale_bg_image() def scale_bg_image(self): @@ -134,7 +134,7 @@ class Renderer(object): frame_height) self._frame = QtGui.QImage(frame_width, frame_height, QtGui.QImage.Format_ARGB32_Premultiplied) - if self._bg_image_filename is not None and self.bg_image is None: + if self._bg_image_filename and not self.bg_image: self.scale_bg_image() if self.bg_frame is None: self._generate_background_frame() @@ -241,13 +241,13 @@ class Renderer(object): """ log.debug(u'generate_frame_from_lines - Start') bbox = self._render_lines_unaligned(lines, False) - if footer_lines is not None: + if footer_lines: bbox1 = self._render_lines_unaligned(footer_lines, True) # reset the frame. first time do not worry about what you paint on. self._frame = QtGui.QImage(self.bg_frame) x, y = self._correctAlignment(self._rect, bbox) bbox = self._render_lines_unaligned(lines, False, (x, y), True) - if footer_lines is not None: + if footer_lines: bbox = self._render_lines_unaligned(footer_lines, True, (self._rect_footer.left(), self._rect_footer.top()), True) log.debug(u'generate_frame_from_lines - Finish') @@ -305,7 +305,7 @@ class Renderer(object): elif self._theme.background_type == u'image': # image painter.fillRect(self._frame.rect(), QtCore.Qt.black) - if self.bg_image is not None: + if self.bg_image: painter.drawImage(0, 0, self.bg_image) painter.end() log.debug(u'render background End') @@ -321,13 +321,13 @@ class Renderer(object): Footer dimensions? """ x = rect.left() - if int(self._theme.display_verticalAlign) == 0: + if self._theme.display_verticalAlign == 0: # top align y = rect.top() - elif int(self._theme.display_verticalAlign) == 2: + elif self._theme.display_verticalAlign == 2: # bottom align y = rect.bottom() - bbox.height() - elif int(self._theme.display_verticalAlign) == 1: + elif self._theme.display_verticalAlign == 1: # centre align y = rect.top() + (rect.height() - bbox.height()) / 2 else: @@ -571,5 +571,5 @@ class Renderer(object): Defaults to *None*. Another image to save to disk. """ image.save(u'renderer.png', u'png') - if image2 is not None: + if image2: image2.save(u'renderer2.png', u'png') diff --git a/openlp/core/lib/rendermanager.py b/openlp/core/lib/rendermanager.py index e08ecff2a..eb36aa473 100644 --- a/openlp/core/lib/rendermanager.py +++ b/openlp/core/lib/rendermanager.py @@ -121,7 +121,7 @@ class RenderManager(object): else: self.theme = self.service_theme else: - if theme is not None: + if theme: self.theme = theme elif self.global_style == u'Song' or \ self.global_style == u'Service': @@ -139,17 +139,19 @@ class RenderManager(object): self.renderer.set_theme(self.themedata) self.build_text_rectangle(self.themedata) #Replace the backgrount image from renderer with one from image - if self.override_background is not None: + if self.override_background: if self.save_bg_frame is None: self.save_bg_frame = self.renderer.bg_frame if self.override_background_changed: - self.renderer.bg_frame = self.resize_image(self.override_background) + self.renderer.bg_frame = self.resize_image( + self.override_background) self.override_background_changed = False else: if self.override_background_changed: - self.renderer.bg_frame = self.resize_image(self.override_background) + self.renderer.bg_frame = self.resize_image( + self.override_background) self.override_background_changed = False - if self.save_bg_frame is not None: + if self.save_bg_frame: self.renderer.bg_frame = self.save_bg_frame self.save_bg_frame = None diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 7fab33ea3..364b27f39 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -57,7 +57,7 @@ class ServiceItem(object): The plugin that this service item belongs to. """ self.plugin = hostplugin - if hostplugin is not None: + if hostplugin: self.RenderManager = self.plugin.render_manager self.shortname = hostplugin.name self.name = self.plugin.name diff --git a/openlp/core/lib/themexmlhandler.py b/openlp/core/lib/themexmlhandler.py index 7aab3bf7a..0501fb06f 100644 --- a/openlp/core/lib/themexmlhandler.py +++ b/openlp/core/lib/themexmlhandler.py @@ -91,7 +91,7 @@ class ThemeXML(object): ``path`` The path name to be added. """ - if self.background_filename is not None and path is not None: + if self.background_filename and path: self.theme_name = self.theme_name.rstrip().lstrip() self.background_filename = self.background_filename.rstrip().lstrip() self.background_filename = os.path.join(path, self.theme_name, @@ -371,7 +371,7 @@ class ThemeXML(object): else: setattr(self, field, e[1]) else: - if element.tag is not None: + if element.tag: field = master + element.tag if element.text == u'True' or element.text == u'False': setattr(self, field, str_to_bool(element.text)) diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index b0473b767..8ab0e1961 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -68,12 +68,12 @@ class OpenLPToolbar(QtGui.QToolBar): The name of the object, as used in `