Skip to content

Commit 2b718a2

Browse files
authored
Merge pull request Embarcadero#2 from Embarcadero/lastmile
Lastmile
2 parents 4f62cb9 + e1cd461 commit 2b718a2

File tree

6 files changed

+423
-6
lines changed

6 files changed

+423
-6
lines changed

Packages/Delphi/Delphi 10.4+/PythonVcl.dpk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ requires
3434
rtl,
3535
vcl,
3636
Python,
37-
VclSmp;
37+
VclSmp,
38+
vclimg,
39+
vclwinx;
3840

3941
contains
4042
Vcl.PythonGUIInputOutput in '..\..\..\Source\vcl\Vcl.PythonGUIInputOutput.pas',
@@ -49,6 +51,8 @@ contains
4951
WrapVclGraphics in '..\..\..\Source\vcl\WrapVclGraphics.pas',
5052
WrapVclGrids in '..\..\..\Source\vcl\WrapVclGrids.pas',
5153
WrapVclSamplesSpin in '..\..\..\Source\vcl\WrapVclSamplesSpin.pas',
52-
WrapVclStdCtrls in '..\..\..\Source\vcl\WrapVclStdCtrls.pas';
54+
WrapVclStdCtrls in '..\..\..\Source\vcl\WrapVclStdCtrls.pas',
55+
WrapVclWinXCtrls in '..\..\..\Source\vcl\WrapVclWinXCtrls.pas',
56+
WrapVclThemes in '..\..\..\Source\vcl\WrapVclThemes.pas';
5357

5458
end.

Source/fmx/WrapFmxForms.pas

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ interface
66

77
uses
88
System.Classes, System.SysUtils, FMX.Forms,
9-
PythonEngine, WrapFmxTypes, WrapDelphiClasses, WrapFmxControls;
9+
PythonEngine, WrapFmxTypes, WrapDelphiClasses, WrapFmxControls, WrapDelphi,
10+
System.TypInfo, System.UITypes;
1011

1112
type
1213
TPyDelphiApplication = class(TPyDelphiComponent)
@@ -20,6 +21,24 @@ TPyDelphiApplication = class(TPyDelphiComponent)
2021
property DelphiObject: TApplication read GetDelphiObject write SetDelphiObject;
2122
end;
2223

24+
TCloseQueryEventHandler = class(TEventHandler)
25+
protected
26+
procedure DoEvent(Sender: TObject; var CanClose : Boolean);
27+
public
28+
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
29+
PropertyInfo : PPropInfo; Callable : PPyObject); override;
30+
class function GetTypeInfo : PTypeInfo; override;
31+
end;
32+
33+
TCloseEventHandler = class(TEventHandler)
34+
protected
35+
procedure DoEvent(Sender: TObject; var Action: TCloseAction);
36+
public
37+
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
38+
PropertyInfo : PPropInfo; Callable : PPyObject); override;
39+
class function GetTypeInfo : PTypeInfo; override;
40+
end;
41+
2342
TPyDelphiCommonCustomForm = class(TPyDelphiFmxObject)
2443
private
2544
function GetDelphiObject: TCommonCustomForm;
@@ -93,7 +112,7 @@ EInvalidFormClass = class(Exception);
93112
implementation
94113

95114
uses
96-
WrapDelphi, System.Types;
115+
System.Types;
97116

98117
{ Register the wrappers, the globals and the constants }
99118
type
@@ -137,6 +156,9 @@ procedure TFormsRegistration.RegisterWrappers(
137156
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiForm);
138157
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiFrame);
139158
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiScreen);
159+
160+
APyDelphiWrapper.EventHandlers.RegisterHandler(TCloseQueryEventHandler);
161+
APyDelphiWrapper.EventHandlers.RegisterHandler(TCloseEventHandler);
140162
end;
141163

142164
{ TPyDelphiApplication }
@@ -156,6 +178,101 @@ procedure TPyDelphiApplication.SetDelphiObject(const Value: TApplication);
156178
inherited DelphiObject := Value;
157179
end;
158180

181+
{ TCloseQueryEventHandler }
182+
183+
constructor TCloseQueryEventHandler.Create(PyDelphiWrapper: TPyDelphiWrapper;
184+
Component: TObject; PropertyInfo: PPropInfo; Callable: PPyObject);
185+
var
186+
LMethod : TMethod;
187+
begin
188+
inherited;
189+
LMethod.Code := @TCloseQueryEventHandler.DoEvent;
190+
LMethod.Data := Self;
191+
SetMethodProp(Component, PropertyInfo, LMethod);
192+
end;
193+
194+
procedure TCloseQueryEventHandler.DoEvent(Sender: TObject;
195+
var CanClose: Boolean);
196+
var
197+
LPyObject, LPyTuple, LPyResult, LPyCanClose : PPyObject;
198+
LVarParam : TPyDelphiVarParameter;
199+
begin
200+
Assert(Assigned(PyDelphiWrapper));
201+
if Assigned(Callable) and PythonOK then
202+
with GetPythonEngine do begin
203+
LPyObject := PyDelphiWrapper.Wrap(Sender);
204+
LPyCanClose := CreateVarParam(PyDelphiWrapper, CanClose);
205+
LVarParam := PythonToDelphi(LPyCanClose) as TPyDelphiVarParameter;
206+
LPyTuple := PyTuple_New(2);
207+
GetPythonEngine.PyTuple_SetItem(LPyTuple, 0, LPyObject);
208+
GetPythonEngine.PyTuple_SetItem(LPyTuple, 1, LPyCanClose);
209+
try
210+
LPyResult := PyObject_CallObject(Callable, LPyTuple);
211+
if Assigned(LPyResult) then
212+
begin
213+
Py_DECREF(LPyResult);
214+
CanClose := PyObject_IsTrue(LVarParam.Value) = 1;
215+
end;
216+
finally
217+
Py_DECREF(LPyTuple);
218+
end;
219+
CheckError;
220+
end;
221+
end;
222+
223+
class function TCloseQueryEventHandler.GetTypeInfo: PTypeInfo;
224+
begin
225+
Result := System.TypeInfo(TCloseQueryEvent);
226+
end;
227+
228+
{ TCloseEventHandler }
229+
230+
constructor TCloseEventHandler.Create(PyDelphiWrapper: TPyDelphiWrapper;
231+
Component: TObject; PropertyInfo: PPropInfo; Callable: PPyObject);
232+
var
233+
LMethod : TMethod;
234+
begin
235+
inherited;
236+
LMethod.Code := @TCloseEventHandler.DoEvent;
237+
LMethod.Data := Self;
238+
SetMethodProp(Component, PropertyInfo, LMethod);
239+
end;
240+
241+
procedure TCloseEventHandler.DoEvent(Sender: TObject; var Action: TCloseAction);
242+
var
243+
LPyObject, LPyTuple, LPyResult, LPyAction : PPyObject;
244+
LVarParam : TPyDelphiVarParameter;
245+
begin
246+
Assert(Assigned(PyDelphiWrapper));
247+
if Assigned(Callable) and PythonOK then
248+
with GetPythonEngine do begin
249+
LPyObject := PyDelphiWrapper.Wrap(Sender);
250+
LPyAction := CreateVarParam(PyDelphiWrapper, NativeInt(Action));
251+
LVarParam := PythonToDelphi(LPyAction) as TPyDelphiVarParameter;
252+
LPyTuple := PyTuple_New(2);
253+
GetPythonEngine.PyTuple_SetItem(LPyTuple, 0, LPyObject);
254+
GetPythonEngine.PyTuple_SetItem(LPyTuple, 1, LPyAction);
255+
try
256+
LPyResult := PyObject_CallObject(Callable, LPyTuple);
257+
if Assigned(LPyResult) then
258+
begin
259+
Py_DECREF(LPyResult);
260+
if PyLong_Check(LVarParam.Value) and
261+
CheckEnum('TCloseAction', PyLong_AsLong(LVarParam.Value), Ord(Low(TCloseAction)), Ord(High(TCloseAction))) then
262+
Action := TCloseAction(PyLong_AsLong(LVarParam.Value));
263+
end;
264+
finally
265+
Py_DECREF(LPyTuple);
266+
end;
267+
CheckError;
268+
end;
269+
end;
270+
271+
class function TCloseEventHandler.GetTypeInfo: PTypeInfo;
272+
begin
273+
Result := System.TypeInfo(TCloseEvent);
274+
end;
275+
159276
{ TPyDelphiCommonCustomForm }
160277

161278
function TPyDelphiCommonCustomForm.CreateComponent(
@@ -312,7 +429,7 @@ procedure TPyDelphiScreen.SetDelphiObject(const Value: TScreen);
312429
inherited DelphiObject := Value;
313430
end;
314431

315-
initialization
432+
Initialization
316433
RegisteredUnits.Add(TFormsRegistration.Create);
317434

318435
end.

Source/vcl/WrapDelphiVCL.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ implementation
2222
WrapVclExtCtrls,
2323
WrapVclButtons,
2424
WrapVclGrids,
25-
WrapVclSamplesSpin;
25+
WrapVclSamplesSpin,
26+
WrapVclWinXCtrls,
27+
WrapVclThemes;
2628

2729
end.

Source/vcl/WrapVclComCtrls.pas

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ TPyDelphiPageControl = class (TPyDelphiWinControl)
103103
property DelphiObject: TPageControl read GetDelphiObject write SetDelphiObject;
104104
end;
105105

106+
TPyDelphiTrackBar = class (TPyDelphiWinControl)
107+
private
108+
function GetDelphiObject: TTrackBar;
109+
procedure SetDelphiObject(const Value: TTrackBar);
110+
public
111+
class function DelphiObjectClass : TClass; override;
112+
// Properties
113+
property DelphiObject: TTrackBar read GetDelphiObject write SetDelphiObject;
114+
end;
115+
106116
implementation
107117

108118
uses
@@ -137,6 +147,7 @@ procedure TComCtrlsRegistration.RegisterWrappers(APyDelphiWrapper: TPyDelphiWrap
137147
{$ENDIF FPC}
138148
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPageControl);
139149
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiTabSheet);
150+
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiTrackBar);
140151

141152
APyDelphiWrapper.EventHandlers.RegisterHandler(TTabChangingEventHandler);
142153
end;
@@ -613,6 +624,23 @@ class function TTabChangingEventHandler.GetTypeInfo: PTypeInfo;
613624
Result := System.TypeInfo(TTabChangingEvent);
614625
end;
615626

627+
{ TPyDelphiTrackBar }
628+
629+
class function TPyDelphiTrackBar.DelphiObjectClass: TClass;
630+
begin
631+
Result := TTrackBar;
632+
end;
633+
634+
function TPyDelphiTrackBar.GetDelphiObject: TTrackBar;
635+
begin
636+
Result := TTrackBar(inherited DelphiObject);
637+
end;
638+
639+
procedure TPyDelphiTrackBar.SetDelphiObject(const Value: TTrackBar);
640+
begin
641+
inherited DelphiObject := Value;
642+
end;
643+
616644
initialization
617645
RegisteredUnits.Add( TComCtrlsRegistration.Create );
618646
{$IFNDEF FPC}

0 commit comments

Comments
 (0)