-
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathWrapVclExtCtrls.pas
637 lines (520 loc) · 17.5 KB
/
WrapVclExtCtrls.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
(**************************************************************************)
(* 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 WrapVclExtCtrls;
interface
uses
Classes, SysUtils, PythonEngine, WrapDelphi, WrapDelphiClasses, WrapVclControls,
Windows, ExtCtrls, TypInfo, Rtti;
type
TPyDelphiShape = class (TPyDelphiGraphicControl)
private
function GetDelphiObject: TShape;
procedure SetDelphiObject(const Value: TShape);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TShape read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiPaintBox = class (TPyDelphiGraphicControl)
private
function GetDelphiObject: TPaintBox;
procedure SetDelphiObject(const Value: TPaintBox);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TPaintBox read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiImage = class (TPyDelphiGraphicControl)
private
function GetDelphiObject: TImage;
procedure SetDelphiObject(const Value: TImage);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TImage read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiBevel = class (TPyDelphiGraphicControl)
private
function GetDelphiObject: TBevel;
procedure SetDelphiObject(const Value: TBevel);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TBevel read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiTimer = class (TPyDelphiComponent)
private
function GetDelphiObject: TTimer;
procedure SetDelphiObject(const Value: TTimer);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TTimer read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiPanel = class (TPyDelphiWinControl)
private
function GetDelphiObject: TPanel;
procedure SetDelphiObject(const Value: TPanel);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TPanel read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiPage = class (TPyDelphiWinControl)
private
function GetDelphiObject: TPage;
procedure SetDelphiObject(const Value: TPage);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TPage read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiNotebook = class (TPyDelphiWinControl)
private
function GetDelphiObject: TNotebook;
procedure SetDelphiObject(const Value: TNotebook);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TNotebook read GetDelphiObject write SetDelphiObject;
end;
{$IFNDEF FPC}
TPyDelphiHeader = class (TPyDelphiWinControl)
private
function GetDelphiObject: THeader;
procedure SetDelphiObject(const Value: THeader);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: THeader read GetDelphiObject write SetDelphiObject;
end;
{$ENDIF FPC}
TPyDelphiRadioGroup = class (TPyDelphiWinControl)
private
function GetDelphiObject: TRadioGroup;
procedure SetDelphiObject(const Value: TRadioGroup);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TRadioGroup read GetDelphiObject write SetDelphiObject;
end;
{$IFDEF FPC}
TPyDelphiSplitter = class (TPyDelphiWinControl)
{$ELSE FPC}
TPyDelphiSplitter = class (TPyDelphiGraphicControl)
{$ENDIF FPC}
private
function GetDelphiObject: TSplitter;
procedure SetDelphiObject(const Value: TSplitter);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TSplitter read GetDelphiObject write SetDelphiObject;
end;
{$IFNDEF FPC}
TPyDelphiControlBar = class (TPyDelphiWinControl)
private
function GetDelphiObject: TControlBar;
procedure SetDelphiObject(const Value: TControlBar);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TControlBar read GetDelphiObject write SetDelphiObject;
end;
{$ENDIF FPC}
TPyDelphiBoundLabel = class (TPyDelphiControl)
private
function GetDelphiObject: TBoundLabel;
procedure SetDelphiObject(const Value: TBoundLabel);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TBoundLabel read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiLabeledEdit = class (TPyDelphiWinControl)
private
function GetDelphiObject: TLabeledEdit;
procedure SetDelphiObject(const Value: TLabeledEdit);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TLabeledEdit read GetDelphiObject write SetDelphiObject;
end;
{$IFNDEF FPC}
TPyDelphiColorBox = class (TPyDelphiWinControl)
private
function GetDelphiObject: TColorBox;
procedure SetDelphiObject(const Value: TColorBox);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TColorBox read GetDelphiObject write SetDelphiObject;
end;
{$ENDIF FPC}
TSysLinkEventHandler = class(TEventHandler)
protected
procedure DoEvent(Sender: TObject; const Link: string; LinkType: TSysLinkType);
public
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
PropertyInfo : PPropInfo; Callable : PPyObject); override;
class function GetTypeInfo : PTypeInfo; override;
end;
TPyDelphiCustomLinkLabel = class (TPyDelphiWinControl)
private
function GetDelphiObject: TCustomLinkLabel;
procedure SetDelphiObject(const Value: TCustomLinkLabel);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TCustomLinkLabel read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiLinkLabel = class (TPyDelphiCustomLinkLabel)
private
function GetDelphiObject: TLinkLabel;
procedure SetDelphiObject(const Value: TLinkLabel);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TLinkLabel read GetDelphiObject write SetDelphiObject;
end;
function SysLinkTypeToPython(const ASysLinkType: TSysLinkType): PPyObject;
implementation
{ Register the wrappers, the globals and the constants }
type
TExtCtrlsRegistration = class(TRegisteredUnit)
public
function Name : string; override;
procedure RegisterWrappers(APyDelphiWrapper : TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper : TPyDelphiWrapper); override;
end;
{ TExtCtrlsRegistration }
procedure TExtCtrlsRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
end;
function TExtCtrlsRegistration.Name: string;
begin
Result := 'ExtCtrls';
end;
procedure TExtCtrlsRegistration.RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiShape);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPaintBox);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiImage);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiBevel);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiTimer);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPanel);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPage);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiNotebook);
{$IFNDEF FPC}
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiHeader);
{$ENDIF FPC}
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiRadioGroup);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiSplitter);
{$IFNDEF FPC}
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiControlBar);
{$ENDIF FPC}
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiBoundLabel);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiLabeledEdit);
{$IFNDEF FPC}
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiColorBox);
{$ENDIF FPC}
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomLinkLabel);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiLinkLabel);
// Event handlers
APyDelphiWrapper.EventHandlers.RegisterHandler(TSysLinkEventHandler);
end;
function SysLinkTypeToPython(const ASysLinkType: TSysLinkType): PPyObject;
begin
Result := GetPythonEngine.PyUnicodeFromString(
TRttiEnumerationType.GetName<TSysLinkType>(ASysLinkType));
end;
{ TPyDelphiShape }
class function TPyDelphiShape.DelphiObjectClass: TClass;
begin
Result := TShape;
end;
function TPyDelphiShape.GetDelphiObject: TShape;
begin
Result := TShape(inherited DelphiObject);
end;
procedure TPyDelphiShape.SetDelphiObject(const Value: TShape);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiPaintBox }
class function TPyDelphiPaintBox.DelphiObjectClass: TClass;
begin
Result := TPaintBox;
end;
function TPyDelphiPaintBox.GetDelphiObject: TPaintBox;
begin
Result := TPaintBox(inherited DelphiObject);
end;
procedure TPyDelphiPaintBox.SetDelphiObject(const Value: TPaintBox);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiImage }
class function TPyDelphiImage.DelphiObjectClass: TClass;
begin
Result := TImage;
end;
function TPyDelphiImage.GetDelphiObject: TImage;
begin
Result := TImage(inherited DelphiObject);
end;
procedure TPyDelphiImage.SetDelphiObject(const Value: TImage);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiBevel }
class function TPyDelphiBevel.DelphiObjectClass: TClass;
begin
Result := TBevel;
end;
function TPyDelphiBevel.GetDelphiObject: TBevel;
begin
Result := TBevel(inherited DelphiObject);
end;
procedure TPyDelphiBevel.SetDelphiObject(const Value: TBevel);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiTimer }
class function TPyDelphiTimer.DelphiObjectClass: TClass;
begin
Result := TTimer;
end;
function TPyDelphiTimer.GetDelphiObject: TTimer;
begin
Result := TTimer(inherited DelphiObject);
end;
procedure TPyDelphiTimer.SetDelphiObject(const Value: TTimer);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiPanel }
class function TPyDelphiPanel.DelphiObjectClass: TClass;
begin
Result := TPanel;
end;
function TPyDelphiPanel.GetDelphiObject: TPanel;
begin
Result := TPanel(inherited DelphiObject);
end;
procedure TPyDelphiPanel.SetDelphiObject(const Value: TPanel);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiPage }
class function TPyDelphiPage.DelphiObjectClass: TClass;
begin
Result := TPage;
end;
function TPyDelphiPage.GetDelphiObject: TPage;
begin
Result := TPage(inherited DelphiObject);
end;
procedure TPyDelphiPage.SetDelphiObject(const Value: TPage);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiNotebook }
class function TPyDelphiNotebook.DelphiObjectClass: TClass;
begin
Result := TNotebook;
end;
function TPyDelphiNotebook.GetDelphiObject: TNotebook;
begin
Result := TNotebook(inherited DelphiObject);
end;
procedure TPyDelphiNotebook.SetDelphiObject(const Value: TNotebook);
begin
inherited DelphiObject := Value;
end;
{$IFNDEF FPC}
{ TPyDelphiHeader }
class function TPyDelphiHeader.DelphiObjectClass: TClass;
begin
Result := THeader;
end;
function TPyDelphiHeader.GetDelphiObject: THeader;
begin
Result := THeader(inherited DelphiObject);
end;
procedure TPyDelphiHeader.SetDelphiObject(const Value: THeader);
begin
inherited DelphiObject := Value;
end;
{$ENDIF FPC}
{ TPyDelphiRadioGroup }
class function TPyDelphiRadioGroup.DelphiObjectClass: TClass;
begin
Result := TRadioGroup;
end;
function TPyDelphiRadioGroup.GetDelphiObject: TRadioGroup;
begin
Result := TRadioGroup(inherited DelphiObject);
end;
procedure TPyDelphiRadioGroup.SetDelphiObject(const Value: TRadioGroup);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiSplitter }
class function TPyDelphiSplitter.DelphiObjectClass: TClass;
begin
Result := TSplitter;
end;
function TPyDelphiSplitter.GetDelphiObject: TSplitter;
begin
Result := TSplitter(inherited DelphiObject);
end;
procedure TPyDelphiSplitter.SetDelphiObject(const Value: TSplitter);
begin
inherited DelphiObject := Value;
end;
{$IFNDEF FPC}
{ TPyDelphiControlBar }
class function TPyDelphiControlBar.DelphiObjectClass: TClass;
begin
Result := TControlBar;
end;
function TPyDelphiControlBar.GetDelphiObject: TControlBar;
begin
Result := TControlBar(inherited DelphiObject);
end;
procedure TPyDelphiControlBar.SetDelphiObject(const Value: TControlBar);
begin
inherited DelphiObject := Value;
end;
{$ENDIF FPC}
{ TPyDelphiBoundLabel }
class function TPyDelphiBoundLabel.DelphiObjectClass: TClass;
begin
Result := TBoundLabel;
end;
function TPyDelphiBoundLabel.GetDelphiObject: TBoundLabel;
begin
Result := TBoundLabel(inherited DelphiObject);
end;
procedure TPyDelphiBoundLabel.SetDelphiObject(const Value: TBoundLabel);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiLabeledEdit }
class function TPyDelphiLabeledEdit.DelphiObjectClass: TClass;
begin
Result := TLabeledEdit;
end;
function TPyDelphiLabeledEdit.GetDelphiObject: TLabeledEdit;
begin
Result := TLabeledEdit(inherited DelphiObject);
end;
procedure TPyDelphiLabeledEdit.SetDelphiObject(const Value: TLabeledEdit);
begin
inherited DelphiObject := Value;
end;
{$IFNDEF FPC}
{ TPyDelphiColorBox }
class function TPyDelphiColorBox.DelphiObjectClass: TClass;
begin
Result := TColorBox;
end;
function TPyDelphiColorBox.GetDelphiObject: TColorBox;
begin
Result := TColorBox(inherited DelphiObject);
end;
procedure TPyDelphiColorBox.SetDelphiObject(const Value: TColorBox);
begin
inherited DelphiObject := Value;
end;
{$ENDIF FPC}
{ TSysLinkEventHandler }
constructor TSysLinkEventHandler.Create(PyDelphiWrapper: TPyDelphiWrapper;
Component: TObject; PropertyInfo: PPropInfo; Callable: PPyObject);
var
LMethod : TMethod;
begin
inherited;
LMethod.Code := @TSysLinkEventHandler.DoEvent;
LMethod.Data := Self;
SetMethodProp(Component, PropertyInfo, LMethod);
end;
procedure TSysLinkEventHandler.DoEvent(Sender: TObject; const Link: string;
LinkType: TSysLinkType);
var
LPyTuple, LPySender, LPyLink, LPyLinkType, PyResult: PPyObject;
begin
Assert(Assigned(PyDelphiWrapper));
if Assigned(Callable) and PythonOK then
with GetPythonEngine do begin
LPySender := PyDelphiWrapper.Wrap(Sender);
LPyLink := PyUnicodeFromString(Link);
LPyLinkType := SysLinkTypeToPython(LinkType);
LPyTuple := PyTuple_New(3);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 0, LPySender);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 1, LPyLink);
GetPythonEngine.PyTuple_SetItem(LPyTuple, 2, LPyLinkType);
try
PyResult := PyObject_CallObject(Callable, LPyTuple);
Py_XDECREF(PyResult);
finally
Py_DECREF(LPyTuple);
end;
CheckError;
end;
end;
class function TSysLinkEventHandler.GetTypeInfo: PTypeInfo;
begin
Result := System.TypeInfo(TSysLinkEvent);
end;
{ TPyDelphiCustomLinkLabel }
class function TPyDelphiCustomLinkLabel.DelphiObjectClass: TClass;
begin
Result := TCustomLinkLabel;
end;
function TPyDelphiCustomLinkLabel.GetDelphiObject: TCustomLinkLabel;
begin
Result := TCustomLinkLabel(inherited DelphiObject);
end;
procedure TPyDelphiCustomLinkLabel.SetDelphiObject(
const Value: TCustomLinkLabel);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiLinkLabel }
class function TPyDelphiLinkLabel.DelphiObjectClass: TClass;
begin
Result := TLinkLabel;
end;
function TPyDelphiLinkLabel.GetDelphiObject: TLinkLabel;
begin
Result := TLinkLabel(inherited DelphiObject);
end;
procedure TPyDelphiLinkLabel.SetDelphiObject(const Value: TLinkLabel);
begin
inherited DelphiObject := Value;
end;
initialization
RegisteredUnits.Add( TExtCtrlsRegistration.Create );
{$IFDEF FPC}
Classes.RegisterClasses([TShape, TPaintBox, TImage, TBevel, TTimer, TPanel, TPage, TNotebook,
TRadioGroup, TSplitter, TBoundLabel, TLabeledEdit]);
{$ELSE FPC}
Classes.RegisterClasses([TShape, TPaintBox, TImage, TBevel, TTimer, TPanel, TPage, TNotebook, THeader,
TRadioGroup, TSplitter, TControlBar, TBoundLabel, TLabeledEdit, TColorBox]);
{$ENDIF FPC}
end.