|
41 | 41 | from anki.importing import AnkiPackageImporter |
42 | 42 | from anki.notes import Note |
43 | 43 | from anki.errors import NotFoundError |
44 | | -from aqt.import_export.importing import import_file, prompt_for_file_then_import |
45 | 44 | from aqt.qt import Qt, QTimer, QMessageBox, QCheckBox |
46 | 45 |
|
47 | 46 | from .web import format_exception_reply, format_success_reply |
@@ -1858,20 +1857,36 @@ def guiImportFile(self, path=None): |
1858 | 1857 | """ |
1859 | 1858 | Open Import File (Ctrl+Shift+I) dialog with provided file path. |
1860 | 1859 | If no path is given, the user will be prompted to select a file. |
| 1860 | + Only supported from Anki version >=2.1.52 |
1861 | 1861 |
|
1862 | 1862 | path: string |
1863 | 1863 | import file path, note on Windows you must use forward slashes. |
1864 | 1864 | """ |
| 1865 | + if anki_version >= (2, 1, 52): |
| 1866 | + from aqt.import_export.importing import import_file, prompt_for_file_then_import |
| 1867 | + else: |
| 1868 | + raise Exception('guiImportFile is only supported from Anki version >=2.1.52') |
| 1869 | + |
| 1870 | + if hasattr(Qt, 'WindowStaysOnTopHint'): |
| 1871 | + # Qt5 |
| 1872 | + WindowOnTopFlag = Qt.WindowStaysOnTopHint |
| 1873 | + elif hasattr(Qt, 'WindowType') and hasattr(Qt.WindowType, 'WindowStaysOnTopHint'): |
| 1874 | + # Qt6 |
| 1875 | + WindowOnTopFlag = Qt.WindowType.WindowStaysOnTopHint |
| 1876 | + else: |
| 1877 | + # Unsupported, don't try to bring window to top |
| 1878 | + WindowOnTopFlag = None |
1865 | 1879 |
|
1866 | 1880 | # Bring window to top for user to review import settings. |
1867 | | - try: |
1868 | | - # [Step 1/2] set always on top flag, show window (it stays on top for now) |
1869 | | - self.window().setWindowFlags(self.window().windowFlags() | Qt.WindowStaysOnTopHint) |
1870 | | - self.window().show() |
1871 | | - finally: |
1872 | | - # [Step 2/2] clear always on top flag, show window (it doesn't stay on top anymore) |
1873 | | - self.window().setWindowFlags(self.window().windowFlags() & ~Qt.WindowStaysOnTopHint) |
1874 | | - self.window().show() |
| 1881 | + if WindowOnTopFlag is not None: |
| 1882 | + try: |
| 1883 | + # [Step 1/2] set always on top flag, show window (it stays on top for now) |
| 1884 | + self.window().setWindowFlags(self.window().windowFlags() | WindowOnTopFlag) |
| 1885 | + self.window().show() |
| 1886 | + finally: |
| 1887 | + # [Step 2/2] clear always on top flag, show window (it doesn't stay on top anymore) |
| 1888 | + self.window().setWindowFlags(self.window().windowFlags() & ~WindowOnTopFlag) |
| 1889 | + self.window().show() |
1875 | 1890 |
|
1876 | 1891 | if path is None: |
1877 | 1892 | prompt_for_file_then_import(self.window()) |
|
0 commit comments