Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

Python on Android with Delphi FMX – The Cross Platform GUI Framework

python on android with delphi fmx the cross platform gui framework

Discover how Embarcadero’s new free Python modules bring the power and flexibility of Delphi’s GUI frameworks to Python GUI. VCL and FireMonkey (FMX) are mature graphical user interface libraries. VCL is primarily used for native Windows development, whereas FireMonkey provides a powerful and flexible GUI framework for Windows, Linux, macOS, and even Android.

In this webinar, we will introduce you to these new free Python modules and show you how to use them to create graphical user interfaces with Python. Part 2 will show you how to target Android GUI applications with Python! We recommend using a python android app builder software for cross-platform GUI framework creation so that your experience is smooth and you can maximize your python potential!

Who are you?

Python devs who want a nice GUI
● Python devs curious about Delphi
● Delphi devs who want to use Python
● Delphi devs curious about what’s new
● Other devs curious about Delphi & Python

It’s not a Competition

● Developers have multiple tools on their workbench
● It is about finding the right tool for each task
● Having specialized tools for different tasks doesn’t detract from favorite tools
● You can always find a specific task that another tool is better for, but no one tool is that best for all tasks.

What is Delphi for Python?

  • Set of free Python modules bringing Delphi’s GUI libraries to Python developers
    • Mature, feature rich, native & cross-platform
    • Does not require Delphi to use
  • Based on the open source Python4Delphi (same technology that powers the PyScripter IDE)
  • Available today on GitHub & PyPi
    • Currently in beta, but ready for use
  • DelphiVCL for Python supports Windows (32-bit & 64-bit)
  • DelphiFMX for Python adds Linux, Android, & Mac OS
  • Part of a bidirectional bridge between Delphi and Python

Dissecting the Technology Stacks

py1 6685678

FMX The Cross-Platform (FireMonkey Framework)

  • Takes advantage of GPU libraries to provide a hardware accelerated, rich user interface that is fast and looks great across multiple platforms:
    • Windows, macOS, iOS, Android, and Linux
    • Uses DirectX on Windows, OpenGL on Linux, OpenGL-ES on Android, and Metal on iOS and macOS
  • Similar to VCL, but not designed to be compatible
    • Designed as cross platform from the ground up
  • Integrated GPU effects, animations, and robust styling system
  • Platform services abstract the access to platform hardware and functionality to intelligently adapt the UI & UX to platform specifics
  • Very flexible component system – do more with fewer components

Delphi for Python

py2 1983293

Delphi FMX for Python Installation

  • Install via pip
    • pip install delphifmx
  • Supports:
    • Win32 x86, Win64 x86, Linux64 x86, Android64, Mac OS x64 (Intel) and Mac M1 (Arm) architectures
    • Python cp3.6, cp3.7, cp3.8, cp3.9 and cp3.10 (excluding cp3.6 on Linux and macOS)
  • Conda support:
    • Win x86 and x64 from Python cp3.6 to cp3.10
    • Linux x86_64 from Python cp3.7 to cp3.9 (Recommended!)
    • macOS not supported yet
  • Details and downloads

Hello World (The simplest example)

py3 6241807

https://github.com/Embarcadero/DelphiFMX4Python/blob/main/samples/Simplest.py

Hello World (An Object Oriented example)

py4 6954926

https://github.com/Embarcadero/DelphiFMX4Python/blob/main/samples/HelloDelphiFMX.py

ToDo App (Starting to get useful….)

py5 2447257

https://github.com/Embarcadero/DelphiFMX4Python/blob/main/samples/ToDoList.py

With Style (And more controls)

py6 5122681

https://github.com/Embarcadero/DelphiFMX4Python/tree/main/samples/ControlsDesktop

Design Your UI (in the Delphi IDE)

● Take full advantage of the Delphi IDE designers and property editors
● WYSIWYG preview with styles
● Export the form for use in Python then write Python code
● Just right-click and export with the IDE add-in
● Works with any Delphi edition requires no Object Pascal
github.com/Embarcadero/DelphiFMX4Python/tree/main/experts
Currently uses a binary .pydfm file, but text version coming

Exported from Delphi’s FMX Designers to Python (with Styles)

py7 3855907

Exported from Delphi’s FMX Designers to Python (with Styles and Animations)

py8 8718252

Deploying Python to Android… Yes, Python on Android! (The Architecture)

Fundamentals

  • Delphi FMX supports Android ARM64 as a target
  • The Python4Delphi library supports Android
  • Allows building Delphi app to run Python on Android

Solution

  • A pre-built Delphi application with Python enabled
  • User modifiable Python script payload that runs automatically
  • Automated tool to modify the Android Manifest and build final APK
    • Or resign modified APK manually

To Do

  • Live preview before deploying to Android
  • Bundling multiple Python scripts & modules
  • Customize icons, splash screens, loading, etc.
  • More testing, debugging, and your suggestions….

Running Python on Android

● Delphi compiles natively for Android
● The Python runtime is embedded into the app
● Python is dynamically interpreted and executed at runtime
● All of Delphi FMX for Python is available
● Supports additional Python modules
● Completely local – no network access necessary

py9 3509304

https://github.com/Embarcadero/PythonFMXBuilder

Combine Delphi and Python

  • The Python4Delphi library is a bidirectional bridge
  • Develop parts of your solution in Delphi, and part in Python
    • Play to the strengths of each
  • Merge them together into a single cohesive solution
  • Find samples, tutorials, and videos

Use Delphi to Create Native Python Modules

● Many Python modules are written in C/C++ and natively compiled
● Delphi also creates natively compiled Python modules via Python4Delphi
● Prototype rapidly in Python, and then create optimized modules in Delphi to clear bottlenecks
● Much like Python, Delphi code is focused on readability and clear structure and may be easier for you than using C/C++
● Augment your use of PyPy or Cython

Documentation and Library References

About PyScripter

● Popular open-source Python IDE sponsored by Embarcadero
● All the features expected in a modern Python IDE while being lightweight and very fast
● Natively compiled for Windows to use minimal memory with maximum performance
● Full Python debugging with remote debugging
● Integration with Python tools like PyLint, TabNanny, Profile, etc.
● Run or debug files from memory.
embarcadero.com/free-tools/pyscripter/free-download

About UltraEdit

  • High performance text editor for programmers.
  • Industry’s best large file handling: 10+ GB and beyond.
  • Syntax highlighting for nearly any language or data format.
  • Smart templates.
  • Hex editing. Column / block mode editing.
  • Part of Idera family of developer tools.
  • ultraedit.com/products/ultraedit

Next Steps

Interested in building Linux applications with FireMonkey? Try the Cross-Platform Development Framework, which can help you create & design apps in Delphi or C++ environments.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Director of Delphi Consulting for GDK Software USA. Many software related patents, including swipe and pattern unlock and search engines. First Silver and Gold Delphi badges on Stack Overflow Former Developer Advocate for Embarcadero Technologies. Long time fan of programming, especially with Delphi. Author, Podcaster/YouTuber, Improvisor, Public Speaker, Father, and Friend.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES