ListAdapter_Form.py

  • Windows Forms アプリケーションとして、IronPython で実現した事例を紹介します。
# -*- coding: utf-8 -*-
#===============================================================================
#    Copyright (C) 2000-2008, 小泉ひよ子とタマゴ倶楽部
#
# History: Design Pattern
#    2008/01/25, IronPython 1.1.1 (download)
#    2008/08/22, IronPython 1.1.2 (download)
#    2008/01/15, ver.1.0, Windows Forms
#    2008/09/28, ver.2.1, IronPython 1.1.2 
#===============================================================================
import clr
clr.AddReference("System.Drawing")
from              System.Drawing import *
clr.AddReference("System.Windows.Forms")
from              System.Windows.Forms import *

from csFile_Bridge import csFile
#===============================================================================
class ListAdapter:                          # Adapter::Adapter
    def __init__(self, lb):
        self.listbox = lb
    def Add(self, s):
        self.listbox.Items.Add(s)
    def SelectedIndex(self):
        return self.listbox.SelectedIndex
    def Clear(self):
        self.listbox.Items.Clear()
    def clearSelection(self):
        i = self.SelectedIndex()
        if i >= 0:
            self.listbox.SelectedIndex = -1

#===============================================================================
class Swimmer:  # IComparable
    def __init__(self, line):
        s, age, club, self.time, sx = line.split(",")   # StringTokenizer
        self.splitName(s)
        female = "F" in sx
    def splitName(self, tok):
        self.name = tok
        i = self.name.find(" ")
        if i>0:
            self.frname, self.lname = tok.split(" ")    # IndexOf

#===============================================================================
class SwimData:     # ICloneable
    def __init__(self, filename):
        self.swdata = []            # ArrayList
        fl = csFile(filename)
        for s in fl.file().readlines():
            sw = Swimmer(s)
            self.swdata.append(sw)  # Add
        else:
            fl.close()
    def __getitem__(self, index):         # getSwimmer(int index)
        if 0<=index= 0:
            sw = self.swdata[i]
            self.lsnewKids.Add(sw.name+"\t"+sw.time)
            self.lskids.clearSelection()
    def putBack_Click(self, sender, e):
        i = self.lsnewKids.SelectedIndex()
        if i >= 0:
            self.lsNewKids.Items.RemoveAt(i)

#===============================================================================
if __name__ == "__main__":
    print __file__,"ver.1.1a"
    form = ListAdapter_Form()
    form.Text = form.__class__.__name__
    Application.Run(form)
#===============================================================================

# -*- coding: utf-8 -*-
#===============================================================================
#    Copyright (C) 2000-2008, 小泉ひよ子とタマゴ倶楽部
#
# History: Design Pattern
#    2008/01/25, IronPython 1.1.1 (download)
#    2008/08/22, IronPython 1.1.2 (download)
#    2008/01/15, ver.1.0, Windows Forms
#    2008/09/28, ver.2.1, IronPython 1.1.2 
#===============================================================================
import clr
clr.AddReference("System.Drawing")
from              System.Drawing import *
clr.AddReference("System.Windows.Forms")
from              System.Windows.Forms import *