Skip to content
Merged
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
114 changes: 114 additions & 0 deletions Source/fmx/WrapFmxDialogs.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
unit WrapFmxDialogs;

interface

uses
FMX.Dialogs, WrapFmxTypes, PythonEngine;


type
TPyDelphiOpenDialog = class(TPyDelphiFmxObject)
private
function GetDelphiObject: TOpenDialog;
procedure SetDelphiObject(const Value: TOpenDialog);
protected
// Exposed Methods
function Execute_Wrapper(args: PPyObject): PPyObject; cdecl;
// Property Getters
function Get_filename(AContext: Pointer): PPyObject; cdecl;
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
class procedure RegisterMethods( PythonType : TPythonType ); override;
// Properties
property DelphiObject: TOpenDialog read GetDelphiObject
write SetDelphiObject;
end;

implementation

uses
WrapDelphi;

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

{ TDialogRegistration }

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

function TDialogRegistration.Name: string;
begin
Result := 'Dialog';
end;

procedure TDialogRegistration.RegisterWrappers(
APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiOpenDialog);
end;

{ TPyDelphiOpenDialog }

class function TPyDelphiOpenDialog.DelphiObjectClass: TClass;
begin
Result := TOpenDialog;
end;

function TPyDelphiOpenDialog.Execute_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':Execute') <> 0 then
Result := VariantAsPyObject(DelphiObject.Execute())
else
Result := nil;
end;
end;

function TPyDelphiOpenDialog.GetDelphiObject: TOpenDialog;
begin
Result := TOpenDialog(inherited DelphiObject);
end;

function TPyDelphiOpenDialog.Get_filename(AContext: Pointer): PPyObject;
begin
Adjust(@self);
Result := GetPythonEngine.VariantAsPyObject(DelphiObject.FileName);
end;

class procedure TPyDelphiOpenDialog.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
PythonType.AddGetSet('FileName', @TPyDelphiOpenDialog.Get_filename,
nil, '', nil);
end;

class procedure TPyDelphiOpenDialog.RegisterMethods(PythonType: TPythonType);
begin
inherited;
PythonType.AddMethod('Execute', @TPyDelphiOpenDialog.Execute_Wrapper,
'TOpenDialog.Execute()'#10 +
'Displays the dialog');
end;

procedure TPyDelphiOpenDialog.SetDelphiObject(const Value: TOpenDialog);
begin
inherited DelphiObject := Value;
end;

initialization
RegisteredUnits.Add(TDialogRegistration.Create);

end.