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


Python QApplication.instance方法代码示例

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


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

示例1: _validate_deletion

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def _validate_deletion(lineedit, method, text, deleted, rest):
    """Run and validate a text deletion method on the ReadLine bridge.

    Args:
        lineedit: The LineEdit instance.
        method: Reference to the method on the bridge to test.
        text: The starting 'augmented' text (see LineEdit.set_aug_text)
        deleted: The text that should be deleted when the method is invoked.
        rest: The augmented text that should remain after method is invoked.
    """
    lineedit.set_aug_text(text)
    method()
    assert readlinecommands.bridge._deleted[lineedit] == deleted
    assert lineedit.aug_text() == rest
    lineedit.clear()
    readlinecommands.rl_yank()
    assert lineedit.aug_text() == deleted + '|' 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:19,代码来源:test_readlinecommands.py

示例2: later

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def later(ms: int, command: str, win_id: int) -> None:
    """Execute a command after some time.

    Args:
        ms: How many milliseconds to wait.
        command: The command to run, with optional args.
    """
    if ms < 0:
        raise cmdutils.CommandError("I can't run something in the past!")
    commandrunner = runners.CommandRunner(win_id)
    timer = usertypes.Timer(name='later', parent=QApplication.instance())
    try:
        timer.setSingleShot(True)
        try:
            timer.setInterval(ms)
        except OverflowError:
            raise cmdutils.CommandError("Numeric argument is too large for "
                                        "internal int representation.")
        timer.timeout.connect(
            functools.partial(commandrunner.run_safely, command))
        timer.timeout.connect(timer.deleteLater)
        timer.start()
    except:
        timer.deleteLater()
        raise 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:27,代码来源:utilcmds.py

示例3: quit_

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def quit_(save: bool = False,
          session: sessions.ArgType = None) -> None:
    """Quit qutebrowser.

    Args:
        save: When given, save the open windows even if auto_save.session
                is turned off.
        session: The name of the session to save.
    """
    if session is not None and not save:
        raise cmdutils.CommandError("Session name given without --save!")
    if save:
        if session is None:
            session = sessions.default
        instance.shutdown(session=session)
    else:
        instance.shutdown() 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:19,代码来源:quitter.py

示例4: _handle_key_event

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def _handle_key_event(self, event: QKeyEvent) -> bool:
        """Handle a key press/release event.

        Args:
            event: The QEvent which is about to be delivered.

        Return:
            True if the event should be filtered, False if it's passed through.
        """
        active_window = QApplication.instance().activeWindow()
        if active_window not in objreg.window_registry.values():
            # Some other window (print dialog, etc.) is focused so we pass the
            # event through.
            return False
        try:
            man = modeman.instance('current')
            return man.handle_event(event)
        except objreg.RegistryUnavailableError:
            # No window available yet, or not a MainWindow
            return False 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:22,代码来源:eventfilter.py

示例5: init_qt_clipboard

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def init_qt_clipboard():
    # $DISPLAY should exist

    # Try to import from qtpy, but if that fails try PyQt5 then PyQt4
    try:
        from qtpy.QtWidgets import QApplication
    except ImportError:
        try:
            from PyQt5.QtWidgets import QApplication
        except ImportError:
            from PyQt4.QtGui import QApplication

    app = QApplication.instance()
    if app is None:
        app = QApplication([])

    def copy_qt(text):
        cb = app.clipboard()
        cb.setText(text)

    def paste_qt():
        cb = app.clipboard()
        return text_type(cb.text())

    return copy_qt, paste_qt 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:clipboards.py

示例6: _get_qt_app

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def _get_qt_app():
    app = None

    if in_ipython():
        from IPython import get_ipython
        ipython = get_ipython()
        ipython.magic('gui qt')

        from IPython.external.qt_for_kernel import QtGui
        app = QtGui.QApplication.instance()

    if app is None:
        from PyQt5.QtWidgets import QApplication
        app = QApplication.instance()
        if not app:
            app = QApplication([''])

    return app 
开发者ID:MICA-MNI,项目名称:BrainSpace,代码行数:20,代码来源:base.py

示例7: __init__

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def __init__(self, customBanner=None, namespace=dict(), *args, **kwargs):
        super(ConsoleWidget, self).__init__(*args, **kwargs)

#        if not customBanner is None:
#            self.banner = customBanner

        self.font_size = 6
        self.kernel_manager = kernel_manager = QtInProcessKernelManager()
        kernel_manager.start_kernel(show_banner=False)
        kernel_manager.kernel.gui = 'qt'
        kernel_manager.kernel.shell.banner1 = ""
        
        self.kernel_client = kernel_client = self._kernel_manager.client()
        kernel_client.start_channels()

        def stop():
            kernel_client.stop_channels()
            kernel_manager.shutdown_kernel()
            QApplication.instance().exit()

        self.exit_requested.connect(stop)
        
        self.clear()
        
        self.push_vars(namespace) 
开发者ID:CadQuery,项目名称:CQ-editor,代码行数:27,代码来源:console.py

示例8: changeLanguage

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def changeLanguage(self, lan):
        """:author : Tich
        :param lan: 0=>Chinese, 1=>English
        change ui language
        """
        if lan == 0 and self.lan != 0:
            self.lan = 0
            print("[MainWindow] Change to zh_CN")
            self.trans.load("zh_CN")
        elif lan == 1 and self.lan != 1:
            self.lan = 1
            print("[MainWindow] Change to English")
            self.trans.load("en")
        else:
            return
        _app = QApplication.instance()
        _app.installTranslator(self.trans)
        self.retranslateUi(self) 
开发者ID:taseikyo,项目名称:PyQt5-Apps,代码行数:20,代码来源:main.py

示例9: __init__

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(parent)
        self.app = QApplication.instance()
        self.toolBox.setCurrentIndex(0)

        self.schedulerRadioMapping = {
            'off': self.scheduleOffRadio,
            'interval': self.scheduleIntervalRadio,
            'fixed': self.scheduleFixedRadio
        }

        self.scheduleApplyButton.clicked.connect(self.on_scheduler_apply)
        self.app.backup_finished_event.connect(self.init_logs)

        self.init_logs()
        self.populate_from_profile()
        self.set_icons() 
开发者ID:borgbase,项目名称:vorta,代码行数:20,代码来源:schedule_tab.py

示例10: load_macos_dark

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def load_macos_dark(self):
        """
        So many DEs on Linux! Hard to compat! We give them macOS
        dark theme colors!

        Users can also design a theme colors by themselves,
        we provider dump_colors/load_colors function for conviniece.
        """
        self.load_dark()
        content = read_resource('macos_dark.colors')
        colors = json.loads(content)
        try:
            QApplication.instance().paletteChanged.disconnect(self.autoload)
        except TypeError:
            pass
        palette = load_colors(colors)
        self._app.setPalette(palette)
        QApplication.instance().paletteChanged.connect(self.autoload) 
开发者ID:feeluown,项目名称:FeelUOwn,代码行数:20,代码来源:theme.py

示例11: __init__

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def __init__(self, parent=None):
        super(QLoadingDialog, self).__init__()
        self.setFixedSize(100, 100)
        # self.setWindowOpacity(0.8)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        app = QApplication.instance()
        curr_theme = "light"
        if app:
            curr_theme = app.property("theme")
        gif_file = os.path.abspath("./assets/icons/{}/loading.gif".format(curr_theme))
        self.movie = QMovie(gif_file)
        self.label = QLabel()
        self.label.setMovie(self.movie)
        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.label) 
开发者ID:haruiz,项目名称:CvStudio,代码行数:18,代码来源:loading_dialog.py

示例12: __init__

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def __init__(self, parent: QWidget=None):
        super(EngineSettings, self).__init__(parent)
        self.setupUi(self)

        # Save the path label text stored in the Qt UI file.
        # It is used to reset the label to this value if a custom module path is currently set and the user deletes it.
        # Do not hard-code it to prevent possible inconsistencies.
        self.initial_folder_label_text = self.folder_label.text()

        self.config_manager = QApplication.instance().configManager
        self.path = self.config_manager.userCodeDir
        self.clear_button.setEnabled(self.path is not None)

        if self.config_manager.userCodeDir is not None:
            self.folder_label.setText(self.config_manager.userCodeDir)
        logger.debug("EngineSettings widget initialised, custom module search path is set to: {}".format(self.path)) 
开发者ID:autokey,项目名称:autokey,代码行数:18,代码来源:engine.py

示例13: set_theme

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def set_theme(theme, prefs=None):
    if theme:
        theme = theme.replace(os.pardir, '').replace('.', '')
        theme = theme.join(theme.split()).lower()
        theme_style = resource_path('assets' + os.sep + theme + '_style.qss')
        if not os.path.exists(theme_style):
            theme_style = ':/assets/' + theme + '_style.qss'

        if prefs is not None:
            prefs.put('dwarf_ui_theme', theme)

        try:
            _app = QApplication.instance()
            style_s = QFile(theme_style)
            style_s.open(QFile.ReadOnly)
            style_content = QTextStream(style_s).readAll()
            _app.setStyleSheet(_app.styleSheet() + '\n' + style_content)
        except Exception as e:
            pass
            # err = self.dwarf.spawn(dwarf_args.package, dwarf_args.script) 
开发者ID:iGio90,项目名称:Dwarf,代码行数:22,代码来源:utils.py

示例14: on_change

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def on_change(self):
        """Call when a change is detected."""
        self._log.debug('Change detected...')

        # If a QApplication event loop has not been started
        # call compile_and_dispatch in the current thread.
        if not QApplication.instance():
            return super(PollingWatcher, self).compile_and_dispatch()

        # Create and use a QtDispatcher to ensure compile and any
        # connected callbacks get executed in the main gui thread.
        self.qtdispatcher.signal.emit() 
开发者ID:spyder-ide,项目名称:qtsass,代码行数:14,代码来源:qt.py

示例15: init_qt_clipboard

# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import instance [as 别名]
def init_qt_clipboard():
    global QApplication
    # $DISPLAY should exist

    # Try to import from qtpy, but if that fails try PyQt5 then PyQt4
    try:
        from qtpy.QtWidgets import QApplication
    except:
        try:
            from PyQt5.QtWidgets import QApplication
        except:
            from PyQt4.QtGui import QApplication

    app = QApplication.instance()
    if app is None:
        app = QApplication([])

    def copy_qt(text):
        text = _stringifyText(text) # Converts non-str values to str.
        cb = app.clipboard()
        cb.setText(text)

    def paste_qt():
        cb = app.clipboard()
        return STR_OR_UNICODE(cb.text())

    return copy_qt, paste_qt 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:29,代码来源:__init__.py


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