The combobox really hinders data entry. It is basically a four click process because the first click selects the cell, the second click starts editing, the third click opens the dropdown, and the fourth selects the option.
In my mind, clicking the cell should open it editable with existing or default option selected allowing user to enter that value or move to another. Also, <esc>
to cancel edit or <del>
to set cell to blank.
demo.py
import wx
import wx.grid
class MyFrame(wx.Frame):
def __init__(self, parent):
super().__init__(parent, title="Grid Column ComboBox Example", size=(400, 200))
panel = wx.Panel(self)
grid = wx.grid.Grid(panel)
grid.CreateGrid(5, 3) # 5 rows, 3 columns
# Define combo box choices
choices = ["Option 1", "Option 2", "Option 3"]
# Set the entire column B (index 1) to use the combo box editor
for row in range(grid.GetNumberRows()):
editor = wx.grid.GridCellChoiceEditor(choices, allowOthers=True)
grid.SetCellEditor(row, 1, editor)
grid.SetCellValue(row, 1, "") # Set initial value to empty
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(grid, 1, wx.EXPAND)
panel.SetSizer(sizer)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None)
frame.Show()
return True
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
wxPython version: 4.2.3
Python version: 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)]
OS version: Windows-11-10.0.26100-SP0
No. Is the combobox demonstrated? I posted a mwe.
I don’t understand this documentation at all. GridSimple.py seems to be the demo but I don’t see how it fits into the docs and it doesn’t have a combobox example.
I’ve tried about every grid/sheet widget library I can find and they all fail at the combobox.
If your class hooks EVT_GRID_SELECT_CELL
Hmm, seem to recognise that from an endless loop.
In my mind
yes, but the assumption cannot be that everyone thinks that way, or wants their user-interface to behave that way. But you have all the events and methods to setup the experience as you wish, it just takes time to code it to reflect your design intent.
Can you point me to a working grid combobox example? Hopefully I can take it from there.
This might get things started:
import wx
import wx.grid
import wx.lib.mixins.grid as mixins
class CustomGrid(wx.grid.Grid, mixins.GridAutoEditMixin):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent)
mixins.GridAutoEditMixin.__init__(self)
class MyFrame(wx.Frame):
def __init__(self, parent):
super().__init__(parent, title="Grid Column ComboBox Example", size=(400, 200))
panel = wx.Panel(self)
grid = CustomGrid(panel)
grid.CreateGrid(5, 3) # 5 rows, 3 columns
# Define combo box choices
choices = ["Option 1", "Option 2", "Option 3"]
# Set the entire column B (index 1) to use the combo box editor
for row in range(grid.GetNumberRows()):
editor = wx.grid.GridCellChoiceEditor(choices, allowOthers=True)
grid.SetCellEditor(row, 1, editor)
grid.SetCellValue(row, 1, "") # Set initial value to empty
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(grid, 1, wx.EXPAND)
panel.SetSizer(sizer)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None)
frame.Show()
return True
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
Is there a special reason why you are using a Grid
control, or is it just to layout the controls in rows and columns?
If it is just the latter, it would be a lot easier to use a GridSizer
or FlexGridSizer
and populate it with actual ComboBox controls. That would eliminate the need to click in a cell to make the ComboBox appear. You should then be able to configure the behaviour of the ComboBoxes to suit your requirements.
The application is essentially a pdf display linked to a grid for data entry. I’m happy to consider an alternate way of implementing it.
I use Adobe XFA Form fields and I want to automate the filling process using a spreadsheet. The only way I can currently fill documents is in Acrobat Reader and I use the fields directly but they can be converted to normal form fields.
I’ve developed a process to extract the box coordinates and display then on the pdf with a grid so fields can be identified and attributes added before generating the form fields creating a pdf updatable in any pdf reader.
Coding the form is a tedious error-prone manual effort. DataMap points are currently filtered before points.csv is written to load into a displayed pdf. A right-mouse-click on the pdf brings up the [proof of concept] grid and selected record is highlighted. Optionally enter the field length and number of boxes or select a template for predefined field characteristics like grouping and finessed spacing.
Useful Grid features:
- load and save
- improve atrocious data entry
- context menu to toggle the row/column coordinate sort
- enter Template value from a dropdown list
- enter an
>
to retain currently selected record allowing another record to be selected for field width calculation
- enter either number of boxes or field length to calculate the other
- launch process to generate updated pdf form with fields
I’ve played around with the prototype a bit more, grid records linked to pdf points with the ability to toggle between row major order and column major order works really well (eg, select first box in a column on pdf then toggle to column major order from context menu and just fill in all fields sequentially). Efficient data entry is essential.
The proof of concept running under Windows 11 is not really workable.