From 743ad7b44aaa34df82c981545fc9fb0656542780 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 11 Jan 2014 21:29:01 +0000 Subject: [PATCH] Clean up inits --- openlp/core/__init__.py | 32 ++++++++------- openlp/core/common/__init__.py | 2 +- openlp/core/lib/__init__.py | 2 +- openlp/core/lib/mediamanageritem.py | 61 ++++++++++++++++++----------- openlp/core/ui/media/__init__.py | 2 +- openlp/core/utils/__init__.py | 3 +- 6 files changed, 61 insertions(+), 41 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index b5a922617..948525839 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -43,7 +43,7 @@ from traceback import format_exception from PyQt4 import QtCore, QtGui -from openlp.core.common import Registry, AppLocation, Settings, UiStrings, check_directory_exists +from openlp.core.common import Registry, OpenLPMixin, AppLocation, Settings, UiStrings, check_directory_exists from openlp.core.lib import ScreenList from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow @@ -58,6 +58,7 @@ __all__ = ['OpenLP', 'main'] log = logging.getLogger() + NT_REPAIR_STYLESHEET = """ QMainWindow::separator { @@ -81,7 +82,7 @@ QToolBar """ -class OpenLP(QtGui.QApplication): +class OpenLP(OpenLPMixin, QtGui.QApplication): """ The core application class. This class inherits from Qt's QApplication class in order to provide the core of the application. @@ -101,6 +102,8 @@ class OpenLP(QtGui.QApplication): def run(self, args): """ Run the OpenLP application. + + :param args: Some Args """ self.is_event_loop_active = False # On Windows, the args passed into the constructor are ignored. Not very handy, so set the ones we want to use. @@ -172,25 +175,20 @@ class OpenLP(QtGui.QApplication): self.shared_memory.create(1) return False - def hook_exception(self, exctype, value, traceback): + def hook_exception(self, exc_type, value, traceback): """ Add an exception hook so that any uncaught exceptions are displayed in this window rather than somewhere where users cannot see it and cannot report when we encounter these problems. - ``exctype`` - The class of exception. - - ``value`` - The actual exception object. - - ``traceback`` - A traceback object with the details of where the exception occurred. + :param exc_type: The class of exception. + :param value: The actual exception object. + :param traceback: A traceback object with the details of where the exception occurred. """ # We can't log.exception here because the last exception no longer exists, we're actually busy handling it. - log.critical(''.join(format_exception(exctype, value, traceback))) + log.critical(''.join(format_exception(exc_type, value, traceback))) if not hasattr(self, 'exception_form'): self.exception_form = ExceptionForm() - self.exception_form.exception_text_edit.setPlainText(''.join(format_exception(exctype, value, traceback))) + self.exception_form.exception_text_edit.setPlainText(''.join(format_exception(exc_type, value, traceback))) self.set_normal_cursor() self.exception_form.exec_() @@ -198,7 +196,6 @@ class OpenLP(QtGui.QApplication): """ Wrapper to make ProcessEvents visible and named correctly """ - log.debug('processing event flush') self.processEvents() def set_busy_cursor(self): @@ -218,6 +215,8 @@ class OpenLP(QtGui.QApplication): def event(self, event): """ Enables direct file opening on OS X + + :param event: The event """ if event.type() == QtCore.QEvent.FileOpen: file_name = event.file() @@ -231,6 +230,8 @@ class OpenLP(QtGui.QApplication): def set_up_logging(log_path): """ Setup our logging using log_path + + :param log_path: the path """ check_directory_exists(log_path, True) filename = os.path.join(log_path, 'openlp.log') @@ -244,7 +245,8 @@ def set_up_logging(log_path): def main(args=None): """ The main function which parses command line options and then runs - the PyQt4 Application. + + :param args: Some args """ # Set up command line options. usage = 'Usage: %prog [options] [qt-options]' diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 11e9d82b2..8963213d3 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -38,7 +38,7 @@ import traceback from PyQt4 import QtCore -log = logging.getLogger(__name__) +log = logging.getLogger(__name__+'.__init__') FIRST_CAMEL_REGEX = re.compile('(.)([A-Z][a-z]+)') diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 549f0879c..d747cb5ba 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -39,7 +39,7 @@ from PyQt4 import QtCore, QtGui, Qt from openlp.core.common import translate -log = logging.getLogger(__name__) +log = logging.getLogger(__name__+'.__init__') class ServiceItemContext(object): diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 34b24e0c2..c45a963d4 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -332,8 +332,7 @@ class MediaManagerItem(QtGui.QWidget): """ Turn file from Drag and Drop into an array so the Validate code can run it. - ``data`` - A dictionary containing the list of files to be loaded and the target + :param data: A dictionary containing the list of files to be loaded and the target """ new_files = [] error_shown = False @@ -353,9 +352,8 @@ class MediaManagerItem(QtGui.QWidget): def dnd_move_internal(self, target): """ Handle internal moving of media manager items - - ``target`` - The target of the DnD action +s + :param target: The target of the DnD action """ pass @@ -364,11 +362,8 @@ class MediaManagerItem(QtGui.QWidget): Process a list for files either from the File Dialog or from Drag and Drop - ``files`` - The files to be loaded. - - ``target_group`` - The QTreeWidgetItem of the group that will be the parent of the added files + :param files: The files to be loaded. + :param target_group: The QTreeWidgetItem of the group that will be the parent of the added files """ names = [] full_list = [] @@ -399,6 +394,8 @@ class MediaManagerItem(QtGui.QWidget): def context_menu(self, point): """ Display a context menu + + :param point: The point the cursor was at """ item = self.list_view.itemAt(point) # Decide if we have to show the context menu or not. @@ -422,6 +419,9 @@ class MediaManagerItem(QtGui.QWidget): def load_list(self, load_list, target_group): """ Load a list. Needs to be implemented by the plugin. + + :param load_list: List object to load + :param target_group: Group to load """ raise NotImplementedError('MediaManagerItem.loadList needs to be defined by the plugin') @@ -454,6 +454,11 @@ class MediaManagerItem(QtGui.QWidget): context=ServiceItemContext.Live): """ Generate the slide data. Needs to be implemented by the plugin. + :param service_item: The service Item to be processed + :param item: The database item to be used to build the service item + :param xml_version: + :param remote: Was this remote triggered (False) + :param context: The service context """ raise NotImplementedError('MediaManagerItem.generate_slide_data needs to be defined by the plugin') @@ -471,12 +476,14 @@ class MediaManagerItem(QtGui.QWidget): Allows the change of current item in the list to be actioned """ if Settings().value('advanced/single click preview') and self.quick_preview_allowed \ - and self.list_view.selectedIndexes() and self.auto_select_id == -1: + and self.list_view.selectedIndexes() and self.auto_select_id == -1: self.on_preview_click(True) def on_preview_click(self, keep_focus=False): """ Preview an item by building a service item then adding that service item to the preview slide controller. + + :param keep_focus: Do we keep focus (False) """ if not self.list_view.selectedIndexes() and not self.remote_triggered: QtGui.QMessageBox.information(self, UiStrings().NISp, @@ -506,14 +513,16 @@ class MediaManagerItem(QtGui.QWidget): """ Remote Call wrapper - ``message`` - The passed data item_id:Remote. + :param message: The passed data item_id:Remote. """ self.go_live(message[0], remote=message[1]) def go_live(self, item_id=None, remote=False): """ Make the currently selected item go live. + + :param item_id: item to make live + :param remote: From Remote """ log.debug('%s Live requested', self.plugin.name) item = None @@ -530,6 +539,8 @@ class MediaManagerItem(QtGui.QWidget): def create_item_from_id(self, item_id): """ Create a media item from an item id. + + :param item_id: Id to make live """ item = QtGui.QListWidgetItem() item.setData(QtCore.Qt.UserRole, item_id) @@ -558,14 +569,17 @@ class MediaManagerItem(QtGui.QWidget): """ Remote Call wrapper - ``message`` - The passed data item:Remote. + :param message: The passed data item:Remote. """ self.add_to_service(message[0], remote=message[1]) def add_to_service(self, item=None, replace=None, remote=False): """ Add this item to the current service. + + :param item: Item to be processed + :param replace: Replace the existing item + :param remote: Triggered from remote """ service_item = self.build_service_item(item, True, remote=remote, context=ServiceItemContext.Service) if service_item: @@ -598,6 +612,10 @@ class MediaManagerItem(QtGui.QWidget): def build_service_item(self, item=None, xml_version=False, remote=False, context=ServiceItemContext.Live): """ Common method for generating a service item + :param item: Service Item to be built. + :param xml_version: version of XML (False) + :param remote: Remote triggered (False) + :param context: The context on which this is called """ service_item = ServiceItem(self.plugin) service_item.add_icon(self.plugin.icon_path) @@ -611,8 +629,7 @@ class MediaManagerItem(QtGui.QWidget): Method to add processing when a service has been loaded and individual service items need to be processed by the plugins. - ``item`` - The item to be processed and returned. + :param item: The item to be processed and returned. """ return item @@ -634,11 +651,8 @@ class MediaManagerItem(QtGui.QWidget): """ Utility method to check items being submitted for slide generation. - ``item`` - The item to check. - - ``remote_item`` - The id to assign if the slide generation was remotely triggered. + :param item: The item to check. + :param remote_item: The id to assign if the slide generation was remotely triggered. """ if item is None: if self.remote_triggered is None: @@ -665,6 +679,9 @@ class MediaManagerItem(QtGui.QWidget): def search(self, string, show_error=True): """ Performs a plugin specific search for items containing ``string`` + + :param string: String to be displayed + :param show_error: Should the error be shown (True) """ raise NotImplementedError('Plugin.search needs to be defined by the plugin') diff --git a/openlp/core/ui/media/__init__.py b/openlp/core/ui/media/__init__.py index 31a27b620..b915e8beb 100644 --- a/openlp/core/ui/media/__init__.py +++ b/openlp/core/ui/media/__init__.py @@ -35,7 +35,7 @@ from openlp.core.common import Settings from PyQt4 import QtCore -log = logging.getLogger(__name__) +log = logging.getLogger(__name__+'.__init__') class MediaState(object): diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 8b63a251f..426606987 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -56,7 +56,8 @@ if sys.platform != 'win32' and sys.platform != 'darwin': from openlp.core.common import translate -log = logging.getLogger(__name__) +log = logging.getLogger(__name__+'.__init__') + APPLICATION_VERSION = {} IMAGES_FILTER = None ICU_COLLATOR = None