當前位置: 首頁>>代碼示例>>Python>>正文


Python QApplication.instance方法代碼示例

本文整理匯總了Python中qtpy.QtWidgets.QApplication.instance方法的典型用法代碼示例。如果您正苦於以下問題:Python QApplication.instance方法的具體用法?Python QApplication.instance怎麽用?Python QApplication.instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qtpy.QtWidgets.QApplication的用法示例。


在下文中一共展示了QApplication.instance方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init_qt_clipboard

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.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

示例2: qapplication

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def qapplication(translate=True, test_time=3):
    """Return QApplication instance
    Creates it if it doesn't already exist"""
    app = QApplication.instance()
    if app is None:
        app = QApplication(['Conda-Manager'])
        app.setApplicationName('Conda-Manager')
    if translate:
        install_translator(app)

    test_travis = os.environ.get('TEST_CI', None)
    if test_travis is not None:
        timer_shutdown = QTimer(app)
        timer_shutdown.timeout.connect(app.quit)
        timer_shutdown.start(test_time*1000)
    return app 
開發者ID:spyder-ide,項目名稱:conda-manager,代碼行數:18,代碼來源:qthelpers.py

示例3: init_qt_clipboard

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.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

示例4: get_qapp

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def get_qapp(icon_path=None):
    qapp = QApplication.instance()
    if qapp is None:
        qapp = QApplication([''])
    return qapp 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:7,代碼來源:test_patch_qheaderview.py

示例5: setup

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def setup(self, n):
        _ = QApplication.instance() or QApplication([])
        np.random.seed(0)
        self.data = np.random.random((n, n))
        self.viewer = None 
開發者ID:napari,項目名稱:napari,代碼行數:7,代碼來源:benchmark_qt_viewer_image.py

示例6: setup

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def setup(self):
        _ = QApplication.instance() or QApplication([])
        np.random.seed(0)
        self.data = np.random.randint(10, size=(512, 512))
        self.viewer = napari.view_labels(self.data)
        self.layer = self.viewer.layers[0]
        self.layer.brush_size = 10
        self.layer.mode = 'paint'
        self.layer.selected_label = 3
        self.layer._last_cursor_coord = (511, 511)
        Event = collections.namedtuple('Event', 'is_dragging')
        self.event = Event(is_dragging=True) 
開發者ID:napari,項目名稱:napari,代碼行數:14,代碼來源:benchmark_qt_viewer_labels.py

示例7: lightTheme

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def lightTheme(self):
        qtmodern.styles.light(QApplication.instance()) 
開發者ID:gmarull,項目名稱:qtmodern,代碼行數:4,代碼來源:mainwindow.py

示例8: darkTheme

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def darkTheme(self):
        qtmodern.styles.dark(QApplication.instance()) 
開發者ID:gmarull,項目名稱:qtmodern,代碼行數:4,代碼來源:mainwindow.py

示例9: icon

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def icon(self, *names, **kwargs):
        """Return a QIcon object corresponding to the provided icon name."""
        cache_key = '{}{}'.format(names,kwargs)
        if cache_key not in self.icon_cache:
            options_list = kwargs.pop('options', [{}] * len(names))
            general_options = kwargs

            if len(options_list) != len(names):
                error = '"options" must be a list of size {0}'.format(len(names))
                raise Exception(error)

            if QApplication.instance() is not None:
                parsed_options = []
                for i in range(len(options_list)):
                    specific_options = options_list[i]
                    parsed_options.append(self._parse_options(specific_options,
                                                              general_options,
                                                              names[i]))

                # Process high level API
                api_options = parsed_options

                self.icon_cache[cache_key] = self._icon_by_painter(self.painter, api_options)
            else:
                warnings.warn("You need to have a running "
                              "QApplication to use QtAwesome!")
                return QIcon()
        return self.icon_cache[cache_key] 
開發者ID:spyder-ide,項目名稱:qtawesome,代碼行數:30,代碼來源:iconic_font.py

示例10: install_translator

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def install_translator(qapp):
    """Install Qt translator to the QApplication instance"""
    global QT_TRANSLATOR
    if QT_TRANSLATOR is None:
        qt_translator = QTranslator()
        if qt_translator.load(
           "qt_"+QLocale.system().name(),
           QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
            QT_TRANSLATOR = qt_translator  # Keep reference alive
    if QT_TRANSLATOR is not None:
        qapp.installTranslator(QT_TRANSLATOR) 
開發者ID:spyder-ide,項目名稱:conda-manager,代碼行數:13,代碼來源:qthelpers.py

示例11: gui_qt

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def gui_qt(*, startup_logo=False):
    """Start a Qt event loop in which to run the application.

    Parameters
    ----------
    startup_logo : bool
        Show a splash screen with the napari logo during startup.

    Notes
    -----
    This context manager is not needed if running napari within an interactive
    IPython session. In this case, use the ``%gui qt`` magic command, or start
    IPython with the Qt GUI event loop enabled by default by using
    ``ipython --gui=qt``.
    """
    splash_widget = None
    app = QApplication.instance()
    if not app:
        # automatically determine monitor DPI.
        # Note: this MUST be set before the QApplication is instantiated
        QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
        # if this is the first time the Qt app is being instantiated, we set
        # the name, so that we know whether to raise_ in Window.show()
        app = _create_application(sys.argv)
        app.setApplicationName('napari')
        if startup_logo:
            logopath = join(dirname(__file__), '..', 'resources', 'logo.png')
            pm = QPixmap(logopath).scaled(
                360, 360, Qt.KeepAspectRatio, Qt.SmoothTransformation
            )
            splash_widget = QSplashScreen(pm)
            splash_widget.show()
            app._splash_widget = splash_widget
    else:
        app._existed = True
    yield app
    # if the application already existed before this function was called,
    # there's no need to start it again.  By avoiding unnecessary calls to
    # ``app.exec_``, we avoid blocking.
    if app.applicationName() == 'napari':
        if splash_widget and startup_logo:
            splash_widget.close()
        app.exec_() 
開發者ID:napari,項目名稱:napari,代碼行數:45,代碼來源:event_loop.py

示例12: __init__

# 需要導入模塊: from qtpy.QtWidgets import QApplication [as 別名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 別名]
def __init__(
        self,
        title='napari',
        ndisplay=2,
        order=None,
        axis_labels=None,
        show=True,
    ):
        # instance() returns the singleton instance if it exists, or None
        app = QApplication.instance()
        # if None, raise a RuntimeError with the appropriate message
        if app is None:
            message = (
                "napari requires a Qt event loop to run. To create one, "
                "try one of the following: \n"
                "  - use the `napari.gui_qt()` context manager. See "
                "https://github.com/napari/napari/tree/master/examples for"
                " usage examples.\n"
                "  - In IPython or a local Jupyter instance, use the "
                "`%gui qt` magic command.\n"
                "  - Launch IPython with the option `--gui=qt`.\n"
                "  - (recommended) in your IPython configuration file, add"
                " or uncomment the line `c.TerminalIPythonApp.gui = 'qt'`."
                " Then, restart IPython."
            )
            raise RuntimeError(message)

        # For perfmon we need a special QApplication. If using gui_qt we already
        # have the special one, and this is a noop. When running inside IPython
        # or Jupyter however this is where we switch out the QApplication.
        if os.getenv("NAPARI_PERFMON", "0") != "0":
            from ._qt.qt_event_timing import convert_app_for_timing

            app = convert_app_for_timing(app)

        if (
            platform.system() == "Windows"
            and not getattr(sys, 'frozen', False)
            and self._napari_app_id
        ):
            import ctypes

            ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
                self._napari_app_id
            )

        logopath = join(dirname(__file__), 'resources', 'logo.png')
        app.setWindowIcon(QIcon(logopath))

        # see docstring of `wait_for_workers_to_quit` for caveats on killing
        # workers at shutdown.
        app.aboutToQuit.connect(wait_for_workers_to_quit)

        super().__init__(
            title=title,
            ndisplay=ndisplay,
            order=order,
            axis_labels=axis_labels,
        )
        qt_viewer = QtViewer(self)
        self.window = Window(qt_viewer, show=show) 
開發者ID:napari,項目名稱:napari,代碼行數:63,代碼來源:viewer.py


注:本文中的qtpy.QtWidgets.QApplication.instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。