#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Posts
    33
    Rep Power
    10

    wxPython Question


    Hello,

    I'm trying to figure out how I get the selection from more than one widget on a frame. Ex. I have a drop down box where a person can select a command, then I have a textctrl box where a person can enter an I.P address, and I have a send button, all on the same panel. What I want to happen is when the person hits the send button, I pull the command from the drop down and the I.P from the textctrl box into a variable that will be processed. Here is the code.

    Code:
    class CommandChoice(wx.Panel):
        def __init__(self, parent, id):
            wx.Panel.__init__(self, parent, -1)
    
            commandList = {'Channel Up': 'c+', 'Channel Down': 'c-', 'Vol Up': 'v+', 'Vol Down': 'v-', 'Guide': 'g', 'Settings': 's',
                          'Select': 'sel', 'Page Up': 'p+', 'Page Down': 'p-', 'Mute': 'm', 'A Key': 'A', 'B Key': 'B', 'C Key': 'C', 
                          'Up Arrow': 'u', 'Down Arrow': 'd', 'Left Arrow': 'l', 'Right Arrow': 'r', 'Info': 'i', 'Exit': 'e','Launch Diags': 'launch'}
    
            wx.StaticText(self, -1, "Choose a Set-top Command.", (15, 10))
            wx.StaticText(self, -1, "Select one:", (15, 50), (75, -1))
            self.ch = wx.Choice(self, -1, (100, 50), choices = commandList.keys())
            self.Bind(wx.EVT_CHOICE, self.commandChoice, self.ch)
            self.enteriplabel = wxStaticText(self, -1, "Enter your I.P address :",wxPoint(15, 100))
            self.enteripbox = wxTextCtrl(self, -1, "", wxPoint(150,100), wxSize(100,-1), style=wxTE_PROCESS_ENTER)
            self.Bind(wx.EVT_TEXT_ENTER, self.EnterIpText, self.enteripbox)
            sendbtn = wx.Button(self, ID_SEND_BTN, "Send", (200, 150))
            sendbtn.SetSize(sendbtn.GetBestSize())
            self.Bind(wx.EVT_BUTTON, self.OnSendBtn, sendbtn)
            
        def commandChoice(self, event):
            pass
            
        def OnSendBtn(self, event):
            pass
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    I don't have access to the help files at the moment to look it up fr you but both widgets have methods for reading (getting?? ) the values selected/contained.

    Simply call the methods within your OnSendBtn method.

    grim
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Code:
    choicevalue = self.ch.GetStringSelection() # returns the text or empty if nothing selected
    
    textvalue = self.enter.GetValue() # gets all of the text control
    Its a good idea to use self.ch.SetSelection(0) in your __init__ function to pre-select the first item in the list.

    grim
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Posts
    33
    Rep Power
    10
    Should have thought of that, only been using python for 2 weeks now, it is much better than Java. Thanks for your help.

IMN logo majestic logo threadwatch logo seochat tools logo