Windows vs Ubuntu re: TE_PROCESS_TAB

Hi,

I have learned the hard way how important style=TE_PROCESS_TAB is for text boxes in grid custom cell editors. Part of what caught me out was that the code in Windows works differently from the same code running in Ubuntu (Jaunty).

At the bottom of the snippet below, there is a setting te_process_TAB you can set to either True or False. Additionally, if you wish, you can set use_dialog to True or False.

Ideally, I guess, the behaviour would be the same under Windows and Ubuntu. But that's not what I found.

Have I misunderstood something?

···

-------------------------------------------------------------------------

import wx
import wx.grid

class TextEditor(wx.grid.PyGridCellEditor):
       def __init__(self, te_process_TAB):
        wx.grid.PyGridCellEditor.__init__(self)
        self.te_process_TAB = te_process_TAB
       def BeginEdit(self, row, col, grid):
        val = grid.GetTable().GetValue(row, col)
        self.start_val = val
        self.txt.SetValue(val)
        self.txt.SetFocus()

    def Clone(self):
        return TextEditor()
       def Create(self, parent, id, evt_handler):
        # created when clicked
            if self.te_process_TAB:
                self.txt = wx.TextCtrl(parent, -1, "", style=wx.TE_PROCESS_TAB)
            else:
                self.txt = wx.TextCtrl(parent, -1, "")
            self.SetControl(self.txt)
            if evt_handler:
                # so the control itself doesn't handle events but passes to handler
                self.txt.PushEventHandler(evt_handler)
                evt_handler.Bind(wx.EVT_KEY_DOWN, self.OnTxtEdKeyDown)
       def EndEdit(self, row, col, grid):
        changed = False
        val = self.txt.GetValue()
        if val != self.start_val:
            changed = True
            grid.GetTable().SetValue(row, col, val)
        return changed
           def StartingKey(self, event):
        keycode = event.GetKeyCode()
        print "Starting key was \"%s\"" % chr(keycode)
        if keycode <= 255 :
            self.txt.SetValue(chr(keycode))
            self.txt.SetInsertionPoint(1)
        else:
            event.Skip()

    def Reset(self):
        pass # N/A
       def OnTxtEdKeyDown(self, event):
        keycode = event.GetKeyCode()
        print "Keypress %s recognised" % keycode
        if keycode in [wx.WXK_TAB]:
            print "OnTxtEdKeyDown - Keypress %s." % keycode
            event.Skip()
        else:
            event.Skip()

class Shared(object):
    def __init__(self):
        self.panel = wx.Panel(self, -1, size=(500, 700))
        grid = wx.grid.Grid(self.panel, size=(500, 100))
        grid.CreateGrid(1,2)
        myed = TextEditor(te_process_TAB)
        grid.SetDefaultEditor(myed)
        btnClose = wx.Button(self.panel, wx.ID_CLOSE)
        btnClose.Bind(wx.EVT_BUTTON, self.OnClose)
        szr = wx.BoxSizer(wx.VERTICAL)
        szr.Add(grid)
        szr.Add(btnClose)
        self.panel.SetSizer(szr)
        szr.SetSizeHints(self)
        self.panel.Layout()
        grid.SetFocus()

    def OnClose(self, event):
        self.Destroy()

class TestDialog(wx.Dialog, Shared):
    def __init__(self, te_process_TAB):
        wx.Dialog.__init__(self, None,
            title="Dialog. TE_PROCESS_TAB=\"%s\"" % te_process_TAB,
                           size=(400, 200))
        Shared.__init__(self)

class TestFrame(wx.Frame, Shared):
    def __init__(self, te_process_TAB):
        wx.Frame.__init__(self, None,
            title="Frame. TE_PROCESS_TAB=\"%s\"" % te_process_TAB,
                           size=(400, 200))
        Shared.__init__(self)
       #*******************************************
# change te_process_TAB parameter and see if tabbing works
# try under Windows and Ubuntu
use_dialog = False # irrelevant under both
te_process_TAB = False # Only matters under Windows
#*******************************************
app = wx.PySimpleApp()
if use_dialog:
    form = TestDialog(te_process_TAB)
else:
    form = TestFrame(te_process_TAB)
form.Show()
app.MainLoop()

--------------------------------

All the best, Grant

Grant Paton-Simpson wrote:

Hi,

I have learned the hard way how important style=TE_PROCESS_TAB is for text boxes in grid custom cell editors. Part of what caught me out was that the code in Windows works differently from the same code running in Ubuntu (Jaunty).

Because Windows makes it much harder to deal with TAB and other navigation keys, arrow keys, etc. as if they were normal characters. The other platforms are not so discriminating.

···

--
Robin Dunn
Software Craftsman

Thanks Robin. It's nice to have this on the searchable record now.
It might help others who experience the same issue in the future.

···

On Jul 21, 9:41 am, Robin Dunn <ro...@alldunn.com> wrote:

Grant Paton-Simpson wrote:

> Hi,

> I have learned the hard way how important style=TE_PROCESS_TAB is for
> text boxes in grid custom cell editors. Part of what caught me out was
> that the code in Windows works differently from the same code running in
> Ubuntu (Jaunty).

Because Windows makes it much harder to deal with TAB and other
navigation keys, arrow keys, etc. as if they were normal characters.
The other platforms are not so discriminating.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org