+
+class HangmanDemo(HangmanWnd):
+ def __init__(self, wf, parent, id, pos, size):
+ HangmanWnd.__init__(self, parent, id, pos, size)
+ self.StartGame("dummy")
+ self.start_new = 1
+ self.wf = wf
+ self.delay = 500
+ self.timer = self.PlayTimer(self.MakeMove)
+ def MakeMove(self):
+ self.timer.Stop()
+ if self.start_new:
+ self.StartGame(self.wf.Get())
+ self.start_new = 0
+ self.left = list('aaaabcdeeeeefghiiiiijklmnnnoooopqrssssttttuuuuvwxyz')
+ else:
+ key = self.left[int(random.random()*len(self.left))]
+ while self.left.count(key): self.left.remove(key)
+ self.start_new = self.HandleKey(key)
+ self.timer.Start(self.delay)
+ def Stop(self):
+ self.timer.Stop()
+ class PlayTimer(wxTimer):
+ def __init__(self,func):
+ wxTimer.__init__(self)
+ self.func = func
+ self.Start(1000)
+ def Notify(self):
+ apply(self.func, ())
+
+class HangmanDemoFrame(wxFrame):
+ def __init__(self, wf, parent, id, pos, size):
+ wxFrame.__init__(self, parent, id, "Hangman demo", pos, size)
+ self.demo = HangmanDemo(wf, self, -1, wxDefaultPosition, wxDefaultSize)
+ def OnCloseWindow(self, event):
+ self.demo.timer.Stop()
+ self.Destroy()
+
+class AboutBox(wxDialog):
+ def __init__(self, parent,wf):
+ wxDialog.__init__(self, parent, -1, "About Hangman", wxDefaultPosition, wxSize(350,450))
+ self.wnd = HangmanDemo(wf, self, -1, wxPoint(1,1), wxSize(350,150))
+ self.static = wxStaticText(self, -1, __doc__, wxPoint(1,160), wxSize(350, 250))
+ self.button = wxButton(self, 2001, "OK", wxPoint(150,420), wxSize(50,-1))
+ EVT_BUTTON(self, 2001, self.OnOK)
+ def OnOK(self, event):
+ self.wnd.Stop()
+ self.EndModal(wxID_OK)