예제 #1
0
def test_load_ui_overwrite_fails():
    """PyQt4/5 loadUi functiion will fail if the widget has a preexisting
    layout. This tests that our custom implementation for PySide does the same
    """
    import sys
    from Qt import QtWidgets, QtCompat
    app = QtWidgets.QApplication(sys.argv)
    win = QtWidgets.QWidget()
    layout = QtWidgets.QVBoxLayout(win)
    win.lineEdit = QtWidgets.QPushButton('Test')
    layout.addWidget(win.lineEdit)
    assert_raises(RuntimeError, QtCompat.loadUi, self.ui_qwidget, win)
    app.exit()
예제 #2
0
def application():
    app = QtWidgets.QApplication.instance()

    if not app:
        print("Starting new QApplication..")
        app = QtWidgets.QApplication(sys.argv)
        yield app
        app.exec_()
    else:
        print("Using existing QApplication..")
        yield app
        if os.environ.get("PYBLISH_GUI_ALWAYS_EXEC"):
            app.exec_()
예제 #3
0
def show():
    if isMaya:
        logger.info('Run in Maya\n')
        uiName = 'RfSplitUI'
        deleteUI(uiName)
        myApp = RFSplitSequence(getMayaWindow())
        return myApp

    else:
        logger.info('Run in standalone\n')
        app = QtWidgets.QApplication(sys.argv)
        myApp = RFSplitSequence()
        sys.exit(app.exec_())
예제 #4
0
def unitTest_SpinBox():
    app = QtWidgets.QApplication(sys.argv)


    testDialog = QtWidgets.QDialog()
    layTest = QtWidgets.QHBoxLayout()
    layTest.addWidget(MoneySpinner())
    testDialog.setLayout(layTest)

    ex = testDialog
    StyleUtils.setStyleSheet(ex)
    ex.show()
    sys.exit(app.exec_())
예제 #5
0
def show():
    if isMaya:
        logger.info('Run in Maya\n')
        uiName = 'MainWindow'
        deleteUI(uiName)
        myApp = MyForm(getMayaWindow())
        return myApp

    else:
        logger.info('Run in standalone\n')
        app = QtWidgets.QApplication(sys.argv)
        myApp = MyForm()
        sys.exit(app.exec_())
예제 #6
0
def test():
    """QtCore is taken out of Qt.py via QtSiteConfig.py"""

    # Expose this directory, and therefore QtSiteConfig, to Python
    sys.path.insert(0, os.path.dirname(__file__))

    try:
        from Qt import QtCore

    except ImportError:
        print("Qt.QtCore was successfully removed by QtSiteConfig.py")

    else:
        raise ImportError(
            "Qt.QtCore was importable, update_members was not "
            "applied correctly."
        )

        # Suppress "Qt.QtCore" imported but unused warning
        QtCore

    # Test _misplaced_members is applied correctly
    from Qt import QtGui
    assert QtGui.QColorTest == QtGui.QColor, \
        "QtGui.QColor was not mapped to QtGui.QColorTest"

    # Test _compatibility_members is applied correctly
    title = "Test Widget"
    from Qt import QtWidgets, QtCompat
    app = QtWidgets.QApplication(sys.argv)
    wid = QtWidgets.QWidget()
    wid.setWindowTitle(title)

    # Verify that our simple remapping of QWidget.windowTitle works
    assert QtCompat.QWidget.windowTitleTest(wid) == title, \
        "Non-decorated function was added to QtCompat.QWidget"
    # Verify that our decorated remapping of QWidget.windowTitle works
    check = "Test: {}".format(title)
    assert QtCompat.QWidget.windowTitleDecorator(wid) == check, \
        "Decorated method was not added to QtCompat.QWidget"

    # Verify that our decorated remapping of QMainWindow.windowTitle is
    # different than the QWidget version.
    win = QtWidgets.QMainWindow()
    win.setWindowTitle(title)
    check = "QMainWindow Test: {}".format(title)
    assert QtCompat.QMainWindow.windowTitleDecorator(win) == check, \
        "Decorated method was added to QtCompat.QMainWindow"
    # Suppress "app" imported but unused warning
    app
예제 #7
0
파일: __init__.py 프로젝트: 3dzayn/pype
def open_dialog():
    """Show Igniter dialog."""
    from Qt import QtWidgets
    from .install_dialog import InstallDialog

    app = QtWidgets.QApplication(sys.argv)

    d = InstallDialog()
    d.finished.connect(get_result)
    d.open()

    app.exec()

    return RESULT
예제 #8
0
 def launch(cls, settings, parent=None):
     # type: (SettingsGroup, QtWidgets.QWidget) -> cls
     """
     Initialises and shows the viewer. If no QApplication instance is
     available, one is initialised.
     """
     app = None if QtWidgets.QApplication.instance() else QtWidgets.QApplication([])
     widget = cls(settings, parent=parent)
     if app:
         widget.show()
         app.exec_()
     else:
         widget.exec_()
     return widget
예제 #9
0
def getParent():
    host = getHostApplication()

    # try running outside of maya
    app = None
    parent = None
    if host == 'standalone':
        app = QtWidgets.QApplication(sys.argv)
        parent = None
    elif host == 'maya':
        parent = getMayaMainWindow()
    else:
        assert False
    return app, parent
예제 #10
0
def cli():

    parser = argparse.ArgumentParser()

    parser.add_argument('-i', '--usdfile', help='usd file to load')
    parser.add_argument('-t',
                        '--textures',
                        action='store_true',
                        help="Load textures (ie, walk attributes)")
    args = parser.parse_args()

    app = QtWidgets.QApplication(sys.argv)
    win = main(args.usdfile, walk_attributes=args.textures)
    sys.exit(app.exec_())
예제 #11
0
파일: tests.py 프로젝트: yoshidakt/Qt.py
def test_load_ui_dockwidget():
    """Tests to see if the baseinstance loading loads a QDockWidget properly"""
    import sys
    from Qt import QtWidgets, QtCompat

    app = QtWidgets.QApplication(sys.argv)
    win = QtWidgets.QDockWidget()

    QtCompat.loadUi(self.ui_qdockwidget, win)

    assert hasattr(win, 'lineEdit'), \
        "loadUi could not load instance to main window"

    app.exit()
예제 #12
0
def Show(path=None):
    import sys
    import os
    from Qt import QtWidgets

    app = QtWidgets.QApplication(sys.argv)
    win = Create()

    if path:
        if os.path.isfile(path) and os.path.splitext(path)[-1].lower() == ".blcs":
            win.openScene(path)

    win.show()
    win.fitInView()
    app.exec_()
예제 #13
0
파일: tests.py 프로젝트: yoshidakt/Qt.py
def test_load_ui_existingLayoutOnWidget():
    """Tests to see if loading a ui onto a layout in a Widget works"""
    import sys
    from Qt import QtWidgets, QtCompat

    msgs = 'QLayout: Attempting to add QLayout "" to QWidget ' \
        '"Form", which already has a layout'

    with ignoreQtMessageHandler([msgs]):
        app = QtWidgets.QApplication(sys.argv)
        win = QtWidgets.QWidget()
        QtWidgets.QComboBox(win)
        QtWidgets.QHBoxLayout(win)
        QtCompat.loadUi(self.ui_qwidget, win)
    app.exit()
예제 #14
0
def show():
    if isMaya:
        logger.info('Run in Maya\n')
        uiName = 'AssetMoverUI'
        deleteUI(uiName)
        myApp = AssetMoverUI(getMayaWindow())
        return myApp

    else:
        logger.info('Run in standalone\n')
        app = QtWidgets.QApplication.instance()
        if not app: 
            app = QtWidgets.QApplication(sys.argv)
        myApp = AssetMoverUI()
        sys.exit(app.exec_())
예제 #15
0
def create_app():
    app = QtCore.QCoreApplication.instance()
    if app:
        try:
            import maya.cmds

            set_working_context("MAYA")
        except:
            pass
    else:
        app = QtWidgets.QApplication(sys.argv)
    setup_style(app)
    setup_dark_mode(app)
    sys.excepthook = excepthook
    return app
예제 #16
0
    def executeQtGUITestsWithXvfb(testClass, argv, XvfbLogPath='./xvfb.log'):
        result= None
        qtApp= None
        import Qt
        from Qt import QtWidgets
        with Xvfb.launch(XvfbLogPath) as xvfb:
            qtApp= QtWidgets.QApplication(argv)
            result= unittest.TextTestRunner().run(
                unittest.TestLoader().loadTestsFromTestCase(testClass))
            assert qtApp is not None
            del qtApp

        assert result is not None
        if not result.wasSuccessful():
            sys.exit(os.EX_SOFTWARE)
예제 #17
0
def getParent():
    host = getHostApplication()

    # try running outside of maya
    app = None
    parent = None
    if host == 'standalone':
        app = QtWidgets.QApplication(sys.argv)
        parent = None
    elif host == 'maya':
        parent = getMayaMainWindow()
    else:
        msg = 'Host application is not valid: host=%r'
        raise ValueError(msg % host)
    return app, parent
예제 #18
0
    def dialog(cls, parent=None, *args, **kwargs):
        """Create the window as a dialog.
        Methods of .dialogAccept and .dialogReject will be added.
        Any variables given to these will be returned.

        Output: (accepted[bool], data[list])
        """
        # Create application if it doesn't exist
        inst = app = QtWidgets.QApplication.instance()
        if app is None:
            app = QtWidgets.QApplication(sys.argv)

        dialog = QtWidgets.QDialog(parent=parent)
        dialog.setWindowTitle(getattr(cls, 'WindowName', 'New Window'))
        if inst is None:
            app.setActiveWindow(dialog)

        # Inheirt the class to set attributes
        class windowClass(cls):
            WindowDockable = False
            _DialogData = []

            # Method of getting data returned from dialog
            def dialogAccept(self, *args):
                self._DialogData += args
                return dialog.accept()

            def dialogReject(self, *args):
                self._DialogData += args
                return dialog.reject()

        # Setup layout
        layout = QtWidgets.QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        #layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        windowInstance = windowClass(*args, **kwargs)
        layout.addWidget(windowInstance)
        dialog.setLayout(layout)

        # Finish setting up window
        windowInstance.loadWindowPosition()
        windowInstance.windowReady.emit()

        try:
            return (dialog.exec_(), windowInstance._DialogData)
        finally:
            windowInstance.saveWindowPosition()
            windowClass.clearWindowInstance(windowClass.WindowID)
예제 #19
0
def create_app():
    """
    If we are in a qt built-in context (Maya, Houdini, ...), an instance of app
    already exists.
    """
    app = QtCore.QCoreApplication.instance()
    if app:
        if check_module_import("maya.cmds"):
            set_working_context("MAYA")
        elif check_module_import("hou"):
            set_working_context("HOUDINI")
    else:
        app = QtWidgets.QApplication(sys.argv)
    setup_style(app)
    sys.excepthook = excepthook
    return app
예제 #20
0
def test():
    import sys

    app = QtWidgets.QApplication(sys.argv)
    mainWin = QtWidgets.QWidget()
    mainWin.setWindowTitle("Flow Layout")
    flowLayout = IFlowLayout()
    flowLayout.addWidget(QtWidgets.QPushButton("Short"))
    flowLayout.addWidget(QtWidgets.QPushButton("Longer"))
    flowLayout.addWidget(QtWidgets.QPushButton("Different text"))
    flowLayout.addWidget(QtWidgets.QPushButton("More text"))
    flowLayout.addWidget(QtWidgets.QPushButton("Even longer button text"))
    mainWin.setLayout(flowLayout)

    mainWin.show()
    sys.exit(app.exec_())
예제 #21
0
def test_qtcompat_base_class():
    """Tests to ensure the QtCompat namespace object works as expected"""
    import sys
    import Qt
    from Qt import QtWidgets
    from Qt import QtCompat
    app = QtWidgets.QApplication(sys.argv)
    # suppress `local variable 'app' is assigned to but never used`
    app
    header = QtWidgets.QHeaderView(Qt.QtCore.Qt.Horizontal)

    # Spot check compatibility functions
    QtCompat.QHeaderView.setSectionsMovable(header, False)
    assert QtCompat.QHeaderView.sectionsMovable(header) is False
    QtCompat.QHeaderView.setSectionsMovable(header, True)
    assert QtCompat.QHeaderView.sectionsMovable(header) is True
예제 #22
0
파일: tests.py 프로젝트: shallowabyss/Qt.py
def test_load_ui_invalidxml():
    """Tests to see if loadUi successfully fails on invalid ui files"""
    import sys
    invalid_xml = os.path.join(self.tempdir, "invalid.ui")
    with io.open(invalid_xml, "w", encoding="utf-8") as f:
        f.write(u"""
        <?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0" garbage
        </ui>
        """)

    from xml.etree import ElementTree
    from Qt import QtWidgets, QtCompat
    app = QtWidgets.QApplication(sys.argv)
    assert_raises(ElementTree.ParseError, QtCompat.loadUi, invalid_xml)
    app.exit()
예제 #23
0
def test():
    app = QtWidgets.QApplication(sys.argv)

    label = QtWidgets.QLabel("Click Test")

    mouseSignal = IMouseClickSignal(label)
    mouseSignal.LClicked.connect(lambda e:sys.stdout.write("left click\n"))
    mouseSignal.LReleased.connect(lambda e:sys.stdout.write("left release\n"))
    mouseSignal.DLClicked.connect(lambda e:sys.stdout.write("double left click\n"))
    mouseSignal.MClicked.connect(lambda e:sys.stdout.write("middle click\n"))
    mouseSignal.DMClicked.connect(lambda e:sys.stdout.write("double middle click\n"))
    mouseSignal.RClicked.connect(lambda e:sys.stdout.write("right click\n"))
    mouseSignal.DRClicked.connect(lambda e:sys.stdout.write("double right click\n"))

    label.show()
    sys.exit(app.exec_())
예제 #24
0
    def test_implicit_wrapInstance_for_derived_types():
        """Tests .wrapInstance implicit cast of `Foo` pointer to `Bar` object

        Testing is based upon the following parameters:

        1. The `base` argument has a default value.
        2. `Bar` is a standard Qt class.
        3. `Foo` is a strict subclass of `Bar`, separated by one or more levels
           of inheritance.
        4. `Foo` is not a standard Qt class.

        Note:
            For sip usage, implicit cast of `Foo` pointer always results in a
            `Foo` object.

        """
        from Qt import QtCompat, QtWidgets

        app = QtWidgets.QApplication(sys.argv)

        try:

            class A(QtWidgets.QPushButton):
                pass

            class B(A):
                pass

            button = B("Hello world")
            button.setObjectName("MySpecialButton")
            pointer = QtCompat.getCppPointer(button)
            widget = QtCompat.wrapInstance(long(pointer))

            assert widget.objectName() == button.objectName()

            if binding("PyQt4") or binding("PyQt5"):
                assert type(widget) is B, widget
            else:
                assert type(widget) is QtWidgets.QPushButton, widget

            if binding("PySide") or binding("PySide2"):
                assert widget != button
            else:
                assert widget == button

        finally:
            app.exit()
def main():
    app = QtWidgets.QApplication.instance()
    if not app:
        app = QtWidgets.QApplication(sys.argv)

    for widget in app.allWidgets():
        if widget.objectName() == 'userNormalTranslatorWindow':
            widget.close()

    ex = userNormalTranslatorWindow()
    ex.setParent(app.activeWindow())
    ex.setWindowFlags(QtCore.Qt.Window)

    ex.show()

    if app.applicationName() in ['python', 'mayapy']:
        sys.exit(app.exec_())
예제 #26
0
def main():

    app = QtWidgets.QApplication(sys.argv)

    # 10 Key frames
    keyframes = [random.randrange(1001, 1100) for _ in range(10)]
    # 5 errors
    errors = [random.randrange(1001, 1100) for _ in range(5)]

    ex = TimelineContainer(start=1001,
                           end=1100,
                           keyframes=keyframes,
                           errors=errors,
                           parent=None)
    ex.setStyle(QtWidgets.QStyleFactory.create("motif"))
    ex.show()
    sys.exit(app.exec_())
예제 #27
0
def main(argv):
    app = QtWidgets.QApplication(argv)

    model = QtWidgets.QStandardItemModel()

    words = ['hola', 'adios', 'hello', 'good bye']
    for i, word in enumerate(words):
        item = QtWidgets.QStandardItem(word)
        model.setItem(i, 0, item)

    combo = ExtendedCombo()
    combo.setModel(model)
    combo.setModelColumn(0)

    combo.show()

    sys.exit(app.exec_())
예제 #28
0
def test():

    app = QtWidgets.QApplication([])

    model = QtGui.QStandardItemModel()

    for i, word in enumerate(['hola', 'adios', 'hello', 'good bye']):
        item = QtGui.QStandardItem(word)
        model.setItem(i, item)

    combo = ICompleterComboBox()
    combo.setModel(model)
    combo.setModelColumn(0)

    combo.show()

    app.exec_()
예제 #29
0
def show():
    if isMaya:
        logger.info('Run in Maya\n')
        uiName = 'StillPublishUI'
        deleteUI(uiName)
        myApp = RFStillPublish(getMayaWindow())
        # myApp.show()
        return myApp

    else:
        logger.info('Run in standalone\n')
        app = QtWidgets.QApplication.instance()
        if not app:
            app = QtWidgets.QApplication(sys.argv)
        myApp = RFStillPublish()
        # myApp.show()
        sys.exit(app.exec_())
예제 #30
0
def message(title=None, message=None, level="info", parent=None):
    app = parent
    if not app:
        app = QtWidgets.QApplication(sys.argv)

    ex = Window(app, title, message, level)
    ex.show()

    # Move widget to center of screen
    try:
        desktop_rect = QtWidgets.QApplication.desktop().availableGeometry(ex)
        center = desktop_rect.center()
        ex.move(center.x() - (ex.width() * 0.5),
                center.y() - (ex.height() * 0.5))
    except Exception:
        # skip all possible issues that may happen feature is not crutial
        log.warning("Couldn't center message.", exc_info=True)