]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxComboBox.py 
   2  from  wxPython
. wx 
import  *    4  #---------------------------------------------------------------------------    6  class  TestComboBox ( wxPanel
):    7      def  OnSetFocus ( self
,  evt
):   10      def  OnKillFocus ( self
,  evt
):   14      def  __init__ ( self
,  parent
,  log
):   16          wxPanel
.__ init
__ ( self
,  parent
, - 1 )   18          sampleList 
= [ 'zero' ,  'one' ,  'two' ,  'three' ,  'four' ,  'five' ,   19                        'six' ,  'seven' ,  'eight' ]   21          wxStaticText ( self
, - 1 ,  "This example uses the wxComboBox control." ,   24          wxStaticText ( self
, - 1 ,  "Select one:" ,  wxPoint ( 15 ,  50 ),  wxSize ( 75 ,  18 ))   25          cb 
=  wxComboBox ( self
,  500 ,  "default value" ,  wxPoint ( 90 ,  50 ),  wxSize ( 95 , - 1 ),   26                          sampleList
,  wxCB_DROPDOWN
) #|wxTE_PROCESS_ENTER)   27          EVT_COMBOBOX ( self
,  500 ,  self
. EvtComboBox
)   28          EVT_TEXT ( self
,  500 ,  self
. EvtText
)   29          EVT_TEXT_ENTER ( self
,  500 ,  self
. EvtTextEnter
)   30          EVT_SET_FOCUS ( cb
,  self
. OnSetFocus
)   31          EVT_KILL_FOCUS ( cb
,  self
. OnKillFocus
)   33          cb
. Append ( "foo" ,  "This is some client data for this item" )   35          cb 
=  wxComboBox ( self
,  501 ,  "default value" ,  wxPoint ( 90 ,  80 ),  wxSize ( 95 , - 1 ),   37          for  item 
in  sampleList
:   38              cb
. Append ( item
,  string
. upper ( item
))   39          EVT_COMBOBOX ( self
,  501 ,  self
. EvtComboBox
)   40          EVT_TEXT ( self
,  501 ,  self
. EvtText
)   43      def  EvtComboBox ( self
,  evt
):   44          cb 
=  evt
. GetEventObject ()   45          data 
=  cb
. GetClientData ( cb
. GetSelection ())   46          self
. log
. WriteText ( 'EvtComboBox:  %s \n ClientData:  %s \n '  % ( evt
. GetString (),  data
))   48      def  EvtText ( self
,  evt
):   49          self
. log
. WriteText ( 'EvtText:  %s \n '  %  evt
. GetString ())   51      def  EvtTextEnter ( self
,  evt
):   52          self
. log
. WriteText ( 'EvtTextEnter: does this work?' )   54  #---------------------------------------------------------------------------   56  def  runTest ( frame
,  nb
,  log
):   57      win 
=  TestComboBox ( nb
,  log
)   60  #---------------------------------------------------------------------------   69  A combobox is like a combination of an edit control and a listbox. It can be displayed as static list with editable or read-only text field; or a drop-down list with text field; or a drop-down list without a text field.   75  if  __name__ 
==  '__main__' :   78      run
. main ([ '' ,  os
. path
. basename ( sys
. argv
[ 0 ])])