From 50f3b2b563b938a0665b94240636a991c4d974cf Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 19 Jul 2013 21:56:31 +0100 Subject: [PATCH] Fix uno import noise in python 3 --- openlp/core/__init__.py | 2 +- openlp/core/ui/exceptionform.py | 48 +++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 23986ffc4..16987df5d 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -185,7 +185,7 @@ class OpenLP(QtGui.QApplication): """ log.exception(''.join(format_exception(exctype, value, traceback))) if not hasattr(self, u'exception_form'): - self.exception_form = ExceptionForm(self.main_window) + self.exception_form = ExceptionForm() self.exception_form.exception_text_edit.setPlainText(''.join(format_exception(exctype, value, traceback))) self.set_normal_cursor() self.exception_form.exec_() diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 49d6b0bef..bbd76446b 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -37,6 +37,8 @@ import platform import bs4 import sqlalchemy from lxml import etree + +from openlp.core.lib import Registry from PyQt4 import Qt, QtCore, QtGui, QtWebKit try: @@ -77,19 +79,7 @@ try: CHERRYPY_VERSION = cherrypy.__version__ except ImportError: CHERRYPY_VERSION = u'-' -try: - import uno - arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue') - arg.Name = u'nodepath' - arg.Value = u'/org.openoffice.Setup/Product' - context = uno.getComponentContext() - provider = context.ServiceManager.createInstance(u'com.sun.star.configuration.ConfigurationProvider') - node = provider.createInstanceWithArguments(u'com.sun.star.configuration.ConfigurationAccess', (arg,)) - UNO_VERSION = node.getByName(u'ooSetupVersion') -except ImportError: - UNO_VERSION = u'-' -except: - UNO_VERSION = u'- (Possible non-standard UNO installation)' + try: WEBKIT_VERSION = QtWebKit.qWebKitVersion() except AttributeError: @@ -100,7 +90,6 @@ try: except ImportError: VLC_VERSION = u'-' - from openlp.core.lib import UiStrings, Settings, translate from openlp.core.utils import get_application_version @@ -113,11 +102,11 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): """ The exception dialog """ - def __init__(self, parent): + def __init__(self): """ Constructor. """ - QtGui.QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, self.main_window) self.setupUi(self) self.settings_section = u'crashreport' @@ -152,7 +141,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): u'Mako: %s\n' % MAKO_VERSION + \ u'CherryPy: %s\n' % CHERRYPY_VERSION + \ u'pyICU: %s\n' % ICU_VERSION + \ - u'pyUNO bridge: %s\n' % UNO_VERSION + \ + u'pyUNO bridge: %s\n' % self._pyuno_import() + \ u'VLC: %s\n' % VLC_VERSION if platform.system() == u'Linux': if os.environ.get(u'KDE_FULL_SESSION') == u'true': @@ -256,3 +245,28 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): """ self.save_report_button.setEnabled(state) self.send_report_button.setEnabled(state) + + def _pyuno_import(self): + try: + import uno + arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue') + arg.Name = u'nodepath' + arg.Value = u'/org.openoffice.Setup/Product' + context = uno.getComponentContext() + provider = context.ServiceManager.createInstance(u'com.sun.star.configuration.ConfigurationProvider') + node = provider.createInstanceWithArguments(u'com.sun.star.configuration.ConfigurationAccess', (arg,)) + return node.getByName(u'ooSetupVersion') + except ImportError: + return u'-' + except: + return u'- (Possible non-standard UNO installation)' + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) \ No newline at end of file