-
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathWrapDelphiTypes.pas
671 lines (597 loc) · 20.3 KB
/
WrapDelphiTypes.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
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
(**************************************************************************)
(* 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 WrapDelphiTypes;
interface
uses
Classes,
SysUtils,
PythonEngine,
Types,
WrapDelphi
{$IFNDEF FPC}
, System.UITypes
{$ENDIF FPC}
;
type
TPyDelphiPoint = class(TPyObject)
private
fValue: TPoint;
protected
// Exposed Getters
function Get_X(Acontext : Pointer) : PPyObject; cdecl;
function Get_Y(Acontext : Pointer) : PPyObject; cdecl;
// Exposed Setters
function Set_X(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_Y(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
public
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
function Compare( obj: PPyObject) : Integer; override;
function Repr : PPyObject; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
class procedure SetupType( PythonType : TPythonType ); override;
property Value : TPoint read fValue write fValue;
end;
TPyDelphiRect = class(TPyObject)
private
fValue: TRect;
protected
// Exposed Getters
function Get_Left(Acontext : Pointer) : PPyObject; cdecl;
function Get_Top(Acontext : Pointer) : PPyObject; cdecl;
function Get_Right(Acontext : Pointer) : PPyObject; cdecl;
function Get_Bottom(Acontext : Pointer) : PPyObject; cdecl;
function Get_TopLeft(Acontext : Pointer) : PPyObject; cdecl;
function Get_BottomRight(Acontext : Pointer) : PPyObject; cdecl;
// Exposed Setters
function Set_Left(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_Top(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_Right(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_Bottom(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_TopLeft(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_BottomRight(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
public
PyDelphiWrapper : TPyDelphiWrapper;
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
function Compare( obj: PPyObject) : Integer; override;
function Repr : PPyObject; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
class procedure SetupType( PythonType : TPythonType ); override;
property Value : TRect read fValue write fValue;
end;
TPyDelphiSize = class(TPyObject)
private
fValue: TSize;
protected
// Exposed Getters
function Get_CX(Acontext : Pointer) : PPyObject; cdecl;
function Get_CY(Acontext : Pointer) : PPyObject; cdecl;
// Exposed Setters
function Set_CX(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_CY(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
public
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
function Compare( obj: PPyObject) : Integer; override;
function Repr : PPyObject; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
class procedure SetupType( PythonType : TPythonType ); override;
property Value : TSize read fValue write fValue;
end;
function WrapPoint(APyDelphiWrapper : TPyDelphiWrapper; const APoint : TPoint) : PPyObject;
function WrapRect(APyDelphiWrapper : TPyDelphiWrapper; const ARect : TRect) : PPyObject;
function WrapSize(APyDelphiWrapper : TPyDelphiWrapper; const ASize : TSize) : PPyObject;
function CheckPointAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : TPoint) : Boolean;
function CheckRectAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : TRect) : Boolean;
function CheckSizeAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : TSize) : Boolean;
{$IFNDEF FPC}
function MouseButtonToPython(const AMouseButton: TMouseButton): PPyObject;
{$ENDIF FPC}
implementation
uses
Math, Rtti;
{ Register the wrappers, the globals and the constants }
type
TTypesRegistration = class(TRegisteredUnit)
public
function Name : string; override;
procedure RegisterWrappers(APyDelphiWrapper : TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper : TPyDelphiWrapper); override;
end;
{ TExtCtrlsRegistration }
procedure TTypesRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
{$IFNDEF FPC}
APyDelphiWrapper.DefineVar('crDefault', crDefault);
APyDelphiWrapper.DefineVar('crNone', crNone);
APyDelphiWrapper.DefineVar('crArrow', crArrow);
APyDelphiWrapper.DefineVar('crCross', crCross);
APyDelphiWrapper.DefineVar('crIBeam', crIBeam);
APyDelphiWrapper.DefineVar('crSize', crSize);
APyDelphiWrapper.DefineVar('crSizeNESW', crSizeNESW);
APyDelphiWrapper.DefineVar('crSizeNS', crSizeNS);
APyDelphiWrapper.DefineVar('crSizeNWSE', crSizeNWSE);
APyDelphiWrapper.DefineVar('crSizeWE', crSizeWE);
APyDelphiWrapper.DefineVar('crUpArrow', crUpArrow);
APyDelphiWrapper.DefineVar('crHourGlass', crHourGlass);
APyDelphiWrapper.DefineVar('crDrag', crDrag);
APyDelphiWrapper.DefineVar('crNoDrop', crNoDrop);
APyDelphiWrapper.DefineVar('crHSplit', crHSplit);
APyDelphiWrapper.DefineVar('crVSplit', crVSplit);
APyDelphiWrapper.DefineVar('crMultiDrag', crMultiDrag);
APyDelphiWrapper.DefineVar('crSQLWait', crSQLWait);
APyDelphiWrapper.DefineVar('crNo', crNo);
APyDelphiWrapper.DefineVar('crAppStart', crAppStart);
APyDelphiWrapper.DefineVar('crHelp', crHelp);
APyDelphiWrapper.DefineVar('crHandPoint', crHandPoint);
APyDelphiWrapper.DefineVar('crSizeAll', crSizeAll);
{$ENDIF FPC}
end;
function TTypesRegistration.Name: string;
begin
Result := 'Types';
end;
procedure TTypesRegistration.RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterHelperType(TPyDelphiPoint);
APyDelphiWrapper.RegisterHelperType(TPyDelphiRect);
APyDelphiWrapper.RegisterHelperType(TPyDelphiSize);
end;
{$IFNDEF FPC}
function MouseButtonToPython(const AMouseButton: TMouseButton): PPyObject;
begin
Result := GetPythonEngine.PyUnicodeFromString(
TRttiEnumerationType.GetName<TMouseButton>(AMouseButton));
end;
{$ENDIF FPC}
{ Helper functions }
function WrapPoint(APyDelphiWrapper : TPyDelphiWrapper; const APoint : TPoint) : PPyObject;
var
_type : TPythonType;
begin
_type := APyDelphiWrapper.GetHelperType('PointType');
Result := _type.CreateInstance;
(PythonToDelphi(Result) as TPyDelphiPoint).Value := APoint;
end;
function WrapRect(APyDelphiWrapper : TPyDelphiWrapper; const ARect : TRect) : PPyObject;
var
_type : TPythonType;
begin
_type := APyDelphiWrapper.GetHelperType('RectType');
Result := _type.CreateInstance;
with PythonToDelphi(Result) as TPyDelphiRect do
begin
PyDelphiWrapper := APyDelphiWrapper;
Value := ARect;
end;
end;
function WrapSize(APyDelphiWrapper : TPyDelphiWrapper; const ASize : TSize) : PPyObject;
var
_type : TPythonType;
begin
_type := APyDelphiWrapper.GetHelperType('SizeType');
Result := _type.CreateInstance;
(PythonToDelphi(Result) as TPyDelphiSize).Value := ASize;
end;
function CheckPointAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : TPoint) : Boolean;
begin
with GetPythonEngine do
begin
if IsDelphiObject(AAttribute) and (PythonToDelphi(AAttribute) is TPyDelphiPoint) then
begin
AValue := TPyDelphiPoint(PythonToDelphi(AAttribute)).Value;
Result := True;
end
else
begin
Result := False;
with GetPythonEngine do
PyErr_SetString(PyExc_AttributeError^,
PAnsiChar(EncodeString(Format('%s receives only Point objects', [AAttributeName]))));
end;
end;
end;
function CheckRectAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : TRect) : Boolean;
begin
with GetPythonEngine do
begin
if IsDelphiObject(AAttribute) and (PythonToDelphi(AAttribute) is TPyDelphiRect) then
begin
AValue := TPyDelphiRect(PythonToDelphi(AAttribute)).Value;
Result := True;
end
else
begin
Result := False;
with GetPythonEngine do
PyErr_SetString(PyExc_AttributeError^,
PAnsiChar(EncodeString(Format('%s receives only Rect objects', [AAttributeName]))));
end;
end;
end;
function CheckSizeAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : TSize) : Boolean;
begin
with GetPythonEngine do
begin
if IsDelphiObject(AAttribute) and (PythonToDelphi(AAttribute) is TPyDelphiSize) then
begin
AValue := TPyDelphiSize(PythonToDelphi(AAttribute)).Value;
Result := True;
end
else
begin
Result := False;
with GetPythonEngine do
PyErr_SetString(PyExc_AttributeError^,
PAnsiChar(EncodeString(Format('%s receives only Size objects', [AAttributeName]))));
end;
end;
end;
{ TPyDelphiPoint }
function TPyDelphiPoint.Compare(obj: PPyObject): Integer;
var
_other : TPyDelphiPoint;
begin
if IsDelphiObject(obj) and (PythonToDelphi(obj) is TPyDelphiPoint) then
begin
_other := TPyDelphiPoint(PythonToDelphi(obj));
Result := CompareValue(Value.X, _other.Value.X);
if Result = 0 then
Result := CompareValue(Value.Y, _other.Value.Y);
end
else
Result := 1;
end;
constructor TPyDelphiPoint.CreateWith(APythonType: TPythonType; args,
kwds: PPyObject);
var
x, y : Integer;
begin
Create(APythonType);
if APythonType.Engine.PyArg_ParseTuple( args, 'ii:Create',@x, @y ) <> 0 then
begin
fValue.X := x;
fValue.Y := y;
end
end;
function TPyDelphiPoint.Get_X(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.X);
end;
function TPyDelphiPoint.Get_Y(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.Y);
end;
class procedure TPyDelphiPoint.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
with PythonType do
begin
AddGetSet('X', @TPyDelphiPoint.Get_X, @TPyDelphiPoint.Set_X,
'Provides access to the X coordinate of a point', nil);
AddGetSet('Y', @TPyDelphiPoint.Get_Y, @TPyDelphiPoint.Set_Y,
'Provides access to the Y coordinate of a point', nil);
end;
end;
function TPyDelphiPoint.Repr: PPyObject;
begin
Result := GetPythonEngine.PyUnicodeFromString(Format('<Point (%d, %d)>',
[Value.X, Value.Y]));
end;
class procedure TPyDelphiPoint.SetupType(PythonType: TPythonType);
begin
inherited;
PythonType.TypeName := 'Point';
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType];
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'wrapper for Delphi TPoint type';
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
end;
function TPyDelphiPoint.Set_X(AValue: PPyObject;
AContext: Pointer): Integer;
var
x : Integer;
begin
if CheckIntAttribute(AValue, 'X', x) then
with GetPythonEngine do begin
Adjust(@Self);
fValue.X := x;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiPoint.Set_Y(AValue: PPyObject;
AContext: Pointer): Integer;
var
y : Integer;
begin
if CheckIntAttribute(AValue, 'Y', y) then
with GetPythonEngine do begin
Adjust(@Self);
fValue.Y := y;
Result := 0;
end
else
Result := -1;
end;
{ TPyDelphiRect }
function TPyDelphiRect.Compare(obj: PPyObject): Integer;
var
_other : TPyDelphiRect;
begin
if IsDelphiObject(obj) and (PythonToDelphi(obj) is TPyDelphiRect) then
begin
_other := TPyDelphiRect(PythonToDelphi(obj));
Result := CompareValue(Value.Left, _other.Value.Left);
if Result = 0 then
Result := CompareValue(Value.Top, _other.Value.Top);
if Result = 0 then
Result := CompareValue(Value.Right, _other.Value.Right);
if Result = 0 then
Result := CompareValue(Value.Bottom, _other.Value.Bottom);
end
else
Result := 1;
end;
constructor TPyDelphiRect.CreateWith(APythonType: TPythonType; args,
kwds: PPyObject);
begin
Create(APythonType);
APythonType.Engine.PyArg_ParseTuple( args, 'iiii:Create',@fValue.Left, @fValue.Top, @fValue.Right, @fValue.Bottom );
end;
function TPyDelphiRect.Get_Bottom(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.Bottom);
end;
function TPyDelphiRect.Get_BottomRight(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := WrapPoint(PyDelphiWrapper, Value.BottomRight);
end;
function TPyDelphiRect.Get_Left(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.Left);
end;
function TPyDelphiRect.Get_Right(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.Right);
end;
function TPyDelphiRect.Get_Top(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.Top);
end;
function TPyDelphiRect.Get_TopLeft(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := WrapPoint(PyDelphiWrapper, Value.TopLeft);
end;
class procedure TPyDelphiRect.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
with PythonType do
begin
AddGetSet('Left', @TPyDelphiRect.Get_Left, @TPyDelphiRect.Set_Left,
'Provides access to the Left coordinate of a rectangle', nil);
AddGetSet('Top', @TPyDelphiRect.Get_Top, @TPyDelphiRect.Set_Top,
'Provides access to the Top coordinate of a rectangle', nil);
AddGetSet('Right', @TPyDelphiRect.Get_Right, @TPyDelphiRect.Set_Right,
'Provides access to the Right coordinate of a rectangle', nil);
AddGetSet('Bottom', @TPyDelphiRect.Get_Bottom, @TPyDelphiRect.Set_Bottom,
'Provides access to the Bottom coordinate of a rectangle', nil);
AddGetSet('TopLeft', @TPyDelphiRect.Get_TopLeft, @TPyDelphiRect.Set_TopLeft,
'Provides access to the TopLeft coordinate of a rectangle', nil);
AddGetSet('BottomRight', @TPyDelphiRect.Get_BottomRight, @TPyDelphiRect.Set_BottomRight,
'Provides access to the BottomRight coordinate of a rectangle', nil);
end;
end;
function TPyDelphiRect.Repr: PPyObject;
begin
Result := GetPythonEngine.PyUnicodeFromString(Format('<Rect (%d, %d, %d, %d)>',
[Value.Left, Value.Top, Value.Right, Value.Bottom]));
end;
function TPyDelphiRect.Set_Bottom(AValue: PPyObject;
AContext: Pointer): Integer;
var
_value : Integer;
begin
if CheckIntAttribute(AValue, 'Bottom', _value) then
begin
Adjust(@Self);
fValue.Bottom := _value;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiRect.Set_BottomRight(AValue: PPyObject;
AContext: Pointer): Integer;
var
_value : TPoint;
begin
if CheckPointAttribute(AValue, 'BottomRight', _value) then
begin
Adjust(@Self);
fValue.BottomRight := _value;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiRect.Set_Left(AValue: PPyObject;
AContext: Pointer): Integer;
var
_value : Integer;
begin
if CheckIntAttribute(AValue, 'Left', _value) then
begin
Adjust(@Self);
fValue.Left := _value;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiRect.Set_Right(AValue: PPyObject;
AContext: Pointer): Integer;
var
_value : Integer;
begin
if CheckIntAttribute(AValue, 'Right', _value) then
begin
Adjust(@Self);
fValue.Right := _value;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiRect.Set_Top(AValue: PPyObject;
AContext: Pointer): Integer;
var
_value : Integer;
begin
if CheckIntAttribute(AValue, 'Top', _value) then
begin
Adjust(@Self);
fValue.Top := _value;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiRect.Set_TopLeft(AValue: PPyObject;
AContext: Pointer): Integer;
var
_value : TPoint;
begin
if CheckPointAttribute(AValue, 'TopLeft', _value) then
begin
Adjust(@Self);
fValue.TopLeft := _value;
Result := 0;
end
else
Result := -1;
end;
class procedure TPyDelphiRect.SetupType(PythonType: TPythonType);
begin
inherited;
PythonType.TypeName := 'Rect';
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType];
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'wrapper for Delphi TRect type';
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
end;
{ TPyDelphiSize }
function TPyDelphiSize.Compare(obj: PPyObject): Integer;
var
_other : TPyDelphiSize;
begin
if IsDelphiObject(obj) and (PythonToDelphi(obj) is TPyDelphiSize) then
begin
_other := TPyDelphiSize(PythonToDelphi(obj));
Result := CompareValue(Value.cx, _other.Value.cx);
if Result = 0 then
Result := CompareValue(Value.cy, _other.Value.cy);
end
else
Result := 1;
end;
constructor TPyDelphiSize.CreateWith(APythonType: TPythonType; args, kwds: PPyObject);
var
cx, cy : Integer;
begin
Create(APythonType);
if APythonType.Engine.PyArg_ParseTuple( args, 'ii:Create',@cx, @cy ) <> 0 then
begin
fValue.cx := cx;
fValue.cy := cy;
end
end;
function TPyDelphiSize.Get_CX(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.cx);
end;
function TPyDelphiSize.Get_CY(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Value.cy);
end;
class procedure TPyDelphiSize.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
with PythonType do
begin
AddGetSet('cx', @TPyDelphiSize.Get_CX, @TPyDelphiSize.Set_CX,
'Provides access to the width of the size', nil);
AddGetSet('cy', @TPyDelphiSize.Get_CY, @TPyDelphiSize.Set_CY,
'Provides access to the height of the size', nil);
end;
end;
function TPyDelphiSize.Repr: PPyObject;
begin
Result := GetPythonEngine.PyUnicodeFromString(Format('<Size (%d, %d)>',
[Value.cx, Value.cy]));
end;
class procedure TPyDelphiSize.SetupType(PythonType: TPythonType);
begin
inherited;
PythonType.TypeName := 'Size';
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType];
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'wrapper for Delphi TSize type';
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
end;
function TPyDelphiSize.Set_CX(AValue: PPyObject;
AContext: Pointer): Integer;
var
cx : Integer;
begin
if CheckIntAttribute(AValue, 'cx', cx) then
begin
Adjust(@Self);
fValue.cx := cx;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiSize.Set_CY(AValue: PPyObject;
AContext: Pointer): Integer;
var
cy : Integer;
begin
if CheckIntAttribute(AValue, 'cy', cy) then
begin
Adjust(@Self);
fValue.cy := cy;
Result := 0;
end
else
Result := -1;
end;
initialization
RegisteredUnits.Add(TTypesRegistration.Create);
end.