forked from lmbelo/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrapFmxColors.pas
More file actions
470 lines (394 loc) · 12.8 KB
/
WrapFmxColors.pas
File metadata and controls
470 lines (394 loc) · 12.8 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
unit WrapFmxColors;
interface
uses
FMX.Colors,
PythonEngine, WrapFmxControls, WrapFmxStdCtrls, WrapFmxListBox;
type
TPyDelphiColorBox = class(TPyDelphiControl)
private
function GetDelphiObject: TColorBox;
procedure SetDelphiObject(const Value: TColorBox);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TColorBox read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiColorQuad = class(TPyDelphiControl)
private
function GetDelphiObject: TColorQuad;
procedure SetDelphiObject(const Value: TColorQuad);
public
class function DelphiObjectClass: TClass; override;
// Properties
property DelphiObject: TColorQuad read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiColorPicker = class(TPyDelphiControl)
private
function GetDelphiObject: TColorPicker;
procedure SetDelphiObject(const Value: TColorPicker);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TColorPicker read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiGradientEdit = class(TPyDelphiControl)
private
function GetDelphiObject: TGradientEdit;
procedure SetDelphiObject(const Value: TGradientEdit);
public
class function DelphiObjectClass: TClass; override;
// Properties
property DelphiObject: TGradientEdit read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiColorPanel = class(TPyDelphiControl)
private
function GetDelphiObject: TColorPanel;
procedure SetDelphiObject(const Value: TColorPanel);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TColorPanel read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiComboColorBox = class(TPyDelphiStyledControl)
private
function GetDelphiObject: TComboColorBox;
procedure SetDelphiObject(const Value: TComboColorBox);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TComboColorBox read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiColorButton = class(TPyDelphiCustomButton)
private
function GetDelphiObject: TColorButton;
procedure SetDelphiObject(const Value: TColorButton);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TColorButton read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiColorListBox = class(TPyDelphiCustomListBox)
private
function GetDelphiObject: TColorListBox;
procedure SetDelphiObject(const Value: TColorListBox);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TColorListBox read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiCustomColorComboBox = class(TPyDelphiCustomComboBox)
private
function GetDelphiObject: TCustomColorComboBox;
procedure SetDelphiObject(const Value: TCustomColorComboBox);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TCustomColorComboBox read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiColorComboBox = class(TPyDelphiCustomColorComboBox)
private
function GetDelphiObject: TColorComboBox;
procedure SetDelphiObject(const Value: TColorComboBox);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
// Properties
property DelphiObject: TColorComboBox read GetDelphiObject
write SetDelphiObject;
end;
implementation
uses
System.Rtti, WrapDelphi;
type
{ Type extension }
TPyDelphiCommonColorEx = class
protected
// Property Getters
class function Get_Color(AContext: Pointer): PPyObject; cdecl;
// Property Setters
class function Set_Color(AValue: PPyObject; AContext: Pointer): integer; cdecl;
protected
class procedure RegisterGetSets(const APythonType: TPythonType);
end;
{ Register the wrappers, the globals and the constants }
TColorsRegistration = class(TRegisteredUnit)
public
function Name: string; override;
procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override;
end;
{ TColorsRegistration }
procedure TColorsRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
end;
function TColorsRegistration.Name: string;
begin
Result := 'Colors';
end;
procedure TColorsRegistration.RegisterWrappers(
APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorBox);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorQuad);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorPicker);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiGradientEdit);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorPanel);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiComboColorBox);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorButton);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorListBox);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomColorComboBox);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorComboBox);
end;
{ TPyDelphiColorBox }
class function TPyDelphiColorBox.DelphiObjectClass: TClass;
begin
Result := TColorBox;
end;
function TPyDelphiColorBox.GetDelphiObject: TColorBox;
begin
Result := TColorBox(inherited DelphiObject);
end;
class procedure TPyDelphiColorBox.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiColorBox.SetDelphiObject(const Value: TColorBox);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiColorQuad }
class function TPyDelphiColorQuad.DelphiObjectClass: TClass;
begin
Result := TColorQuad;
end;
function TPyDelphiColorQuad.GetDelphiObject: TColorQuad;
begin
Result := TColorQuad(inherited DelphiObject);
end;
procedure TPyDelphiColorQuad.SetDelphiObject(const Value: TColorQuad);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiColorPicker }
class function TPyDelphiColorPicker.DelphiObjectClass: TClass;
begin
Result := TColorPicker;
end;
function TPyDelphiColorPicker.GetDelphiObject: TColorPicker;
begin
Result := TColorPicker(inherited DelphiObject);
end;
class procedure TPyDelphiColorPicker.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiColorPicker.SetDelphiObject(const Value: TColorPicker);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiGradientEdit }
class function TPyDelphiGradientEdit.DelphiObjectClass: TClass;
begin
Result := TGradientEdit;
end;
function TPyDelphiGradientEdit.GetDelphiObject: TGradientEdit;
begin
Result := TGradientEdit(inherited DelphiObject);
end;
procedure TPyDelphiGradientEdit.SetDelphiObject(
const Value: TGradientEdit);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiColorPanel }
class function TPyDelphiColorPanel.DelphiObjectClass: TClass;
begin
Result := TColorPanel;
end;
function TPyDelphiColorPanel.GetDelphiObject: TColorPanel;
begin
Result := TColorPanel(inherited DelphiObject);
end;
class procedure TPyDelphiColorPanel.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiColorPanel.SetDelphiObject(const Value: TColorPanel);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiComboColorBox }
class function TPyDelphiComboColorBox.DelphiObjectClass: TClass;
begin
Result := TComboColorBox;
end;
function TPyDelphiComboColorBox.GetDelphiObject: TComboColorBox;
begin
Result := TComboColorBox(inherited DelphiObject);
end;
class procedure TPyDelphiComboColorBox.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiComboColorBox.SetDelphiObject(const Value: TComboColorBox);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiColorButton }
class function TPyDelphiColorButton.DelphiObjectClass: TClass;
begin
Result := TColorButton;
end;
function TPyDelphiColorButton.GetDelphiObject: TColorButton;
begin
Result := TColorButton(inherited DelphiObject);
end;
class procedure TPyDelphiColorButton.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiColorButton.SetDelphiObject(const Value: TColorButton);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiColorListBox }
class function TPyDelphiColorListBox.DelphiObjectClass: TClass;
begin
Result := TColorListBox;
end;
function TPyDelphiColorListBox.GetDelphiObject: TColorListBox;
begin
Result := TColorListBox(inherited DelphiObject);
end;
class procedure TPyDelphiColorListBox.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiColorListBox.SetDelphiObject(const Value: TColorListBox);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiCustomColorComboBox }
class function TPyDelphiCustomColorComboBox.DelphiObjectClass: TClass;
begin
Result := TCustomColorComboBox;
end;
function TPyDelphiCustomColorComboBox.GetDelphiObject: TCustomColorComboBox;
begin
Result := TCustomColorComboBox(inherited DelphiObject);
end;
class procedure TPyDelphiCustomColorComboBox.RegisterGetSets(
PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
procedure TPyDelphiCustomColorComboBox.SetDelphiObject(
const Value: TCustomColorComboBox);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiColorComboBox }
class function TPyDelphiColorComboBox.DelphiObjectClass: TClass;
begin
Result := TColorComboBox;
end;
class procedure TPyDelphiColorComboBox.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
TPyDelphiCommonColorEx.RegisterGetSets(PythonType);
end;
function TPyDelphiColorComboBox.GetDelphiObject: TColorComboBox;
begin
Result := TColorComboBox(inherited DelphiObject);
end;
procedure TPyDelphiColorComboBox.SetDelphiObject(const Value: TColorComboBox);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiCommonColorEx }
class procedure TPyDelphiCommonColorEx.RegisterGetSets(
const APythonType: TPythonType);
begin
with APythonType do begin
//Fixing the cardinal->variant/variant->cardinal conversion error
AddGetSet('Color',
@TPyDelphiCommonColorEx.Get_Color,
@TPyDelphiCommonColorEx.Set_Color,
'Returns a integer with the color value', nil);
end;
end;
class function TPyDelphiCommonColorEx.Get_Color(AContext: Pointer): PPyObject;
var
LSelf: TPyDelphiControl;
LRttiCtx: TRttiContext;
LRttiType: TRttiType;
LRttiProp: TRttiProperty;
begin
LSelf := PythonToDelphi(PPyObject(Self)) as TPyDelphiControl;
LRttiCtx := TRttiContext.Create();
try
LRttiType := LRttiCtx.GetType(LSelf.DelphiObject.ClassInfo);
LRttiProp := LRttiType.GetProperty('Color');
if not Assigned(LRttiProp) then
Exit(GetPythonEngine().Py_None);
Result := GetPythonEngine().PyLong_FromLong(
LRttiProp.GetValue(LSelf.DelphiObject).AsInteger);
finally
LRttiCtx.Free();
end;
end;
class function TPyDelphiCommonColorEx.Set_Color(AValue: PPyObject;
AContext: Pointer): integer;
var
LValue: integer;
LSelf: TPyDelphiControl;
LRttiCtx: TRttiContext;
LRttiType: TRttiType;
LRttiProp: TRttiProperty;
begin
if CheckIntAttribute(AValue, 'Color', LValue) then begin
with GetPythonEngine() do begin
LSelf := PythonToDelphi(PPyObject(Self)) as TPyDelphiControl;
LRttiCtx := TRttiContext.Create();
try
LRttiType := LRttiCtx.GetType(LSelf.DelphiObject.ClassInfo);
LRttiProp := LRttiType.GetProperty('Color');
if not Assigned(LRttiProp) then
Exit(-1);
LRttiProp.SetValue(LSelf.DelphiObject, LValue);
finally
LRttiCtx.Free();
end;
Result := 0;
end;
end else
Result := -1;
end;
initialization
RegisteredUnits.Add(TColorsRegistration.Create());
end.