Skip to content

Commit c3eb3a2

Browse files
committed
Fixing unit naming convention
1 parent 68c3672 commit c3eb3a2

File tree

2 files changed

+67
-10
lines changed

2 files changed

+67
-10
lines changed

Packages/Delphi/Delphi 10.4+/PythonFmx.dpk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ contains
6060
WrapFmxStyles in '..\..\..\Source\fmx\WrapFmxStyles.pas',
6161
WrapFmxTypes in '..\..\..\Source\fmx\WrapFmxTypes.pas',
6262
WrapFmxDateTime in '..\..\..\Source\fmx\WrapFmxDateTime.pas',
63-
WrapFMXImgList in '..\..\..\Source\fmx\WrapFMXImgList.pas';
63+
WrapFmxImgList in '..\..\..\Source\fmx\WrapFmxImgList.pas';
6464

6565
end.

Source/fmx/WrapFMXImgList.pas renamed to Source/fmx/WrapFmxImgList.pas

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{$I Definition.Inc}
22

3-
unit WrapFMXImgList;
3+
unit WrapFmxImgList;
44

55
interface
66

@@ -16,6 +16,7 @@ TPyDelphiCustomImageList = class (TPyDelphiBaseImageList)
1616
protected
1717
function BitmapItemByName_Wrapper(AArgs: PPyObject): PPyObject; cdecl;
1818
function BestSize_Wrapper(AArgs: PPyObject): PPyObject; cdecl;
19+
function AddOrSet_Wrapper(AArgs: PPyObject): PPyObject; cdecl;
1920
public
2021
class function DelphiObjectClass : TClass; override;
2122
class procedure RegisterMethods(PythonType: TPythonType); override;
@@ -39,7 +40,7 @@ implementation
3940
System.Types,
4041
FMX.MultiResBitmap,
4142
WrapDelphiTypes,
42-
WrapFmxTypes;
43+
WrapFmxTypes, System.UITypes;
4344

4445
{ Register the wrappers, the globals and the constants }
4546
type
@@ -66,6 +67,52 @@ procedure TFmxImageListRegistration.RegisterWrappers(
6667

6768
{ TPyDelphiCustomImageList }
6869

70+
function TPyDelphiCustomImageList.AddOrSet_Wrapper(AArgs: PPyObject): PPyObject;
71+
var
72+
LPySourceName: PPyObject;
73+
LPyScales: PPyObject;
74+
LPyFileNames: PPyObject;
75+
76+
LSourceName: string;
77+
LScales: array of single;
78+
LFileNames: array of string;
79+
LTransparentColor: integer;
80+
LWidth: integer;
81+
LHeight: integer;
82+
I: integer;
83+
begin
84+
Adjust(@Self);
85+
LTransparentColor := TColors.SysNone;
86+
LWidth := 0;
87+
LHeight := 0;
88+
if GetPythonEngine().PyArg_ParseTuple(AArgs, 'OOO|iii:AddOrSet',
89+
@LPySourceName, @LPyScales, @LPyFileNames, @LTransparentColor, @LWidth, @LHeight) <> 0 then
90+
begin
91+
if not CheckStrAttribute(LPySourceName, 'SourceName', LSourceName) then
92+
Exit(nil);
93+
94+
if not GetPythonEngine().PyList_Check(LPyScales) then
95+
Exit(nil);
96+
97+
if not GetPythonEngine().PyList_Check(LPyFileNames) then
98+
Exit(nil);
99+
100+
SetLength(LScales, PythonType.Engine.PyList_Size(LPyScales));
101+
for I := 0 to GetPythonEngine().PyList_Size(LPyScales) - 1 do
102+
LScales[I] := GetPythonEngine().PyFloat_AsDouble(
103+
GetPythonEngine().PyList_GetItem(LPyScales, I));
104+
105+
SetLength(LFileNames, PythonType.Engine.PyList_Size(LPyFileNames));
106+
for I := 0 to GetPythonEngine().PyList_Size(LPyFileNames) - 1 do
107+
LFileNames[I] := GetPythonEngine.PyUnicodeAsString(
108+
GetPythonEngine().PyList_GetItem(LPyFileNames, I));
109+
110+
Result := GetPythonEngine().PyLong_FromLong(
111+
DelphiObject.AddOrSet(LSourceName, LScales, LFileNames, LTransparentColor, LWidth, LHeight));
112+
end else
113+
Result := nil;
114+
end;
115+
69116
function TPyDelphiCustomImageList.BestSize_Wrapper(AArgs: PPyObject): PPyObject;
70117

71118
procedure Append(const AList, AItem: PPyObject; const AIx: integer);
@@ -77,7 +124,6 @@ function TPyDelphiCustomImageList.BestSize_Wrapper(AArgs: PPyObject): PPyObject;
77124
end;
78125

79126
var
80-
LPyIndex: PPyObject;
81127
LPySize: PPyObject;
82128
LIndex: integer;
83129
LSize: TSize;
@@ -89,11 +135,9 @@ function TPyDelphiCustomImageList.BestSize_Wrapper(AArgs: PPyObject): PPyObject;
89135

90136
// We adjust the transmitted self argument
91137
Adjust(@Self);
92-
if GetPythonEngine().PyArg_ParseTuple(AArgs, 'iO:BestSize', @LPyIndex, @LPySize) <> 0 then begin
93-
if CheckIntAttribute(LPyIndex, 'Index', LIndex)
94-
and (CheckSizeAttribute(LPySize, 'Size', LSize)
95-
or
96-
(CheckSizeFAttribute(LPySize, 'Size', LSizeF))) then
138+
if GetPythonEngine().PyArg_ParseTuple(AArgs, 'iO:BestSize', @LIndex, @LPySize) <> 0 then begin
139+
if (CheckSizeAttribute(LPySize, 'Size', LSize) or
140+
(CheckSizeFAttribute(LPySize, 'Size', LSizeF))) then
97141
begin
98142
if not CheckIndex(LIndex, DelphiObject.Count) then
99143
Exit(nil);
@@ -141,7 +185,7 @@ function TPyDelphiCustomImageList.BitmapItemByName_Wrapper(
141185

142186
// We adjust the transmitted self argument
143187
Adjust(@Self);
144-
if GetPythonEngine().PyArg_ParseTuple(AArgs, 'sOO:BitmapItemByName', @LPyName, @LPyItem, @LPySize) <> 0 then begin
188+
if GetPythonEngine().PyArg_ParseTuple(AArgs, 'OOO:BitmapItemByName', @LPyName, @LPyItem, @LPySize) <> 0 then begin
145189
if CheckStrAttribute(LPyName, 'Name', LName)
146190
and CheckObjAttribute(LPyItem, 'Item', TCustomBitmapItem, TObject(LItem))
147191
and CheckSizeAttribute(LPySize, 'Size', LSize) then
@@ -175,6 +219,19 @@ class procedure TPyDelphiCustomImageList.RegisterMethods(
175219
@TPyDelphiCustomImageList.BitmapItemByName_Wrapper,
176220
'TCustomImageList.BitmapItemByName()'#10 +
177221
'Tries to find, in the source collection, the bitmap item specified by name.');
222+
223+
PythonType.AddMethod('BestSize',
224+
@TPyDelphiCustomImageList.BestSize_Wrapper,
225+
'TCustomImageList.BestSize()'#10 +
226+
'Tries to find, in the source collection, the bitmap item specified by name. ' +
227+
'This method trying to determine the maximum size of layer, which less than input size. '+
228+
'If TLayer.MultiResBitmap has multiple images for different scales, then the search is performed among all images.');
229+
230+
PythonType.AddMethod('AddOrSet',
231+
@TPyDelphiCustomImageList.AddOrSet_Wrapper,
232+
'TCustomImageList.AddOrSet()'#10 +
233+
'Adds or replaces several files in the source collection, ' +
234+
'and adds the item to the destination collection if it does not exist.');
178235
end;
179236

180237
procedure TPyDelphiCustomImageList.SetDelphiObject(

0 commit comments

Comments
 (0)