ããã«ã¡ã¯ãããã©ãïŒ
ãã®èšäºã§ã¯ã
wxPythonãªã©ã®ãã°ãããã©ã€ãã©ãªãŒã«ã€ããŠã®èããå®åŒåããŸãã ã«ããã®äžã«ã¯ãå°ãã®çè«ããã©ãŒã ã®èª¬æããã©ãŒã ã®ããããã£ã®åæãããŸããŸãªã³ã³ãããŒã«ãwxPythonã«é¢é£ãããã¹ãŠããããŸãã
wxPythonãžãããã ã
åæããŒã¿
ããã€ãã®çè«çŽ¹ä»ã
1.
wxPython in actionïŒãã·ã¢èªïŒ -æ¬ã®ãã·ã¢èªçïŒãªãªãžãã«ã®æ¹ã奜ããªã®ã§ããã®å質ãšèµ·æºã«ã€ããŠã¯äœãèšããŸããããå®éã«ã¯
wxPythonãåäœããŠããŸãïŒè±èªïŒ -ããã§ã¯çŽã®åœ¢åŒã§54ãã«ïŒé»åïŒäžè¬çãªæèŠã¯ããã®æ¬ã¯åªããŠãããšããããšã§ãããã¹ãŠã詳现ã«èšè¿°ãããæžãããŠããŸãããã¡ãããå€ãã®ç¹ã¯è©³çŽ°ã§ã¯ãªããããã€ãã®äºæã¯
ããã¥ã¡ã³ãã§æãããèŠãã
ãŸãããäžè¬ã«ããã¹ãŠã®äŸã¯çå®ã§ããåå¿è
ã«æé©ã§ãã
2.wxPython 2.8ã¢ããªã±ãŒã·ã§ã³éçºã¯ãã¯ãã㯠ã ç§ã¯ãã·ã¢èªçã§ãã®æ¬ãèŠã€ããããšããããŸããã§ããã ãã®æ¬ã«ã¯ãGUIãã©ãŒã ãæžãããã®ãã¬ã·ãããå«ãŸããŠããŸãããããã¯ãããŠãç°¡åã§ã¯ãªãã解æãç°¡åã§ã¯ãããŸããïŒãã ããæ¬ã®åè¡ãç解ããããšããè©Šã¿ããããŸãã
3.
python.suã¯ãããŸããŸãªãããã¯ã«é¢ãããããã¯ã®åªããããŒã¿ããŒã¹ãåããåªãããã©ãŒã©ã ã§ãã åºåãšã¯èããªãã§ãã ããããããããã¯æ¬åœã«è¯ãããšã§ããæè¿å®å®ããŠæ©èœããŠããªãã®ã¯æ®å¿µã§ãã
4.
habrahabr.ru-ããã§å€§å€±æãåŸ
ã£ãŠããã ç§ãæ¢ããŠãããã®ç¬éããã®ã©ã€ãã©ãªã«é¢ããèšäºã¯1ã€ããããŸããã§ããã ã»ãã®å°ãåã«ãåºæ¬ã®å°ããªèšäºããã©ãã·ã¥ãããŸããïŒæåã®ããŒãžã®æ¬ã«æžãããŠãããã®ïŒã å®éãããã§ããã®èšäºãæžãããšãèããŠããŸããã
å°æ¥ã«ç®ãåããŠãç§ã¯å³æžé€šã§é·ãéåããåŸã«èŠã€ããããã€ãã®ããŒã«ãããã«ã¢ããã€ã¹ããããšæããŸãã
1.wxPythomã®ãã¢ãšããã¥ã¡ã³ã ããã¯ãwxpythonã©ã€ãã©ãªã䜿çšããŠèšè¿°ãããã³ã³ãããŒã«ãšãã©ãŒã ã®æè¯ã®äŸã§ãã ããŸããŸãªãã©ãŒã ãšã³ã³ãããŒã«ããªã¹ããããªãŒãããã³ãããã®ããŸããŸãªçµã¿åããã®äŸããããŸãã ããããã¹ãŠã®äŸã®ãœãŒã¹ã³ãŒãã«ã¯ã³ã¡ã³ããè±å¯ã§ã¯ãªãã®ã§ãåŸã§ãããèŠã€ããŠãäœãèµ·ãã£ãŠããã®ããç解ãããšãäœãèµ·ãã£ãŠããã®ããç解ããã®ã«éåžžã«åœ¹ç«ã¡ãŸããã
2.
wxFormBuilder -wxPythonã®ãã©ãŒã ãšã³ã³ãããŒã«ã®ã¢ããªã±ãŒã·ã§ã³ã³ã³ã¹ãã©ã¯ã¿ãŒïŒã ãã§ã¯ãããŸããïŒã ãã®ã¢ããªã±ãŒã·ã§ã³ã¯ã30åã®ãã©ãŒã ãæã§æžãããšãã«èŠã€ããŸããã ã€ãŸã ãã©ãŒã ã®ãµã€ãºãããããŸããŸãªã¿ã€ãã®ãµã€ã¶ãŒãšãã®ããããã£ã®äœ¿çšãŸã§ããã¹ãŠãæã§æžãããŸããã ããããã°ãäœãã©ãã§ãã©ã®ããã«ããªãç¥ã£ãŠããã®ã§ãæéãç¯çŽã§ããŸãã ãã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯ã©ã€ãã©ãªå
šäœã®å®å
šãªæ©èœã¯ãããŸãããããã¯ç解ã§ããŸããwxã¯è€éã§éåžžã«èšå€§ãªã©ã€ãã©ãªã§ããã©ã€ãã©ãªã³ã³ã¹ãã©ã¯ã¿ã®å®å
šãªèšè¿°ã«ã¯èšå€§ãªæéãããããŸããç¹å¥ãªå¿
èŠã¯ãããŸããã ãã®ã¢ããªã±ãŒã·ã§ã³ã䜿çšããŠãã©ãŒã ãæ¥ãã§äœæããããšã¯äžåºŠã«äŸ¡å€ããããŸãããã©ã€ãã©ãªå
šäœã®æ©èœã®30ïŒ
ããã£ããããããšã¯ã§ãããã€ã³ã¿ãŒãã§ã€ã¹ã¯3ã€ã®ãã¿ã³ãš2ã€ã®ã€ãã³ãã«å¶éãããŸãã
ã¯ããã«
ããŸããŸãªçš®é¡ã®ãŠã£ã³ããŠãšãã®ããããã£ã«ã€ããŠè©³ãã調ã¹ãåã«ãããã€ãã®ãã€ã³ããåŠç¿ããå¿
èŠããããŸãããããã®ãã€ã³ãããªããšããŠã£ã³ããŠã®çš®é¡ãšæ¹æ³ãç解ããã®ãé£ãããªããŸãã
1.ãã¹ãŠã®ã¢ã€ãã ã¯ãµã€ã¶ãŒå
ã«ãªããã°ãªããŸããã SizerïŒ
wx.Sizer ïŒã¯ããã©ãŒã ã®ãã¹ãŠã®ã³ã³ããŒãã³ãã®å Žæã瀺ãç¹å®ã®é衚瀺ãã©ãŒã èŠçŽ ã§ãã
2.éå±€ã¯æ¬¡ã®ãšããã§ãããã©ãŒã ïŒ
wx.Frame ïŒã«ã¯
ãµã€ã¶ãŒããããã³ã³ãããŒããã«ïŒ
wx.Panel ïŒããµã€ã¶ãŒã«è¿œå ãããå¥ã®ãµã€ã¶ãŒãããã«ã«è¿œå ããããã¹ãŠã®ãã©ãŒã èŠçŽ ããã®ãµã€ã¶ãŒã«æ¢ã«è¿œå ãããŠããŸãã
3.ã³ã³ããŒãã³ãããµã€ã¶ãŒã«è¿œå ããã«ããã«ã«è¿œå ããã®ã¯æ£ãããã
ãŸãã ïŒwxFormBuilderã§ã¯ãã
ãå®è¡
ã§ããŸããïŒã
4.ãã¹ãŠã®ã³ã³ãããŒã«ã®ããããã£ãå®å
šã«èŠå®ãããŠããªãå ŽåããããŸãã ããã¹ãå
¥åãã£ãŒã«ãã®ãµã€ãºãéèŠã§ãªãå ŽåãæšæºãšããŠèªåçã«æ§ç¯ãããŸãã
åºæ¬èŠçŽ
wxã«ã¯ããã€ãã®ã¿ã€ãã®ãã©ãŒã ããããŸãã
wx.Dialog-ãã€ã¢ãã°ããã¯ã¹ã
wx.Frame-æšæºæ©èœïŒæå°åïŒ
wx.ICONIZE ïŒãæ倧åïŒ
wx.MAXIMIZE ïŒãéããïŒ
wx.Close ïŒïŒãæã€ãŠã£ã³ããŠãè¡šãéåžžã®ãã©ãŒã ã
ã³ãŒãå
ã®wx.Frameã®éåžžã®è¡šçŸïŒ
wx.Frame.__init__ ( self, parent=None, id = wx.ID_ANY, title = u"NameWindow", pos = wx.DefaultPosition, size = wx.Size( int,int ), style = wx.CAPTION )
ãã®ã³ãŒãè¡ã¯ãã©ãŒã ãåæåããå
¥åãããããããã£ã䜿çšããŠãã©ãŒã ãæç»ããŸãã ãšããã§ïŒ
wx.Frame.__init__ (self, parent = None)
ãŸãããã©ãŒã ãæç»ãããã©ãŒã ã®ãã¹ãŠã®ããããã£ãæšæºã«ãªããŸãã
selfãš
parent㯠ãä»»æã®åœ¢åŒã®2ã€ã®å¿
é ãã©ã¡ãŒã¿ãŒã§ãã
ãã©ãŒã ã®åæåãåæããŸãããïŒ
selfã¯ã¯ã©ã¹ãè¡šããparentã¯ãã®ãŠã£ã³ããŠã®èŠªãè¡šããŸãã
id-åèŠçŽ ããŠã£ã³ããŠã¯ãèŠçŽ ã«ã¢ã¯ã·ã§ã³ãã€ãã³ãã«ã¢ã¯ã»ã¹ãŸãã¯å²ãåœãŠãããã®ç¬èªã®IDãæã£ãŠããŸãã ãããæ°ã«ããã-1ãŸãã¯
wx.ID_ANYãèšå®ããããšã¯ã§ããŸãã-ããã¯ä»»æã®IDã圢åŒåããŸãïŒåèŠçŽ ã¯ç¬èªã®äžæã®IDãæã€å¿
èŠãããããããåŒã³åºãããèŠçŽ ã«ã¢ã¯ã·ã§ã³ãå²ãåœãŠãããã«äœ¿çšã§ããŸãããããäžèŠãªå Žåã¯ãIDãèšå®ã§ããŸãwx.ID_ANYå€ãå®éã¯-1ïŒã
title-ãŠã£ã³ããŠã®ã¿ã€ãã«ã
pos-ç»é¢äžã®xããã³y座æšã§ã®ãã©ãŒã ã®äœçœ®ã
size-ãã¯ã»ã«åäœã®ãã©ãŒã ã®ãµã€ãºãstyle-ãŠã£ã³ããŠã¹ã¿ã€ã« ããã¥ã¡ã³ãã§ããããçš®é¡ã®ã¹ã¿ã€ã«ãèŠãããšãã§ããŸãã ããã€ã泚æããŠãã ããïŒ
wx.CAPTION-ã¿ã€ãã«ä»ãã®ãããããŒã衚瀺ããŸãããã·ã¹ãã ã¡ãã¥ãŒã¯ãããŸããã
wx.STAY_ON_TOP-ä»ã®ã¢ããªã±ãŒã·ã§ã³ã®ãŠã£ã³ããŠã®æäžéšã«ãšã©ãŸããŸãã詳现ã1ã€èª¬æããŸããè€æ°ã®ãŠã£ã³ããŠã«ãã®ã¹ã¿ã€ã«ãããå Žåãã¢ããªã±ãŒã·ã§ã³ã®èŠªéå±€ã®äžäœã«ãããŠã£ã³ããŠã¯ãæäžéšãã®ãŸãŸã«ãªããŸãã
wx.SYSTEM_MENU- ãéããããã¿ã³ããããããŒã«è¡šç€ºãããŸãããã¢ã¯ãã£ãã§ã¯ãããŸããã
ãã€ã¢ãã°ãš
ãã¬ãŒã ã®éãã¯æ¬¡ã®ãšããã§ãã
1.ãã€ã¢ãã°ã¢ãŒãã«ãŠã£ã³ããŠãã€ãŸã ãã®ãŠã£ã³ããŠã§ã¢ã¯ã·ã§ã³ãå®è¡ãããŸã§ããŠãŒã¶ãŒã¯éããŠããä»ã®ãŠã£ã³ããŠã«ç§»åã§ããŸãã
ãã®ã¢ããªã±ãŒã·ã§ã³ã
2.ãã€ã¢ãã°ãŠã£ã³ããŠã«ã¯æ¢ã«ããã«ãå«ãŸããŠããããããã€ã¢ãã°ããã¯ã¹ã«ã¯ãµã€ã¶ãŒã®ã¿ãå¿
èŠã§ããããã¹ãŠã®èŠçŽ ã¯ãã®ãµã€ã¶ãŒã«æ¢ã«é
眮ãããŠããå¿
èŠããããŸãã
3.ãã€ã¢ãã°ããã¯ã¹ã¯ããã¿ã³äžã®è¿œå ã€ãã³ããªãã§å®è¡ã§ããŸãïŒè©³çŽ°ã¯åŸã»ã©ïŒã
ã©ã€ãã©ãªãææããããŸããŸãªã³ã³ãããŒã«ã®è±å¯ãã¯é©ãã¹ããã®ã§ãã ãã¿ã³ããã¿ãä»ãã®ããŒãããã¯ãŸã§ããã¹ãŠããããŸãïŒããã€ãã®ã¿ã€ãããããŸãïŒã
ããã§ãã¹ãŠã®ããšã話ãã®ã¯ç¡æå³ã§ããæ°ãæéç¶ããŸãã®ã§ãããã€ãã®èŠçŽ ã«ã€ããŠç°¡åã«èª¬æããã»ãšãã©ãã¹ãŠã®ã³ã³ãããŒã«ãšèŠçŽ ã«æšæºçãªç¬éã説æããŸãã
æãåçŽãªèŠçŽ ã次ã®ã³ãŒãã«ç€ºããŸãã
class regexps ( wx.Frame ): def __init__( self, main, schema, table, connection ): wx.Frame.__init__ ( self, parent=None, id = wx.ID_ANY, title = u"Data Quality -- ", pos = wx.DefaultPosition, size = wx.Size( 510,477 ), style = wx.CAPTION|wx.STAY_ON_TOP|wx.TAB_TRAVERSAL ) sizer1 = wx.BoxSizer( wx.HORIZONTAL ) self.regexps_notebook = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) self.dq_params_tab = wx.Panel( self.regexps_notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
ã¿ã€ã
wx.Frameã®ãŠã£ã³ããŠã®åæåã
ã芧ã®ãšãã ããã¹ãŠã®ããããã£ãååšããŸãã ãããã®ããã€ãã¯æšæºå€ã«äžããããŸãã ã¹ã¿ã€ã«ã®ã¬ã€ã¢ãŠãã«æ³šæãã䟡å€ããããŸãã ãŠã£ã³ããŠã«ã¯ããããããŒãšãéã¢ã¯ãã£ããªéãããã¿ã³ãšããŠã®ã·ã¹ãã ã¡ãã¥ãŒã衚瀺ãããŸãã ãŸãããŠã£ã³ããŠã¯åžžã«ã¢ã¯ãã£ãã§ãïŒ
wx.STAY_ON_TOP ïŒã ãµã€ã¶ãŒçºè¡šã ãµã€ã¶ãŒã¿ã€ãwx.BoxSizerã¯ããã¯ã¹ã§ãã ãã¹ãŠã®ãšãã£ã¡ã³ããæ°Žå¹³æ¹åãŸãã¯åçŽæ¹åã«æ¬¡ã
ã«äžŠãã§ããŸãïŒãã®å Žåã¯ã
ãµã€ãºæ±ºå®ããã°ã©ã ã«æž¡ãããåŒæ°ã
wx.HORIZONTALã«è²¬ä»»ããããŸã ïŒã ããŒãããã¯åºåïŒã¿ãä»ãããã«ïŒã æåã«ã圌ã«ã¯åå
self.regexps_notebookãäžããããŸãããããã«ãããä»»æã®ã¯ã©ã¹ã¡ãœããããäœæã§ããŸãã 次ã«ãããããã£ãæã€
wx.Notebookã³ã³ããŒãã³ãã®å®£èšãã©ãããããã«åãŸãããã«ã®çºè¡šã§ãã ã©ãããããã«é
眮ãããããã«ã¯ããã¹ãŠã®ã¿ãã®ãã©ãããã©ãŒã ã«ãªãããšã«æ³šæããŠãã ããã ãŸããããã«ãã©ãããããã¿ããšããŠé
眮ããå Žåãåå¥ã®ãµã€ã¶ãŒã¯å¿
èŠãããŸããïŒããã¯ããã¹ãŠã®èŠçŽ ããµã€ã¶ãŒã«ããå¿
èŠããããšããäºå®ãšççŸããŸããã€ãŸããããã¯ãã®ã«ãŒã«ã®äŸå€ã§ãïŒ
sizer2 = wx.BoxSizer( wx.VERTICAL ) self.use_param_checkbox = wx.CheckBox( self.dq_params_tab, wx.ID_ANY, u" ", wx.DefaultPosition, wx.DefaultSize, 0 )
2çªç®ã®ãµã€ã¶ãŒã®çºè¡šã ãµã€ã¶ãŒã®æå°ãµã€ãºã æ°ãããã§ãã¯ããã¯ã¹ã³ã³ããŒãã³ããè¿œå ããŸãã
self.dq_params_tabããã«ã«è¿œå ããŸããã€ãŸã ããŒãããœã³ã³ã®ã¿ãã«ã
sizer2.Add( self.use_param_checkbox, 0, wx.ALL, 5 ) self.params_quality_choices = [1,2,3,4,5,6,7,8,9,10] self.params_choice_pull = wx.Choice( self.dq_params_tab, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.params_quality_choices, 0 )
éèŠãªãã€ã³ãã äœæãããã§ãã¯ããã¯ã¹ãããã«ïŒã¿ãïŒäžã«ãããµã€ã¶ãŒã«è¿œå ããŸããè¿œå ã®æ§é ã¯æ¬¡ã®ãšããã§ããããã¯è¡šç€ºãã©ã¡ãŒã¿ãŒã§ããããã®å Žåãelmenetã¯ãã«ãµã€ãºã§è¡šç€ºãããŸã
ã0 ïŒããã¯èŠçŽ ã®æ¯äŸã§ããã
5 ïŒããã¯èŠçŽ ã®
å¢çç·ã®ãµã€ãºã§ãïŒã次ã¯å€ãæã€ããããããŠã³ãªã¹ãã®å®£èšã§ããããã omeschaetsyaã¿ãã
sizer2.Add( self.static_line, 0, wx.EXPAND |wx.ALL, 5 ) self.static_text = wx.StaticText( self.dq_params_tab, wx.ID_ANY, u" ", wx.DefaultPosition, wx.DefaultSize, 0 ) sizer2.Add( self.static_text, 0, wx.ALL, 5 ) self.weights_txt = wx.TextCtrl( self.dq_params_tab, validator = WeightsValidator() ) sizer2.Add( self.weights_txt, 0, wx.ALL, 5 )
ããã«è¿œå ãªãã·ã§ã³ããããŸãã
wx.EXPAND-ããã¯ããµã€ãºã«å¿ããŠãè¿œå ãããèŠçŽ ã®å¹
ãæ¡å€§ãããããšãæå³ããŸãã ããã¹ããã£ãŒã«ããè¿œå ããŠ
wx.TextCtrlãå
¥åã
ãŸã ã ããã«ã¯è¿œå ã®
æ€èšŒãªãã·ã§ã³ããã
ãŸã ã ããã«ã€ããŠã¯ãå¥ã®ã³ãŒãã§èª¬æããŸãã
self.dq_params_tab.SetSizer( sizer2 ) self.dq_params_tab.Layout() sizer2.Fit( self.dq_params_tab )
èå³æ·±ãç¹ã«æ¥ãŸããã ããã«ïŒ
self.dq_params_tab ïŒã«ãããµã€ã¶ãŒïŒ
sizer2 ïŒã«ãã¹ãŠã®èŠçŽ ãè¿œå ããåŸããµã€ã¶ãŒãããã«ã®é åå
šäœã«ãæ¡åŒµããããµã€ã¶ãŒãããã«ã«åºå®ããå¿
èŠããããŸãã
regexps_listboxChoices = [] self.regexps_listbox = wx.ListBox( self.regexps_tab, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, regexps_listboxChoices, wx.LB_HSCROLL|wx.LB_SINGLE )
ãªã¹ãããã¯ã¹ïŒ
wx.ListBox ïŒãè¿œå ããŸãã ãªãã·ã§ã³
wx.LB_HSCROLL |
wx.LB_SINGLEã¯ãæ°Žå¹³ã¹ã¯ããŒã«ã®ååšãšããªã¹ãå
ã®1ã€ã®ã¢ã€ãã ã®ã¿ãéžæã§ããããšã«ã€ããŠè©±ããŸãã ã°ãªããã®äœæã ããã«ã³ã¡ã³ãã®ãã¹ãŠã説æãããŠããŸãã
è¡ãé·ããããã€ã³ãã³ãã®æ§æã¯å°ããããŸãã§ãã ããã¯ã©ã€ãã©ãªã®æ§æã§ãã
åæ§ã®èŠçŽ ã®æ§é ãšé
眮ã¯ã³ãŒãã«ãããŸããããã¢ãžã¥ãŒã«å
šäœã®å®å
šãªã³ãŒããå®è¡ãããšã次ã®ããã«è¡šç€ºãããŸãïŒå®å
šãªã³ãŒãã«èå³ããã人ã¯æžããŠãã ããïŒïŒ
æåã®ã¿ã
2çªç®ã®ã¿ã
3çªç®ã®ã¿ãã
建ç©ãªã¹ã管ç
æãåçŽãªèŠçŽ ã®ããã€ãã調ã¹ãåŸãããã«è€éãªãã®ã«é²ã¿ãŸãã
ã³ã³ãããŒã«ã·ãŒãã¯æ®éçãªèŠçŽ ã§ãããããŸããŸãªã¢ããªã±ãŒã·ã§ã³ã§é »ç¹ã«èŠãããŸãã
次ã«ãã©ã³ãã ããŒã¿ã®ã³ã³ãããŒã«ã·ãŒããäœæããããã®ã³ãŒããåæããŸãã
class main_stat(listmix.ColumnSorterMixin): def __init__( self, rows, columns ): data = [] self.columns = columns self.rows = rows self.list = wx.ListCtrl(self.main.panelMainStat, 0, style=wx.LC_REPORT | wx.BORDER_NONE | wx.LC_EDIT_LABELS | wx.LC_SORT_ASCENDING | wx.LC_SINGLE_SEL)
ã¯ã©ã¹ãåŒæ°ãšããŠå®£èšãã
listmix 'ã³ã³ããŒãã³ããæž¡ããåã®ããŒã¿ããœãŒãããŸãã 次ã¯ãèã®å¶åŸ¡ã®åæåã§ããã¹ãŠã®æãç§å¯ãèµ·ãããŸãã
åïŒ
columns ïŒãšè¡ïŒ
rows ïŒã®ååãæž¡ã
ãŸã ã è¡ãå«ããªã¹ãã®é·ãã¯ãåã®ååãå«ããªã¹ãã®é·ããšçãããªããã°ãªããŸããã listcontrol
self.listãåŒã³åºããŠãããããã£ã
å²ãåœãŠãŸãã
ããããã£ã«é¢ããŠïŒ
wx.LC_REPORTã¹ã¿ã€ã«-æäžéšã®ååã®åœ¢ã®ãªãŒãã³ã³ãããŒã«ãè¡šã®ãããªåã®äžã®ãã¹ãŠã®ããŒã¿ãé¡äŒŒæ§ã®äžçš®ã ãããã£ãŠãæ®ãã®ã¹ã¿ã€ã«ã¯è±èªããã®ç¿»èš³ã«åºã¥ããŠç解ã§ããŸãã
for col, text in enumerate(self.columns): self.list.InsertColumn(col, text) for item in rows: info = '%s:(%s)' % (col, item) data.append(info) index = self.list.InsertStringItem(sys.maxint, item[0]) for col, text in enumerate(item[1:]): self.list.SetStringItem(index, col+1, text)
次ã«ãå°ãunningãªããŒã¿çæã¢ã«ãŽãªãºã ã ããã¯wxãšã¯é¢ä¿ãªãã®ã§ã詳ããã¯èª¬æããŸããã ãããããã€ã³ãã¯
ã³ã³ãããŒã«ã·ãŒãã®ããŒã¿ã¯æ¬¡ã®ããã«ãªã£ãŠããå¿
èŠããããŸãã
rows = {1 :( "data0"ã "data0.1"ã "data0.2"ïŒã2 :( "data1"ã "data1.0"ã "data1.1"ã "data1.2"ïŒã... }äžèšã®ã¢ã«ãŽãªãºã ã¯ããã®åœ¢åŒã«ã©ã³ãã ããŒã¿ããããããŸãã
self.list.SetSize((900, 200)) self.list.SetColumnWidth(0, 120) self.list.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list) self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) self.list.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected) self.itemDataMap = data listmix.ColumnSorterMixin.__init__(self, 3)
ã³ã³ãããŒã«ã·ãŒãã®ãµã€ãºãåã®ãµã€ãºãã€ãã³ããã€ã³ããèšå®ããŸãïŒããã«ã€ããŠã¯åŸã§èª¬æããŸãïŒã 以äžã¯ãå®éã«åäœããã³ãŒãã§ã¯ãããŸããã
self.itemDataMapã¯ãäžèšã®ããã«ãããŒã¿ã䞊ã¹æ¿ããããã«ãªã¹ãã³ã³ãããŒã«ã«çŽã¡ã«å
¥åãããæç¹ã§ãæå®ãããããŒã¿ãšçãããªããã°ãªããŸããã
def getColumnText(self, index, col): item = self.list.GetItem(index, col) return item.GetText() def OnRightClick(self, event): index = self.list.GetFirstSelected() print index def OnColClick(self, event): print ("OnColClick: %d\n" % event.GetColumn()) event.Skip() def OnItemSelected(self, event): self.currentItem = event.m_itemIndex self.data = (self.getColumnText(self.currentItem, 1), self.getColumnText(self.currentItem, 2), self.getColumnText(self.currentItem, 3), self.getColumnText(self.currentItem, 4))( True )
ããŒã¿ã®ããè¡ãå³ã¯ãªãã¯ãããšããã®è¡ã®ã·ãªã¢ã«çªå·ã衚瀺ãããŸãã
OnColClickã¡ãœããã¯ãåã®ã·ãªã¢ã«çªå·ãæäŸããŸãã ãããŠãããŒã¿ã®ããè¡ãéžæãããšããå€æ°ã®äžã«ããŸã
self.dataãªã¹ãã«ã¯ãéžæããããŒã¿ãæžã蟌ãŸããŸãïŒããã§ã¯ã
getColumnTextã¡ãœããã䜿çšããŠãååããããŒã¿ãååŸããŸãïŒã
æ§ç¯ããããªãŒãã³ã³ãããŒã«ã®äŸã
ã¡ãã¥ãŒ
ããã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®äžå¯æ¬ ãªéšåã§ããã¡ãã¥ãŒã«ç§»ããŸãããã
self.menubar = wx.MenuBar( 0 ) self.BD = wx.Menu() self.m_menuItem1 = wx.MenuItem( self.BD, 1, u" ", u' ', wx.ITEM_NORMAL ) self.BD.AppendItem(self.m_menuItem1, ) self.m_menuItem2 = wx.MenuItem( self.BD, 2, u" \tCtrl+T", u' ', wx.ITEM_NORMAL ) self.BD.AppendItem( self.m_menuItem2 ) self.m_menuItem3 = wx.MenuItem( self.BD, 3, u" \tCtrl+Q", u' ', wx.ITEM_NORMAL ) self.BD.AppendItem( self.m_menuItem3 )
ã¡ãã¥ãŒããŒåºåã ã¡ãã¥ãŒããŒã¯ãããããããŠã³ãªã¹ãã®ãããã¹ãŠã®ã¡ãã¥ãŒé
ç®ãé
眮ãããã¹ããªããã§ãã
self.BD = wx.MenuïŒïŒ -ã¡ãã¥ãŒé
ç®ãäœæããŠããè¿œå ããŸã
self.BDã®ã¡ãã¥ãŒé
ç®
ã ããã«è©³ããåæããŸãããã
self.m_menuItem1 = wx.MenuItem( self.BD, 1, u" ", u' ', wx.ITEM_NORMAL )
wx.MenuItem ïŒ
ã¡ãã¥ãŒã«ã¡ãã¥ãŒé
ç®ãIDãåå\ãããããŒãã¹ããŒã¿ã¹ããŒã«è¡šç€ºããããã«ãããã¹ãïŒããå ŽåïŒãã¡ãã¥ãŒé
ç®ã®çš®é¡ãè¿œå ããŸã ïŒ
ååã®åŸã«ã
\ t ïŒã¿ãæåïŒã®åŸã«ãããããŒãç¶ããŸããã¯ãªãã¯ãããšãã¢ã¯ãã£ããªå Žåã«ã¡ãã¥ãŒé
ç®ãåŒã³åºãããŸãã ãã®ã€ãã³ããè¿œå ã§åŠçããå¿
èŠã¯ãããŸããã
ã¡ãã¥ãŒé
ç®ã®ã¿ã€ãã¯ç°ãªãå ŽåããããŸãã
wx.ITEM_RADIO-ã©ãžãªãã¿ã³ã®ãããªå
ã®ã¢ã€ãã ã
wx.ITEM_CHECK-ãã§ãã¯ããã¯ã¹ã®åœ¢åŒã
次ã«ãåãæ¹æ³ã§ããã€ãã®ã¡ãã¥ãŒé
ç®ãè¿œå ããŸãã
self.statusbar = self.CreateStatusBar( 1, wx.ST_SIZEGRIP, wx.ID_ANY ) self.BD.Enable(2, False) self.statusbar.SetStatusText(u' , , .')
ã¹ããŒã¿ã¹è¡ã®äœæã ãããŠãã¡ãã¥ãŒé
ç®ã®1ã€ãéã¢ã¯ãã£ããšããŠè¡šç€ºããŸãã
TrueåŒæ°ã¯ããããã¢ã¯ãã£ãã«ããŸãã ãŸããã¯ã©ã¹ã®åæåçŽåŸã«ããã¹ããã¹ããŒã¿ã¹ããŒã«è¿œå ããŸãã
ãããŠãããã«ã¡ãã¥ãŒããããŸãã
ã€ãã³ãé§ååç°å¢
ããããèŠçŽ ããããããã©ãŒã ããŠãŒã¶ãŒã®åœ±é¿ãåããŸãã wxPythonã©ã€ãã©ãªãŒã䜿çšãããšããŠãŒã¶ãŒã ãã§ãªãããã°ã©ã ãå«ããŠã絶察ã«ãããããŠãŒã¶ãŒã¢ã¯ã·ã§ã³ãèšè¿°ã§ããŸãã
ã€ãã³ãã宣èšããããã®ã«ãŒã«ããå§ããŸãããã ãã¿ã³ããããŸãïŒ
self.ok_btn = wx.Button( self.m_panel5, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0 )
ãããŠããã¿ã³ãæŒããŠããã°ã©ã ã«2 + 2ãè¿œå ããŸãã
self.ok_btn.Bind( wx.EVT_BUTTON, self.OnOk )
OnOkã¡ãœããã¯ããã¿ã³ãã¯ãªãã¯ããã ãã§æ©èœããŸãã å®éããããã€ãã³ãã®å
šäœçãªãã€ã³ãã§ãã éãã¯ãwx.EVT_BUTTONïŒåŠçäžã®ã€ãã³ãå
ïŒãšããã®ã€ãã³ãããã³ã°ãããèŠçŽ ïŒãã®å Žåãself.ok_btnãã¿ã³ïŒã®ã¿ã§ãã
ã€ãã³ãçªå·1ã¯å¯Ÿå¿ããã¡ãã¥ãŒé
ç®ãæŒããšããªã¬ãŒããããã©ãŒã ãã¢ã€ãã«ç¶æ
ïŒãŠãŒã¶ãŒãéã¢ã¯ãã£ãïŒã®å Žåã¯ã€ãã³ãçªå·2ã衚瀺ãããŸãã
ããªããŒã¿ãŒ
äºæããããšã©ãŒããä¿è·ããããã«ããŠãŒã¶ãŒã¯ããã¹ããã£ãŒã«ããæ€èšŒããå¿
èŠããããŸãã ãããè¡ãããã«ãwxã¯
ããªããŒã¿ãŒ -èªå·±èšè¿°ãã§ãã¯ãæäŸããŸãã ãã«ãã€ã³ãã§ãã¯ããªããããåããªããŒã¿ãèšè¿°ããå¿
èŠããããŸãã
以äžã«èª¬æä»ãã®äŸã瀺ããŸãã
class Numbers(wx.PyValidator): def __init__(self): wx.PyValidator.__init__(self) self.Bind(wx.EVT_CHAR, self.OnChar) def Clone(self): return Numbers() def Validate(self, win): tc = self.GetWindow() val = tc.GetValue() for x in val: if x not in string.digits: return False return True def OnChar(self, event): key = event.GetKeyCode() try:
åŒæ°ãæã€ã¯ã©ã¹ãäœæãããã®ã¯ã©ã¹ãããªããŒã¿ã§ããããšã瀺ã
wx.PyValidatorãæž¡ããŸãã
OnCharã¡ãœãã
ã¯self.Bindã€ãã³ã
ïŒwx.EVT_CHARãself.OnCharïŒã«ãã£ãŠèšè¿°ãããããŒããŒãããæåãå
¥åããããšãã«å®è¡ãããŸãã
key = event.GetKeyCodeïŒïŒã³ãã³ãã䜿çšããŠãæŒããã³ã«ã³ãŒãããã£ããããçµã¿èŸŒã¿ã®
chrïŒïŒé¢æ°ããæŒãããããŒã®éåžžã®è¡šçŸã«ã³ãŒãã·ã³ãã«ãå€æããŸãã
string.digitsã«ã¯0ãã9ãŸã§ã®æ°åã®ãªã¹ããå«ãŸããæååã¯ã©ã¹ã«ã¯ããŒããŒãããå
¥åãããã»ãšãã©ãã¹ãŠã®æåã
16é²æ°ãŸã§å«ãŸããŠã
ãŸã ïŒæ®å¿µãªãã
ASCIIæåããããŸããããã·ã¢èªã¯ç§ãç解ããŠããéããå
¥åããŸããïŒ
æ€èšŒæ¹æ³
tc = self.GetWindowïŒïŒã¯ãããã¹ããã£ãŒã«ããé
眮ãããŠãããŠã£ã³ããŠãå®çŸ©ã
ãå
¥åãããå€ãæ€èšŒããŠããæ€èšŒãµã€ã¯ã«ãè¡ããŸãã ãã®ããªããŒã¿ãŒã¯ãæ°åãããªãªããããã¯ã¹ããŒã¹ä»¥å€ã®åäžã®ããŒããŠãŒã¶ãŒãæŒãããšãèš±å¯ããŸããã ããã¯ã¹ããŒã¹ãšããã°ãwxã¯ãã¹ãŠã®ããŒãããšãã°wx.WXK_Numpad0ãèšè¿°ããŸãããããã¯ã¹ããŒã¹ã¯ãããŸãããF1ããNumlockãŸã§ãã¹ãŠããããããããŒå€ã远跡ããå¿
èŠããããŸããã
ããªããŒã¿ãèšè¿°ããåŸãããã¹ããã£ãŒã«ããå®çŸ©ããããã«å¯Ÿå¿ããããªããŒã¿ããã€ã³ãããå¿
èŠããããŸãã
self.ip_ctrl = wx.TextCtrl( self.m_panel5, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 190,-1 ), 0, Numbers() )
ããã ãã§ãã èšäºã¯éåžžã«ããªã¥ãŒã ããããå°ãåä»ã§ããããšãå€æããŸããã ããã¯ãããšãã°wx.ListCtrlã«ãã€ã³ãã§ãããã¹ãŠã®ããããã£ãšã€ãã³ãã®èª¬æãéå§ãããšãèšäºã¯ãã以äžã®ãã®ã«ãªãããã§ãã èšäºãæ°ã«å
¥ã£ãŠç¶è¡ããã®ãçã«ããªã£ãŠããå Žåã¯ã次ã®èšäºãæžãå§ããã©ã€ãã©ãªã®ä»ã®èŠçŽ ãšæ©èœãããšãã°wx.auiãæããã«ããŸã-ããã¯ã¿ãä»ãã®é«åºŠãªããŒãããã¯ã§ãå±éããå ŽæããããŸãã
ãæž
èŽããããšãããããŸããã
è¿œå ïŒã³ãŒã
ã¯ã©ã¹æ£èŠè¡šçŸïŒwx.FrameïŒïŒ
def __init __ïŒselfãmainãschemaãtableãconnectionïŒïŒ
wx.Frame .__ init__ïŒselfãparent = Noneãid = wx.ID_ANYã...ïŒ
superã䜿çšããŠããé©åã«æžãæããããšãã§ããŸãã
ã¯ã©ã¹æ£èŠè¡šçŸïŒwx.FrameïŒïŒ
def __init __ïŒselfãmainãschemaãtableãconnectionïŒïŒ
superïŒæ£èŠè¡šçŸãèªå·±ïŒ.__ init__ïŒèŠª=ãªããid = wx.ID_ANYã...ïŒ
ã«ãã£ãŠ