Skip to content

Commit 46d2e38

Browse files
authored
Merge pull request pyscripter#254 from Embarcadero/fmxdialogs
Fmx Dialogs wrappers
2 parents 033c4ad + 710e791 commit 46d2e38

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

Source/fmx/WrapFmxDialogs.pas

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
unit WrapFmxDialogs;
2+
3+
interface
4+
5+
uses
6+
FMX.Dialogs, WrapFmxTypes, PythonEngine;
7+
8+
9+
type
10+
TPyDelphiOpenDialog = class(TPyDelphiFmxObject)
11+
private
12+
function GetDelphiObject: TOpenDialog;
13+
procedure SetDelphiObject(const Value: TOpenDialog);
14+
protected
15+
// Exposed Methods
16+
function Execute_Wrapper(args: PPyObject): PPyObject; cdecl;
17+
// Property Getters
18+
function Get_filename(AContext: Pointer): PPyObject; cdecl;
19+
public
20+
class function DelphiObjectClass: TClass; override;
21+
class procedure RegisterGetSets(PythonType: TPythonType); override;
22+
class procedure RegisterMethods( PythonType : TPythonType ); override;
23+
// Properties
24+
property DelphiObject: TOpenDialog read GetDelphiObject
25+
write SetDelphiObject;
26+
end;
27+
28+
implementation
29+
30+
uses
31+
WrapDelphi;
32+
33+
{ Register the wrappers, the globals and the constants }
34+
type
35+
TDialogRegistration = class(TRegisteredUnit)
36+
public
37+
function Name: string; override;
38+
procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override;
39+
procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override;
40+
end;
41+
42+
{ TDialogRegistration }
43+
44+
procedure TDialogRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
45+
begin
46+
inherited;
47+
end;
48+
49+
function TDialogRegistration.Name: string;
50+
begin
51+
Result := 'Dialog';
52+
end;
53+
54+
procedure TDialogRegistration.RegisterWrappers(
55+
APyDelphiWrapper: TPyDelphiWrapper);
56+
begin
57+
inherited;
58+
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiOpenDialog);
59+
end;
60+
61+
{ TPyDelphiOpenDialog }
62+
63+
class function TPyDelphiOpenDialog.DelphiObjectClass: TClass;
64+
begin
65+
Result := TOpenDialog;
66+
end;
67+
68+
function TPyDelphiOpenDialog.Execute_Wrapper(args: PPyObject): PPyObject;
69+
begin
70+
// We adjust the transmitted self argument
71+
Adjust(@Self);
72+
with GetPythonEngine do begin
73+
if PyArg_ParseTuple( args, ':Execute') <> 0 then
74+
Result := VariantAsPyObject(DelphiObject.Execute())
75+
else
76+
Result := nil;
77+
end;
78+
end;
79+
80+
function TPyDelphiOpenDialog.GetDelphiObject: TOpenDialog;
81+
begin
82+
Result := TOpenDialog(inherited DelphiObject);
83+
end;
84+
85+
function TPyDelphiOpenDialog.Get_filename(AContext: Pointer): PPyObject;
86+
begin
87+
Adjust(@self);
88+
Result := GetPythonEngine.VariantAsPyObject(DelphiObject.FileName);
89+
end;
90+
91+
class procedure TPyDelphiOpenDialog.RegisterGetSets(PythonType: TPythonType);
92+
begin
93+
inherited;
94+
PythonType.AddGetSet('FileName', @TPyDelphiOpenDialog.Get_filename,
95+
nil, '', nil);
96+
end;
97+
98+
class procedure TPyDelphiOpenDialog.RegisterMethods(PythonType: TPythonType);
99+
begin
100+
inherited;
101+
PythonType.AddMethod('Execute', @TPyDelphiOpenDialog.Execute_Wrapper,
102+
'TOpenDialog.Execute()'#10 +
103+
'Displays the dialog');
104+
end;
105+
106+
procedure TPyDelphiOpenDialog.SetDelphiObject(const Value: TOpenDialog);
107+
begin
108+
inherited DelphiObject := Value;
109+
end;
110+
111+
initialization
112+
RegisteredUnits.Add(TDialogRegistration.Create);
113+
114+
end.

0 commit comments

Comments
 (0)