Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Add a method to bring up Import File dialog #392

Merged
merged 3 commits into from
Jul 6, 2023
Merged

Add a method to bring up Import File dialog #392

merged 3 commits into from
Jul 6, 2023

Conversation

mikkkee
Copy link
Contributor

@mikkkee mikkkee commented Jun 17, 2023

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
Copy link
Owner

FooSoft commented Jun 27, 2023

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

@mikkkee
Copy link
Contributor Author

mikkkee commented Jul 2, 2023

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
Copy link
Owner

FooSoft commented Jul 5, 2023

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

@mikkkee
Copy link
Contributor Author

mikkkee commented Jul 5, 2023

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

Thank you! just committed the test

@FooSoft FooSoft merged commit 9f7dcca into FooSoft:master Jul 6, 2023
@mikkkee
Copy link
Contributor Author

mikkkee commented Jul 6, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants