本文整理汇总了Python中qtpy.QtWidgets.QApplication.topLevelWidgets方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.topLevelWidgets方法的具体用法?Python QApplication.topLevelWidgets怎么用?Python QApplication.topLevelWidgets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QApplication
的用法示例。
在下文中一共展示了QApplication.topLevelWidgets方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_syspath
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def test_get_syspath(ipyconsole, qtbot):
"""Test that showing sys.path contents is working as expected."""
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
# Add a new entry to sys.path
with qtbot.waitSignal(shell.executed):
tmp_dir = tempfile.mkdtemp()
shell.execute("import sys, tempfile; sys.path.append('%s')" % tmp_dir)
# Ask for sys.path contents
with qtbot.waitSignal(shell.sig_show_syspath):
shell.get_syspath()
# Get sys.path contents from the generated widget
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, CollectionsEditor):
syspath_contents = w.get_value()
qtbot.keyClick(w, Qt.Key_Enter)
# Assert that our added entry is part of sys.path
assert tmp_dir in syspath_contents
# Remove temporary directory
try:
os.rmdir(tmp_dir)
except:
pass
示例2: open_file_in_editor
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def open_file_in_editor(main_window, fname, directory=None):
"""Open a file using the Editor and its open file dialog"""
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, QFileDialog):
if directory is not None:
w.setDirectory(directory)
input_field = w.findChildren(QLineEdit)[0]
input_field.setText(fname)
QTest.keyClick(w, Qt.Key_Enter)
示例3: close_message_box
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def close_message_box(qtbot):
"""
Closes QMessageBox's that can appear when testing.
You can use this with QTimer to close a QMessageBox.
Before calling anything that may show a QMessageBox call:
QTimer.singleShot(1000, lambda: close_message_box(qtbot))
"""
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, QMessageBox):
qtbot.keyClick(w, Qt.Key_Enter)
示例4: find_all_windows_that_are_savable
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def find_all_windows_that_are_savable():
"""
Finds all windows and then checks if they have an encoder, if they do return them in a list of windows and encoders.
:return: List of Lists of Windows and Encoders; Window at index 0 and Encoder at index 1 in each sub-list.
"""
# Get all top level widgets and check if they have an encoder
list_of_windows_and_encoder = []
windows = QApplication.topLevelWidgets()
for window in windows:
encoder_class = EncoderFactory.find_encoder(window)
if encoder_class is not None:
list_of_windows_and_encoder.append((window, encoder_class))
return list_of_windows_and_encoder
示例5: close_save_message_box
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def close_save_message_box(qtbot):
"""
Closes QMessageBox's for save that can appear when testing.
You can use this with QTimer to close a QMessageBox for save functions.
Before calling anything that may show a QMessageBox for save call:
QTimer.singleShot(1000, lambda: close_save_message_box(qtbot))
"""
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, QMessageBox):
if os.name == 'nt':
qtbot.keyClick(w, Qt.Key_Enter)
else:
qtbot.keyClick(w, Qt.Key_N, modifier=Qt.ShiftModifier)
示例6: test_get_env
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def test_get_env(ipyconsole, qtbot):
"""Test that showing env var contents is working as expected."""
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
# Add a new entry to os.environ
with qtbot.waitSignal(shell.executed):
shell.execute("import os; os.environ['FOO'] = 'bar'" )
# Ask for os.environ contents
with qtbot.waitSignal(shell.sig_show_env):
shell.get_env()
# Get env contents from the generated widget
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, CollectionsEditor):
env_contents = w.get_value()
qtbot.keyClick(w, Qt.Key_Enter)
# Assert that our added entry is part of os.environ
env_contents = listdict2envdict(env_contents)
assert env_contents['FOO'] == 'bar'
示例7: open_client_from_connection_info
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def open_client_from_connection_info(connection_info, qtbot):
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, KernelConnectionDialog):
w.cf.setText(connection_info)
qtbot.keyClick(w, Qt.Key_Enter)
示例8: find_widgets_of_type
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def find_widgets_of_type(self, type_name):
top_widgets = QApplication.topLevelWidgets()
return [x for x in top_widgets if type_name.lower() in str(type(x)).lower()]
示例9: assert_no_toplevel_widgets
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def assert_no_toplevel_widgets(self):
a = QApplication.topLevelWidgets()
self.assertEqual(len(a), 0, "Widgets are present in the QApplication: {}".format(a))
示例10: assert_widget_created
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def assert_widget_created(self):
self.assertGreater(len(QApplication.topLevelWidgets()), 0)
示例11: find_qt_toplevel_widget
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import topLevelWidgets [as 别名]
def find_qt_toplevel_widget(self, name):
all = QApplication.topLevelWidgets()
return [x for x in all if name.lower() in str(type(x)).lower()]