Hi!
I tried again to make ImageControl Object that can have focus.
The main problem that this control is eating the TAB key, and the moving with TAB is not working on it.
I search for a possibility to set the focus to the next control, or a possibility to say the key handler that it use the
normal key routines when the TAB pressed; but nothing I found.
Thanks for any advance!
dd
···
encoding: iso-8859-2
import os, sys, wx
class ImageControlObject(wx.Control):
def __init__(self, parent, id=wx.ID_ANY, label="", pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.NO_BORDER|wx.WANTS_CHARS, validator=wx.DefaultValidator,
name="ImageControlObject"):
wx.Control.__init__(self, parent, id, pos, size, style, validator, name)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown)
self._Focused = 0
#for s in dir(self):
# print s
def OnSetFocus(self, event):
self._Focused = 1
self.Refresh(1)
def OnKillFocus(self, event):
self._Focused = 0
self.Refresh(1)
def OnPaint(self, event):
dc = wx.PaintDC(self)
if self._Focused:
dc.SetBrush(wx.Brush('BLUE'))
else:
dc.SetBrush(wx.Brush('RED'))
w, h = self.GetClientSize()
dc.DrawRectangle(0, 0, w, h)
def AcceptsFocus(self):
return True
def AcceptsFocusFromKeyboard(self):
return True
def _OnKeyDown(self, Event):
keycode = Event.GetKeyCode()
#if keycode == wx.WXK_TAB:
# self.SelectNextControl()
Event.Skip()
if name == “main”:
#import TestImage
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.Panel = wx.Panel(self, -1)
box = wx.BoxSizer(wx.VERTICAL)
box.Add(self.Panel, 1, wx.ALL | wx.EXPAND, 10)
self.SetSizer(box)
box = wx.BoxSizer(wx.VERTICAL)
tc = wx.TextCtrl(self.Panel)
box.Add(tc, 1, wx.ALL | wx.EXPAND, 10)
IW = ImageControlObject(self.Panel, size=wx.Size(200, 200))
IW.OnKeyDownEvent = self.OKD
box.Add(IW, 1, wx.ALL | wx.EXPAND, 10)
tc = wx.TextCtrl(self.Panel)
box.Add(tc, 1, wx.ALL | wx.EXPAND, 10)
self.Panel.SetSizer(box)
self.Layout()
class App(wx.App):
def OnInit(self):
frame = TestFrame(None, title="ImageWindow Test", size=(300, 300))
self.SetTopWindow(frame)
frame.Show(True)
return True
app = App(False)
app.MainLoop()