Fix previous commit with version check for Anki and Qt
This commit is contained in:
parent
9e214e90e5
commit
14a8a84150
@ -1619,7 +1619,7 @@ corresponding to when the API was available for use.
|
|||||||
|
|
||||||
#### `guiImportFile`
|
#### `guiImportFile`
|
||||||
|
|
||||||
* Invokes the *Import... (Ctrl+Shift+I)* dialog with an optional file path. Brings up the dialog for user to review the import. Supports all file types that Anki supports. Brings open file dialog if no path is provided. Forward slashes must be used in the path on Windows.
|
* Invokes the *Import... (Ctrl+Shift+I)* dialog with an optional file path. Brings up the dialog for user to review the import. Supports all file types that Anki supports. Brings open file dialog if no path is provided. Forward slashes must be used in the path on Windows. Only supported for Anki 2.1.52+.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><i>Sample request:</i></summary>
|
<summary><i>Sample request:</i></summary>
|
||||||
|
@ -41,7 +41,6 @@ from anki.exporting import AnkiPackageExporter
|
|||||||
from anki.importing import AnkiPackageImporter
|
from anki.importing import AnkiPackageImporter
|
||||||
from anki.notes import Note
|
from anki.notes import Note
|
||||||
from anki.errors import NotFoundError
|
from anki.errors import NotFoundError
|
||||||
from aqt.import_export.importing import import_file, prompt_for_file_then_import
|
|
||||||
from aqt.qt import Qt, QTimer, QMessageBox, QCheckBox
|
from aqt.qt import Qt, QTimer, QMessageBox, QCheckBox
|
||||||
|
|
||||||
from .web import format_exception_reply, format_success_reply
|
from .web import format_exception_reply, format_success_reply
|
||||||
@ -1858,19 +1857,35 @@ class AnkiConnect:
|
|||||||
"""
|
"""
|
||||||
Open Import File (Ctrl+Shift+I) dialog with provided file path.
|
Open Import File (Ctrl+Shift+I) dialog with provided file path.
|
||||||
If no path is given, the user will be prompted to select a file.
|
If no path is given, the user will be prompted to select a file.
|
||||||
|
Only supported from Anki version >=2.1.52
|
||||||
|
|
||||||
path: string
|
path: string
|
||||||
import file path, note on Windows you must use forward slashes.
|
import file path, note on Windows you must use forward slashes.
|
||||||
"""
|
"""
|
||||||
|
if anki_version >= (2, 1, 52):
|
||||||
|
from aqt.import_export.importing import import_file, prompt_for_file_then_import
|
||||||
|
else:
|
||||||
|
raise Exception('guiImportFile is only supported from Anki version >=2.1.52')
|
||||||
|
|
||||||
|
if hasattr(Qt, 'WindowStaysOnTopHint'):
|
||||||
|
# Qt5
|
||||||
|
WindowOnTopFlag = Qt.WindowStaysOnTopHint
|
||||||
|
elif hasattr(Qt, 'WindowType') and hasattr(Qt.WindowType, 'WindowStaysOnTopHint'):
|
||||||
|
# Qt6
|
||||||
|
WindowOnTopFlag = Qt.WindowType.WindowStaysOnTopHint
|
||||||
|
else:
|
||||||
|
# Unsupported, don't try to bring window to top
|
||||||
|
WindowOnTopFlag = None
|
||||||
|
|
||||||
# Bring window to top for user to review import settings.
|
# Bring window to top for user to review import settings.
|
||||||
|
if WindowOnTopFlag is not None:
|
||||||
try:
|
try:
|
||||||
# [Step 1/2] set always on top flag, show window (it stays on top for now)
|
# [Step 1/2] set always on top flag, show window (it stays on top for now)
|
||||||
self.window().setWindowFlags(self.window().windowFlags() | Qt.WindowStaysOnTopHint)
|
self.window().setWindowFlags(self.window().windowFlags() | WindowOnTopFlag)
|
||||||
self.window().show()
|
self.window().show()
|
||||||
finally:
|
finally:
|
||||||
# [Step 2/2] clear always on top flag, show window (it doesn't stay on top anymore)
|
# [Step 2/2] clear always on top flag, show window (it doesn't stay on top anymore)
|
||||||
self.window().setWindowFlags(self.window().windowFlags() & ~Qt.WindowStaysOnTopHint)
|
self.window().setWindowFlags(self.window().windowFlags() & ~WindowOnTopFlag)
|
||||||
self.window().show()
|
self.window().show()
|
||||||
|
|
||||||
if path is None:
|
if path is None:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from conftest import ac, wait_until, \
|
from conftest import ac, anki_version, wait_until, \
|
||||||
close_all_dialogs_and_wait_for_them_to_run_closing_callbacks, \
|
close_all_dialogs_and_wait_for_them_to_run_closing_callbacks, \
|
||||||
get_dialog_instance
|
get_dialog_instance
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ def test_guiDeckOverview(setup):
|
|||||||
|
|
||||||
|
|
||||||
def test_guiImportFile(setup):
|
def test_guiImportFile(setup):
|
||||||
|
if anki_version >= (2, 1, 52):
|
||||||
ac.guiImportFile()
|
ac.guiImportFile()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user