New Ansys.UI.Toolkit.GridViewTextCell __init__ problem
I try to create a new Ansys.UI.Toolkit.GridViewTextCell Class and set the new init defination, but there is one problem occur.
import clr clr.AddReference("Ans.UI.Toolkit") clr.AddReference("Ans.UI.Toolkit.Base") import Ansys.UI.Toolkit import Ansys.UI.Toolkit.Base from Ansys.UI.Toolkit import * from Ansys.UI.Toolkit.Base import * class TextCell(Ansys.UI.Toolkit.GridViewTextCell): def __init__(self, Value, ReadOnly): self.TextAlignment = Alignment.MiddleCenter self.TextWrap = TextWrap.Word self.ReadOnly = ReadOnly self.Text = Value a = TextCell('1',False)
The error is:Traceback (most recent call last): TypeError: TextCell() takes at most 2 arguments (3 given)
It seems the new TextCell class init function don't work. I don't why.
Best Answer
-
The init call inherits the arguments from the base class. I would not modify those, but instead make a method outside the class as a constructor with the user-based args you want:
class TextCell(Ansys.UI.Toolkit.GridViewTextCell): def __init__(self, Value): pass def NewTextCell(Value, ReadOnly): MyCell = TextCell(Value) MyCell.ReadOnly = ReadOnly MyCell.TextAlignment = Alignment.MiddleCenter MyCell.TextWrap = TextWrap.Word return MyCell
0
Answers
-
@Mike.Thompson said:
The init call inherits the arguments from the base class. I would not modify those, but instead make a method outside the class as a constructor with the user-based args you want:class TextCell(Ansys.UI.Toolkit.GridViewTextCell): def __init__(self, Value): pass def NewTextCell(Value, ReadOnly): MyCell = TextCell(Value) MyCell.ReadOnly = ReadOnly MyCell.TextAlignment = Alignment.MiddleCenter MyCell.TextWrap = TextWrap.Word return MyCell
Thanks.
It seems if the class inherits from C# base class, the new class init don't work.
I will try the new way. Thanks.0