+
+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)
+
+class MyFrame(wxFrame):
+ def __init__(self, wf):
+ self.wf = wf
+ wxFrame.__init__(self, NULL, -1, "hangman", wxDefaultPosition, wxSize(400,300))
+ self.wnd = HangmanWnd(self, -1)
+ menu = wxMenu()
+ menu.Append(1001, "New")
+ menu.Append(1002, "End")
+ menu.AppendSeparator()
+ menu.Append(1003, "Reset")
+ menu.Append(1004, "Demo...")
+ menu.AppendSeparator()
+ menu.Append(1005, "Exit")
+ menubar = wxMenuBar()
+ menubar.Append(menu, "Game")
+ menu = wxMenu()
+ #menu.Append(1010, "Internal", "Use internal dictionary", TRUE)
+ menu.Append(1011, "ASCII File...")
+ urls = [ 'wxPython home', 'http://208.240.253.245/wxPython/main.html',
+ 'slashdot.org', 'http://slashdot.org/',
+ 'cnn.com', 'http://cnn.com',
+ 'The New York Times', 'http://www.nytimes.com',
+ 'De Volkskrant', 'http://www.volkskrant.nl/frameless/25000006.html',
+ 'Gnu GPL', 'http://www.fsf.org/copyleft/gpl.html',
+ 'Bijbel: Genesis', 'http://www.coas.com/bijbel/gn1.htm']
+ urlmenu = wxMenu()
+ for item in range(0,len(urls),2):
+ urlmenu.Append(1020+item/2, urls[item], urls[item+1])
+ urlmenu.Append(1080, 'Other...', 'Enter an URL')
+ menu.AppendMenu(1012, 'URL', urlmenu, 'Use a webpage')
+ menu.Append(1013, 'Dump', 'Write contents to stdout')
+ menubar.Append(menu, "Dictionary")
+ self.urls = urls
+ self.urloffset = 1020
+ menu = wxMenu()
+ menu.Append(1090, "About...")
+ menubar.Append(menu, "Help")
+ self.SetMenuBar(menubar)
+ self.CreateStatusBar(2)
+ EVT_MENU(self, 1001, self.OnGameNew)
+ EVT_MENU(self, 1002, self.OnGameEnd)
+ EVT_MENU(self, 1003, self.OnGameReset)
+ EVT_MENU(self, 1004, self.OnGameDemo)
+ EVT_MENU(self, 1005, self.OnWindowClose)
+ EVT_MENU(self, 1011, self.OnDictFile)
+ EVT_MENU_RANGE(self, 1020, 1020+len(urls)/2, self.OnDictURL)
+ EVT_MENU(self, 1080, self.OnDictURLSel)
+ EVT_MENU(self, 1013, self.OnDictDump)
+ EVT_MENU(self, 1090, self.OnHelpAbout)
+ EVT_CHAR(self.wnd, self.OnChar)
+ self.OnGameReset()