def __setPyQt4API(element, api_version=2): try: ver = sip.getapi(element) except ValueError: ver = -1 if ver < 0: try: sip.setapi(element, api_version) log.debug("%s API set to version %d", element, sip.getapi("QString")) except ValueError: log.warning("Error setting %s API to version %s", element, api_version, exc_info=1) return False elif ver < api_version: log.info("%s API set to version %s (advised: version >= %s)", element, ver, api_version) return True
def Application(argv=None, **properties): """Returns a QApplication. If the process has initialized before a QApplication it returns the existing instance, otherwise it creates a new one. When a QApplication is created it takes argv into account. If argv is None (default), it take arguments from :attr:`sys.argv`. If argv is given and a QApplication already exists, argv will have no effect. :param argv: optional arguments to QApplication. If the QApplication is already initialized, argv will have no effect. Example:: from qarbon.external.qt import QtGui from qarbon.qt.gui.application import Application app = Application() label = QtGui.QLabel("Hello, world!") label.show() app.exec_() :param properties: currently unused :return: the QApplication :rtype: QtGui.QApplication""" init_logging = properties.get('init_logging', False) if init_logging: log.initialize() from qarbon.external.qt import QtGui app = QtGui.QApplication.instance() if app is None: if argv is None: from sys import argv app = QtGui.QApplication(argv) elif argv: log.info("QApplication already initialized. argv will have no " "effect") return app
def Application(argv=None, **kwargs): """Returns a QApplication. If the process has initialized before a QApplication it returns the existing instance, otherwise it creates a new one. When a QApplication is created it takes argv into account. If argv is None (default), it take arguments from :attr:`sys.argv`. If argv is given and a QApplication already exists, argv will have no effect. :param argv: optional arguments to QApplication. If the QApplication is already initialized, argv will have no effect. Example:: from qarbon.external.qt import QtGui from qarbon.qt.gui.application import Application app = Application() label = QtGui.QLabel("Hello, world!") label.show() app.exec_() :param kwargs: currently unused :return: the QApplication :rtype: QtGui.QApplication""" # It is important to initialize logging before Qt because Qt might # fire some log messages init_logging = kwargs.get('init_logging', False) if init_logging: log.initialize() from qarbon.external.qt import QtGui app = QtGui.QApplication.instance() if app is None: if argv is None: from sys import argv app = QtGui.QApplication(argv) init_application = kwargs.get('init_application', True) init_organization = kwargs.get('init_organization', True) if init_application: app_name = kwargs.get('application_name', config.APPLICATION_NAME) app.setApplicationName(app_name) app_version = kwargs.get('application_version', config.APPLICATION_VERSION) app.setApplicationVersion(app_version) if init_organization: org_name = kwargs.get('organization_name', config.ORGANIZATION_NAME) app.setOrganizationName(org_name) org_domain = kwargs.get('organization_domain', config.ORGANIZATION_DOMAIN) app.setOrganizationDomain(org_domain) elif argv: log.info("QApplication already initialized. argv will have no " "effect") return app