åã®èšäºã§ã¯ãPyGTKã¢ããªã±ãŒã·ã§ã³ãéçºããããã«WindowsãšUbuntuãæºåããGladeã€ã³ã¿ãŒãã§ã€ã¹ãšãã£ã¿ãŒã§äœæ¥ããæ°Žå¹³ããã³åçŽã¬ã€ã¢ãŠãã¿ã€ãã調ã¹ãã¹ã¯ããŒã«ãã€ã³ãšããã¹ããšãã£ã¿ãŒããã¿ã³ããã¿ã³ãããã³å°ããªä¿¡å·ã®åçŽã°ã«ãŒãã䜿çšããŸããã ãã®çµæãUbuntuãšWindowsã§æ£åžžã«æ©èœããæåã®çã®ã¯ãã¹ãã©ãããã©ãŒã ã¢ããªã±ãŒã·ã§ã³ãæã«å ¥ããŸããã åã®èšäºããŸã èªãã§ããªãå Žåã¯ã ããããå§ããããšããå§ãããŸãã
ãã®èšäºã§ã¯ãç°¡åãªã²ãŒã ãäœæãããã®éçšã§ã¬ã€ã¢ãŠãã«ã€ããŠããå°ãåŠã³ãPyGTKãŠã£ãžã§ããã«ç²Ÿéãç¶ãããã€ã¢ãã°ãæäœããŸãã
ã¢ã€ãã¢ãèæ¬
ãŸã第äžã«ãç§ãã¡ãäœããããã«ã€ããŠã話ããããšæããŸãã ã²ãŒã ã«ãªããŸãã ã²ãŒã ã¯ã·ã³ãã«ã§æ¥œãããã®ã§ãªããã°ãªããŸããã ç§ã«èµ·ãã£ãæãç°¡åãªããšã¯äžç®äžŠã¹ã§ããã ã²ãŒã ã«ã¯å¯ŸæŠçžæã®ãã£ã©ã¯ã¿ãŒãå¿ èŠã§ãã ç§ãç¥ã£ãŠããæãã¯ãŒã«ãªãã£ã©ã¯ã¿ãŒã¯ãã³ããŒã§ãã ãã®ããããã³ããŒãæµãšããŠäžç®äžŠã¹ãäœæããŸãã
ãŠã£ãããã£ã¢ã§ã²ãŒã ã®ã¢ã«ãŽãªãºã ã䜿çšããŠãã ãããéåžžã«ã·ã³ãã«ã§ãããããã説æãããŠããŸãã ç§ãã¡ã¯PyGTKããã¹ã¿ãŒããŠããã®ã§ãã¡ã€ã³ãããã¯ããè€éãªã¢ã«ãŽãªãºã ãåãé€ããŠãã ããã ã¢ã«ãŽãªãºã ã«ã€ããŠè©³ããç¥ãããå Žåã¯ã Donald Knuthãã芧ãã ããã
ã·ããªãªã¯æ¬¡ã®ãšããã§ãããã¬ãŒã€ãŒã¯ã¯ãã¹ãé 眮ãããã³ããŒã¯ãŒãã§å¿çããŸãã ã²ãŒã ã®çµããã«ãåè ã«ãç¥ãã®èšèã衚瀺ããããã®åŸã²ãŒã ãåéãããŸãã
ããã«ã䜿ããããã®èŠ³ç¹ãããã¡ã€ã³ãŠã£ã³ããŠã«éãªããã€ã¢ãã°ã䜿çšããããããã²ãŒã ãéåžžã«æªãããšã«æ³šæããŠãã ããã è¯ããã¥ãŒã¹ã¯ããã€ã¢ãã°ã«ç²Ÿéããä»»æã®ãŠã£ã³ããŠããã¢ãŒãã«ãã€ã¢ãã°ãäœæã§ããããšã§ãã
Inkscapeã®ã€ã³ã¿ãŒãã§ãŒã¹ãã¹ã±ããããŸãããïŒ
ã€ã³ã¿ãŒãã§ãŒã¹ãã¡ã€ã«ãäœæããã«ã¯ãGladeã€ã³ã¿ãŒãã§ãŒã¹ãšãã£ã¿ãŒã䜿çšããŸãã Gladeãå®è¡ããŠãã ããã äœãå±éºãªã®ãããããªãå Žåã¯ã åã®èšäºãèªãã§ãã ããã
ããŒãã«ã¬ã€ã¢ãŠã
ããŒãã«ã¬ã€ã¢ãŠãã¯ãå€æ°ã®ãŠã£ãžã§ãããé 眮ããå Žåã«éåžžã«äŸ¿å©ã§ããããã¯ç§ãã¡ã®å Žåã§ãã
ã¹ã±ãããããäžç®äžŠã¹ã«3æ¬ã®ç·ãå¿ èŠã§ããããã¿ã³ãäžäžã«é 眮ããã®ã«1æ¬ã®ç·ãå¿ èŠã§ããããšãããããŸãã
æ°ãããŠã£ã³ããŠãäœæãã
ããã«è¡šç€ºããŸãïŒãããããã°ã©ã ã®ã¡ã€ã³ãŠã£ã³ããŠã«ãªããŸãïŒã
ããŒãã«ã¬ã€ã¢ãŠããè¿œå ããŸã
5è¡3åã§
ã
ããŒãã«ã®ã»ã«ãæ£æ¹åœ¢ã«ãªãããã«ãŠã£ã³ããŠãã¹ã±ãŒãªã³ã°ããæçµçµæãæ³åããããããŸãã
ã
2ã€ã®ãã¿ã³ãè¿œå ããŸãã ããŒãã«ã®æåã®ã»ã«ã«ãã¿ã³ãé 眮ããŸãã
ã
ã芧ã®ãšããããã¿ã³ã¯ã»ã«å šäœãå ããŠããŸããã ãã®æ©èœã䜿çšããŠç«¶æå Žãæç»ã§ããŸãããå®è¡ããŸãããããã§ã¯ããã®åäœãå¿ èŠãªããããããããã£ã®[ããã±ãŒãž]ã¿ãã«åãæ¿ããŸãã ãåçŽãªãã·ã§ã³ãã§ããã£ã«ãã®ãã§ãã¯ãå€ããŸã
ã
ãããã£ãŠããã¿ã³ã¯å©çšå¯èœãªãã¹ãŠã®ã¹ããŒã¹ãé«ãã§åããã¹ãã§ã¯ãªãããšã瀺ããŸã
ã
æ°ã¥ããããè¡šã®ã»ã«ã®å¹ ã¯åãã§ã¯ãããŸããã ããã«ãããåãã»ã«ã§ç«¶æå Žãäœæã§ããªããªããŸãã ãããã£ãŠãtable1ãéžæããäž»ãªããããã£ã§ãå質æ§ãããã¯ããã«å€æŽããŸã
ã
ã»ã«ã®å¹ ã¯åãã«ãªããŸããã
ã¹ã±ããã§ã¯ãäžéšãšäžéšã®ãã¿ã³ãæ°Žå¹³æ¹åã®ã¹ããŒã¹å šäœãå æããäžéšã®ãã¿ã³ã¯1ã€ã®ã»ã«ã®ã¿ãå æããŸãã å¹ ã3ã€ã®ã»ã«ãå ããããšãå¿ èŠã§ãã ãã¿ã³ãéžæããããããã£ãããã±ãŒãžã³ã°ãããå³åŽã«è¿œå ãã
å€ã3ã«å¢ãããŸãã ãã¿ã³ã®å¹ ã¯3ã»ã«ã§ã
ã
ã¢ã€ã³ã³ãã¿ã³
ãNew gameããã¿ã³ãšãQuit the gameããã¿ã³ã«ããã¹ãã ãã§ãªãã¢ã€ã³ã³ãå«ããããã«ããŸãã ããã¯éåžžã«ç°¡åã§ãã ã¡ã€ã³ããããã£ã§ã[ã¿ã€ãã®ç·šé]ã[ã³ã³ãã]ã«å€æŽããŸãã
ã
ããã§ããã¿ã³ã®è¡šé¢ã®ã³ã³ããã«äœã§ãé 眮ã§ããŸãã
ã¢ã€ã³ã³ä»ãã®ããã¹ããé 眮ããæãç°¡åã§æãæ£ããæ¹æ³ã¯ãå¥ã®ã¬ã€ã¢ãŠãããŒã«ã䜿çšããããšã§ãã ãã¢ã©ã€ã¡ã³ãããã¿ã³ã«è¿œå ããŸã
ã
äž»ãªããããã£ã§ãåçŽããã³æ°Žå¹³ã¹ã±ãŒãªã³ã°ããŒãã«èšå®ããŸã
ã
ãããã£ãŠãã¢ã©ã€ã³ã¡ã³ãã¯ãå©çšå¯èœãªãã¹ãŠã®ã¹ããŒã¹ãããã£ããã£ãããŸããããå¿ èŠæå°éã«å¶éãããŸãã ãããå¿ èŠãªã®ã¯ãã¢ã€ã³ã³ãããã¹ãããé¢ããªãããã«ããããã§ãã
é 眮å ã«ã¯ã1ã€ã®èŠçŽ ã ãã®ã¹ããŒã¹ãããã2ã€é 眮ããå¿ èŠããããŸãã 2ã€ã®ã»ã«ãæã€æ°Žå¹³ã¬ã€ã¢ãŠãã䜿çšããé 眮ã«é 眮ããŸã
ã
å·Šã®ã»ã«ã«ã¢ã€ã³ã³ãé 眮ããŸã
ã
å³åŽ-ãNew Gameããšããããã¹ãã®ä»ããããã¹ãã©ãã«
ã
ã
ã¢ã€ã³ã³ãæ€çŽ¢ããŠæç»ããªãããã«ãåŸã§ããã°ã©ã ãèµ·åãããšãã«ã¢ã€ã³ã³ãããŒãããªãããã«ãæ¢è£œã®GTKã¢ã€ã³ã³ã䜿çšããŸãã ã¡ã€ã³ããããã£ã®[äœæ]ã¢ã€ã³ã³ãéžæããŸã
ã
ã¢ã€ã³ã³ãããŒã¯ã«è¿ãããŸãã ããã¯ãæ°Žå¹³ã¬ã€ã¢ãŠãã®ã®ã£ãããµã€ãºãèšå®ããããã¢ã€ã³ã³èªäœã®ãã¯ã»ã«åäœã§ããã£ã³ã°ãèšå®ããããšã§ä¿®æ£ã§ããŸãã ã¢ã€ã³ã³ã«4ãã¯ã»ã«ã®ããã£ã³ã°ãèšå®ããŸã
ã
çµæã¯æ¬¡ã®ããã«ãªããŸãã
ã
äžéšã®[ã²ãŒã ãçµäº]ãã¿ã³ã«ã€ããŠãåãæäœãè¡ããŸãã ãã®ãããªãã®ã§ãªããã°ãªããŸãã
ã
éããã¢ã€ã³ã³ã䜿çšããŸããã
ã€ã³ã¿ãŒãã§ã€ã¹ãgui.gladeãã¡ã€ã«ã«ä¿åãããšãã²ãŒã ã®éå§æã«ããã°ã©ã ã«ãã£ãŠãã¬ã€ãã£ãŒã«ããäœæãããŸãã
競æå Ž
ãããã®æ©èœãããããç 究ããããã«ãããã¹ãã©ãã«ã«åºã¥ããŠç«¶æå Žãæ§ç¯ããŸãã
9ã€ã®ã©ãã«ããããGladeã§ããããåå¥ã«äœæ¥ããããšã¯æå³ããããŸãããããã¯æ°è¡ã®ã³ãŒãã§ãããè¡ãããšãã§ããããã§ãã ããã«ããã¹ãŠã®ã©ãã«ã®ããããã£ãäžåºŠã«å€æŽããæ©äŒããããŸãããããã¯ééããªãå¿ èŠã§ãã
空çœã®ããã°ã©ã ãäœæããŸãããïŒ
ïŒïŒ/ usr / bin / env python ïŒã³ãŒãã£ã³ã°ïŒutf-8 ã€ã³ããŒãã·ã¹ãã èŒžå ¥OS pygtkãã€ã³ããŒããã pygtk.requireïŒ '2.0'ïŒ ã€ã³ããŒãgtk ã€ã³ããŒãgtk.glade ã¯ã©ã¹ã¢ããªïŒ def __init __ïŒselfïŒïŒ ïŒã€ã³ã¿ãŒãã§ãŒã¹ãã¡ã€ã«ãããŠã³ããŒããã self.gladefile = "gui.glade" ïŒã€ã³ã¿ãŒãã§ãŒã¹èŠçŽ ã®ããªãŒ self.widgetsTree = gtk.glade.XMLïŒself.gladefileïŒ ïŒè¡š self.table1 = self.widgetsTree.get_widgetïŒ "table1"ïŒ ïŒç«¶æå Žãåæåãã self.init_boardïŒïŒ ïŒãŠã£ã³ããŠãéããã€ãã³ããã¢ããªã±ãŒã·ã§ã³çµäºé¢æ°ã«æ¥ç¶ããŸã self.window = self.widgetsTree.get_widgetïŒ "window1"ïŒ ifïŒself.windowïŒïŒ self.window.connectïŒ "destroy"ãself.close_appïŒ def close_appïŒselfãwidgetïŒïŒ gtk.main_quitïŒïŒ __name__ == "__main__"ã®å ŽåïŒ app = AppïŒïŒ gtk.mainïŒïŒ
ã²ãŒã ãã£ãŒã«ãã¯self.init_boardïŒïŒã§äœæãããŸãã
def init_boardïŒselfïŒïŒ ïŒç«¶æå Žã®èŸæžä¿ç®¡ã©ãã« self.board_widgets = {} ïŒ1ã3è¡ç®ã«ã©ãã«ãè¿œå ããŸã ç¯å²ïŒ0.3ïŒã®è¡ã®å ŽåïŒ ïŒã¹ãã¬ãŒãžè¡ãåæåãã空ã®èŸæžãäœæ ïŒããŒãã«ã»ã«ã®å 容ãä¿åãã self.board_widgets [è¡] = {} ïŒå0ãã2ãéé ç¯å²ïŒ0,3ïŒã®åã®å ŽåïŒ ïŒã©ãã«ãäœæããŸãããã®ããã¹ãã«ã¯è¡ãšåã®çªå·ãå«ãŸããŸã self.board_widgets [è¡] [å] = \ gtk.LabelïŒ "label_ïŒ d_ïŒ d"ïŒ ïŒåãè¡ïŒïŒ ïŒã©ãã«ãããŒãã«ã«æ·»ä» self.table1.attachïŒself.board_widgets [è¡] [å]ã åãå+ 1 è¡+ 1ãè¡+ 2ïŒ ïŒã©ãã«ã衚瀺ãã self.board_widgets [è¡] [å] .showïŒïŒ
競æå Žã¯ãèŸæžã«åºã¥ããŠäœæãããã2次å é åãã«ä¿åãããŸãã ã©ãã«ã³ã³ã¹ãã©ã¯ã¿ãŒgtk.LabelïŒïŒã¯ãã©ãã«ã衚瀺ããããã¹ããæž¡ããŸãã ã¢ã¿ããããŒãã«ã¡ãœããã¯ããŠã£ãžã§ãããæåã®ãã©ã¡ãŒã¿ãŒããã®å Žåã¯ã©ãã«ãšããŠäœ¿çšããŸãã 2çªç®ã¯ã©ãã«ã®å·ŠåŽãæ·»ä»ãããåçªå·ã3çªç®ã¯ã©ãã«ã®å³åŽãæ·»ä»ãããåçªå·ã§ãã ã€ãŸããæåã®åã«ã©ãã«ãé 眮ããã«ã¯ã2çªç®ãš3çªç®ã®ãã©ã¡ãŒã¿ãŒã0ãš1ã§ããå¿ èŠããããŸãã ããã¥ã¡ã³ãã®ãã¹ãŠã®ãã©ã¡ãŒã¿ã®èª¬æãèªãããšãã§ããŸã ã
ããã°ã©ã ãèµ·åãããšã次ã®ãããªãŠã£ã³ããŠã衚瀺ãããã¯ãã§ãã
ã
ã€ãã³ããšãªã¢ããã¬ãŒã
ããã°ã©ã ã埩掻ãããæãæ¥ãŸãããäžã®ãã¿ã³ãæ©èœãããããŠã¹ã®å·Šãã¿ã³ãã¯ãªãã¯ããããã®ãã³ãã©ãŒãåã©ãã«ã«è¿œå ããŸãã GladeãéããŠããã¿ã³ã«ã¯ãªãã¯ãã³ãã©ãŒãè¿œå ããŸãã ãã¿ã³ãéžæããããããã£ã®ãä¿¡å·ãã¿ãã«ç§»åããŠãã¯ãªãã¯ããä¿¡å·ã«ãã³ãã©ãŒãå²ãåœãŠãŸã
ã
å€æŽãä¿åããã³ãŒãç·šéã«æ»ããŸãã 次ã®è¡ã__init__ã«è¿œå ããŸãã
ïŒãã³ãã©ãŒé¢æ°ãšã€ãã³ãã®é¢é£ä»ããæå®ããèªåœ dic = { ãbutton2_clicked_cbãïŒself.close_appã } ïŒã·ã°ãã«ããã³ãã©ãŒã«æ¥ç¶ããããžãã¯ã³ãã³ã self.widgetsTree.signal_autoconnectïŒdicïŒ
ã³ãŒããä¿åããŸãã äžã®ãã¿ã³ãã¯ãªãã¯ãããšãããã°ã©ã ãéãããã©ããã確èªã§ããŸãã
åã©ãã«ã«ã¯ãããŠã¹ã¯ãªãã¯ã€ãã³ããã³ãã©ãŒbutton-press-eventãå¿ èŠã§ãã ãã ããä»ããè¿œå ããŠããã°ã©ã ãå®è¡ããæ©èœãããã©ããã確èªããŠãããæ©èœããªãããšã確èªããŠãã ããã ã©ãã«ã«ã¯ç¬èªã®ãŠã£ã³ããŠããªãããããã®ãããªã€ãã³ããåŠçããããšã¯ã§ããŸããã ç¬èªã®ãŠã£ã³ããŠãæããªããã¹ãŠã®ãŠã£ãžã§ããã¯ããã®ãªã¹ãã«ãªã¹ããããŠããŸã ã
ãã®å¶éãå æããã«ã¯ãç¹å¥ãªã¿ã€ãã®ã¬ã€ã¢ãŠã-ã€ãã³ããšãªã¢ã䜿çšããå¿ èŠããããŸãã Gladeãã¬ããã§ã¯ããã®ããã«èŠããŸã
ã
次ã®ããã«æ©èœããŸããã€ãã³ããšãªã¢ã¯ãŠã£ã³ããŠã«é 眮ãããã©ãã«ã¯ã€ãã³ããšãªã¢ã«é 眮ãããŸãã ã€ãã³ããã³ãã©ãŒã¯ãã€ãã³ããã€ã³ã«å²ãåœãŠãããŸãã ãã®çµæãå¿ èŠãªãã¹ãŠã®ã€ãã³ããã€ã³ã¿ãŒã»ãããããŸãã
ãããself.init_boardïŒïŒã«åæ ãããšåæã«ãã€ãã³ããšãªã¢ã®ã€ãã³ããã³ãã©ãŒãè¿œå ããå¿ èŠããããŸãã
def init_boardïŒselfïŒïŒ ïŒç«¶æå Žã®èŸæžä¿ç®¡ã©ãã« self.board_widgets = {} ïŒ1ã3è¡ç®ã«ã©ãã«ãè¿œå ããŸã ç¯å²ïŒ0.3ïŒã®è¡ã®å ŽåïŒ ïŒã¹ãã¬ãŒãžè¡ãåæåãã空ã®èŸæžãäœæ ïŒããŒãã«ã»ã«ã®å 容ãä¿åãã self.board_widgets [è¡] = {} ïŒå0ãã2ãéé ç¯å²ïŒ0,3ïŒã®åã®å ŽåïŒ ïŒã€ãã³ããšãªã¢ãäœæ event_box = gtk.EventBoxïŒïŒ ïŒã©ãã«ãäœæããŸãããã®ããã¹ãã«ã¯è¡ãšåã®çªå·ãå«ãŸããŸã label = gtk.LabelïŒ "label_ïŒ d_ïŒ d"ïŒ ïŒåãè¡ïŒïŒ ïŒã©ãã«ã衚瀺ãã label.showïŒïŒ ïŒã€ãã³ããšãªã¢ã«ã©ãã«ã貌ã event_box.addïŒã©ãã«ïŒ ïŒãšãªã¢ã®ã€ãã³ããã³ãã©ãŒãå®çŸ©ãã event_box.connectïŒ "button_press_event"ãself.label_clickedãè¡ãåïŒ ïŒãã®çµæžããã¹ãŠã¹ãã¬ãŒãžã«æžã蟌ã self.board_widgets [è¡] [å] = event_box ïŒã©ãã«ä»ãã®ã€ãã³ããšãªã¢ãããŒãã«ã«æ·»ä» self.table1.attachïŒself.board_widgets [è¡] [å]ã åãå+ 1 è¡+ 1ãè¡+ 2ïŒ ïŒã©ãã«ã衚瀺ãããã€ãã³ããšãªã¢ãäœæãã self.board_widgets [è¡] [å] .showïŒïŒ def label_clickedïŒèªå·±ããŠã£ãžã§ãããã€ãã³ããè¡ãåïŒïŒ print "columnïŒ sãrowïŒ s"ïŒ ïŒåãè¡ïŒ
æ¥ç¶é¢æ°ã§ã¯ãä¿¡å·ãšãŠã£ãžã§ããã«å ããŠãè¡ãšåãšãã2ã€ã®è¿œå ãã©ã¡ãŒã¿ãŒãæå®ããŸãã ãããã®ãã©ã¡ãŒã¿ãŒã¯label_clickedã§èªã¿åãããã²ãŒã ã®å¶åŸ¡ã«äœ¿çšãããŸãã ã€ãã³ããšãªã¢ãšã©ãã«ã®äž¡æ¹ãshowïŒïŒã䜿çšããŠè¡šç€ºããå¿ èŠããããŸãã ããã°ã©ã ãå®è¡ããŠã©ãã«ãã¯ãªãã¯ãããšãã³ã³ãœãŒã«ã§ãã©ãã«ãé 眮ãããŠããããŒãã«ã®åãšè¡ã®åºåã®åœ¢åŒã§åå¿ã衚瀺ãããŸãã
ã€ã³ã¿ãŒãã§ã€ã¹ã¯ã»ãšãã©æºåãã§ããŠããŸãããã»ã«ã«ç·ã®ããŒã¯ãä»ããã«ãã¬ã€ããã®ã¯äžäŸ¿ã§ãã ã©ãã«ã«ãã¬ãŒã ãè¿œå ããå¿ èŠããããŸãã GTKã«ã¯ããã¬ãŒã ã衚瀺ããç¹å¥ãªãŠã£ãžã§ããã³ã³ãããŒããããŸãã Gladeã§ã¯ãããã¬ãŒã ããšåŒã°ããŸã
ã
ã€ãã³ãé åããã¬ãŒã å ã«åãŸãããã«ã³ãŒããå€æŽããå¿ èŠããããŸãã åæã«ãã©ãã«äžã®ããã¹ãã®åºåãåé€ããŸããããã¯ããå¿ èŠãããŸããã
def init_boardïŒselfïŒïŒ ïŒç«¶æå Žã®èŸæžä¿ç®¡ã©ãã« self.board_widgets = {} ïŒ1ã3è¡ç®ã«ã©ãã«ãè¿œå ããŸã ç¯å²ïŒ0.3ïŒã®è¡ã®å ŽåïŒ ïŒã¹ãã¬ãŒãžè¡ãåæåãã空ã®èŸæžãäœæ ïŒããŒãã«ã»ã«ã®å 容ãä¿åãã self.board_widgets [è¡] = {} ïŒå0ãã2ãéé ç¯å²ïŒ0,3ïŒã®åã®å ŽåïŒ ïŒãã¬ãŒã ãäœæ ãã¬ãŒã = gtk.FrameïŒïŒ frame.set_shadow_typeïŒgtk.SHADOW_ETCHED_INïŒ ïŒã€ãã³ããšãªã¢ãäœæ event_box = gtk.EventBoxïŒïŒ ïŒã©ãã«ãäœæ ã©ãã«= gtk.LabelïŒïŒ ïŒã©ãã«ã衚瀺ãã label.showïŒïŒ ïŒã€ãã³ããšãªã¢ã«ã©ãã«ã貌ã event_box.addïŒã©ãã«ïŒ ïŒãšãªã¢ã®ã€ãã³ããã³ãã©ãŒãå®çŸ©ãã event_box.connectïŒ "button_press_event"ãself.label_clickedãè¡ãåïŒ event_box.showïŒïŒ frame.addïŒevent_boxïŒ ïŒãã®çµæžããã¹ãŠã¹ãã¬ãŒãžã«æžã蟌ã self.board_widgets [è¡] [å] =ãã¬ãŒã ïŒã©ãã«ä»ãã®ã€ãã³ããšãªã¢ãããŒãã«ã«æ·»ä» self.table1.attachïŒself.board_widgets [è¡] [å]ã åãå+ 1 è¡+ 1ãè¡+ 2ïŒ ïŒã©ãã«ã衚瀺ãããã€ãã³ããšãªã¢ãäœæãã self.board_widgets [è¡] [å] .showïŒïŒ
ãã®ãããªçªãå€æ
ã©ãã«äžã®æžåŒä»ãããã¹ãåºå
ã¿ã°ã¯ãã©ãŒããããããããã¹ãã衚瀺ã§ããŸãã ç¹å®ã®ãã©ã³ãããµã€ãºãã¹ã¿ã€ã«ãè²ã§ããã¹ãã衚瀺ã§ããŸãã init_boardã«æ°è¡è¿œå ããŸã
ïŒã©ãã«åŸ= gtk.LabelïŒïŒ label.set_use_markupïŒTrueïŒ label.set_markupïŒ "<span font_desc = 'Arial 64'> X </ span>"ïŒ
ããã°ã©ã ãå®è¡ããŸãã
ã
察話
Gladeã«ã¯ãã»ãšãã©ãã¹ãŠã®æ©äŒã«ãã€ã¢ãã°ããããŸãã ä»»æã®ãŠã£ã³ããŠã«åºã¥ããŠã¢ãŒãã«ãã€ã¢ãã°ãäœæããæ¹æ³ã玹ä»ããŸãã
æ°ãããŠã£ã³ããŠãäœæãããã®ããããã£ã«ç§»åããŸãã
ç¢å°ã¯ããŠã£ã³ããŠã®ã¢ããªãã£ãšé¢é£ãããŠã£ã³ããŠãšãã2ã€ã®éèŠãªããããã£ã匷調ããŠããŸãã ã¢ããªãã£ã«æ³šç®ãã¹ãçç±ã¯æããã ãšæããŸã-ã¢ãŒãã«ãªå¯Ÿè©±ãè¡ã£ãŠããŸãã ããªã³ã¯ãŠã£ã³ããŠãããããã£ã¯ããããã¢ãŒãã«ãã€ã¢ãã°ã«ãªãã¡ã€ã³ãŠã£ã³ããŠã瀺ããŸãã
æ¢ç¥ã®ãŠã£ãžã§ãããšã¬ã€ã¢ãŠãã䜿çšããŠããã®ãã€ã¢ãã°ãã¹ã±ããããŸããã
ãŠã£ãžã§ããããªãŒïŒ
ãã¹ãŠãéåžžã«ç°¡åã§ããã€ã¡ãŒãžã«ã€ããŠã¯ããã¡ã€ã«ããœãŒã¹ãšããŠæå®ãããŠããããšã«æ³šæããŠãã ããã
ã€ã³ã¿ãŒãã§ã€ã¹ãä¿åããã³ãŒããšãã£ã¿ãŒã«æ»ããŸãã
æåã«è¡ãããšã¯ãåé€ã€ãã³ããã€ã¢ãã°ãŠã£ã³ããŠã€ãã³ãã®ãã³ãã©ãŒãèšå®ããããšã§ãã ãããè¡ãããªãå ŽåããŠã£ã³ããŠã¿ã€ãã«ã®Xãã¿ã³ã䜿çšããŠãã€ã¢ãã°ãéããåŸïŒãŸãã¯ãŠã£ã³ããŠãããŒãžã£ãŒã䜿çšããŠä»ã®æ¹æ³ã§ïŒããã®ãŠã£ã³ããŠã®ãã¹ãŠã®ãŠã£ãžã§ããããæ¶æ» ãããŸãã 次åãã®ãŠã£ã³ããŠãéããšã埮èŠçã«ãªããå®å šã«ç©ºã«ãªããŸãã __init__ã«è¿œå ããŸã
self.winner_dialog = self.widgetsTree.get_widgetïŒ "window2"ïŒ self.winner_dialog.connectïŒ "delete-event"ãself.on_delete_eventïŒ
on_delete_eventã¡ãœããã¯ãã€ãã³ããããã«åŠçãããªãããã«Trueãè¿ãå¿ èŠããããŸãã
äžè¬ã«ãã»ãšãã©ãã¹ãŠã®æºåãæŽã£ãã®ã§ãã¡ãœããã³ãŒãã¯èå³æ·±ããã®ã«ãªããã²ãŒã ã®åè ã衚瀺ãããŸãã
def show_winnerïŒselfïŒïŒ self.game.and_the_winner_isïŒïŒ== -1ïŒã®å Žå self.widgetsTree.get_widgetïŒ "image3"ïŒãset_from_fileïŒ '1.png'ïŒ self.widgetsTree.get_widgetïŒ "label3"ïŒãset_markupïŒ "<span font_desc = 'Arial 18'>ããŠãããªãã¯ç§ãããè³¢ããšããããšãç解ããŠããŸããïŒ</ span>"ïŒ self.widgetsTree.get_widgetïŒ "label4"ïŒãset_textïŒ "ã¯ããã¯ãŒã ã§ãã®ã§èªããŠããŸãã"ïŒ self.widgetsTree.get_widgetïŒ "label5"ïŒãset_textïŒ ãããªãã¯ãã ã®\ n猶ããã³ããŒã\ nandã ãä»ããã蚌æããŸãïŒãïŒ ãã®ä»ïŒ self.widgetsTree.get_widgetïŒ "image3"ïŒãset_from_fileïŒ '2.png'ïŒ self.widgetsTree.get_widgetïŒ "label3"ïŒãset_markupïŒ "<span font_desc = 'Arial 18'>ç·ã¯ããããã«è² ããªããã°ãªããŸããïŒ</ span>"ïŒ self.widgetsTree.get_widgetïŒ "label4"ïŒãset_textïŒ "ã¯ããã¡ããã©å¹žéã§ãã"ïŒ self.widgetsTree.get_widgetïŒ "label5"ïŒãset_textïŒ "ããªãã¯å°æ°ã§ããïŒããŠãã¡ãã£ãšåŸ ã£ãŠãã ããïŒ"ïŒ self.winner_dialog.showïŒïŒ
set_from_fileã¡ãœããã䜿çšããŠç»åãã¡ã€ã«ãæå®ããŸããã©ãã«ã®set_markupã¯ããŒã¯ã¢ããã瀺ããself.winner_dialog.showïŒïŒã¯ãã€ã¢ãã°ãéããŸãã
Windowsã§ã²ãŒã ãå®è¡ããããã«æ®ããŸãïŒ
ããã³Linux
æå³ãããšããããã¹ãŠãäž¡æ¹ã®OSã§åäœããŸãïŒ
ã¢ã«ãŽãªãºã ã¯ããã¬ãŒã€ãŒã匱ãå ŽåïŒåäŸãªã©ïŒãå¶ç¶ã«åããŸãããã®ãããåã€ãã£ã³ã¹ãããããã³ããŒã¯è² ããŸãã
ä»ããã²ãŒã ãããŠã³ããŒããããã³ããŒã§éã¶æéã§ãã