mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
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
1 changed files with 19 additions and 4 deletions
|
@ -233,11 +233,23 @@ def run():
|
||||||
"Please notify support of this error:\n\n"+
|
"Please notify support of this error:\n\n"+
|
||||||
traceback.format_exc())
|
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
|
global mw
|
||||||
|
|
||||||
|
if argv is None:
|
||||||
|
argv = sys.argv
|
||||||
|
|
||||||
# parse args
|
# parse args
|
||||||
opts, args = parseArgs(sys.argv)
|
opts, args = parseArgs(argv)
|
||||||
opts.base = opts.base or ""
|
opts.base = opts.base or ""
|
||||||
opts.profile = opts.profile or ""
|
opts.profile = opts.profile or ""
|
||||||
|
|
||||||
|
@ -250,7 +262,7 @@ def _run():
|
||||||
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
||||||
|
|
||||||
# create the app
|
# create the app
|
||||||
app = AnkiApp(sys.argv)
|
app = AnkiApp(argv)
|
||||||
QCoreApplication.setApplicationName("Anki")
|
QCoreApplication.setApplicationName("Anki")
|
||||||
if app.secondInstance():
|
if app.secondInstance():
|
||||||
# we've signaled the primary instance, so we should close
|
# 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
|
# load the main window
|
||||||
import aqt.main
|
import aqt.main
|
||||||
mw = aqt.main.AnkiQt(app, pm, args)
|
mw = aqt.main.AnkiQt(app, pm, args)
|
||||||
app.exec_()
|
if exec:
|
||||||
|
app.exec()
|
||||||
|
else:
|
||||||
|
return app
|
||||||
|
|
Loading…
Reference in a new issue