-
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathWrapVclMedia.pas
205 lines (175 loc) · 6.33 KB
/
WrapVclMedia.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
(**************************************************************************)
(* This unit is part of the Python for Delphi (P4D) library *)
(* Project home: https://github.com/pyscripter/python4delphi *)
(* *)
(* Project Maintainer: PyScripter (pyscripter@gmail.com) *)
(* Original Authors: Dr. Dietmar Budelsky (dbudelsky@web.de) *)
(* Morgan Martinet (https://github.com/mmm-experts) *)
(* Core developer: Lucas Belo (lucas.belo@live.com) *)
(* Contributors: See contributors.md at project home *)
(* *)
(* LICENCE and Copyright: MIT (see project home) *)
(**************************************************************************)
{$I ..\Definition.Inc}
unit WrapVclMedia;
interface
uses
System.TypInfo, Vcl.MPlayer,
PythonEngine, WrapDelphi, WrapVclControls;
type
TEMPNotifyEventHandler = class(TEventHandler)
protected
procedure DoEvent(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
public
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
PropertyInfo : PPropInfo; Callable : PPyObject); override;
class function GetTypeInfo : PTypeInfo; override;
end;
TEMPPostNotifyEventHandler = class(TEventHandler)
protected
procedure DoEvent(Sender: TObject; Button: TMPBtnType);
public
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
PropertyInfo : PPropInfo; Callable : PPyObject); override;
class function GetTypeInfo : PTypeInfo; override;
end;
TPyDelphiMediaPlayer = class (TPyDelphiCustomControl)
private
function GetDelphiObject: TMediaPlayer;
procedure SetDelphiObject(const Value: TMediaPlayer);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TMediaPlayer read GetDelphiObject write SetDelphiObject;
end;
implementation
type
TMediaRegistration = class(TRegisteredUnit)
public
function Name: string; override;
procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override;
end;
{ TVclMediaRegistration }
function TMediaRegistration.Name: string;
begin
Result := 'Media';
end;
procedure TMediaRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
end;
procedure TMediaRegistration.RegisterWrappers(
APyDelphiWrapper: TPyDelphiWrapper);
begin
APyDelphiWrapper.EventHandlers.RegisterHandler(TEMPNotifyEventHandler);
APyDelphiWrapper.EventHandlers.RegisterHandler(TEMPPostNotifyEventHandler);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayer);
end;
{ TPyDelphiMediaPlayer }
class function TPyDelphiMediaPlayer.DelphiObjectClass: TClass;
begin
Result := TMediaPlayer;
end;
function TPyDelphiMediaPlayer.GetDelphiObject: TMediaPlayer;
begin
Result := TMediaPlayer(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayer.SetDelphiObject(const Value: TMediaPlayer);
begin
inherited DelphiObject := Value;
end;
{ TEMPNotifyEventHandler }
constructor TEMPNotifyEventHandler.Create(PyDelphiWrapper: TPyDelphiWrapper;
Component: TObject; PropertyInfo: PPropInfo; Callable: PPyObject);
var
LMethod: TMethod;
begin
inherited;
LMethod.Code := @TEMPNotifyEventHandler.DoEvent;
LMethod.Data := Self;
SetMethodProp(Component, PropertyInfo, LMethod);
end;
procedure TEMPNotifyEventHandler.DoEvent(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
var
LPyObject: PPyObject;
LPyTuple: PPyObject;
LPyResult: PPyObject;
LPyButton: PPyObject;
LDoDefault: PPyObject;
LVarParam: TPyDelphiVarParameter;
begin
Assert(Assigned(PyDelphiWrapper));
if Assigned(Callable) and PythonOK() then
with GetPythonEngine do begin
LPyObject := PyDelphiWrapper.Wrap(Sender);
LPyButton := PyLong_FromLong(Integer(Button));
LDoDefault := CreateVarParam(PyDelphiWrapper, DoDefault);
LVarParam := PythonToDelphi(LDoDefault) as TPyDelphiVarParameter;
LPyTuple := PyTuple_New(3);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 0, LPyObject);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 1, LPyButton);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 2, LDoDefault);
try
LPyResult := PyObject_CallObject(Callable, LPyTuple);
if Assigned(LPyResult) then begin
Py_DECREF(LPyResult);
DoDefault := PyObject_IsTrue(LVarParam.Value) = 1;
end;
finally
Py_DECREF(LPyTuple);
end;
CheckError();
end;
end;
class function TEMPNotifyEventHandler.GetTypeInfo: PTypeInfo;
begin
Result := System.TypeInfo(EMPNotify);
end;
{ TEMPPostNotifyEventHandler }
constructor TEMPPostNotifyEventHandler.Create(PyDelphiWrapper: TPyDelphiWrapper;
Component: TObject; PropertyInfo: PPropInfo; Callable: PPyObject);
var
LMethod: TMethod;
begin
inherited;
LMethod.Code := @TEMPPostNotifyEventHandler.DoEvent;
LMethod.Data := Self;
SetMethodProp(Component, PropertyInfo, LMethod);
end;
procedure TEMPPostNotifyEventHandler.DoEvent(Sender: TObject;
Button: TMPBtnType);
var
LPyObject: PPyObject;
LPyTuple: PPyObject;
LPyResult: PPyObject;
LPyButton: PPyObject;
begin
Assert(Assigned(PyDelphiWrapper));
if Assigned(Callable) and PythonOK() then
with GetPythonEngine do begin
LPyObject := PyDelphiWrapper.Wrap(Sender);
LPyButton := PyLong_FromLong(Integer(Button));
LPyTuple := PyTuple_New(2);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 0, LPyObject);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 1, LPyButton);
try
LPyResult := PyObject_CallObject(Callable, LPyTuple);
if Assigned(LPyResult) then begin
Py_DECREF(LPyResult);
end;
finally
Py_DECREF(LPyTuple);
end;
CheckError();
end;
end;
class function TEMPPostNotifyEventHandler.GetTypeInfo: PTypeInfo;
begin
Result := System.TypeInfo(EMPPostNotify);
end;
initialization
RegisteredUnits.Add(TMediaRegistration.Create);
end.