Doge log

Abby CTO 雑賀 力王のオフィシャルサイトです

IronPythonでDnD

IronPythonを少しづつはじめたいとおもっている今日この頃。
実はC#とあんまし変わらないので生産性はあがってないんじゃなかろうか?
C#だと静的チェックがかなり入るし、補完が効くのでその分有利に見えちゃうな。
DnDしたファイルのファイルパスがListBoxに表示されるサンプル

Form.py
import System
from System.Windows.Forms import *
from System.ComponentModel import *
from System.Drawing import *
from clr import *
class WindowsApplication6: # namespace
    
    class Form1(System.Windows.Forms.Form):
        """type(_listBox1) == System.Windows.Forms.ListBox"""
        __slots__ = ['_listBox1']
        def __init__(self):
            self.InitializeComponent()
        
        @accepts(Self(), bool)
        @returns(None)
        def Dispose(self, disposing):
            super(type(self), self).Dispose(disposing)
        
        @returns(None)
        def InitializeComponent(self):
            self._listBox1 = System.Windows.Forms.ListBox()
            self.SuspendLayout()
            # 
            # listBox1
            # 
            self._listBox1.AllowDrop = True
            self._listBox1.FormattingEnabled = True
            self._listBox1.ItemHeight = 12
            self._listBox1.Location = System.Drawing.Point(12, 19)
            self._listBox1.Name = 'listBox1'
            self._listBox1.Size = System.Drawing.Size(413, 208)
            self._listBox1.TabIndex = 0
            self._listBox1.DragEnter += self._drag_enter
            self._listBox1.DragDrop += self._drag_drop
            # 
            # Form1
            # 
            self.AllowDrop = True
            self.ClientSize = System.Drawing.Size(709, 416)
            self.Controls.Add(self._listBox1)
            self.Name = 'Form1'
            self.Text = 'Form1'
            self.ResumeLayout(False)
        
        @accepts(Self(), System.Object, System.Windows.Forms.DragEventArgs)
        @returns(None)
        def _drag_enter(self, sender, e):
            if e.Data.GetDataPresent(DataFormats.FileDrop):
                e.Effect = DragDropEffects.All
            else:
                e.Effect = DragDropEffects.None
        
        @accepts(Self(), System.Object, System.Windows.Forms.DragEventArgs)
        @returns(None)
        def _drag_drop(self, sender, e):            
            data = e.Data.GetData(DataFormats.FileDrop, False)            
            for s in data:
        print self._listBox1.Items.Add(s)

デコレーターの嵐になるのは仕方ない。
VS2005に組み込んでるけどなんかイマイチ。
IronPythonMicrosoftに染まりすぎてるのでなんだか使いにくい印象を覚えるな。
もう少し評価しないと。
うくく。