Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Modules/DelphiFMX/DelphiFMX.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library DelphiFMX;

uses
SysUtils,
Classes,
uMain in 'uMain.pas';

{$I ..\..\Source\Definition.Inc}

exports
// This must match the pattern "PyInit_[ProjectName]"
// So if the project is named DelphiFMX then
// the export must be PyInit_DelphiFMX
PyInit_DelphiFMX;
{$IFDEF MSWINDOWS}
{$E pyd}
{$ENDIF}
{$IFDEF LINUX}
{$SONAME 'DelphiFMX'}

{$ENDIF}

begin
end.

820 changes: 820 additions & 0 deletions Modules/DelphiFMX/DelphiFMX.dproj

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions Modules/DelphiFMX/TestFMX.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from DelphiFMX import *

class MainForm(Form):

def __init__(self, Owner):
self.Caption = "A FMX Form..."
self.SetBounds(10, 10, 500, 400)

self.lblHello = Label(self)
self.lblHello.SetProps(Parent=self, Text="Hello Python")
self.lblHello.SetBounds(10, 10, 300, 24)

self.edit1 = Edit(self)
self.edit1.SetProps(Parent=self)
self.edit1.SetBounds(10, 30, 250, 24)

self.button1 = Button(self)
self.button1.Parent = self
self.button1.SetBounds(270,24,100,30)
self.button1.Text = "Add"
self.button1.OnClick = self.Button1Click

self.lb1 = ListBox(self)
self.lb1.Parent = self
self.lb1.SetBounds(10,60,300,300)

self.OnClose = self.MainFormClose

def MainFormClose(self, Sender, Action):
Action.Value = caFree
Application.Terminate

def Button1Click(self, Sender):
self.lb1.Items.Add(self.edit1.Text)
self.edit1.Text = ""

def main():
Application.Initialize()
Application.Title = "MyDelphiApp"
f = MainForm(Application)
f.Show()
#FreeConsole()
Application.Run()

main()

56 changes: 56 additions & 0 deletions Modules/DelphiFMX/uMain.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
unit uMain;

interface

uses PythonEngine;

function PyInit_DelphiFMX: PPyObject; cdecl;

implementation

uses WrapDelphi, WrapDelphiFMX;

var
gEngine : TPythonEngine;
gModule : TPythonModule;
gDelphiWrapper : TPyDelphiWrapper;

// This must match the pattern "PyInit_[ProjectName]"
// So if the project is named DelphiFMX then
// the function must be PyInit_DelphiFMX
function PyInit_DelphiFMX: PPyObject;
begin
try
gEngine := TPythonEngine.Create(nil);
gEngine.AutoFinalize := False;
gEngine.UseLastKnownVersion := False;
// Adapt to the desired python version - Will only work with this version
gEngine.RegVersion := '3.9';
gEngine.DllName := 'python39.dll';

gModule := TPythonModule.Create(nil);
gModule.Engine := gEngine;
// This must match the ProjectName and the function name pattern
gModule.ModuleName := 'DelphiFMX';

gDelphiWrapper := TPyDelphiWrapper.Create(nil);
gDelphiWrapper.Engine := gEngine;
gDelphiWrapper.Module := gModule;

gEngine.LoadDll;
except
end;
Result := gModule.Module;
end;

initialization
gEngine := nil;
gModule := nil;
gDelphiWrapper := nil;
finalization
gEngine.Free;
gModule.Free;
gDelphiWrapper.Free;
end.


4 changes: 3 additions & 1 deletion Packages/Delphi/Delphi 10.4+/PythonFmx.dpk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ contains
WrapFmxShapes in '..\..\..\Source\fmx\WrapFmxShapes.pas',
WrapFmxStdCtrls in '..\..\..\Source\fmx\WrapFmxStdCtrls.pas',
WrapFmxTypes in '..\..\..\Source\fmx\WrapFmxTypes.pas',
WrapDelphiFmx in '..\..\..\Source\fmx\WrapDelphiFmx.pas';
WrapDelphiFmx in '..\..\..\Source\fmx\WrapDelphiFmx.pas',
WrapFmxEdit in '..\..\..\Source\fmx\WrapFmxEdit.pas',
WrapFmxListBox in '..\..\..\Source\fmx\WrapFmxListBox.pas';

end.
2 changes: 2 additions & 0 deletions Source/fmx/WrapDelphiFmx.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ implementation
WrapFireDac,
WrapFmxTypes,
WrapFmxStdCtrls,
WrapFmxEdit,
WrapFmxListBox,
WrapFmxActnList,
WrapFmxComCtrls,
WrapFmxDialogs,
Expand Down
105 changes: 105 additions & 0 deletions Source/fmx/WrapFmxEdit.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{$I ..\Definition.Inc}

unit WrapFmxEdit;

interface

uses
FMX.Edit, PythonEngine, WrapFmxTypes, WrapFmxControls;


type
TPyDelphiCustomEdit = class(TPyDelphiPresentedControl)
private
function GetDelphiObject: TCustomEdit;
procedure SetDelphiObject(const Value: TCustomEdit);
public
class function DelphiObjectClass: TClass; override;
// Properties
property DelphiObject: TCustomEdit read GetDelphiObject
write SetDelphiObject;
end;

TPyDelphiEdit = class(TPyDelphiCustomEdit)
private
function GetDelphiObject: TEdit;
procedure SetDelphiObject(const Value: TEdit);
public
class function DelphiObjectClass: TClass; override;
// Properties
property DelphiObject: TEdit read GetDelphiObject
write SetDelphiObject;
end;

implementation

uses
WrapDelphi;

{ Register the wrappers, the globals and the constants }
type
TEditRegistration = class(TRegisteredUnit)
public
function Name: string; override;
procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override;
end;

{ TEditRegistration }

procedure TEditRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
end;

function TEditRegistration.Name: string;
begin
Result := 'Edit';
end;

procedure TEditRegistration.RegisterWrappers(
APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomEdit);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiEdit);
end;

{ TPyDelphiCustomEdit }

class function TPyDelphiCustomEdit.DelphiObjectClass: TClass;
begin
Result := TCustomEdit;
end;

function TPyDelphiCustomEdit.GetDelphiObject: TCustomEdit;
begin
Result := TCustomEdit(inherited DelphiObject);
end;

procedure TPyDelphiCustomEdit.SetDelphiObject(const Value: TCustomEdit);
begin
inherited DelphiObject := Value;
end;

{ TPyDelphiEdit }

class function TPyDelphiEdit.DelphiObjectClass: TClass;
begin
Result := TEdit;
end;

function TPyDelphiEdit.GetDelphiObject: TEdit;
begin
Result := TEdit(inherited DelphiObject);
end;

procedure TPyDelphiEdit.SetDelphiObject(const Value: TEdit);
begin
inherited DelphiObject := Value;
end;

initialization
RegisteredUnits.Add(TEditRegistration.Create);

end.
133 changes: 133 additions & 0 deletions Source/fmx/WrapFmxListBox.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{$I ..\Definition.Inc}

unit WrapFmxListBox;

interface

uses
FMX.ListBox, WrapFmxTypes, WrapFmxControls, WrapFmxLayouts, PythonEngine;

type
TPyListBoxItem = class(TPyDelphiTextControl)
private
function GetDelphiObject: TListBoxItem;
procedure SetDelphiObject(const Value: TListBoxItem);
public
class function DelphiObjectClass: TClass; override;
property DelphiObject: TListBoxItem read GetDelphiObject
write SetDelphiObject;
end;

TPyDelphiCustomListBox = class(TPyDelphiScrollBox)
private
function GetDelphiObject: TCustomListBox;
procedure SetDelphiObject(const Value: TCustomListBox);
public
class function DelphiObjectClass: TClass; override;
// Properties
property DelphiObject: TCustomListBox read GetDelphiObject
write SetDelphiObject;
end;

TPyDelphiListBox = class(TPyDelphiCustomListBox)
private
function GetDelphiObject: TListBox;
procedure SetDelphiObject(const Value: TListBox);
public
class function DelphiObjectClass: TClass; override;
// Properties
property DelphiObject: TListBox read GetDelphiObject
write SetDelphiObject;
end;

implementation

uses
WrapDelphi;

{ Register the wrappers, the globals and the constants }
type
TListBoxRegistration = class(TRegisteredUnit)
public
function Name: string; override;
procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override;
end;

{ TListBoxRegistration }

procedure TListBoxRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
end;

function TListBoxRegistration.Name: string;
begin
Result := 'ListBox';
end;

procedure TListBoxRegistration.RegisterWrappers(
APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyListBoxItem);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomListBox);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiListBox);
end;

{ TPyListBoxItem }

class function TPyListBoxItem.DelphiObjectClass: TClass;
begin
Result := TListBox;
end;

function TPyListBoxItem.GetDelphiObject: TListBoxItem;
begin
Result := TListBoxItem(inherited DelphiObject);
end;

procedure TPyListBoxItem.SetDelphiObject(const Value: TListBoxItem);
begin
inherited DelphiObject := Value;
end;

{ TPyDelphiCustomListBox }

class function TPyDelphiCustomListBox.DelphiObjectClass: TClass;
begin
Result := TCustomListBox;
end;

function TPyDelphiCustomListBox.GetDelphiObject: TCustomListBox;
begin
Result := TCustomListBox(inherited DelphiObject);
end;

procedure TPyDelphiCustomListBox.SetDelphiObject(const Value: TCustomListBox);
begin
inherited DelphiObject := Value;
end;

{ TPyDelphiListBox }

class function TPyDelphiListBox.DelphiObjectClass: TClass;
begin
Result := TListBox;
end;

function TPyDelphiListBox.GetDelphiObject: TListBox;
begin
Result := TListBox(inherited DelphiObject);
end;


procedure TPyDelphiListBox.SetDelphiObject(const Value: TListBox);
begin
inherited DelphiObject := Value;
end;

initialization
RegisteredUnits.Add(TListBoxRegistration.Create);

end.