《付録》apple.py


# -*- coding: utf-8 -*-
#===============================================================================
# Copyright (C) 2000-2008, 小泉ひよ子とタマゴ倶楽部
#
# History: WPF examples
# 2008/01/25, IronPython 1.1.1 (download)
# 2008/08/22, IronPython 1.1.2 (download)
# 2008/03/16, ver.2.0, WPF
# 2008/00/00, ver.2.1, IronPython 1.1.2
#===============================================================================
from _ant import *
from System.Windows import *
from System.Windows.Media import *

## --------------------
class ExWindow(Window):
def __init__(self, Content=None, **args):
self.InitializeComponent(Content)
self.init()

def InitializeComponent(self, Content):
self.Content = LoadXaml(Content)

def init(self):
target = "listBox", "colorBox"
self._Controls(target)
for e in self.colorBrushes():
self.listBox.Items.Add(e)
self.listBox.SelectionChanged += self.selectionChanged

def _Controls(self, target):
controls = xaml_controls(self)
for e in target:
setattr(self, e, controls[e])

def colorBrushes(self):
return [e for e in dir(Brushes)
if isinstance(getattr(Brushes, e), SolidColorBrush)]

def selectionChanged(self, sender, e):
s = sender.SelectedItem
self.colorBox.Background = getattr(Brushes, s)

## --------------------
if __name__ == "__main__":
xaml = __file__.replace(".py",".xaml")
win = ExWindow(
Title=xaml,
Width=250, Height=150,
Content=xaml,
)
Application().Run(win)

## --------------------