2017-09-16 14 views
0

DevExpress.v17.1ライブラリからXtraFormを拡張した(C#で作成された)フォームのカスタムコンストラクタに問題があります。pythonnetを使用したカスタムフォームのコンストラクタ

protected BaseForm() 
{ 
    InitializeComponent(); 
} 

iClientは、インターフェースである
protected BaseForm(IClient client) 
{ 
    InitializeComponent(); 
    ... many code 
} 

:それは2つのコンストラクタを持っています。 このフォームには多くの依存関係があり、すべてがライブラリにコンパイルされています。 私はこのフォームを拡張し、コードでインスタンスを作成しようとすると:

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) 

ランのinitコード:

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 

のPython = 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

PythonでクラスでTestApp(ベースフォーム)ミーン。お手伝いをしていただきありがとうございます。 –

答えて

1

BaseFormのコンストラクタはprotectedアクセス修飾子によって隠されており、BaseFormおよびその派生クラスインスタンス内でのみアクセスできます。空の引数を持つコンストラクタが隠されているので、form = TestApp()は使用できません。

これを解決するには、少なくとも2つの方法があります。

0あなたのBaseFormコンストラクタでpublicアクセス修飾子を使用することができます。

public BaseForm() 
{ 
    InitializeComponent(); 
} 

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

1.あなたは、あなたの派生クラスで__new__メソッドを使用して.NETのコンストラクタをオーバーロードしようとすることができます:でTestAppがベースフォームを拡張

def __new__(cls):   
    return BaseForm.__new__(cls) 
関連する問題