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

    Join Date
    Jan 2005
    Posts
    4
    Rep Power
    0

    Dropdown choice box in a grid cell? (wxPython)


    Any way to stick a choice box (dropdown menu) in a specific cell in a grid? I've been trying to do this with no luck for a week now . Any thoughts? Thanks.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    I'm not too good with wxPython, or Tkinter, or whatever program you're using for this. You should be able to do something like this by using wxPython. There website is wxPython.org, it comes with tons of samples, so maybe one of those could help you if you havn't already looked over them.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    4
    Rep Power
    0
    Originally Posted by †Yegg†
    I'm not too good with wxPython, or Tkinter, or whatever program you're using for this. You should be able to do something like this by using wxPython. There website is wxPython.org, it comes with tons of samples, so maybe one of those could help you if you havn't already looked over them.
    Yeah, I'm using wxPython. I should have specified. I can set up the grid just fine using the wxPython demo sample code. But I can't get the dropdown choice sample code to work.

    Here's the code from the "choice" demo:

    import wx

    #---------------------------------------------------------------------------

    class TestChoice(wx.Panel):
    def __init__(self, parent, log):
    self.log = log
    wx.Panel.__init__(self, parent, -1)

    sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
    'six', 'seven', 'eight']

    wx.StaticText(self, -1, "This example uses the wxChoice control.", (15, 10))
    wx.StaticText(self, -1, "Select one:", (15, 50), (75, 20))
    self.ch = wx.Choice(self, -1, (80, 50), choices = sampleList)
    self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)


    def EvtChoice(self, event):
    self.log.WriteText('EvtChoice: %s\n' % event.GetString())
    self.ch.Append("A new item")

    if event.GetString() == 'one':
    self.log.WriteText('Well done!\n')


    #---------------------------------------------------------------------------

    def runTest(frame, nb, log):
    win = TestChoice(nb, log)
    return win

    #---------------------------------------------------------------------------

    overview = """
    A Choice control is used to select one of a list of strings. Unlike a listbox,
    only the current selection is visible until the user pulls down the menu of
    choices.

    This demo illustrates how to set up the Choice control and how to extract the
    selected choice once it is selected.

    Note that the syntax of the constructor is different than the C++ implementation.
    The number of choices and the choice array are consilidated into one python
    <code>list</code>.
    """


    if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

    I dont know what the hell that last bit of code is for, but it's giving me all the trouble. This stupid demo makes me want to poke myself in the eye.
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Are you referring to,
    if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
    as the last bit of your code, if so, try removing it and see what happens. It doesn't seem to be needed.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    4
    Rep Power
    0
    Originally Posted by †Yegg†
    Are you referring to,
    if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
    as the last bit of your code, if so, try removing it and see what happens. It doesn't seem to be needed.
    Yeah that part is definitely not needed. Just got it to work though:

    from wxPython.wx import *
    import wx
    import sys
    #---------------------------------------------------------------------------

    class TestChoice(wx.Panel):
    def __init__(self, parent):
    print 'test'
    wx.Panel.__init__(self, parent, -1)
    sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
    'six', 'seven', 'eight']
    wx.StaticText(self, -1, "Choose:", wxPoint(20, 75), wxSize(100, 50))
    self.ch = wx.Choice(self, -1, (20, 100), choices = sampleList)
    self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)


    def EvtChoice(self, event):
    if event.GetString() == 'one':
    print('Well done!\n')

    ###and replace everthing after 'self.log.WriteText('Well done!\n')' with:

    if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame( None, -1, 'ComboBox Test' )
    panel = TestChoice( frame )
    frame.Show( True )
    app.MainLoop()


    Now how can I stick this choice box in a grid cell?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    11

    wxGridCellEditor


    Have you tried using

    wxGridCellEditor
    wxGridCellChoiceEditor

    Let me know if this helps . I can work out a simple example if you want
    cheers
    wx_uab
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    4
    Rep Power
    0
    Originally Posted by wx_uab
    Have you tried using

    wxGridCellEditor
    wxGridCellChoiceEditor

    Let me know if this helps . I can work out a simple example if you want
    cheers
    wx_uab
    Yeah, I don't quite follow. Could you post that simple example? Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo