pyscripter / python4delphi

Free components that wrap up Python into Delphi and Lazarus (FPC)
MIT License
895 stars 307 forks source link

TPyDelphiStyleManager does not contain SetStyle function #414

Closed fansxs closed 11 months ago

fansxs commented 1 year ago

TPyDelphiStyleManager does not contain SetStyle function,and an error occurred when I tried to wrap the SetStyle function.

pyscripter commented 1 year ago

What error did you get?

Could you please submit a test project?

fansxs commented 1 year ago

// Add a SetStyle function function TPyDelphiStyleManager.SetStyle_Wrapper( AArgs: PPyObject): PPyObject; var LName: PAnsiChar; begin with GetPythonEngine do begin if PyArg_ParseTuple(AArgs, 's:SetStyle', @LName) <> 0 then begin TStyleManager.SetStyle(string(LName)); Result := GetPythonEngine().ReturnNone(); end else Result := nil; end; end;

class procedure TPyDelphiStyleManager.RegisterMethods(PythonType: TPythonType); begin PythonType.AddMethod('LoadFromFile', @TPyDelphiStyleManager.LoadFromFileName_Wrapper, 'TStyleManager.LoadFromFile()'#10 + 'Loads a VCL style from a file'); PythonType.AddMethod('IsValidStyle', @TPyDelphiStyleManager.IsValidStyle_Wrapper, 'TStyleManager.IsValidStyle()'#10 + 'Check if a Vcl Style file is valid'); // Add PythonType.AddMethod('SetStyle', @TPyDelphiStyleManager.SetStyle_Wrapper, 'TStyleManager.SetStyle()'#10 + 'Set a VCL style from a file'); end;

Then build it into the pyd file, and test in python code, like this(DelphiVCL4Python samples, activityindicator.py): ... self.sm.loadFromFile(style_file_path) ... self.sm.SetStyle(self.cbx_vcl_style.Text) ... Then an error occurs: TT截图未命名 Thank you for your reply. : )

pyscripter commented 1 year ago

@lmbelo Could you please have a look at this?

pyscripter commented 11 months ago

You do not need to wrap the SetStyle method. It is available via RTTI.

>>> from delphivcl import *
>>> dir(StyleManager)
['ActiveStyle',
 'AfterConstruction',
 'BeforeDestruction',
 'CheckSysClassName',
 'ClassInfo',
 'ClassName',
 'ClassNameIs',
 'ClassParent',
 'ClassType',
 'CleanupInstance',
 'Create',
 'DefaultHandler',
 'Destroy',
 'Dispatch',
 'DisposeOf',
 'Equals',
 'FieldAddress',
 'Free',
 'FreeInstance',
 'GetHashCode',
 'GetInterface',
 'GetInterfaceEntry',
 'GetInterfaceTable',
 'GetStyle',
 'HandleMessage',
 'InheritsFrom',
 'InitInstance',
 'Initialize',
 'InstanceSize',
 'IsCustomStyleAvailable',
 'IsSystemStyleDefault',
 'IsValidStyle',
 'LoadDesigningStyle',
 'LoadDesigningStyles',
 'LoadFromFile',
 'LoadFromResource',
 'MethodAddress',
 'MethodName',
 'NewInstance',
 'Notification',
 'QualifiedClassName',
 'RegisterStyle',
 'RegisterStyleClass',
 'RemoveDesigningStyle',
 'ResetDesigningStyles',
 'SafeCallException',
 'SetDesigningStyle',
 'SetProps',
 'SetStyle',
 'StyleNames',
 'ToList',
 'ToString',
 'ToTuple',
 'TryLoadFromResource',
 'TrySetDesigningStyle',
 'TrySetStyle',
 'UnInitialize',
 'UnRegisterStyle',
 'UnRegisterStyleClass',
 'UnRegisterStyleEngine',
 'UnitName',
 'UnitScope',
 '__bound__',
 '__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__owned__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__']
>>>