Skip to content

Commit 7683200

Browse files
committed
Added WrapDelphiDialogs.pas and updated Demo31 to test the wrapper and also work with python 3.x. Note that the new wrapper is incomplete and is in response to pyscripter#74
1 parent 0209f11 commit 7683200

File tree

6 files changed

+791
-12
lines changed

6 files changed

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

PythonForDelphi/Demos/Demo31/Project1.dpr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ program Project1;
55
uses
66
Forms,
77
Unit1 in 'Unit1.pas' {Form1},
8+
Unit2 in 'Unit2.pas' {TestForm},
89
WrapDelphiExtCtrls in '..\..\Components\Sources\Core\WrapDelphiExtCtrls.pas',
910
WrapDelphiTypes in '..\..\Components\Sources\Core\WrapDelphiTypes.pas',
10-
Unit2 in 'Unit2.pas' {TestForm},
1111
WrapDelphiWindows in '..\..\Components\Sources\Core\WrapDelphiWindows.pas',
1212
WrapDelphiComCtrls in '..\..\Components\Sources\Core\WrapDelphiComCtrls.pas',
1313
WrapDelphiGrids in '..\..\Components\Sources\Core\WrapDelphiGrids.pas',
1414
WrapDelphiGraphics in '..\..\Components\Sources\Core\WrapDelphiGraphics.pas',
15-
WrapDelphiButtons in '..\..\Components\Sources\Core\WrapDelphiButtons.pas';
15+
WrapDelphiButtons in '..\..\Components\Sources\Core\WrapDelphiButtons.pas',
16+
WrapDelphiDialogs in '..\..\Components\Sources\Core\WrapDelphiDialogs.pas';
1617

1718
{$R *.res}
1819

0 commit comments

Comments
 (0)