本文整理汇总了Python中qtpy.QtWidgets.QApplication.exec_方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.exec_方法的具体用法?Python QApplication.exec_怎么用?Python QApplication.exec_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QApplication
的用法示例。
在下文中一共展示了QApplication.exec_方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def main():
from qtpy.QtCore import Qt, QCoreApplication
from qtpy.QtWidgets import QApplication
from qtpy import API
import hyperspyui.info
from hyperspyui.settings import Settings
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
# Need to set early to make QSettings accessible
QCoreApplication.setApplicationName("HyperSpyUI")
QCoreApplication.setOrganizationName("Hyperspy")
QCoreApplication.setApplicationVersion(hyperspyui.info.__version__)
# First, clear all default settings!
# TODO: This will cause a concurrency issue with multiple launch
Settings.clear_defaults()
# Setup default for single/multi-instance
settings = Settings(group="General")
settings.set_default('allow_multiple_instances', False)
if settings['allow_multiple_instances', bool]:
# Using multiple instances, get a new application
app = QApplication(sys.argv)
else:
# Make sure we only have a single instance
from hyperspyui.singleapplication import get_app
app = get_app('hyperspyui')
splash = get_splash()
log_file = _get_logfile()
if log_file:
sys.stdout = sys.stderr = log_file
else:
@contextmanager
def dummy_context_manager(*args, **kwargs):
yield
log_file = dummy_context_manager()
with log_file:
# Need to have import here, since QApplication needs to be called first
from hyperspyui.mainwindow import MainWindow
form = MainWindow(splash=splash)
if not settings['allow_multiple_instances', bool]:
if "pyqt" in API:
app.messageAvailable.connect(form.handleSecondInstance)
elif API == 'pyside':
app.messageReceived.connect(form.handleSecondInstance)
form.showMaximized()
form.splash.hide()
form.load_complete.emit()
# Ensure logging is OK
import hyperspy.api as hs
hs.set_log_level(LOGLEVEL)
app.exec_()
示例2: run
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def run():
import sys
from qtpy.QtWidgets import QApplication
def selection():
print('hello')
app = QApplication(sys.argv)
dialog = PeriodicTableDialog(None)
dialog.selectionChanged.connect(selection)
dialog.exec_()
print(dialog.selection())
app.exec_()
示例3: main
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def main(args=sys.argv):
app = QApplication(args)
widget = SpellCheckTextEdit('Type here')
widget.show()
widget.raise_()
return app.exec_()
示例4: test
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def test(nr):
if nr == 1:
MyMainWindow().start()
elif nr == 2:
MyDialog(None, True).start()
elif nr == 3:
app = QApplication(sys.argv)
w = WidgetWindow()
print (w)
app.exec_()
if nr == 4:
app = QApplication(sys.argv)
window = QMainWindow()
w = MyWidget(window)
print (w)
window.show()
app.exec_()
if nr == 5:
MyMainWindowWithMenu().start()
if nr == 6:
MyCombinationWindow().start()
示例5: open_in_window
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def open_in_window(widget_name, script):
"""
Displays a widget in a window.
:param widget_name: A qualified name of a widget, ie mantidqt.mywidget.MyWidget
:param script: A qualified name of a test function that can be run after the
widget is created. The test function must have the signature:
def test(widget):
...
where argument widget is an instance of the tested widget.
The test function can yield from time to time after which the widget can update itself.
This will make the test non-blocking and changes can be viewed as the script runs.
If the test yields an integer it is interpreted as the number of seconds to wait
until the next step.
"""
raw_input('Please attach the Debugger now if required. Press any key to continue')
setup_library_paths()
app = QApplication([""])
w = create_widget(widget_name)
w.setWindowTitle(widget_name)
w.show()
if script is not None:
try:
# If script is a generator script_iter allows non-blocking
# test execution
script_iter = iter(run_script(script, w))
pause_timer = QTimer()
pause_timer.setSingleShot(True)
def idle():
if not pause_timer.isActive():
try:
# Run test script until the next 'yield'
pause_sec = script_iter.next()
if pause_sec is not None:
# Start non-blocking pause in seconds
pause_timer.start(int(pause_sec * 1000))
except StopIteration:
pass
except:
traceback.print_exc()
timer = QTimer()
# Zero-timeout timer runs idle() between Qt events
timer.timeout.connect(idle)
timer.start()
except:
pass
sys.exit(app.exec_())
示例6: test
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def test():
""" """
app = QApplication([])
win = TourTestWindow()
win.show()
app.exec_()
示例7: xmax
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
@xmax.setter
def xmax(self, value):
xmin = self.ax1.get_xlim()[0]
self.ax1.set_xlim(xmin, value)
# ymin property
@property
def ymin(self):
return self.ax1.get_ylim()[0]
@ymin.setter
def ymin(self, value):
ymax = self.ax1.get_ylim()[1]
self.ax1.set_ylim(value, ymax)
# ymax property
@property
def ymax(self):
return self.ax1.get_ylim()[1]
@ymax.setter
def ymax(self, value):
ymin = self.ax1.get_ylim()[0]
self.ax1.set_ylim(ymin, value)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = PlotWidget()
w.show()
app.exec_()
示例8: ModalTester
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
class ModalTester(object):
"""
Helper class for testing modal widgets (dialogs).
"""
def __init__(self, creator, tester):
"""
Initialise ModalTester.
:param creator: Function without arguments that creates a modal widget. Can be a class name.
A modal widget must have exec_() method.
:param tester: A function taking a widget as its argument that does testing.
"""
self.app = QApplication.instance()
if self.app is None:
self.app = QApplication([''])
self.creator = creator
self.tester = tester
self.widget = None
self.timer = None
self.passed = False
def __call__(self):
"""
Initialise testing.
"""
try:
self.widget = self.creator()
except:
traceback.print_exc()
self.app.exit(0)
if self.widget is not None:
self.widget.exec_()
def _idle(self):
"""
This function runs every time in QApplication's event loop.
Call the testing function.
"""
modal_widget = self.app.activeModalWidget()
if modal_widget is not None:
if self.widget is modal_widget:
try:
self.tester(self.widget)
self.passed = True
except:
traceback.print_exc()
if modal_widget.isVisible():
modal_widget.close()
def start(self):
"""
Start this tester.
"""
self.timer = QTimer()
# Connecting self.idle to a QTimer with 0 time delay
# makes it called when there are no events to process
self.timer.timeout.connect(self._idle)
self.timer.start()
# This calls __call__() method
QTimer.singleShot(0, self)
# Start the event loop
self.app.exec_()
示例9: Exception
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
if hdu is None:
raise Exception("Could not make cutout. "
"Object may be out of the image's range.")
if self.session is not None:
iv = StandaloneImageViewer(hdu.data)
iv.setWindowFlags(iv.windowFlags() | Qt.Tool)
iv.show()
else:
import matplotlib.pyplot as plt
plt.imshow(hdu.data)
plt.show()
@menubar_plugin("Cutout Tool (JWST/NIRSpec MSA)")
def nIRSpec_cutout_tool(session, data_collection):
ex = NIRSpecCutoutTool(session)
return
@menubar_plugin("General Purpose Cutout Tool")
def general_cutout_tool(session, data_collection):
ex = GeneralCutoutTool(session)
return
if __name__ == "__main__":
app = QApplication(sys.argv)
ex1 = NIRSpecCutoutTool()
ex2 = GeneralCutoutTool()
sys.exit(app.exec_())
示例10: main
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def main():
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
示例11: main
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def main():
app = QApplication([])
main_window = MainWindow()
main_window.show()
app.exec_()
示例12: test
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def test():
"""Run conda packages widget test"""
app = QApplication([])
widget = TestWidget(None)
widget.show()
sys.exit(app.exec_())
示例13: new_figure_manager_given_figure
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def new_figure_manager_given_figure(num, figure):
"""
Create a new figure manager instance for the given figure.
"""
canvas = FigureCanvasQTAgg(figure)
manager = FigureManagerWorkbench(canvas, num)
return manager
if __name__ == '__main__':
# testing code
import numpy as np
qapp = QApplication([' '])
qapp.setAttribute(Qt.AA_UseHighDpiPixmaps)
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
qapp.setAttribute(Qt.AA_EnableHighDpiScaling, True)
x = np.linspace(0, 10*np.pi, 1000)
cx, sx = np.cos(x), np.sin(x)
fig_mgr_1 = new_figure_manager(1)
fig1 = fig_mgr_1.canvas.figure
ax = fig1.add_subplot(111)
ax.set_title("Test title")
ax.set_xlabel("$\mu s$")
ax.set_ylabel("Counts")
ax.plot(x, cx)
fig1.show()
qapp.exec_()
示例14: main
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exec_ [as 别名]
def main():
app = QApplication(sys.argv)
win = ManiWindow()
win.show()
sys.exit(app.exec_())