|
| 1 | +unit WrapDelphiDialogs; |
| 2 | +{$I Definition.Inc} |
| 3 | + |
| 4 | +interface |
| 5 | + |
| 6 | +uses |
| 7 | + Classes, SysUtils, PythonEngine, WrapDelphi, WrapDelphiClasses, |
| 8 | + WrapDelphiControls, Windows, Dialogs, TypInfo; |
| 9 | + |
| 10 | +type |
| 11 | + TPyDelphiOpenDialog = class(TPyDelphiComponent) |
| 12 | + private |
| 13 | + function GetDelphiObject: TOpenDialog; |
| 14 | + procedure SetDelphiObject(const Value: TOpenDialog); |
| 15 | + protected |
| 16 | + // Exposed Methods |
| 17 | + function Execute_Wrapper(args: PPyObject): PPyObject; cdecl; |
| 18 | + // Property Getters |
| 19 | + function Get_filename(AContext: Pointer): PPyObject; cdecl; |
| 20 | + public |
| 21 | + class function DelphiObjectClass: TClass; override; |
| 22 | + class procedure RegisterGetSets(PythonType: TPythonType); override; |
| 23 | + class procedure RegisterMethods( PythonType : TPythonType ); override; |
| 24 | + // Properties |
| 25 | + property DelphiObject: TOpenDialog read GetDelphiObject |
| 26 | + write SetDelphiObject; |
| 27 | + end; |
| 28 | + |
| 29 | +implementation |
| 30 | + |
| 31 | +uses |
| 32 | + WrapDelphiTypes; |
| 33 | + |
| 34 | +{ Register the wrappers, the globals and the constants } |
| 35 | +type |
| 36 | + TDialogRegistration = class(TRegisteredUnit) |
| 37 | + public |
| 38 | + function Name: String; override; |
| 39 | + procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override; |
| 40 | + procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override; |
| 41 | + end; |
| 42 | + |
| 43 | + { TDialogRegistration } |
| 44 | +procedure TDialogRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper); |
| 45 | +begin |
| 46 | + inherited; |
| 47 | +end; |
| 48 | + |
| 49 | +function TDialogRegistration.Name: String; |
| 50 | +begin |
| 51 | + Result := 'Dialog'; |
| 52 | +end; |
| 53 | + |
| 54 | +procedure TDialogRegistration.RegisterWrappers(APyDelphiWrapper |
| 55 | + : TPyDelphiWrapper); |
| 56 | +begin |
| 57 | + inherited; |
| 58 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiOpenDialog); |
| 59 | +end; |
| 60 | + |
| 61 | +{ TPyDelphiOpenDialog } |
| 62 | +class function TPyDelphiOpenDialog.DelphiObjectClass: TClass; |
| 63 | +begin |
| 64 | + Result := TOpenDialog; |
| 65 | +end; |
| 66 | + |
| 67 | +function TPyDelphiOpenDialog.GetDelphiObject: TOpenDialog; |
| 68 | +begin |
| 69 | + Result := TOpenDialog(inherited DelphiObject); |
| 70 | +end; |
| 71 | + |
| 72 | +function TPyDelphiOpenDialog.Execute_Wrapper(args: PPyObject): PPyObject; |
| 73 | +begin |
| 74 | + with GetPythonEngine do begin |
| 75 | + // We adjust the transmitted self argument |
| 76 | + Adjust(@Self); |
| 77 | + if PyArg_ParseTuple( args, ':Execute') <> 0 then |
| 78 | + Result := VariantAsPyObject(DelphiObject.Execute()) |
| 79 | + else |
| 80 | + Result := nil; |
| 81 | + end; |
| 82 | +end; |
| 83 | + |
| 84 | +function TPyDelphiOpenDialog.Get_filename(AContext: Pointer): PPyObject; |
| 85 | +begin |
| 86 | + with GetPythonEngine do |
| 87 | + begin |
| 88 | + Adjust(@self); |
| 89 | + Result := VariantAsPyObject(DelphiObject.FileName); |
| 90 | + end; |
| 91 | +end; |
| 92 | + |
| 93 | +class procedure TPyDelphiOpenDialog.RegisterGetSets(PythonType: TPythonType); |
| 94 | +begin |
| 95 | + inherited; |
| 96 | + PythonType.AddGetSet('FileName', @TPyDelphiOpenDialog.Get_filename, |
| 97 | + nil, '', nil); |
| 98 | +end; |
| 99 | + |
| 100 | +class procedure TPyDelphiOpenDialog.RegisterMethods(PythonType: TPythonType); |
| 101 | +begin |
| 102 | + inherited; |
| 103 | + PythonType.AddMethod('Execute', @TPyDelphiOpenDialog.Execute_Wrapper, |
| 104 | + 'TOpenDialog.Execute()'#10 + |
| 105 | + 'Displays the dialog'); |
| 106 | +end; |
| 107 | + |
| 108 | +procedure TPyDelphiOpenDialog.SetDelphiObject(const Value: TOpenDialog); |
| 109 | +begin |
| 110 | + inherited DelphiObject := Value; |
| 111 | +end; |
| 112 | + |
| 113 | +initialization |
| 114 | + RegisteredUnits.Add(TDialogRegistration.Create); |
| 115 | +end. |
0 commit comments