Skip to content

D4P Exporter

Priyatham edited this page May 29, 2022 · 1 revision

Introduction

Delphi4Python Exporter is an offering to the people who doesn't have Delphi expertise but want to take advantage of Delphi IDE's GUI design capabilities. You can export the UI of both:

  • VCL applications
  • FMX applications

Most importantly you can take advantage of assigning empty event methods at design time. This reduces the tedious work of coding the events and their associated methods in the Python code.

Detailed guide to export UI of a GUI application

For a quick usage, please refer to the README: https://github.com/Embarcadero/Delphi4PythonExporter#usage

  • First step is to design the UI of the GUI application by placing all the components on the Form window.
  • On the menu bar, select Tools > Export to Python. We have two options here:
    • Export entire Project
    • Export selected Forms under the project

Export entire Project

When we export entire project, the Application Initialization will happen in a separate python file. Whereas, the logical implementation of the application will happen in other python files. For example, let's consider a minimal Multi-Device (FMX) application consisting of two forms. Say,

  • Project name: D4P_export_demo
  • Form1.pas: parent_window.pas
  • Form2.pas: child_window.pas

image

The Form images of the parent_window (Parent_Form) and child_window (Child_Form) are:

image image

  • Let's create an event method for OnClick event of the Press Me button on the Parent_Form.

image image

  • Then on double click on that my_buttonClick event, the code for it's event method gets created. Now, please type at least a single comment in it; image

  • The entered comment in the event method will make sure the method doesn't go away as we save the file. No need to write any run-time implementation code because we don't export the run-time implementation using the Delphi4PythonExporter yet. We have ideas to provide support to export the run-time code implementation from Delphi to Python codebase in future. The major here idea is to create event methods at design time to export them to python to reduce time and effort to create them manually in python.

  • Then we shall export the entire application project using Tools>Export to Python>Export Entire Current Project

image

  • Observe that the Application Main Form is set to parent_window.Parent_Form out of two available forms because we created it first. We have provided links to download and install DelphiVCL and/or DelphiFMX to use this exported application with those python packages.

As a result, Exporter creates 3 Python files and 2 form files:

  • D4P_export_demo.py file that contains the Application Initialization
  • parent_window.py file and it's form file parent_window.pyfmx
  • child_window.py file and it's form file child_window.pyfmx

The form file extension for VCL applications is .pydfm. Now it's your turn to create assign a functionality to event method my_buttonClick in parent_window.py file. First it'll be an empty event method with pass in it as part of the export.

image

  • The streamer will load the events and properties from the form files automatically as we run the python code.

Here, as an example we're assigning the text in the Edit box of parent_window to the empty string of a label in child_window as we click on the Press Me button.

image

Find more explanation about how to create GUI application using DelphiFMX and DelphiVCL, please check out our ebook: https://embt.co/PythonGUIBundle.

Export selected Forms

  • We can export all the selected forms using this option.
  • This option will not create a separate Application initialization python file.
  • If you're creating individual different applications in separate delphi(.pas) files, then you can have initialization ticked for all of them
  • Here, we're creating a single multi window application. So, we can just tick the Initialize option only for the MainForm (Parent_Form).

image

  • Now you can observe that there's no separate Application initialization file and it happens as part of the parent_window.py file.

image