Python clr OpenFileDialog でフリーズ
System.Windows.Forms でFormを作成。
以下を実行すると dialog.ShowDialog() でフリーズする。
MessageBox は問題なく表示されます。
Windows10、python 3.4.4 pythonnet 2.3.0 です。
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, TextBox
from System.Windows.Forms import ToolBar, ToolBarButton, OpenFileDialog, MessageBox
from System.Windows.Forms import DialogResult, ScrollBars, DockStyle, IWin32Window
class IForm(Form):
def __init__(self):
self.Text = "OpenDialog"
toolbar = ToolBar()
toolbar.Parent = self
openb = ToolBarButton()
self.textbox = TextBox()
self.textbox.Parent = self
self.textbox.Multiline = True
self.textbox.ScrollBars = ScrollBars.Both
self.textbox.WordWrap = False
self.textbox.Parent = self
self.textbox.Dock = DockStyle.Fill
toolbar.Buttons.Add(openb)
toolbar.ButtonClick += self.OnClicked
self.CenterToScreen()
#@staticmethod
def OnClicked(self, sender, event=None):
MessageBox.Show("Test")
dialog = OpenFileDialog()
dialog.Filter = "C# files (*.cs)|*.cs"
if dialog.ShowDialog() == DialogResult.OK:
#dialog.ShowDialog()
f = open(dialog.FileName)
data = f.read()
f.Close()
self.textbox.Text = data
Application.Run(IForm())