beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.66k stars 372 forks source link

Add support for Kivy, pygame, pyqt, pyside as alternative GUI framework targetting Android and iOS #1484

Open bin-san opened 1 year ago

bin-san commented 1 year ago

What is the problem or limitation you are having?

Any thoughts about adding those alternatives? Because briefcase is a packaging utility... I think it should be able to package any python package (including GUIs) to any platform. What do think? Will briefcase ever support those? Because they already run on Android using their own packaging tool called "python-for-android", adding those alternatives to briefcase seems extremely feasible!?

Describe the solution you'd like

GUI Libraries like kivy, pygame uses a surface as a canvas and draw their stuffs. What about NativeActivity in Android? We can use the surface of NativeActivity as a drawing board for those libraries. Packaging tools like python-for-android does the same.

Describe alternatives you've considered

To be clear.. kivy is a mature framework. But it's packaging tool python-for-android follows a horrible strategy by cythonizing whole python and kivy and everything it finds.... taking hours to compile an apk that too crashes on start up... Frustration!!

I adore beeware for it's extremely fast compile time and it's strategy of precompiled binaries.

I would like to see these two work together on Android where I would have versatility of kivy and powerful packaging utility of briefcase.

Additional context

No response

bin-san commented 1 year ago

How I think we can achieve this:

  1. Creating a simple NativeActivity App which uses A small C program to draw a line on the NativeActivity.
  2. Finding the way to give kivy the NativeActivity as the surface, it will draw on.
  3. Compiling kivy for arm (kivy is open source, so we will have C source code for the parts that is written in C)
  4. Adding all the previous pieces together and combine them to an App.
freakboy3742 commented 1 year ago

First off - we're definitely in support of any changes that would broaden the list of GUI toolkits that Briefcase can support. We're obviously very fond of Toga, but Briefcase is by design not Toga specific.

That said Kivy, Pygame, PyQt and PySide all have very different needs when it comes to iOS/Android packaging.

Kivy clearly can run on iOS and Android; however, I haven't investigated what changes would be needed (on the part of Kivy, Chaquopy, or Briefcase) to make this work.

Qt can apparently run on iOS and Android, but I've never seen an example of it working. (I will also admit that I haven't looked very hard). PySide and PyQt are another story entirely - I haven't seen any evidence that PySide or PyQt can work on iOS or Android. Again - I'm happy to be proven wrong on this front.

I've seen suggestions that PyGame can be made to work on Android with some unofficial patches; but I haven't seen how that is meant to be deployed. I haven't seen anything comparable for Pygame on iOS; however, as you have noted, Pygame is essentially a "draw on a bitmap canvas" API, so solving the iOS problem seems possible.

As for how to tackle this from a technical perspective - each library has very distinct needs, so the approaches will be different. However, what Briefcase encodes is a basic interface: a set of requirements for what an "app" must look like. Fundamentally, this is "a module with a main"; on mobile, it adds an additional requirement of defining a class for OS-level app integration - a UIApplicationDelegate on iOS, and an implementation of an IPythonApp class on Android. Beyond that, it's up to the app. Briefcase provides mechanisms for building and deploy binary wheels, so it should be possible to produce iOS and Android wheels for Pygame, Kivy etc; and, more fundamentally, the bridging libraries (like PyObjUs and PyJNIus used by Kivy).

If you want to tackle integration with any of these GUI libraries, go right ahead. However, be aware that we will be very limited in what support we can provide on the "other" side of the fence. We know almost nothing about Kivy, PyGame, etc; so we're not going to be able to provide much advice on how to resolve issues with Kivy/PyGame internals. What we can advise on is what Briefcase is doing or can do.