ComboBox in a Grid ?

I'm trying to find a widget to put in a grid cell which would either allow a data lookup via a button, or just have data typed in the cell.

If I could capture the 'button-click' event on the ComboBox I think I could manage this, but this appears to be contrary to how this widget is used.

Can somebody give me a suggestion on how I can solve this problem?

Thanks,
Mike

Ive never done this before, but what you're looking for can be found in the
demo under wxGrid. T

Gilad

···

----- Original Message -----
From: "Michael Beaulieu" <michael@sentai.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, October 03, 2003 1:51 PM
Subject: [wxPython-users] ComboBox in a Grid ?

I'm trying to find a widget to put in a grid cell which would either
allow a data lookup via a button, or just have data typed in the cell.

If I could capture the 'button-click' event on the ComboBox I think I
could manage this, but this appears to be contrary to how this widget is
used.

Can somebody give me a suggestion on how I can solve this problem?

Thanks,
Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Ya except I need more flexibility than what I found in the demo.
I want to have the ability to populate the control at the time of the user clicking on the down arrow, or perhaps throw up a dialog before populating the values in the drop down.

This widget is fine for small table lookups, but how can I deal with something like a product lookup, where I might want to throw a search dialog up instead of the list?

Gilad Suberri wrote:

···

Ive never done this before, but what you're looking for can be found in the
demo under wxGrid. T

Gilad
----- Original Message ----- From: "Michael Beaulieu" <michael@sentai.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, October 03, 2003 1:51 PM
Subject: [wxPython-users] ComboBox in a Grid ?

I'm trying to find a widget to put in a grid cell which would either
allow a data lookup via a button, or just have data typed in the cell.

If I could capture the 'button-click' event on the ComboBox I think I
could manage this, but this appears to be contrary to how this widget is
used.

Can somebody give me a suggestion on how I can solve this problem?

Thanks,
Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Michael Beaulieu wrote:

Ya except I need more flexibility than what I found in the demo.
I want to have the ability to populate the control at the time of the user clicking on the down arrow, or perhaps throw up a dialog before populating the values in the drop down.

This widget is fine for small table lookups, but how can I deal with something like a product lookup, where I might want to throw a search dialog up instead of the list?

Create your own class derived from wxPyGridCellEditor

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

OK I might be close but as I see it I have a text control and a button side by side but my attempts, see below, continually gpf when I exit.

Can you tell me if I'm on the right track? Do I just need to clean up properly or is there an inherent problem with setting more than one control to this class?

Thanks for your time,
Mike

···

#######################################################################

from wxPython.wx import *
from wxPython.grid import *

class CustomCellChoiceEditor(wxPyGridCellEditor):
     def __init__(self):
         wxPyGridCellEditor.__init__(self)

     def Create(self, parent, id, evtHandler):
         """
         Called to create the control, which must derive from wxControl.
         """
         self._t = wxTextCtrl(parent, id, 'testing')
         self._tc = wxButton(parent, id, '',size=wxSize(18,18))

         EVT_BUTTON(self._tc, self._tc.GetId(), self.btnClick)
         self.SetControl(self._tc)
         self.SetControl(self._t)
         if evtHandler:
             self._tc.PushEventHandler(evtHandler)
  
     def btnClick(self, evt):
         print 'yay'
     def SetSize(self, rect):
         """
         Called to position/size the edit control within the cell rectangle.
         If you don't fill the cell (the rect) then be sure to override
         PaintBackground and do something meaningful there.
         """
         self._t.SetDimensions(rect.x, rect.y, rect.width-25, rect.height+4,
                               wxSIZE_ALLOW_MINUS_ONE)
         self._tc.SetDimensions(rect.x+rect.width-20, rect.y+1, 20, rect.height,wxSIZE_ALLOW_MINUS_ONE)

     def BeginEdit(self, row, col, grid):
         """
         Fetch the value from the table and prepare the edit control
         to begin editing. Set the focus to the edit control.
         """
         self.startValue = grid.GetTable().GetValue(row, col)

         self._t.SetFocus()

     def EndEdit(self, row, col, grid):
         """
         Complete the editing of the current cell. Returns true if the value
         has changed. If necessary, the control may be destroyed.
         """
         changed = false
         pclDescr = self._t.GetStringSelection()
         print pclDescr
         return true

     def Reset(self):
         """
         Reset the value in the control back to its starting value.
         """
         pclDescr = self._t.SetStringSelection('bla')

     def Clone(self):
         """
         Create a new object which is the copy of this one
         """
         return CustomCellChoiceEditor()

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

class TestFrame(wxFrame):
     def __init__(self, parent):
         wxFrame.__init__(self, parent, -1, "Custom Grid Cell Editor Test",
                          size=(400,120))
         grid = wxGrid(self, 2001, size = wxSize(360, 80))
         grid.CreateGrid(2, 2)
         grid.SetColLabelValue(0, 'Col 1')
         grid.SetColLabelValue(1, 'Col 2')
         grid.SetColLabelAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE)
         grid.SetColSize(1, 280)
         grid.SetRowLabelSize(0)
         grid.SetCellValue(1, 1, 'A')

         grid.SetCellEditor(1, 1, CustomCellChoiceEditor())

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

if __name__ == '__main__':
     import sys
     app = wxPySimpleApp()
     frame = TestFrame(None)
     frame.Show(true)
     app.MainLoop()

#######################################################################
Robin Dunn wrote:

Michael Beaulieu wrote:

Ya except I need more flexibility than what I found in the demo.
I want to have the ability to populate the control at the time of the user clicking on the down arrow, or perhaps throw up a dialog before populating the values in the drop down.

This widget is fine for small table lookups, but how can I deal with something like a product lookup, where I might want to throw a search dialog up instead of the list?

Create your own class derived from wxPyGridCellEditor

Michael Beaulieu wrote:

OK I might be close but as I see it I have a text control and a button side by side but my attempts, see below, continually gpf when I exit.

Can you tell me if I'm on the right track? Do I just need to clean up properly or is there an inherent problem with setting more than one control to this class?

The grid expects only one control per GridCellEditor. Try creating a separate window class and put both of your controls on it, then use that class in the GridCellEditor.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Michael Beaulieu wrote:

OK I might be close but as I see it I have a text control and a button side by side but my attempts, see below, continually gpf when I exit.

Can you tell me if I'm on the right track? Do I just need to clean up properly or is there an inherent problem with setting more than one control to this class?

The grid expects only one control per GridCellEditor. Try creating a separate window class and put both of your controls on it, then use that class in the GridCellEditor.

I found that I had to subclass off of wxControl in order to use the SetControl method in GridCellEditor but I am very confused since all my attempts at using a sizer in this new window ( wxControl ) did not work.

  Is there a quick explanation for this?

Michael Beaulieu wrote:

I found that I had to subclass off of wxControl in order to use the SetControl method in GridCellEditor but I am very confused since all my attempts at using a sizer in this new window ( wxControl ) did not work.

Is there a quick explanation for this?

Yes. wxControl does not do AutoLayout, so you need to handle the EVT_SIZE event and call self.Layout() from there.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!