FooSoft / anki-connect

Anki plugin to expose a remote API for creating flash cards.
https://foosoft.net/projects/anki-connect/
Other
1.92k stars 218 forks source link

Add a method to bring up Import File dialog #392

Closed mikkkee closed 1 year ago

mikkkee commented 1 year ago

Hi,

Thanks for this great plugin! Hope you can have a look at this PR when you have a moment.

Currently AnkiConnect only supports importing of apkg file. This PR adds the support to import all file types by adding a GUI action to bring up the "Import... (Ctrl+Shift+I)" dialog.

If a path is provided, it brings up an "Import File" window with provided file. If no path is provided, it brings up select file window followed by "Import File" window.

To avoid being overlooked by the user, Anki window is brought to front in this action.

See below screenshot for the "Import File" window brought up by the following command in PowerShell.

(Invoke-RestMethod -Uri http://localhost:8765 -Method Post -Body '{"action": "guiImportFile", "version": 6, "params": {"path": "C:/Users/Downloads/anki-import.txt"}}')

image

Thanks a lot.

Please kindly let me know if any comments.

FooSoft commented 1 year ago

Looks good, could you please add a test that just calls this API?

mikkkee commented 1 year ago

Looks good, could you please add a test that just calls this API?

Hi thanks for your comments but I'm not sure how to run tests for an Anki plugin. Does it work if I simply add the following function to /tests/test_graphical.py ?

def test_guiImportFile(setup):
    ac.guiImportFile()
FooSoft commented 1 year ago

Yep, assuming that passes, something like that should be just fine!

mikkkee commented 1 year ago

Yep, assuming that passes, something like that should be just fine!

Thank you! just committed the test

mikkkee commented 1 year ago

oops looks it breaks the test, weird because it worked when I loaded the plugin locally

 plugin/__init__.py:44: in <module>
    from aqt.import_export.importing import import_file, prompt_for_file_then_import
E   ModuleNotFoundError: No module named 'aqt.import_export'

Looks it's due to version, i.e., Anki 2.1.45 doesn't have this aqt.import_export folder yet

Another error is from Qt.WindowStaysOnTopHint which should be Qt.WindowType.WindowStaysOnTopHint in Qt6.