2017-09-16 4 views
0

DevExpress.v17.1 라이브러리에서 XtraForm을 확장하는 C#에서 만든 양식의 사용자 지정 생성자에 문제가 있습니다.pythonnet을 사용하여 사용자 지정 폼의 생성자

protected BaseForm() 
{ 
    InitializeComponent(); 
} 

protected BaseForm(IClient client) 
{ 
    InitializeComponent(); 
    ... many code 
} 

IClient 인터페이스는

: 그것은 두 개의 생성자가 있습니다. 이 양식에는 많은 종속성이 있으며 모든 종속성이 라이브러리에 컴파일됩니다. 나는이 양식을 확장하고 코드 인스턴스를 만들려고 할 때 는 :

class TestApp(BaseForm): 

def __init__(self): 
    self.Text = "Hello World From Python" 
    self.components = System.ComponentModel.Container() 
    self.AutoScaleBaseSize = Size(5, 13) 
    self.ClientSize = Size(392, 117) 
    h = WinForms.SystemInformation.CaptionHeight 
    self.MinimumSize = Size(392, (117 + h)) 

    # Create the button 
    self.button = WinForms.Button() 
    self.button.Location = Point(160, 64) 
    self.button.Size = Size(150, 20) 
    self.button.TabIndex = 2 
    self.button.Text = "Click Me!" 

    # Register the event handler 
    self.button.Click += self.button_Click 

    # Create the text box 
    self.textbox = WinForms.TextBox() 
    self.textbox.Text = "Hello World" 
    self.textbox.TabIndex = 1 
    self.textbox.Size = Size(126, 40) 
    self.textbox.Location = Point(160, 24) 

    # Add the controls to the form 
    self.AcceptButton = self.button 
    self.Controls.Add(self.button) 
    self.Controls.Add(self.textbox) 

def button_Click(self, sender, args): 
    """Button click event handler""" 
    print ("Click") 
    WinForms.MessageBox.Show("Please do not press this button again.") 

def run(self): 
    WinForms.Application.Run(self) 

def Dispose(self): 
    self.components.Dispose() 
    WinForms.Form.Dispose(self) 

실행 초기화 코드 :

Traceback (most recent call last): 
    File "C:/Users/v.khvorostianyi/PycharmProjects/CSharp/Test.py", line 141, in <module> 
    main() 
    File "C:/Users/v.khvorostianyi/PycharmProjects/CSharp/Test.py", line 85, in main 
    form = TestApp() 
TypeError: no constructor matches given arguments 

파이썬 = 3.6.2 :

def main(): 
    form = TestApp() 
    form.run() 
    form.Dispose() 

if __name__ == '__main__': 
    main() 

나는 오류가 , pythonnet = 2.3.0
. NET = 4.6.1

Pro 자동화 된 테스트가 필요합니다.이 양식은 업무 프로세스에 필요합니다. 왜 그런 오류가 있습니까?

+0

파이썬에서 TestApp 클래스 (BaseForm) MEEN. 도와 주셔서 감사합니다. –

답변

1

BaseForm의 생성자는 protected 액세스 수정 자에 의해 숨겨져 있으며 BaseForm 및 파생 클래스 인스턴스에서만 액세스 할 수 있습니다. 따라서 빈 인수가있는 생성자가 숨겨져 있으므로 form = TestApp()을 사용할 수 없습니다.

0 당신은 당신의 BaseForm 생성자에서 public 액세스 한정자를 사용할 수 있습니다

는이 문제를 해결하기 위해 적어도 두 가지 방법이 있습니다.

public BaseForm() 
{ 
    InitializeComponent(); 
} 

public BaseForm(IClient client) 
{ 
    InitializeComponent(); 
    //... many code 
} 

1. 당신은 당신의 파생 클래스에서 __new__ 방법을 사용하여 .NET 생성자를 오버로드를 시도 할 수 있습니다 : TestApp가이 BaseForm을 확장

def __new__(cls):   
    return BaseForm.__new__(cls) 
관련 문제