当前位置: 首页>>代码示例>>Python>>正文


Python QtWidgets.QApplication方法代码示例

本文整理汇总了Python中Qt.QtWidgets.QApplication方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QApplication方法的具体用法?Python QtWidgets.QApplication怎么用?Python QtWidgets.QApplication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Qt.QtWidgets的用法示例。


在下文中一共展示了QtWidgets.QApplication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def run():
    app = App()
    
    def interrupt(*args):
        """ Cleanly exit the application if a KeyboardInterrupt is detected.
        """
        logger.info("KeyboardInterrupt")
        app.onExit()
        QtWidgets.QApplication.quit()
        sys.exit(0)
    
    # Allow Ctrl+C to kill the GUI, but first clean up any temp files we left lying around.
    try:
        signal.signal(signal.SIGINT, interrupt)
    except ValueError as e:
        logger.warning("You may not be able to kill this app via Ctrl-C: {}".format(e))
    
    app.run() 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:20,代码来源:__init__.py

示例2: test_load_ui_customwidget

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test_load_ui_customwidget():
    """Tests to see if loadUi loads a custom widget properly"""
    import sys
    from Qt import QtWidgets, QtCompat

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

    QtCompat.loadUi(self.ui_qcustomwidget, win)

    # Ensure that the derived class was properly created
    # and not the base class (in case of failure)
    custom_class_name = getattr(win, "customwidget", None).__class__.__name__
    excepted_class_name = CustomWidget(win).__class__.__name__
    assert custom_class_name == excepted_class_name, \
        "loadUi could not load custom widget to main window"

    app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:20,代码来源:tests.py

示例3: test_load_ui_invalidxml

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
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() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:18,代码来源:tests.py

示例4: test_qtcompat_base_class

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
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

    # Verify that the grab function actually generates a non-null image
    button = QtWidgets.QPushButton('TestImage')
    pixmap = QtCompat.QWidget.grab(button)
    assert not pixmap.isNull() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:23,代码来源:tests.py

示例5: test_wrapInstance

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test_wrapInstance():
        """.wrapInstance and .getCppPointer is identical across all bindings"""
        from Qt import QtCompat, QtWidgets

        app = QtWidgets.QApplication(sys.argv)

        try:
            button = QtWidgets.QPushButton("Hello world")
            button.setObjectName("MySpecialButton")
            pointer = QtCompat.getCppPointer(button)
            widget = QtCompat.wrapInstance(long(pointer),
                                           QtWidgets.QWidget)
            assert isinstance(widget, QtWidgets.QWidget), widget
            assert widget.objectName() == button.objectName()

            # IMPORTANT: this differs across sip and shiboken.
            if binding("PySide") or binding("PySide2"):
                assert widget != button
            else:
                assert widget == button

        finally:
            app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:25,代码来源:tests.py

示例6: test

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test():
    """Example: QtCompat.loadUi with setup_ui wrapper"""
    working_directory = os.path.dirname(__file__)
    os.chdir(working_directory)

    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()

    # Tests
    assert isinstance(window, QtWidgets.QWidget)
    assert isinstance(window.parent(), type(None))
    assert isinstance(window.base_instance, QtWidgets.QWidget)
    assert isinstance(window.lineEdit, QtWidgets.QWidget)
    assert window.lineEdit.text() == ''
    window.lineEdit.setText('Hello')
    assert window.lineEdit.text() == 'Hello'

    app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:20,代码来源:baseinstance1.py

示例7: test

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test():
    """Example: load_ui with custom uic.loadUi-like wrapper"""
    working_directory = os.path.dirname(__file__)
    os.chdir(working_directory)

    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()

    # Tests
    assert isinstance(window, QtWidgets.QWidget)
    assert isinstance(window.parent(), type(None))
    assert isinstance(window.base_instance, QtWidgets.QWidget)
    assert isinstance(window.lineEdit, QtWidgets.QWidget)
    assert window.lineEdit.text() == ''
    window.lineEdit.setText('Hello')
    assert window.lineEdit.text() == 'Hello'

    app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:20,代码来源:baseinstance2.py

示例8: main

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def main():
    global debug

    # Parse command line arguments
    parser = argparse.ArgumentParser(
        prog="qspectrumanalyzer",
        description="Spectrum analyzer for multiple SDR platforms",
    )
    parser.add_argument("--debug", action="store_true",
                        help="detailed debugging messages")
    parser.add_argument("--version", action="version",
                        version="%(prog)s {}".format(__version__))
    args, unparsed_args = parser.parse_known_args()
    debug = args.debug

    try:
        # Hide console window on Windows
        if sys.platform == 'win32' and not debug:
            from qspectrumanalyzer import windows
            windows.set_attached_console_visible(False)

        # Start PyQt application
        app = QtWidgets.QApplication(sys.argv[:1] + unparsed_args)
        app.setOrganizationName("QSpectrumAnalyzer")
        app.setOrganizationDomain("qspectrumanalyzer.eutopia.cz")
        app.setApplicationName("QSpectrumAnalyzer")
        window = QSpectrumAnalyzerMainWindow()
        sys.exit(app.exec_())
    finally:
        # Unhide console window on Windows (we don't want to leave zombies behind)
        if sys.platform == 'win32' and not debug:
            windows.set_attached_console_visible(True) 
开发者ID:xmikos,项目名称:qspectrumanalyzer,代码行数:34,代码来源:__main__.py

示例9: setOverrideCursor

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def setOverrideCursor(self, cursor=QtCore.Qt.WaitCursor):
        """ Set the override cursor if it is not already set.
        
        :Parameters:
            cursor
                Qt cursor
        """
        if not QtWidgets.QApplication.overrideCursor():
            QtWidgets.QApplication.setOverrideCursor(cursor) 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:11,代码来源:__init__.py

示例10: restoreOverrideCursor

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def restoreOverrideCursor(self):
        """ If an override cursor is currently set, restore the previous cursor.
        """
        if QtWidgets.QApplication.overrideCursor():
            QtWidgets.QApplication.restoreOverrideCursor() 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:7,代码来源:__init__.py

示例11: copySelectionToClipboard

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def copySelectionToClipboard(self):
        """ Store current selection to the middle mouse selection.
        
        Doing this on selectionChanged signal instead of mouseReleaseEvent causes the following to be output in Qt5:
        "QXcbClipboard: SelectionRequest too old"
        
        For some reason, this isn't needed for QTextEdit but is for QTextBrowser?
        """
        cursor = self.textCursor()
        if cursor.hasSelection():
            selection = cursor.selectedText().replace(u'\u2029', '\n')
            clipboard = QtWidgets.QApplication.clipboard()
            clipboard.setText(selection, clipboard.Selection) 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:15,代码来源:__init__.py

示例12: main

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def main():
    app = QApplication(sys.argv)

    instance = PyFlow.instance(software="standalone")
    if instance is not None:
        app.setActiveWindow(instance)
        instance.show()

        try:
            sys.exit(app.exec_())
        except Exception as e:
            print(e) 
开发者ID:wonderworks-software,项目名称:PyFlow,代码行数:14,代码来源:pyflow.py

示例13: test_load_ui_returntype

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test_load_ui_returntype():
    """load_ui returns an instance of QObject"""

    import sys
    from Qt import QtWidgets, QtCore, QtCompat
    app = QtWidgets.QApplication(sys.argv)
    obj = QtCompat.loadUi(self.ui_qwidget)
    assert isinstance(obj, QtCore.QObject)
    app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:11,代码来源:tests.py

示例14: test_load_ui_baseinstance

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test_load_ui_baseinstance():
    """Tests to see if the baseinstance loading loads a QWidget on properly"""
    import sys
    from Qt import QtWidgets, QtCompat
    app = QtWidgets.QApplication(sys.argv)
    win = QtWidgets.QWidget()
    QtCompat.loadUi(self.ui_qwidget, win)
    assert hasattr(win, 'lineEdit'), "loadUi could not load instance to win"
    app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:11,代码来源:tests.py

示例15: test_load_ui_signals

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QApplication [as 别名]
def test_load_ui_signals():
    """Tests to see if the baseinstance connects signals properly"""
    import sys
    from Qt import QtWidgets, QtCompat
    app = QtWidgets.QApplication(sys.argv)
    win = QtWidgets.QWidget()
    QtCompat.loadUi(self.ui_qwidget, win)

    win.lineEdit.setText('Hello')
    assert str(win.label.text()) == 'Hello', "lineEdit signal did not fire"

    app.exit() 
开发者ID:mottosso,项目名称:Qt.py,代码行数:14,代码来源:tests.py


注:本文中的Qt.QtWidgets.QApplication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。