カレンダーの使用例となります。
以下のようなファイルをcalender.pyとして作成してみましょう。
文字コードはcp932(sjis)です。
# coding : cp932 import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import (Form, MonthCalendar, Label, Button, Application) from System.Drawing import Point class calendarform(Form): def __init__(self): self.Height= 300 self.Width = 260 self.Text = 'カレンダーのデモ' self.cal = MonthCalendar() self.cal.MaxSelectionCount = 1 self.cal.DateChanged += self.dateselect self.Controls.Add(self.cal) self.label = Label() self.label.Width = 200 self.label.Height = 20 self.label.Location = Point(5, 200) self.setdatehash() self.Controls.Add(self.label) self.button = Button() self.button.Text = 'OK' self.button.Width = 50 self.button.Location = Point(self.ClientSize.Width/2-self.button.Width/2, 225) self.button.Click+=self.button_click self.Controls.Add(self.button) def dateselect(self, sender, args): self.setdatehash() def setdatehash(self): selectcalender = self.cal.SelectionRange.Start self.label.Text = ('選択されている日付:' + selectcalender.ToString('o')[:10]) # 手抜き selectcalender = self.cal.SelectionRange.Start # ユーザーが選択する度にマクロに渡す用途のハッシュに入れておく hm.Macro.Var['$year'] = selectcalender.Year hm.Macro.Var['$month'] = selectcalender.Month hm.Macro.Var['$day'] = selectcalender.Day def button_click(self, sender, args): self.Close() try: form = calendarform() Application.Run(form) finally: form.Close()
#PY = loaddll( hidemarudir + "\\hmPy.dll" ); #_ = dllfuncw( #PY, "DoFile", currentmacrodirectory + "\\calender.py" ); message( $year + "/" + $month + "/" + $day ); freedll( #PY );