wx.EVT_SET_FOCUS Fires 2wice

oops!!! i forgot the app sample code. Here it is. The Problem and help request is copied at the bottom.

#!/usr/bin/env python

-- coding: iso-8859-15 --

generated by wxGlade 0.6.2 on Thu May 14 10:47:44 2009

import wx

begin wxGlade: extracode

end wxGlade

class MyFrame(wx.Frame):
def init(self, *args, **kwds):
# begin wxGlade: MyFrame.init
kwds[“style”] = wx.DEFAULT_FRAME_STYLE
wx.Frame.init(self, *args, **kwds)
self.panel_1 = wx.Panel(self, -1)
self.text_ctrl_1 = wx.TextCtrl(self.panel_1, -1, “”)
self.combo_box_1 = wx.ComboBox(self.panel_1, -1, choices=[], style=wx.CB_DROPDOWN)

    self.__set_properties()
    self.__do_layout()
    # end wxGlade
    self.combo_box_1.Bind(wx.EVT_SET_FOCUS, self.CombosSetFocus)
def __set_properties(self):
    # begin wxGlade: MyFrame.__set_properties
    self.SetTitle("frame_1")
    # end wxGlade

def __do_layout(self):
    # begin wxGlade: MyFrame.__do_layout
    sizer_1 = wx.BoxSizer(wx.VERTICAL)
    sizer_2 = wx.BoxSizer(wx.VERTICAL)
    sizer_2.Add(self.text_ctrl_1, 0, 0, 0)
    sizer_2.Add(self.combo_box_1, 0, 0, 0)
    self.panel_1.SetSizer(sizer_2)
    sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
    self.SetSizer(sizer_1)
    sizer_1.Fit(self)
    self.Layout()
    # end wxGlade
   
def CombosSetFocus(self, evt):
  print "CombosSetFocus Fired"
  evt.Skip()

end of class MyFrame

if name == “main”:
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, “”)
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()

Help please,
I put a txtCtrl and Combobox on a panel and tab from
the textCtrl to the combobox. I bound the wx.EVT_SET_FOCUS event to a
handler that just prints a line saying it fired, and then evt.Skip().
But it runs 2 times. This causes trouble in a larger program where i
want it to run only once. There the double run causes the combobox kill
focus evt to run and then the set focus runs its second time.
If i don’t use evt.Skip() then the combobox never gets the cursor in its textbox part.

In the larger program when 1 combobox gets enter pressed it sends
focus to the next combobox. The double focusing causes trouble because
some code and functions are running twice.

How to have a wx.EVT_SET_FOCUS for a combobox only run 1 time, even
with Evt.Skip(). Also any reason for this double running behaviour so i
might understand it better?

Many thanks, my head and desk already have dents from banging into each other. Markandeya

Did you notice it only sends the event twice if you click on the combobox's
dropdown? If you just click in the text area, it sends it once. I guess there
in some sense two "states" of the combobox, regular and displaying drop-
down, so that is why it sends two focus events when doing that?

I haven't seen you larger code, but is it possible that it is not a good idea
to link other functions to merely giving focus to the comboBox? What are
you trying to do?

Che

···

On Thu, May 14, 2009 at 1:52 AM, Markandeya <mrc55519@gmail.com> wrote:

oops!!! i forgot the app sample code. Here it is. The Problem and help
request is copied at the bottom.

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.2 on Thu May 14 10:47:44 2009

import wx

# begin wxGlade: extracode
# end wxGlade

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel_1 = wx.Panel(self, -1)
self.text_ctrl_1 = wx.TextCtrl(self.panel_1, -1, "")
self.combo_box_1 = wx.ComboBox(self.panel_1, -1, choices=,
style=wx.CB_DROPDOWN)

    self\.\_\_set\_properties\(\)
    self\.\_\_do\_layout\(\)
    \# end wxGlade
    self\.combo\_box\_1\.Bind\(wx\.EVT\_SET\_FOCUS, self\.CombosSetFocus\)
def \_\_set\_properties\(self\):
    \# begin wxGlade: MyFrame\.\_\_set\_properties
    self\.SetTitle\(&quot;frame\_1&quot;\)
    \# end wxGlade

def \_\_do\_layout\(self\):
    \# begin wxGlade: MyFrame\.\_\_do\_layout
    sizer\_1 = wx\.BoxSizer\(wx\.VERTICAL\)
    sizer\_2 = wx\.BoxSizer\(wx\.VERTICAL\)
    sizer\_2\.Add\(self\.text\_ctrl\_1, 0, 0, 0\)
    sizer\_2\.Add\(self\.combo\_box\_1, 0, 0, 0\)
    self\.panel\_1\.SetSizer\(sizer\_2\)
    sizer\_1\.Add\(self\.panel\_1, 1, wx\.EXPAND, 0\)
    self\.SetSizer\(sizer\_1\)
    sizer\_1\.Fit\(self\)
    self\.Layout\(\)
    \# end wxGlade

def CombosSetFocus\(self, evt\):
  print &quot;CombosSetFocus Fired&quot;
  evt\.Skip\(\)

# end of class MyFrame

if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()

Help please,
I put a txtCtrl and Combobox on a panel and tab from the textCtrl to the
combobox. I bound the wx.EVT_SET_FOCUS event to a handler that just prints a
line saying it fired, and then evt.Skip(). But it runs 2 times. This causes
trouble in a larger program where i want it to run only once. There the
double run causes the combobox kill focus evt to run and then the set focus
runs its second time.
If i don't use evt.Skip() then the combobox never gets the cursor in its
textbox part.
In the larger program when 1 combobox gets enter pressed it sends focus
to the next combobox. The double focusing causes trouble because some code
and functions are running twice.

How to have a wx.EVT_SET_FOCUS for a combobox only run 1 time, even with
Evt.Skip(). Also any reason for this double running behaviour so i might
understand it better?

Many thanks, my head and desk already have dents from banging into each
other. Markandeya