Porting ankiqml (MeeGo) app to Sailfish

I’d like to use Anki on Sailfish, but there is no app. I found this project and I’m wondering what the best way would be to port it to Sailfish.

Should I start from zero or fix all the errors in the existing project?
Thanks for your advice.

Sources are on CodeBerg


Current issue:

Day 3

  • related to the last error, @vlagged contacted me and explained where the error was. Actually, I had to git clone anki’s repository and exec following commands:
bash tools/install-n2
# Added ~/.cargo/bin to my PATH
# build anki running
./run

Day 2

  • I finally got python working thanks to nephros. Now I need to figure out how to move from PySide to pyotherside.
  • As the project is really, really old I had to migrate to python3. There are still some jobs to do.
  • I imported a new version of anki, but I’m not sure if it was a good idea. Future will confirm. I’m now stuck with this error:
[D] onError:25 - ERROR - unhandled error received: Cannot import module: ankiqml.py (Traceback (most recent call last):

  File "/usr/share/harbour-anki/src/ankiqml.py", line 16, in <module>
    from anki.sync import SyncClient, HttpSyncServerProxy, copyLocalMedia

  File "/usr/share/harbour-anki/src/anki/sync.py", line 4, in <module>
    from anki import sync_pb2

ImportError: cannot import name 'sync_pb2' from 'anki' (unknown location)
)
[D] onError:25 - ERROR - unhandled error received: Function not found: 'ankiqml.decksModel' (Traceback (most recent call last):

  File "<string>", line 1, in <module>

NameError: name 'ankiqml' is not defined
)

Day 1

  • I renamed the project and it’s now called harbour-anki
  • I got it to compile and is able to run on the emulator. Sources are here. I’ll merge to the master branch once everything is working. Afterwards, I’ll publish to OpenRepos/Chum

Day 0

  • Finally, I decided to port ankiqml to Sailfish. At least, some code is already written and it’s allow me to discover from zero how QML+Python works
6 Likes

If it’s a pure qml app try just changing ListView to SilicaListView etc, should save you a lot of time than building from scratch

2 Likes

More info: https://forum.sailfishos.org/t/native-anki-app/21421

1 Like

I’ll use this topic as a logbook :slight_smile:

4 Likes

Day 4

anki is somehow working, but I get this error:

[D] unknown:0 - Got library name:  "/usr/lib/qt5/qml/io/thp/pyotherside/libpyothersideplugin.so"
[D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"/usr/share/harbour-anki/src/ankiqml.py\", line 17, in <module>\n    import sync\n\n  File \"/usr/share/harbour-anki/src/sync.py\", line 4, in <module>\n    from anki import sync_pb2\n\n  File \"/usr/share/harbour-anki/src/anki/sync_pb2.py\", line 7, in <module>\n    from google.protobuf import descriptor as _descriptor\n\nModuleNotFoundError: No module named 'google'\n"
[D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"<string>\", line 1, in <module>\n\nNameError: name 'ankiqml' is not defined\n"
[D] onError:25 - ERROR - unhandled error received: Cannot import module: ankiqml.py (Traceback (most recent call last):

  File "/usr/share/harbour-anki/src/ankiqml.py", line 17, in <module>
    import sync

  File "/usr/share/harbour-anki/src/sync.py", line 4, in <module>
    from anki import sync_pb2

  File "/usr/share/harbour-anki/src/anki/sync_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor

ModuleNotFoundError: No module named 'google'
)
[D] onError:25 - ERROR - unhandled error received: Function not found: 'ankiqml.decksModel' (Traceback (most recent call last):

  File "<string>", line 1, in <module>

NameError: name 'ankiqml' is not defined
)

What interests me are these lines:

    from google.protobuf import descriptor as _descriptor
ModuleNotFoundError: No module named 'google'

Now I need to figure out what that means, because protobuf is installed.

I finally installed python3-pip on the emulator and get some new errors:

ImportError: cannot import name 'MethodType' from partially initialized module 'types' (most likely due to a circular import) (/usr/share/harbour-anki/src/types.py)

so you installed google with pip?

I did:
pip install protobuf

1 Like

Is your source up in a repo so we can look at it?

Depending on how you did the pip install, the libraries may not be available at import. Did you do pip install as root or user? If you install for an app, unless doing the install with the rpm, then you need to make sure the library is in the application scope:

/usr/share/my-app/lib or some such.

protobuf has been installed as root. All sources are here.

Ok. It should be available. Though you shouldn’t do that :slight_smile: Still, try making all your import declarations in the main python file that is imported with the python handler in QML.

As a note from my experience, it’s easiest to have all your dependancies in one folder in the application scope. I don’t use pip since it’s a pita but settle on the libs at a particular version and install them into the application scope.

I finally managed to move the ankiqml.py file to the root of the project (the parent folder of the src folder). I also moved the generated Anki folder to /usr/lib/python3.8/site-packages/, but now I’m facing a different issue.

[D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"<string>\", line 1, in <module>\n\nNameError: name 'ankiqml' is not defined\n"
[D] onError:26 - ERROR - unhandled error received: Cannot import module: ankiqml.py (Traceback (most recent call last):

  File "/usr/share/harbour-anki/ankiqml.py", line 17, in <module>
    from src import sync

  File "/usr/share/harbour-anki/src/sync.py", line 4, in <module>
    from anki import sync_pb2

  File "/usr/lib/python3.8/site-packages/anki/sync_pb2.py", line 12, in <module>
    _runtime_version.ValidateProtobufRuntimeVersion(

  File "/usr/lib/python3.8/site-packages/google/protobuf/runtime_version.py", line 106, in ValidateProtobufRuntimeVersion
    _ReportVersionError(

  File "/usr/lib/python3.8/site-packages/google/protobuf/runtime_version.py", line 50, in _ReportVersionError
    raise VersionError(msg)

google.protobuf.runtime_version.VersionError: Detected mismatched Protobuf Gencode/Runtime major versions when loading anki/sync.proto: gencode 6.31.1 runtime 5.29.5. Same major version is required. See Protobuf version guarantees at https://protobuf.dev/support/cross-version-runtime-guarantee.
)
[D] onError:26 - ERROR - unhandled error received: Function not found: 'ankiqml.decksModel' (Traceback (most recent call last):

  File "<string>", line 1, in <module>

NameError: name 'ankiqml' is not defined
)
What is interesting is this line:
google.protobuf.runtime_version.VersionError: Detected mismatched Protobuf Gencode/Runtime major versions when loading anki/sync.proto: gencode 6.31.1 runtime 5.29.5.
Same major version is required.
See Protobuf version guarantees at https://protobuf.dev/support/cross-version-runtime-guarantee.

Now, I need to figure out how to go ahead. I managed to compile/generate these files on my laptop, but the result isn’t compatible with the version installed on Sailfish. If I try to compile on Sailfish it requires Rust 1.81.0, but Sailfish provides 1.75.0-nightly :confused:

Ok, it wasn’t so difficult. I installed the same version of protobuf on my laptop, compiled anki again and it did the trick!
Now, let’s fix this error:

[D] unknown:0 - "PyOtherSide error: No module named 'ankiqml'"
[D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"<string>\", line 1, in <module>\n\nNameError: name 'ankiqml' is not defined\n"
[D] onError:26 - ERROR - unhandled error received: Cannot import module: ankiqml.py (No module named 'ankiqml')
[D] onError:26 - ERROR - unhandled error received: Function not found: 'ankiqml.decksModel' (Traceback (most recent call last):

  File "<string>", line 1, in <module>

NameError: name 'ankiqml' is not defined
)

EDIT: Actully, I still have the issue with the version of protobuf :frowning:

Finally, I decided to wait until the new version of Python is released as I struggle with the old version of protobuf provided by Sailfish.

At the meantime, I’ll work on the UI.

1 Like

I started to draw a wireframe, as it’s easier to start from scratch. I’d be grateful if someone with more experience could check my work and offer some advice before I start coding the new UI :slight_smile:

Here is the wireframe: Excalidraw Whiteboard

A picture is worth a thousand words, here are some news:

Once a user install harbour-anki and open it:

Once a deck is present:

4 Likes

wow very cool. thanks

Now, I need to figure out how to set a context menu inside a SilicaGridView! Stay tuned!

2 Likes

I’m not totally satisfied, but it’s better than nothing.


Let’s keep so and go ahead :wink:

2 Likes