Python on
Android
with Delphi FMX
The Cross Platform GUI Framework
Part 2
Jim McKeeth
Chief Developer Advocate
Embarcadero Technologies
jim.mckeeth@embarcadero.com
@JimMcKeeth
Slides, links & replay: blogs.embarcadero.com/?p=130176
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Agenda
• Introduction to Delphi FMX
• Architecture and platforms
• Installing and using Delphi FMX for Python
• Demonstrations & Code
• Python on Android
• Going Beyond - Mixing Delphi & Python
• More information, Next steps, Q&A
Slides, links & replay: blogs.embarcadero.com/?p=130176
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
About Jim McKeeth
● Chief Developer Advocate & Engineer for Embarcadero
● Long time software developer
○ Delphi, C/C++, Python, Java, JavaScript, Ruby, etc.
● Invented and patented pattern and swipe to unlock
○ e.g. US Patents # 8352745 & 6766456
● Built thought controlled drone with Google Glass and
wireless EEG headset
● Contributor to Internet of Things and Data Analytics Handbook
● Blogger, podcaster, conference speaker, webinar host, etc.
● Twitter, TikTok, YouTube, etc. @JimMcKeeth
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
I’ll do my best not to assume too much familiarity with either
Delphi or Python, but also include code and technical details.
Copyright © 2022 by Embarcadero, an Idera company Delphi for 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.
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Dissecting the Technology Stacks
Python Delphi
Visual Component
Delphi VCL
Library (VCL)
for Python
An interpreted high-level A compiled general-purpose
general-purpose programming stack (IDE +
programming language. Compiler + Libraries)
Introduced in 1991 as the Delphi FMX FireMonkey introduced in 1995 as the
successor to ABC. for Python (FMX) successor to Turbo Pascal.
Delphi Library for
Windows GUI
development
Python module for
Windows GUI development. Python4Delphi
Delphi Library for
Python module for cross-platform GUI
cross platform GUI development
development.
Open-source bidirectional
bridge combining Delphi
and Python
Open source.
Free to use, Free and
modify, and commercial
redistribute. licenses with
source.
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
The Cross-Platform
FMX 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
(nestable & styleable)
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Getting Started with
Delphi FMX for Python
Rich GUI Framework for Python
on Windows, Mac, Linux, & Android
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Delphi for Python
d in
e r e
v
Co art 1 Delphi VCL for Python Delphi FMX for Python
P
● Windows 32-bit and 64-bit only ● Uses GPU for custom rendering
● Windows 8.1 through Windows 11 ● Multi-platform for Windows, Linux,
○ (Earlier versions may work, but not supported.) Android, and Mac OS
● Based on native Windows components ● Higher level of abstraction
● Includes Windows Handles, Messages, ● Platform services simplifies behaviors
Accessibility, etc.
● Styling system
● Styling system
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
○ github.com/Embarcadero/DelphiFMX4Python
○ pypi.org/project/delphifmx/
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Hello Delphi FMX for Python
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Hello World
from delphifmx import *
The simplest example
Application.Initialize() Configure the Application
Application.Title = "Hello Delphi FMX"
Application.MainForm = Form(Application)
Configure the form
Application.MainForm.SetProps(Caption = "Hello World")
msg = Label(Application.MainForm)
msg.SetProps(Parent = Application.MainForm, Create and configure the label
Text = "Hello Python from Delphi FMX",
Position = Position(PointF(20, 20)),
Width = 200)
Application.MainForm.Show()
Show the form and start the
Application.Run() # This is the main loop main loop
Application.MainForm.Destroy()
https://github.com/Embarcadero/DelphiFMX4Python/blob/main/samples/Simplest.py
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
from delphifmx import *
Hello World class HelloForm(Form): HelloForm is an FMX Form object
def __init__(self, owner):
An Object Oriented example self.SetProps(Caption = "Hello Python",
Position = "poScreenCenter", OnShow = self.__form_show)
self.hello = Label(self)
self.hello.SetProps(Parent = self,
Text = "Hello Python from Delphi FMX",
Position = Position(PointF(20, 20)), Width = 200)
self.clickme = Button(self)
self.clickme.SetProps(Parent = self, Text = "Click Me",
Position = Position(PointF(20, 50)), OnClick = self.__button_click) Button has an event handler assigned
def __form_show(self, sender):
self.SetProps(Width = 300, Height = 400)
def __button_click(self, sender):
self.hello.Text = "Thanks!" Event handler for button click
self.Width = 300
def main():
Application.Initialize()
Application.Title = "Hello Delphi FMX"
Application.MainForm = HelloForm(Application) Show the form and start the
Application.MainForm.Show() main loop
Application.Run()
Application.MainForm.Destroy()
if __name__ == '__main__':
main()
https://github.com/Embarcadero/DelphiFMX4Python/blob/main/samples/HelloDelphiFMX.py
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
from delphifmx import *
from os.path import exists
ToDo App class HelloForm(Form):
def __init__(self, owner):
Starting to get useful…. self.SetProps(Caption = "My To Do List", OnShow = self.__form_show, OnClose = self.__form_close)
self.hello = Label(self)
self.hello.SetProps(Parent = self, Text = "Next Do: ", Position = Position(PointF(20, 20)))
self.edit = Edit(self)
self.edit.SetProps(Parent = self, Position = Position(PointF(80,18)))
self.clickme = Button(self)
self.clickme.SetProps(Parent = self, Text = "Add",
Position = Position(PointF(190, 18)), Width = 80, OnClick = self.__button_click)
self.list = ListBox(self)
self.list.SetProps(Parent = self, Position = Position(PointF(20, 60)), Width = 250, OnClick = self.__list_item_click)
def __list_item_click(self, sender):
if (self.list.itemindex > -1):
self.list.items.delete(self.list.itemindex)
def __form_show(self, sender):
self.SetProps(Width = 300, Height = 320)
if exists("todo.txt"):
self.list.items.loadfromfile("todo.txt")
def __form_close(self, sender, action):
self.list.items.savetofile("todo.txt")
action = "caFree"
def __button_click(self, sender):
self.list.items.add(self.edit.text) Left main() off for space.
https://github.com/Embarcadero/DelphiFMX4Python/blob/main/samples/ToDoList.py self.edit.text = ""
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
With Style
And more controls
Load and apply style
StyleManager().SetStyle(
StyleStreaming().LoadFromFile("StyleFile.style"))
Embarcadero is working on a
free style bundle for Python
https://github.com/Embarcadero/DelphiFMX4Python/tree/main/samples/ControlsDesktop
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Desig 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
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Exported from Delphi’s FMX Designers to Python
with Styles
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Exported from Delphi’s FMX Designers to Python
with Styles and Animations
Native Delphi on Windows Pure Cross-Platform Python App
The spinning animations are just because I could…
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Deploying
Python to
Android
Yes, Python
on Android!
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
○ On GitHub github.com/Embarcadero/PythonFMXBuilder (alpha?)
○ 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….
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
github.com/Embarcadero/PythonFMXBuilder
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Going Further…
Exploring the
Delphi for Python
Bridge
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Customizing
Python on
Android
Take your
app further
with Delphi
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
○ github.com/pyscripter/python4delphi
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Documentation and
Library References
● Main Delphi documentation
○ Main docwiki.embarcadero.com/RADStudio/en/
○ VCL docwiki.embarcadero.com/RADStudio/en/VCL_Overview
○ FMX docwiki.embarcadero.com/RADStudio/en/FireMonkey
● Library Reference
○ Main docwiki.embarcadero.com/Libraries/en/
○ VCL docwiki.embarcadero.com/Libraries/en/Vcl
○ FMX docwiki.embarcadero.com/Libraries/en/FMX
● Delphi prefixes type names with a “T”
○ TEdit in Delphi is an Edit in Python
○ It is just a naming convention
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
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/
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Next Steps
● Install Delphi FMX for Python github.com/Embarcadero/DelphiFMX4Python
○ See the samples, Star the Repository, file issues, and make feature requests
● Read the blog post (links, replays) blogs.embarcadero.com/?p=130176
● See part 1 on Delphi VCL blogs.embarcadero.com/?p=128183
● Start a 30-day Delphi trial embarcadero.com/products/delphi/start-for-free
● Subscribe on YouTube youtube.com/c/EmbarcaderoTechnologies
● Follow us on Twitter twitter.com/embarcaderotech
● Like us on Facebook facebook.com/embarcaderotech
● Follow us on LinkedIn linkedin.com/company/embarcadero-technologies
● Read our blog pythongui.org
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python
Python on
Android
with Delphi FMX
The Cross Platform GUI Framework
Part 2
Q&A
Jim McKeeth
Chief Developer Advocate
Embarcadero Technologies
jim.mckeeth@embarcadero.com
@JimMcKeeth
Slides, links & replay: blogs.embarcadero.com/?p=130176
Copyright © 2022 by Embarcadero, an Idera company Delphi for Python