本文整理汇总了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
示例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
示例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
示例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
示例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
示例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)
示例7: lightTheme
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def lightTheme(self):
qtmodern.styles.light(QApplication.instance())
示例8: darkTheme
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def darkTheme(self):
qtmodern.styles.dark(QApplication.instance())
示例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]
示例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)
示例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_()
示例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)