From 39477ed17cf6be15017c87ee1b1ed29593507e89 Mon Sep 17 00:00:00 2001 From: minoue Date: Tue, 11 Oct 2016 22:25:24 -0400 Subject: [PATCH] Delete Qt.py inside this repo --- __init__.py | 8 +- app/Qt.py | 301 ------------------------------------------- app/__init__.py | 7 +- app/customWidgets.py | 7 +- app/miExec.py | 7 +- 5 files changed, 4 insertions(+), 326 deletions(-) delete mode 100644 app/Qt.py diff --git a/__init__.py b/__init__.py index c2e1921..d380d6b 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,4 @@ -try: - # Try import Qt.py from global site-package, if not import copy of Qt.py - # in a current directory - import Qt -except ImportError: - from app import Qt - +import Qt import app reload(app) diff --git a/app/Qt.py b/app/Qt.py deleted file mode 100644 index 9d1361f..0000000 --- a/app/Qt.py +++ /dev/null @@ -1,301 +0,0 @@ -""" -Qt.py from https://github.com/mottosso/Qt.py - -The MIT License (MIT) - -Copyright (c) 2016 Marcus Ottosson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - -Map all bindings to PySide2 - -This module replaces itself with the most desirable binding. - -Project goals: - Qt.py was born in the film and visual effects industry to address - the growing need for the development of software capable of running - with more than one flavour of the Qt bindings for Python - PySide, - PySide2, PyQt4 and PyQt5. - - 1. Build for one, run with all - 2. Explicit is better than implicit - 3. Support co-existence - -Default resolution order: - - PySide2 - - PyQt5 - - PySide - - PyQt4 - -Usage: - >>> import sys - >>> from Qt import QtWidgets - >>> app = QtWidgets.QApplication(sys.argv) - >>> button = QtWidgets.QPushButton("Hello World") - >>> button.show() - >>> app.exec_() - -""" - -import os -import sys - -__version__ = "0.4.2" - -# All unique members of Qt.py -__added__ = list() - -# Members copied from elsewhere, such as QtGui -> QtWidgets -__remapped__ = list() - -# Existing members modified in some way -__modified__ = list() - - -def remap(object, name, value, safe=True): - """Prevent accidental assignment of existing members - - Arguments: - object (object): Parent of new attribute - name (str): Name of new attribute - value (object): Value of new attribute - safe (bool): Whether or not to guarantee that - the new attribute was not overwritten. - Can be set to False under condition that - it is superseded by extensive testing. - - """ - - if safe: - # Cannot alter original binding. - if hasattr(object, name): - raise AttributeError("Cannot override existing name: " - "%s.%s" % (object.__name__, name)) - - # Cannot alter classes of functions - if type(object).__name__ != "module": - raise AttributeError("%s != 'module': Cannot alter " - "anything but modules" % object) - - elif hasattr(object, name): - # Keep track of modifications - __modified__.append(name) - - if name not in __added__: - __remapped__.append(name) - - setattr(object, name, value) - - -def add(object, name, value, safe=True): - """Identical to :func:`remap` and provided for readability only""" - __added__.append(name) - remap(object, name, value, safe) - - -def pyqt5(): - import PyQt5.Qt - from PyQt5 import QtCore, uic - - remap(QtCore, "Signal", QtCore.pyqtSignal) - remap(QtCore, "Slot", QtCore.pyqtSlot) - remap(QtCore, "Property", QtCore.pyqtProperty) - - add(PyQt5, "__wrapper_version__", __version__) - add(PyQt5, "__binding__", "PyQt5") - add(PyQt5, "__binding_version__", QtCore.PYQT_VERSION_STR) - add(PyQt5, "__qt_version__", QtCore.QT_VERSION_STR, safe=False) - add(PyQt5, "__added__", __added__) - add(PyQt5, "__remapped__", __remapped__) - add(PyQt5, "__modified__", __modified__) - add(PyQt5, "load_ui", lambda fname: uic.loadUi(fname)) - - return PyQt5 - - -def pyqt4(): - # Attempt to set sip API v2 (must be done prior to importing PyQt4) - import sip - try: - sip.setapi("QString", 2) - sip.setapi("QVariant", 2) - sip.setapi("QDate", 2) - sip.setapi("QDateTime", 2) - sip.setapi("QTextStream", 2) - sip.setapi("QTime", 2) - sip.setapi("QUrl", 2) - except AttributeError: - raise ImportError - # PyQt4 < v4.6 - except ValueError: - # API version already set to v1 - raise ImportError - - import PyQt4.Qt - from PyQt4 import QtCore, QtGui, uic - - remap(PyQt4, "QtWidgets", QtGui) - remap(QtCore, "Signal", QtCore.pyqtSignal) - remap(QtCore, "Slot", QtCore.pyqtSlot) - remap(QtCore, "Property", QtCore.pyqtProperty) - remap(QtCore, "QItemSelection", QtGui.QItemSelection) - remap(QtCore, "QStringListModel", QtGui.QStringListModel) - remap(QtCore, "QItemSelectionModel", QtGui.QItemSelectionModel) - remap(QtCore, "QSortFilterProxyModel", QtGui.QSortFilterProxyModel) - remap(QtCore, "QAbstractProxyModel", QtGui.QAbstractProxyModel) - - try: - from PyQt4 import QtWebKit - remap(PyQt4, "QtWebKitWidgets", QtWebKit) - except ImportError: - # QtWebkit is optional in Qt , therefore might not be available - pass - - add(PyQt4, "__wrapper_version__", __version__) - add(PyQt4, "__binding__", "PyQt4") - add(PyQt4, "__binding_version__", QtCore.PYQT_VERSION_STR) - add(PyQt4, "__qt_version__", QtCore.QT_VERSION_STR) - add(PyQt4, "__added__", __added__) - add(PyQt4, "__remapped__", __remapped__) - add(PyQt4, "__modified__", __modified__) - add(PyQt4, "load_ui", lambda fname: uic.loadUi(fname)) - - return PyQt4 - - -def pyside2(): - import PySide2 - from PySide2 import QtGui, QtCore, QtUiTools - - remap(QtCore, "QStringListModel", QtGui.QStringListModel) - - add(PySide2, "__wrapper_version__", __version__) - add(PySide2, "__binding__", "PySide2") - add(PySide2, "__binding_version__", PySide2.__version__) - add(PySide2, "__qt_version__", PySide2.QtCore.qVersion()) - add(PySide2, "__added__", __added__) - add(PySide2, "__remapped__", __remapped__) - add(PySide2, "__modified__", __modified__) - add(PySide2, "load_ui", lambda fname: QtUiTools.QUiLoader().load(fname)) - - return PySide2 - - -def pyside(): - import PySide - from PySide import QtGui, QtCore, QtUiTools - - remap(PySide, "QtWidgets", QtGui) - remap(QtCore, "QSortFilterProxyModel", QtGui.QSortFilterProxyModel) - remap(QtCore, "QStringListModel", QtGui.QStringListModel) - remap(QtCore, "QItemSelection", QtGui.QItemSelection) - remap(QtCore, "QItemSelectionModel", QtGui.QItemSelectionModel) - remap(QtCore, "QAbstractProxyModel", QtGui.QAbstractProxyModel) - - try: - from PySide import QtWebKit - remap(PySide, "QtWebKitWidgets", QtWebKit) - except ImportError: - # QtWebkit is optional in Qt , therefore might not be available - pass - - add(PySide, "__wrapper_version__", __version__) - add(PySide, "__binding__", "PySide") - add(PySide, "__binding_version__", PySide.__version__) - add(PySide, "__qt_version__", PySide.QtCore.qVersion()) - add(PySide, "__added__", __added__) - add(PySide, "__remapped__", __remapped__) - add(PySide, "__modified__", __modified__) - add(PySide, "load_ui", lambda fname: QtUiTools.QUiLoader().load(fname)) - - return PySide - - -def log(text, verbose): - if verbose: - sys.stdout.write(text) - - -def init(): - """Try loading each binding in turn - - Please note: the entire Qt module is replaced with this code: - sys.modules["Qt"] = binding() - - This means no functions or variables can be called after - this has executed. - - """ - - preferred = os.getenv("QT_PREFERRED_BINDING") - verbose = os.getenv("QT_VERBOSE") is not None - bindings = (pyside2, pyqt5, pyside, pyqt4) - - if preferred: - # Internal flag (used in installer) - if preferred == "None": - sys.modules[__name__].__wrapper_version__ = __version__ - return - - preferred = preferred.split(os.pathsep) - available = { - "PySide2": pyside2, - "PyQt5": pyqt5, - "PySide": pyside, - "PyQt4": pyqt4 - } - - try: - bindings = [available[binding] for binding in preferred] - except KeyError: - raise ImportError( - "Available preferred Qt bindings: " - "\n".join(preferred) - ) - - for binding in bindings: - log("Trying %s" % binding.__name__, verbose) - - try: - binding = binding() - - except ImportError as e: - log(" - ImportError(\"%s\")\n" % e, verbose) - continue - - else: - # Reference to this module - binding.__shim__ = sys.modules[__name__] - - sys.modules.update({ - __name__: binding, - - # Fix #133, `from Qt.QtWidgets import QPushButton` - __name__ + ".QtWidgets": binding.QtWidgets - - }) - - return - - # If not binding were found, throw this error - raise ImportError("No Qt binding were found.") - - -init() diff --git a/app/__init__.py b/app/__init__.py index 3fc7c13..b987ed8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,9 +1,3 @@ -try: - # Try import Qt.py from global site-package, if not import copy of Qt.py - # in a current directory - import Qt -except ImportError: - from . import Qt from preference import miExecPref import maya.cmds as cmds import miExec @@ -12,6 +6,7 @@ import json import imp import os +import Qt reload(miExecPref) reload(miExec) diff --git a/app/customWidgets.py b/app/customWidgets.py index 0eafddc..3538cbd 100644 --- a/app/customWidgets.py +++ b/app/customWidgets.py @@ -1,9 +1,4 @@ -try: - # Try import Qt.py from global site-package, if not import copy of Qt.py - # in a current directory - import Qt -except ImportError: - from . import Qt +import Qt class CustomQLineEdit(Qt.QtWidgets.QLineEdit): diff --git a/app/miExec.py b/app/miExec.py index 63d2280..1b755c0 100644 --- a/app/miExec.py +++ b/app/miExec.py @@ -1,13 +1,8 @@ -try: - # Try import Qt.py from global site-package, if not import copy of Qt.py - # in a current directory - import Qt -except ImportError: - from . import Qt import maya.cmds as cmds import maya.mel as mel import json import os +import Qt import preference import customWidgets from pymel.all import mel as pa