@@ -731,7 +731,8 @@ TPyDelphiListView = class(TPyDelphiCustomListView)
731
731
732
732
function CustomDrawTargetToPython (const ACustomDrawTarget: TCustomDrawTarget): PPyObject;
733
733
function CustomDrawStageToPython (const ACustomDrawStage: TCustomDrawStage): PPyObject;
734
- function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState): PPyObject;
734
+ function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState;
735
+ DelphiWrapper: TPyDelphiWrapper): PPyObject;
735
736
736
737
function ItemChangeToPython (const AItemChange: TItemChange): PPyObject;
737
738
function ItemStateToPython (const AItemState: TItemState): PPyObject;
@@ -742,8 +743,10 @@ TPyDelphiListView = class(TPyDelphiCustomListView)
742
743
implementation
743
744
744
745
uses
745
- WrapDelphiTypes, WrapDelphiWindows,
746
- Vcl.ExtCtrls;
746
+ System.Rtti,
747
+ Vcl.ExtCtrls,
748
+ WrapDelphiTypes,
749
+ WrapDelphiWindows;
747
750
748
751
{ Register the wrappers, the globals and the constants }
749
752
type
@@ -780,31 +783,14 @@ function CustomDrawStageToPython(const ACustomDrawStage: TCustomDrawStage): PPyO
780
783
Ord(ACustomDrawStage)));
781
784
end ;
782
785
783
- function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState): PPyObject;
784
-
785
- procedure Append (const AList: PPyObject; const AString: string);
786
- var
787
- LItem: PPyObject;
788
- begin
789
- with GetPythonEngine do begin
790
- LItem := PyUnicodeFromString(AString);
791
- PyList_Append(AList, LItem);
792
- Py_XDecRef(LItem);
793
- end ;
794
- end ;
795
-
786
+ function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState;
787
+ DelphiWrapper: TPyDelphiWrapper): PPyObject;
796
788
var
797
- LCompType: PTypeInfo;
798
- LMin: integer;
799
- LMax: integer;
800
- LState: integer;
789
+ ErrMsg: string;
790
+ Value : TValue;
801
791
begin
802
- Result := GetPythonEngine().PyList_New(0 );
803
- LCompType := GetTypeData(TypeInfo(TCustomDrawState)).CompType^;
804
- LMin := LCompType^.TypeData^.MinValue;
805
- LMax := LCompType^.TypeData^.MaxValue;
806
- for LState := LMin to LMax do
807
- Append(Result, GetEnumName(LCompType, LState));
792
+ Value := TValue.From(ACustomDrawState);
793
+ Result := TValueToPyObject(Value , DelphiWrapper, ErrMsg);
808
794
end ;
809
795
810
796
function ItemChangeToPython (const AItemChange: TItemChange): PPyObject;
@@ -2203,7 +2189,7 @@ procedure TTVCustomDrawItemEventHandler.DoEvent(Sender: TCustomTreeView;
2203
2189
LPyTuple := PyTuple_New(4 );
2204
2190
PyTuple_SetItem(LPyTuple, 0 , LPyObject);
2205
2191
PyTuple_SetItem(LPyTuple, 1 , LPyNode);
2206
- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
2192
+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
2207
2193
PyTuple_SetItem(LPyTuple, 3 , LPyDefaultDraw);
2208
2194
try
2209
2195
LPyResult := PyObject_CallObject(Callable, LPyTuple);
@@ -2306,7 +2292,7 @@ procedure TTVAdvancedCustomDrawItemEventHandler.DoEvent(Sender: TCustomTreeView;
2306
2292
LPyTuple := PyTuple_New(6 );
2307
2293
PyTuple_SetItem(LPyTuple, 0 , LPyObject);
2308
2294
PyTuple_SetItem(LPyTuple, 1 , LPyNode);
2309
- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
2295
+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
2310
2296
PyTuple_SetItem(LPyTuple, 3 , CustomDrawStageToPython(Stage));
2311
2297
PyTuple_SetItem(LPyTuple, 4 , LPyPaintImages);
2312
2298
PyTuple_SetItem(LPyTuple, 5 , LPyDefaultDraw);
@@ -3098,7 +3084,7 @@ procedure TLVCustomDrawItemEventHandler.DoEvent(Sender: TCustomListView;
3098
3084
LPyTuple := PyTuple_New(4 );
3099
3085
PyTuple_SetItem(LPyTuple, 0 , LPyObject);
3100
3086
PyTuple_SetItem(LPyTuple, 1 , LPyItem);
3101
- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
3087
+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
3102
3088
PyTuple_SetItem(LPyTuple, 3 , LPyDefaultDraw);
3103
3089
try
3104
3090
LPyResult := PyObject_CallObject(Callable, LPyTuple);
@@ -3150,7 +3136,7 @@ procedure TLVCustomDrawSubItemEventHandler.DoEvent(Sender: TCustomListView;
3150
3136
PyTuple_SetItem(LPyTuple, 0 , LPyObject);
3151
3137
PyTuple_SetItem(LPyTuple, 1 , LPyItem);
3152
3138
PyTuple_SetItem(LPyTuple, 2 , PyLong_FromLong(SubItem));
3153
- PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State));
3139
+ PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State, PyDelphiWrapper ));
3154
3140
PyTuple_SetItem(LPyTuple, 4 , LPyDefaultDraw);
3155
3141
try
3156
3142
LPyResult := PyObject_CallObject(Callable, LPyTuple);
@@ -3251,7 +3237,7 @@ procedure TLVAdvancedCustomDrawItemEventHandler.DoEvent(Sender: TCustomListView;
3251
3237
LPyTuple := PyTuple_New(5 );
3252
3238
PyTuple_SetItem(LPyTuple, 0 , LPyObject);
3253
3239
PyTuple_SetItem(LPyTuple, 1 , LPyItem);
3254
- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
3240
+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
3255
3241
PyTuple_SetItem(LPyTuple, 3 , CustomDrawStageToPython(Stage));
3256
3242
PyTuple_SetItem(LPyTuple, 4 , LPyDefaultDraw);
3257
3243
try
@@ -3304,7 +3290,7 @@ procedure TLVAdvancedCustomDrawSubItemEventHandler.DoEvent(
3304
3290
PyTuple_SetItem(LPyTuple, 0 , LPyObject);
3305
3291
PyTuple_SetItem(LPyTuple, 1 , LPyItem);
3306
3292
PyTuple_SetItem(LPyTuple, 2 , PyLong_FromLong(SubItem));
3307
- PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State));
3293
+ PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State, PyDelphiWrapper ));
3308
3294
PyTuple_SetItem(LPyTuple, 4 , CustomDrawStageToPython(Stage));
3309
3295
PyTuple_SetItem(LPyTuple, 5 , LPyDefaultDraw);
3310
3296
try
0 commit comments