Merge pull request #211 from krassowski/master
Allow to run App&GUI without entering the main event loop
This commit is contained in:
commit
fff49a1370
@ -233,11 +233,23 @@ def run():
|
||||
"Please notify support of this error:\n\n"+
|
||||
traceback.format_exc())
|
||||
|
||||
def _run():
|
||||
def _run(argv=None, exec=True):
|
||||
"""Start AnkiQt application or reuse an existing instance if one exists.
|
||||
|
||||
If the function is invoked with exec=False, the AnkiQt will not enter
|
||||
the main event loop - instead the application object will be returned.
|
||||
|
||||
The 'exec' and 'argv' arguments will be useful for testing purposes.
|
||||
|
||||
If no 'argv' is supplied then 'sys.argv' will be used.
|
||||
"""
|
||||
global mw
|
||||
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
# parse args
|
||||
opts, args = parseArgs(sys.argv)
|
||||
opts, args = parseArgs(argv)
|
||||
opts.base = opts.base or ""
|
||||
opts.profile = opts.profile or ""
|
||||
|
||||
@ -250,7 +262,7 @@ def _run():
|
||||
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
||||
|
||||
# create the app
|
||||
app = AnkiApp(sys.argv)
|
||||
app = AnkiApp(argv)
|
||||
QCoreApplication.setApplicationName("Anki")
|
||||
if app.secondInstance():
|
||||
# we've signaled the primary instance, so we should close
|
||||
@ -285,4 +297,7 @@ environment points to a valid, writable folder.""")
|
||||
# load the main window
|
||||
import aqt.main
|
||||
mw = aqt.main.AnkiQt(app, pm, args)
|
||||
app.exec_()
|
||||
if exec:
|
||||
app.exec()
|
||||
else:
|
||||
return app
|
||||
|
Loading…
Reference in New Issue
Block a user