-
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathWrapVclForms.pas
2566 lines (2328 loc) · 87.5 KB
/
WrapVclForms.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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(**************************************************************************)
(* 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 WrapVclForms;
interface
uses
Classes, SysUtils, PythonEngine, WrapDelphi, WrapDelphiClasses, WrapVclControls,
Windows, Forms, Graphics, TypInfo;
type
TCloseQueryEventHandler = class(TEventHandler)
protected
procedure DoEvent(Sender: TObject; var CanClose : Boolean);
public
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
PropertyInfo : PPropInfo; Callable : PPyObject); override;
class function GetTypeInfo : PTypeInfo; override;
end;
TCloseEventHandler = class(TEventHandler)
protected
procedure DoEvent(Sender: TObject; var Action: TCloseAction);
public
constructor Create(PyDelphiWrapper : TPyDelphiWrapper; Component : TObject;
PropertyInfo : PPropInfo; Callable : PPyObject); override;
class function GetTypeInfo : PTypeInfo; override;
end;
{
PyObject wrapping TCustomForm
Exposes methods ShowModal, Close, CloseQuery, Release
Exposes property ModalResult
}
TPyDelphiCustomForm = class (TPyDelphiWinControl)
private
function GetDelphiObject: TCustomForm;
procedure SetDelphiObject(const Value: TCustomForm);
protected
function CreateComponent(AOwner : TComponent) : TComponent; override;
// Exposed Methods
function Close_Wrapper(args: PPyObject): PPyObject; cdecl;
function CloseQuery_Wrapper(args: PPyObject): PPyObject; cdecl;
function ShowModal_Wrapper(args: PPyObject): PPyObject; cdecl;
function Release_Wrapper(args : PPyObject) : PPyObject; cdecl;
//Load properties from .pydfm file
function LoadProps_Wrapper(args : PPyObject) : PPyObject; cdecl;
// Property Getters
function Get_ModalResult(AContext : Pointer) : PPyObject; cdecl;
// Property Setters
function Set_ModalResult(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
public
class function DelphiObjectClass : TClass; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
class procedure RegisterMethods( PythonType : TPythonType ); override;
// Properties
property DelphiObject: TCustomForm read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiForm = class (TPyDelphiCustomForm)
private
function GetDelphiObject: TForm;
procedure SetDelphiObject(const Value: TForm);
public
class function DelphiObjectClass : TClass; override;
// Properties
property DelphiObject: TForm read GetDelphiObject write SetDelphiObject;
end;
{
PyObject wrapping TMonitor
Exposes properties Handle, MonitorNum, Left, Height, Top, Width, BoundsRect, WorkareaRect, Primary
}
TPyDelphiMonitor = class (TPyDelphiObject)
private
function GetDelphiObject: TMonitor;
procedure SetDelphiObject(const Value: TMonitor);
protected
function Get_Handle(AContext : Pointer): PPyObject; cdecl;
function Get_MonitorNum(AContext : Pointer): PPyObject; cdecl;
function Get_Left(AContext : Pointer): PPyObject; cdecl;
function Get_Height(AContext : Pointer): PPyObject; cdecl;
function Get_Top(AContext : Pointer): PPyObject; cdecl;
function Get_Width(AContext : Pointer): PPyObject; cdecl;
function Get_BoundsRect(AContext : Pointer): PPyObject; cdecl;
function Get_WorkareaRect(AContext : Pointer): PPyObject; cdecl;
function Get_Primary(AContext : Pointer): PPyObject; cdecl;
public
// Class methods
class function DelphiObjectClass : TClass; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
// Properties
property DelphiObject: TMonitor read GetDelphiObject write SetDelphiObject;
end;
TBaseScreenAccess = class(TContainerAccess)
private
function GetContainer: TScreen;
public
class function ExpectedContainerClass : TClass; override;
property Container : TScreen read GetContainer;
end;
{
Access to the custom forms of the Screen singleton.
}
TScreenCustomFormsAccess = class(TBaseScreenAccess)
public
function GetItem(AIndex : Integer) : PPyObject; override;
function GetSize : Integer; override;
//function IndexOf(AValue : PPyObject) : Integer; override;
//class function SupportsIndexOf : Boolean; override;
class function Name : string; override;
end;
{
Access to the forms of the Screen singleton.
}
TScreenFormsAccess = class(TBaseScreenAccess)
public
function GetItem(AIndex : Integer) : PPyObject; override;
function GetSize : Integer; override;
//function IndexOf(AValue : PPyObject) : Integer; override;
//class function SupportsIndexOf : Boolean; override;
class function Name : string; override;
end;
{
Access to the TDataModule items of the Screen singleton.
}
TScreenDataModulesAccess = class(TBaseScreenAccess)
public
function GetItem(AIndex : Integer) : PPyObject; override;
function GetSize : Integer; override;
//function IndexOf(AValue : PPyObject) : Integer; override;
//class function SupportsIndexOf : Boolean; override;
class function Name : string; override;
end;
{
Access to the Cursors of the Screen singleton.
}
TScreenCursorsAccess = class(TBaseScreenAccess)
public
function GetItem(AIndex : Integer) : PPyObject; override;
function GetSize : Integer; override;
//function IndexOf(AValue : PPyObject) : Integer; override;
//class function SupportsIndexOf : Boolean; override;
class function Name : string; override;
end;
{
Access to the Monitors of the Screen singleton.
}
TScreenMonitorsAccess = class(TBaseScreenAccess)
public
function GetItem(AIndex : Integer) : PPyObject; override;
function GetSize : Integer; override;
//function IndexOf(AValue : PPyObject) : Integer; override;
//class function SupportsIndexOf : Boolean; override;
class function Name : string; override;
end;
{
PyObject wrapping TScreen
Exposes methods DisableAlign, EnableAlign, Realign, ResetFonts
Exposes all properties of TScreen
}
TPyDelphiScreen = class (TPyDelphiComponent)
private
fOnActiveControlChange: PPyObject;
fOnActiveFormChange: PPyObject;
function GetDelphiObject: TScreen;
procedure SetDelphiObject(const Value: TScreen);
procedure HandleOnActiveControlChange(Sender : TObject);
procedure HandleOnActiveFormChange(Sender : TObject);
protected
// Exposed Methods
function DisableAlign_Wrapper(args : PPyObject) : PPyObject; cdecl;
function EnableAlign_Wrapper(args : PPyObject) : PPyObject; cdecl;
function MonitorFromPoint_Wrapper(args : PPyObject) : PPyObject; cdecl;
//TODO: implementation
//function MonitorFromRect(const Rect: TRect; MonitorDefault: TMonitorDefaultTo = mdNearest): TMonitor;
//function MonitorFromWindow(const Handle: THandle; MonitorDefault: TMonitorDefaultTo = mdNearest): TMonitor;
function Realign_Wrapper(args : PPyObject) : PPyObject; cdecl;
function ResetFonts_Wrapper(args : PPyObject) : PPyObject; cdecl;
// Property Getters
function Get_ActiveControl(AContext : Pointer) : PPyObject; cdecl;
function Get_ActiveCustomForm(AContext : Pointer) : PPyObject; cdecl;
function Get_ActiveForm(AContext : Pointer) : PPyObject; cdecl;
function Get_CustomFormCount(AContext : Pointer) : PPyObject; cdecl;
function Get_CustomForms(AContext : Pointer) : PPyObject; cdecl;
function Get_Cursor(AContext : Pointer) : PPyObject; cdecl;
function Get_Cursors(AContext : Pointer) : PPyObject; cdecl;
function Get_DataModules(AContext : Pointer) : PPyObject; cdecl;
function Get_DataModuleCount(AContext : Pointer) : PPyObject; cdecl;
function Get_MonitorCount(AContext : Pointer) : PPyObject; cdecl;
function Get_Monitors(AContext : Pointer) : PPyObject; cdecl;
function Get_DesktopRect(AContext : Pointer) : PPyObject; cdecl;
function Get_DesktopLeft(AContext : Pointer) : PPyObject; cdecl;
function Get_DesktopTop(AContext : Pointer) : PPyObject; cdecl;
function Get_DesktopWidth(AContext : Pointer) : PPyObject; cdecl;
function Get_DesktopHeight(AContext : Pointer) : PPyObject; cdecl;
function Get_WorkAreaRect(AContext : Pointer) : PPyObject; cdecl;
function Get_WorkAreaHeight(AContext : Pointer) : PPyObject; cdecl;
function Get_WorkAreaLeft(AContext : Pointer) : PPyObject; cdecl;
function Get_WorkAreaTop(AContext : Pointer) : PPyObject; cdecl;
function Get_WorkAreaWidth(AContext : Pointer) : PPyObject; cdecl;
function Get_HintFont(AContext : Pointer) : PPyObject; cdecl;
function Get_IconFont(AContext : Pointer) : PPyObject; cdecl;
function Get_MenuFont(AContext : Pointer) : PPyObject; cdecl;
function Get_Fonts(AContext : Pointer) : PPyObject; cdecl;
function Get_FormCount(AContext : Pointer) : PPyObject; cdecl;
function Get_Forms(AContext : Pointer) : PPyObject; cdecl;
function Get_Imes(AContext : Pointer) : PPyObject; cdecl;
function Get_DefaultIme(AContext : Pointer) : PPyObject; cdecl;
function Get_DefaultKbLayout(AContext : Pointer) : PPyObject; cdecl;
function Get_Height(AContext : Pointer) : PPyObject; cdecl;
function Get_PixelsPerInch(AContext : Pointer) : PPyObject; cdecl;
function Get_Width(AContext : Pointer) : PPyObject; cdecl;
function Get_OnActiveControlChange(AContext : Pointer) : PPyObject; cdecl;
function Get_OnActiveFormChange(AContext : Pointer) : PPyObject; cdecl;
// Property Setters
function Set_Cursor(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_HintFont(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_IconFont(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_MenuFont(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_OnActiveControlChange(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
function Set_OnActiveFormChange(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
public
destructor Destroy; override;
// Class methods
class function DelphiObjectClass : TClass; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
class procedure RegisterMethods( PythonType : TPythonType ); override;
// Properties
property DelphiObject: TScreen read GetDelphiObject write SetDelphiObject;
end;
TPyDelphiApplication = class (TPyDelphiComponent)
private
function GetDelphiObject: TApplication;
procedure SetDelphiObject(const Value: TApplication);
protected
// Exposed Methods
function ActivateHint_Wrapper(args : PPyObject) : PPyObject; cdecl;
function BringToFront_Wrapper(args : PPyObject) : PPyObject; cdecl;
function CancelHint_Wrapper(args : PPyObject) : PPyObject; cdecl;
function ExecuteAction_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HandleException_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HandleMessage_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HelpCommand_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HelpContext_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HelpJump_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HelpKeyword_Wrapper(args : PPyObject) : PPyObject; cdecl;
function HideHint_Wrapper(args : PPyObject) : PPyObject; cdecl;
function Initialize_Wrapper(args : PPyObject) : PPyObject; cdecl;
function IsRightToLeft_Wrapper(args : PPyObject) : PPyObject; cdecl;
function MessageBox_Wrapper(args : PPyObject) : PPyObject; cdecl;
function Minimize_Wrapper(args : PPyObject) : PPyObject; cdecl;
function ModalStarted_Wrapper(args : PPyObject) : PPyObject; cdecl;
function ModalFinished_Wrapper(args : PPyObject) : PPyObject; cdecl;
function NormalizeAllTopMosts_Wrapper(args : PPyObject) : PPyObject; cdecl;
function NormalizeTopMosts_Wrapper(args : PPyObject) : PPyObject; cdecl;
function RestoreTopMosts_Wrapper(args : PPyObject) : PPyObject; cdecl;
function ProcessMessages_Wrapper(args : PPyObject) : PPyObject; cdecl;
function Restore_Wrapper(args : PPyObject) : PPyObject; cdecl;
function Run_Wrapper(args : PPyObject) : PPyObject; cdecl;
function ShowException_Wrapper(args : PPyObject) : PPyObject; cdecl;
function Terminate_Wrapper(args : PPyObject) : PPyObject; cdecl;
function UpdateAction_Wrapper(args : PPyObject) : PPyObject; cdecl;
function UseRightToLeftAlignment_Wrapper(args : PPyObject) : PPyObject; cdecl;
function UseRightToLeftReading_Wrapper(args : PPyObject) : PPyObject; cdecl;
function UseRightToLeftScrollBar_Wrapper(args : PPyObject) : PPyObject; cdecl;
// property getters
function Get_Active(AContext : Pointer): PPyObject; cdecl;
function Get_AllowTesting(AContext : Pointer): PPyObject; cdecl;
function Get_AutoDragDocking(AContext : Pointer): PPyObject; cdecl;
function Get_CurrentHelpFile(AContext : Pointer): PPyObject; cdecl;
function Get_DialogHandle(AContext : Pointer): PPyObject; cdecl;
function Get_Handle(AContext : Pointer): PPyObject; cdecl;
function Get_ExeName(AContext : Pointer): PPyObject; cdecl;
function Get_HelpFile(AContext : Pointer): PPyObject; cdecl;
function Get_Hint(AContext : Pointer): PPyObject; cdecl;
function Get_HintColor(AContext : Pointer): PPyObject; cdecl;
function Get_HintHidePause(AContext : Pointer): PPyObject; cdecl;
function Get_HintPause(AContext : Pointer): PPyObject; cdecl;
function Get_HintShortCuts(AContext : Pointer): PPyObject; cdecl;
function Get_HintShortPause(AContext : Pointer): PPyObject; cdecl;
function Get_Icon(AContext : Pointer): PPyObject; cdecl;
function Get_MainForm(AContext : Pointer): PPyObject; cdecl;
function Get_BiDiMode(AContext : Pointer): PPyObject; cdecl;
function Get_BiDiKeyboard(AContext : Pointer): PPyObject; cdecl;
function Get_NonBiDiKeyboard(AContext : Pointer): PPyObject; cdecl;
function Get_ShowHint(AContext : Pointer): PPyObject; cdecl;
function Get_ShowMainForm(AContext : Pointer): PPyObject; cdecl;
function Get_Terminated(AContext : Pointer): PPyObject; cdecl;
function Get_Title(AContext : Pointer): PPyObject; cdecl;
function Get_UpdateFormatSettings(AContext : Pointer): PPyObject; cdecl;
function Get_UpdateMetricSettings(AContext : Pointer): PPyObject; cdecl;
// property setters
function Set_AllowTesting(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_AutoDragDocking(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_DialogHandle(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_Handle(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_HelpFile(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_Hint(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_HintColor(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_HintHidePause(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_HintPause(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_HintShortCuts(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_HintShortPause(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_Icon(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_BiDiMode(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_BiDiKeyboard(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_NonBiDiKeyboard(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_ShowHint(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_ShowMainForm(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_Title(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_UpdateFormatSettings(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
function Set_UpdateMetricSettings(AValue : PPyObject; AContext : Pointer): Integer; cdecl;
public
// Class methods
class function DelphiObjectClass : TClass; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
class procedure RegisterMethods( PythonType : TPythonType ); override;
// Properties
property DelphiObject: TApplication read GetDelphiObject write SetDelphiObject;
end;
implementation
uses
WrapDelphiTypes, System.IOUtils, System.Rtti;
{ Global Functions }
function FreeConsole_Wrapper(pself, args: PPyObject): PPyObject; cdecl;
begin
FreeConsole;
Result := GetPythonEngine.ReturnNone;
end;
{ Register the wrappers, the globals and the constants }
type
TFormsRegistration = class(TRegisteredUnit)
public
function Name : string; override;
procedure RegisterWrappers(APyDelphiWrapper : TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper : TPyDelphiWrapper); override;
procedure DefineFunctions(APyDelphiWrapper : TPyDelphiWrapper); override;
end;
{ TFormsRegistration }
procedure TFormsRegistration.DefineFunctions(
APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterFunction(PAnsiChar('FreeConsole'), FreeConsole_Wrapper,
PAnsiChar('FreeConsole_Wrapper()'#10 +
'Frees the MS-DOS console associated with the process.'));
end;
procedure TFormsRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
// Singletons
APyDelphiWrapper.DefineVar('Application', Application);
APyDelphiWrapper.DefineVar('Screen', Screen);
// MessageBox flags
APyDelphiWrapper.DefineVar('MB_ABORTRETRYIGNORE', MB_ABORTRETRYIGNORE);
APyDelphiWrapper.DefineVar('MB_OK', MB_OK);
APyDelphiWrapper.DefineVar('MB_OKCANCEL', MB_OKCANCEL);
APyDelphiWrapper.DefineVar('MB_RETRYCANCEL', MB_RETRYCANCEL);
APyDelphiWrapper.DefineVar('MB_YESNO', MB_YESNO);
APyDelphiWrapper.DefineVar('MB_YESNOCANCEL', MB_YESNOCANCEL);
// MessageBox results
APyDelphiWrapper.DefineVar('IDOK', IDOK);
APyDelphiWrapper.DefineVar('IDCANCEL', IDCANCEL);
APyDelphiWrapper.DefineVar('IDABORT', IDABORT);
APyDelphiWrapper.DefineVar('IDRETRY', IDRETRY);
APyDelphiWrapper.DefineVar('IDIGNORE', IDIGNORE);
APyDelphiWrapper.DefineVar('IDYES', IDYES);
APyDelphiWrapper.DefineVar('IDNO', IDNO);
// TCloseAction enum
APyDelphiWrapper.DefineVar('caNone', caNone);
APyDelphiWrapper.DefineVar('caHide', caHide);
APyDelphiWrapper.DefineVar('caFree', caFree);
APyDelphiWrapper.DefineVar('caMinimize', caMinimize);
// TMonitorDefaultTo enum
APyDelphiWrapper.DefineVar('mdNearest', mdNearest);
APyDelphiWrapper.DefineVar('mdNull', mdNull);
APyDelphiWrapper.DefineVar('mdPrimary', mdPrimary);
end;
function TFormsRegistration.Name: string;
begin
Result := 'Forms';
end;
procedure TFormsRegistration.RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper);
begin
APyDelphiWrapper.EventHandlers.RegisterHandler(TCloseQueryEventHandler);
APyDelphiWrapper.EventHandlers.RegisterHandler(TCloseEventHandler);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomForm);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiForm);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiApplication);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiScreen);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMonitor);
end;
{ TPyDelphiCustomForm }
function TPyDelphiCustomForm.Close_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if GetPythonEngine.PyArg_ParseTuple( args, ':Close') <> 0 then begin
DelphiObject.Close;
Result := ReturnNone;
end else
Result := nil;
end;
end;
function TPyDelphiCustomForm.CloseQuery_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':CloseQuery') <> 0 then begin
Result := VariantAsPyObject(DelphiObject.CloseQuery)
end else
Result := nil;
end;
end;
function TPyDelphiCustomForm.Release_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do
begin
if PyArg_ParseTuple( args, ':Release') <> 0 then
begin
if Owned then begin
(DelphiObject as TForm).Release;
DelphiObject := nil;
Owned := False;
Result := ReturnNone;
end else begin
PyErr_SetString (PyExc_AttributeError^,
PAnsiChar('The Delphi form cannot be released, since it is not Owned'));
Result := nil;
end;
end
else
Result := nil;
end;
end;
function TPyDelphiCustomForm.ShowModal_Wrapper(args: PPyObject): PPyObject;
Var
ModalResult : integer;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ShowModal') <> 0 then begin
ModalResult := (DelphiObject as TForm).ShowModal;
Result := PyLong_FromLong(ModalResult);
end else
Result := nil;
end;
end;
function TPyDelphiCustomForm.GetDelphiObject: TCustomForm;
begin
Result := TCustomForm(inherited DelphiObject);
end;
procedure TPyDelphiCustomForm.SetDelphiObject(const Value: TCustomForm);
begin
inherited DelphiObject := Value;
end;
class procedure TPyDelphiCustomForm.RegisterGetSets(PythonType: TPythonType);
begin
with PythonType do
begin
AddGetSet('ModalResult', @TPyDelphiCustomForm.Get_ModalResult, @TPyDelphiCustomForm.Set_ModalResult,
'Represents the return value of a form that is used as a modal dialog.', nil);
end;
end;
class procedure TPyDelphiCustomForm.RegisterMethods(PythonType: TPythonType);
begin
PythonType.AddMethod('Close', @TPyDelphiCustomForm.Close_Wrapper,
'TForm.Close()'#10 +
'Closes the wrapped Form');
PythonType.AddMethod('CloseQuery', @TPyDelphiCustomForm.CloseQuery_Wrapper,
'TForm.CloseQuery()'#10 +
'Asked the wrapped Form if it can close');
PythonType.AddMethod('ShowModal', @TPyDelphiCustomForm.ShowModal_Wrapper,
'TForm.ShowModal()'#10 +
'Shows the wrapped Form as a modal form');
PythonType.AddMethod('Release', @TPyDelphiCustomForm.Release_Wrapper,
'TForm.Release()'#10 +
'Releases (destroys) the wrapped Form');
PythonType.AddMethod('LoadProps', @TPyDelphiCustomForm.LoadProps_Wrapper,
'TForm.LoadProps()'#10 +
'Load properties from a .pydfm file');
end;
class function TPyDelphiCustomForm.DelphiObjectClass: TClass;
begin
Result := TCustomForm;
end;
function TPyDelphiCustomForm.Get_ModalResult(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ModalResult);
end;
function TPyDelphiCustomForm.LoadProps_Wrapper(args: PPyObject): PPyObject;
function FindResource(): string;
var
LStr: PAnsiChar;
begin
with GetPythonEngine() do begin
if PyArg_ParseTuple(args, 's:LoadProps', @LStr) <> 0 then begin
Result := string(LStr);
end else
Result := String.Empty;
end;
end;
begin
Adjust(@Self);
try
if InternalReadComponent(FindResource(), DelphiObject) then
Exit(GetPythonEngine().ReturnTrue)
else
Exit(GetPythonEngine().ReturnFalse);
except
on E: Exception do
with GetPythonEngine() do
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(EncodeString(E.Message)));
end;
Result := nil;
end;
function TPyDelphiCustomForm.Set_ModalResult(AValue: PPyObject;
AContext: Pointer): Integer;
var
_modalResult : Integer;
begin
if CheckIntAttribute(AValue, 'ModalResult', _modalResult) then
with GetPythonEngine do begin
Adjust(@Self);
DelphiObject.ModalResult := _modalResult;
Result := 0;
end
else
Result := -1;
end;
function TPyDelphiCustomForm.CreateComponent(AOwner: TComponent): TComponent;
var
_class : TClass;
_compClass : TComponentClass;
_className : string;
begin
// get the default form class
_compClass := TComponentClass(DelphiObjectClass);
// if we have a subclass of our Form wrapper, then check if we can find
// a Delphi class that would have the same name as the Python class.
// This would allow Python to instanciate an existing Delphi form class,
// instead of only using a blank form.
if ob_type <> PythonType.TheTypePtr then
begin
_className := string(ob_type.tp_name);
_class := GetClass(_className);
if not Assigned(_class) then
_class := GetClass('T'+_className);
if Assigned(_class) and _class.InheritsFrom(TCustomForm) then
_compClass := TComponentClass(_class);
end;
// if the Owner is Application, then we have to call its CreateForm method,
// otherwise we won't have a main form defined, as the main form is the
// first created form. Of course, this is a concern only when Python
// controls all the GUI and calls Application.Run by itself.
if AOwner = Application then
Application.CreateForm(_compClass, Result)
else
Result := _compClass.Create(AOwner);
end;
{ TPyDelphiForm }
class function TPyDelphiForm.DelphiObjectClass: TClass;
begin
Result := TForm;
end;
function TPyDelphiForm.GetDelphiObject: TForm;
begin
Result := TForm(inherited DelphiObject);
end;
procedure TPyDelphiForm.SetDelphiObject(const Value: TForm);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiScreen }
class function TPyDelphiScreen.DelphiObjectClass: TClass;
begin
Result := TScreen;
end;
destructor TPyDelphiScreen.Destroy;
begin
if PythonOK then
begin
GetPythonEngine.Py_XDECREF(fOnActiveControlChange);
GetPythonEngine.Py_XDECREF(fOnActiveFormChange);
end;
inherited;
end;
function TPyDelphiScreen.DisableAlign_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':DisableAlign') <> 0 then begin
DelphiObject.DisableAlign;
Result := ReturnNone;
end else
Result := nil;
end;
end;
function TPyDelphiScreen.EnableAlign_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':EnableAlign') <> 0 then begin
DelphiObject.EnableAlign;
Result := ReturnNone;
end else
Result := nil;
end;
end;
function TPyDelphiScreen.GetDelphiObject: TScreen;
begin
Result := TScreen(inherited DelphiObject);
end;
function TPyDelphiScreen.Get_ActiveControl(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.ActiveControl);
end;
function TPyDelphiScreen.Get_ActiveCustomForm(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.ActiveCustomForm);
end;
function TPyDelphiScreen.Get_ActiveForm(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.ActiveForm);
end;
function TPyDelphiScreen.Get_Cursor(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Cursor);
end;
function TPyDelphiScreen.Get_Cursors(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := PyDelphiWrapper.DefaultContainerType.CreateInstance;
with PythonToDelphi(Result) as TPyDelphiContainer do
Setup(Self.PyDelphiWrapper, TScreenCursorsAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
end;
function TPyDelphiScreen.Get_CustomFormCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.CustomFormCount);
end;
function TPyDelphiScreen.Get_CustomForms(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := PyDelphiWrapper.DefaultContainerType.CreateInstance;
with PythonToDelphi(Result) as TPyDelphiContainer do
Setup(Self.PyDelphiWrapper, TScreenCustomFormsAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
end;
function TPyDelphiScreen.Get_DataModuleCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DataModuleCount);
end;
function TPyDelphiScreen.Get_DataModules(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := PyDelphiWrapper.DefaultContainerType.CreateInstance;
with PythonToDelphi(Result) as TPyDelphiContainer do
Setup(Self.PyDelphiWrapper, TScreenDataModulesAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
end;
function TPyDelphiScreen.Get_DefaultIme(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyUnicodeFromString(DelphiObject.DefaultIme);
end;
function TPyDelphiScreen.Get_DefaultKbLayout(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DefaultKbLayout);
end;
function TPyDelphiScreen.Get_DesktopHeight(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopHeight);
end;
function TPyDelphiScreen.Get_DesktopLeft(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopLeft);
end;
function TPyDelphiScreen.Get_DesktopRect(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := WrapRect(PyDelphiWrapper, DelphiObject.DesktopRect);
end;
function TPyDelphiScreen.Get_DesktopTop(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopTop);
end;
function TPyDelphiScreen.Get_DesktopWidth(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopWidth);
end;
function TPyDelphiScreen.Get_Fonts(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.Fonts);
end;
function TPyDelphiScreen.Get_FormCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.FormCount);
end;
function TPyDelphiScreen.Get_Forms(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := PyDelphiWrapper.DefaultContainerType.CreateInstance;
with PythonToDelphi(Result) as TPyDelphiContainer do
Setup(Self.PyDelphiWrapper, TScreenFormsAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
end;
function TPyDelphiScreen.Get_Height(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Height);
end;
function TPyDelphiScreen.Get_HintFont(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.HintFont);
end;
function TPyDelphiScreen.Get_IconFont(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.IconFont);
end;
function TPyDelphiScreen.Get_Imes(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.Imes);
end;
function TPyDelphiScreen.Get_MenuFont(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.MenuFont);
end;
function TPyDelphiScreen.Get_MonitorCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.MonitorCount);
end;
function TPyDelphiScreen.Get_Monitors(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := PyDelphiWrapper.DefaultContainerType.CreateInstance;
with PythonToDelphi(Result) as TPyDelphiContainer do
Setup(Self.PyDelphiWrapper, TScreenMonitorsAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
end;
function TPyDelphiScreen.Get_OnActiveControlChange(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
with GetPythonEngine do begin
if Assigned(fOnActiveControlChange) then
begin
Result := fOnActiveControlChange;
Py_XINCREF(Result);
end
else
Result := ReturnNone;
end;
end;
function TPyDelphiScreen.Get_OnActiveFormChange(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
with GetPythonEngine do begin
if Assigned(fOnActiveFormChange) then
begin
Result := fOnActiveFormChange;
Py_XINCREF(Result);
end
else
Result := ReturnNone;
end;
end;
function TPyDelphiScreen.Get_PixelsPerInch(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.PixelsPerInch);
end;
function TPyDelphiScreen.Get_Width(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Width);
end;
function TPyDelphiScreen.Get_WorkAreaHeight(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaHeight);
end;
function TPyDelphiScreen.Get_WorkAreaLeft(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaLeft);
end;
function TPyDelphiScreen.Get_WorkAreaRect(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := WrapRect(PyDelphiWrapper, DelphiObject.WorkAreaRect);
end;
function TPyDelphiScreen.Get_WorkAreaTop(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaTop);
end;
function TPyDelphiScreen.Get_WorkAreaWidth(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaWidth);
end;
procedure TPyDelphiScreen.HandleOnActiveControlChange(Sender: TObject);
begin
RaiseNotifyEvent(PyDelphiWrapper, fOnActiveControlChange, Sender);
end;
procedure TPyDelphiScreen.HandleOnActiveFormChange(Sender: TObject);
begin
RaiseNotifyEvent(PyDelphiWrapper, fOnActiveFormChange, Sender);
end;
function TPyDelphiScreen.MonitorFromPoint_Wrapper(args: PPyObject): PPyObject;
var
p : TPoint;
_pointObj : PPyObject;
_monitorDefault : Integer;
begin
// We adjust the transmitted self argument
Adjust(@Self);
if GetPythonEngine.PyArg_ParseTuple( args, 'Oi:MonitorFromPoint',@_pointObj, @_monitorDefault ) <> 0 then
begin
if CheckPointAttribute(_pointObj, 'First parameter', p) and
CheckEnum('TMonitorDefaultTo', _monitorDefault, Ord(Low(TMonitorDefaultTo)), Ord(High(TMonitorDefaultTo))) then
begin
Result := Wrap(DelphiObject.MonitorFromPoint(p, TMonitorDefaultTo(_monitorDefault)));
end
else
Result := nil;
end
else
Result := nil;
end;
function TPyDelphiScreen.Realign_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':Realign') <> 0 then begin
DelphiObject.Realign;
Result := ReturnNone;
end else
Result := nil;
end;
end;
function TPyDelphiScreen.ResetFonts_Wrapper(args: PPyObject): PPyObject;
begin
// We adjust the transmitted self argument
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ResetFonts') <> 0 then begin
DelphiObject.ResetFonts;
Result := ReturnNone;
end else
Result := nil;
end;
end;
class procedure TPyDelphiScreen.RegisterGetSets(PythonType: TPythonType);
begin
with PythonType do
begin
AddGetSet('ActiveControl', @TPyDelphiScreen.Get_ActiveControl, nil,
'Indicates which control currently has input focus on the screen.', nil);
AddGetSet('ActiveCustomForm', @TPyDelphiScreen.Get_ActiveCustomForm, nil,
'Indicates the descendant of TCustomForm that currently has focus.', nil);
AddGetSet('ActiveForm', @TPyDelphiScreen.Get_ActiveForm, nil,
'Indicates which form currently has focus.', nil);
AddGetSet('CustomFormCount', @TPyDelphiScreen.Get_CustomFormCount, nil,
'Indicates the number of forms or property pages displayed on the screen.', nil);
AddGetSet('CustomForms', @TPyDelphiScreen.Get_CustomForms, nil,