本文整理汇总了Python中qtpy.QtWidgets.QApplication.instance方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.instance方法的具体用法?Python QApplication.instance怎么用?Python QApplication.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QApplication
的用法示例。
在下文中一共展示了QApplication.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pydmdrawing_paintEvent
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_pydmdrawing_paintEvent(qtbot, signals, alarm_sensitive_content):
"""
Test the paintEvent handling of the widget. This test method will also execute PyDMDrawing alarm_severity_changed
and draw_item().
Expectations:
The paintEvent will be triggered, and the widget's brush color is correctly set.
NOTE: This test depends on the default stylesheet having different values for 'qproperty-brush' for different alarm states of PyDMDrawing.
Parameters
----------
qtbot : fixture
Window for widget testing
signals : fixture
The signals fixture, which provides access signals to be bound to the appropriate slots
alarm_sensitive_content : bool
True if the widget will be redraw with a different color if an alarm is triggered; False otherwise.
"""
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
qtbot.addWidget(main_window)
pydm_drawing = PyDMDrawing(parent=main_window, init_channel='fake://tst')
qtbot.addWidget(pydm_drawing)
pydm_drawing.alarmSensitiveContent = alarm_sensitive_content
brush_before = pydm_drawing.brush.color().name()
signals.new_severity_signal.connect(pydm_drawing.alarmSeverityChanged)
signals.new_severity_signal.emit(PyDMWidget.ALARM_MAJOR)
brush_after = pydm_drawing.brush.color().name()
if alarm_sensitive_content:
assert brush_before != brush_after
else:
assert brush_before == brush_after
示例2: test_no_menu_with_one_file
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_no_menu_with_one_file(qtbot):
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
main_window.setWindowTitle("Related Display Button Test")
qtbot.addWidget(main_window)
button = PyDMRelatedDisplayButton(parent=main_window)
button.filenames = [test_ui_path]
qtbot.addWidget(button)
button._rebuild_menu()
assert button.menu() is None
示例3: set_font_size
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def set_font_size(self, old, new):
current_font = self.app.font()
current_font.setPointSizeF(current_font.pointSizeF()/old*new)
QApplication.instance().setFont(current_font)
for w in self.app.allWidgets():
w_c_f = w.font()
w_c_f.setPointSizeF(w_c_f.pointSizeF()/old*new)
w.setFont(w_c_f)
QTimer.singleShot(0, self.resizeForNewDisplayWidget)
示例4: test_press_without_filename
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_press_without_filename(qtbot):
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
main_window.setWindowTitle("Related Display Button Test")
qtbot.addWidget(main_window)
button = PyDMRelatedDisplayButton(parent=main_window)
qtbot.addWidget(button)
button._rebuild_menu()
qtbot.mouseRelease(button, Qt.LeftButton)
qtbot.wait(250)
assert "Form" not in QApplication.instance().main_window.windowTitle()
示例5: test_menu_goes_away_when_files_all_blank
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_menu_goes_away_when_files_all_blank(qtbot):
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
main_window.setWindowTitle("Related Display Button Test")
qtbot.addWidget(main_window)
button = PyDMRelatedDisplayButton(parent=main_window)
button.filenames = ["", ""]
button.titles = ["", ""]
qtbot.addWidget(button)
button._rebuild_menu()
assert button.menu() is None
示例6: setAppIcon
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def setAppIcon(self):
""" Set up the Qudi application icon.
"""
iconpath = 'artwork/logo/logo-qudi-'
self.appIcon = QIcon()
self.appIcon.addFile('{0}16x16.png'.format(iconpath), QSize(16, 16))
self.appIcon.addFile('{0}24x24.png'.format(iconpath), QSize(24, 24))
self.appIcon.addFile('{0}32x32.png'.format(iconpath), QSize(32, 32))
self.appIcon.addFile('{0}48x48.png'.format(iconpath), QSize(48, 48))
self.appIcon.addFile('{0}256x256.png'.format(iconpath),
QSize(256, 256))
QApplication.instance().setWindowIcon(self.appIcon)
示例7: test_label_alarms
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_label_alarms(qtbot, signals, alarm_severity, alarm_sensitive_content, alarm_sensitive_border):
"""
Test the widget's appearance changes according to changes in alarm severity.
Expectations:
1. The widget receives the correct alarm severity
2. The appearance changes to check for are the alarm content (alarm color), and the widget's border appearance, e.g.
solid, transparent, etc.
3. The alarm color and border appearance will change only if each corresponding Boolean flag is set to True
NOTE: This test depends on the default stylesheet having different values for 'color' for different alarm states of PyDMLabel.
Parameters
----------
qtbot : fixture
pytest-qt window for widget testing
signals : fixture
The signals fixture, which provides access signals to be bound to the appropriate slots
alarm_severity : int
The severity of an alarm (NONE, MINOR, MAJOR, INVALID, or DISCONNECTED)
alarm_sensitive_content : bool
True if the widget will change color accordingly to the alarm's severity; False if not
alarm_sensitive_border : bool
True if the widget's border will change color and thickness accordingly to the alarm's severity; False if not
"""
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
qtbot.addWidget(main_window)
pydm_label = PyDMLabel(parent=main_window, init_channel="ca://FOOO")
qtbot.addWidget(pydm_label)
pydm_label.alarmSensitiveContent = alarm_sensitive_content
pydm_label.alarmSensitiveBorder = alarm_sensitive_border
signals.connection_state_signal.connect(pydm_label.connectionStateChanged)
signals.connection_state_signal.emit(True)
signals.new_severity_signal.connect(pydm_label.alarmSeverityChanged)
initial_severity = pydm_label._alarm_state
option = QStyleOption()
option.initFrom(pydm_label)
before_color = option.palette.text().color().name()
signals.new_severity_signal.emit(alarm_severity)
assert pydm_label._alarm_state == alarm_severity
option = QStyleOption()
option.initFrom(pydm_label)
after_color = option.palette.text().color().name()
if alarm_sensitive_content and (alarm_severity != initial_severity):
assert after_color != before_color
else:
assert after_color == before_color
示例8: test_press_with_filename
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_press_with_filename(qtbot):
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
main_window.setWindowTitle("Related Display Button Test")
qtbot.addWidget(main_window)
button = PyDMRelatedDisplayButton(parent=main_window)
button.filenames = [test_ui_path]
qtbot.addWidget(button)
button._rebuild_menu()
qtbot.mouseRelease(button, Qt.LeftButton)
def check_title():
assert "Form" in QApplication.instance().main_window.windowTitle()
qtbot.waitUntil(check_title)
示例9: 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
示例10: closeEvent
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def closeEvent(self, event):
# Check whether or not to save project
if not self.project.saved:
# Offer save
if self.project.offer_save(self):
# Cancel has been clicked
event.ignore()
return
# Close editors
if self.editor.app_closing():
self.writeSettings(CONF) # write current window information to global settings object
# Close all open plots
# We don't want this at module scope here
import matplotlib.pyplot as plt # noqa
plt.close('all')
app = QApplication.instance()
if app is not None:
app.closeAllWindows()
event.accept()
else:
# Cancel was pressed when closing an editor
event.ignore()
示例11: test_menu_goes_away_when_files_removed
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def test_menu_goes_away_when_files_removed(qtbot):
QApplication.instance().make_main_window()
main_window = QApplication.instance().main_window
main_window.setWindowTitle("Related Display Button Test")
qtbot.addWidget(main_window)
button = PyDMRelatedDisplayButton(parent=main_window)
main_window.set_display_widget(button)
button.filenames = ["one.ui", "two.ui"]
button.titles = ["One", "Two"]
qtbot.addWidget(button)
button._rebuild_menu()
assert button.menu() is not None
button.filenames = []
button.titles = []
button._rebuild_menu()
assert button.menu() is None
示例12: qapplication
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def qapplication():
"""Either return a reference to an existing application instance
or create a new one
:return: A reference to the QApplication object
"""
app = QApplication.instance()
if app is None:
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
argv = sys.argv[:]
argv[0] = APPNAME # replace application name
# Workaround a segfault with the IPython console when using Python 3.5 + PyQt 5
# Without this using this fix the above combination causes a segfault when the IPython
# console is started
# The workaround mentioned in https://groups.google.com/forum/#!topic/leo-editor/ghiIN7irzY0
# is to ensure readline is imported before the QApplication object is created
if sys.version_info[0] == 3 and sys.version_info[1] == 5:
importlib.import_module("readline")
app = QApplication(argv)
app.setOrganizationName(ORGANIZATION)
app.setOrganizationDomain(ORG_DOMAIN)
app.setApplicationName(APPNAME)
app.setApplicationVersion(mantid_version_str())
# Spin up the usage service and set the name for the usage reporting
# The report is sent when the FrameworkManager kicks up
UsageService.setApplicationName(APPNAME)
return app
示例13: 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 str(cb.text())
return copy_qt, paste_qt
示例14: __init__
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def __init__(self, channel, address, protocol=None, parent=None):
super(PyDMConnection, self).__init__(parent)
self.protocol = protocol
self.address = address
self.connected = False
self.value = None
self.listener_count = 0
self.app = QApplication.instance()
示例15: __init__
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import instance [as 别名]
def __init__(self, target, executable=None, name=None,
extra_args=None, libs=None, cwd=None, env=None):
super(AsyncClient, self).__init__()
self.executable = executable or sys.executable
self.extra_args = extra_args
self.target = target
self.name = name or self
self.libs = libs
self.cwd = cwd
self.env = env
self.is_initialized = False
self.closing = False
self.context = zmq.Context()
QApplication.instance().aboutToQuit.connect(self.close)
# Set up the heartbeat timer.
self.timer = QTimer(self)
self.timer.timeout.connect(self._heartbeat)