[wxPython] How to change deafult tab traversing (radiobuttons & panel)

W

w.p.

Hello!

I want change default tab traversing in my app. But i don't know how to do it :(

Belowe i include simple example - i want change default tab order:

radiobutton "mode11" -> radiobutton "mode31" -> button OK

I can't find any option, flag, or another way.

I try use wx.EVT_KEY_DOWN macro, or Bind - but without success.


When i use Borland Builder C++ i must only set tabStop=False ....

sorry for my english !

w.p.

#######################################################################################
import wx

class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title)

mainPanel = wx.Panel(self)
mainSizer = wx.BoxSizer(wx.VERTICAL)

panel1=wx.Panel(mainPanel,style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER,size=(200,100))
mainSizer.Add(panel1,flag=wx.ALL,border=5)

panel2=wx.Panel(mainPanel,style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER,size=(200,100))
mainSizer.Add(panel2,flag=wx.ALL,border=5)

# group 1
gridSiz1 = wx.FlexGridSizer(2,2)
panel1.SetSizer(gridSiz1)

self.rb11 = wx.RadioButton(panel1, -1, style=wx.RB_GROUP, label="mode 11")
self.rb12 = wx.RadioButton(panel1, -1, label="mode 12")
self.rb21 = wx.RadioButton(panel1, -1, style=wx.RB_GROUP, label="mode 21")
self.rb22 = wx.RadioButton(panel1, -1, label="mode 22")

gridSiz1.Add(self.rb11,flag=wx.ALL,border=3)
gridSiz1.Add(self.rb12,flag=wx.ALL,border=3)
gridSiz1.Add(self.rb21,flag=wx.ALL,border=3)
gridSiz1.Add(self.rb22,flag=wx.ALL,border=3)

# group 2
gridSiz2 = wx.FlexGridSizer(2,2)
panel2.SetSizer(gridSiz2)

self.rb31 = wx.RadioButton(panel2, -1, style=wx.RB_GROUP, label="mode 31")
self.rb32 = wx.RadioButton(panel2, -1, label="mode 32")
self.rb41 = wx.RadioButton(panel2, -1, style=wx.RB_GROUP, label="mode 41")
self.rb42 = wx.RadioButton(panel2, -1, label="mode 42")

gridSiz2.Add(self.rb31,flag=wx.ALL,border=3)
gridSiz2.Add(self.rb32,flag=wx.ALL,border=3)
gridSiz2.Add(self.rb41,flag=wx.ALL,border=3)
gridSiz2.Add(self.rb42,flag=wx.ALL,border=3)

okBut = wx.Button(mainPanel,label="-- OK --")
mainSizer.Add(okBut,flag=wx.ALL|wx.ALIGN_CENTER,border=10)

mainPanel.SetSizer(mainSizer)
self.Layout()

# wx.EVT_KEY_DOWN(self.rb11,self.OnRBKD)
self.rb11.Bind(wx.EVT_KEY_DOWN, self.OnRBKD)


def OnRBKD(self,event):
print "OnKey!"
event.Skip()


class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, "Simple wxPython App")
self.SetTopWindow(frame)
frame.Show(True)
return True

app = MyApp(0)
app.MainLoop()
 
M

Mudcat

I just figured this out myself, but probably not the way you're asking.
There are supposed to be ways to change the tab order using
tk_focusNext() and tk_focusPrevious(), but I've never used it.

What I've done is simply point one widget to the next one, basically
creating a linked list of tabs. I only had a couple that I wanted to
change the order of, so this was pretty easy to change.

I bound the widgets I wanted changed to <tab> and had a function that
knew where to go. Here's a simple example:

def tab(self, event):
self.port.component('entry').focus_set()

return 'break'

The return 'break' is very important, because if you don't include it
then the default tab functionality of window will be used which will
override whatever changes you make.

I had problems using the tk_focusNext() and tk_focusPrevious() commands
because the two widgets that were supposed to be next to each other in
order were in different windows. I kept getting errors when I tried it.


And since I only had two widgets I created two different functions to
handle the tabs. But if I had more than two I would have created a
forwarding table based on widget names or ids using the event that is
returned in the callback from the binding. Based on the event id
returned I would know where to set focuse next.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top