[wxPython] custom control

Hi,
I needed a wxChoice (or wxComboBox) multicolumn, but i realized that
wxPython doesn't have it.
So I decide to make a more simple control that help me to show to
the user a description of the code that it selects from a wxChoice.
Now that I have a wxDialog with many controls in it and some of them
are instances of my custom control, all the controls works and receive
the focus with the mouse.
My problem is that I don't understand why my custom controls doesn't
receive the focus with the tab key.

Here I've included a very little demostration for the problem.
my system: win2000, python 2.2.1, wxPython 2.3.2.

Sorry for my bad english.

Thanks.
Gabriele.

from wxPython.wx import *
class ChoiceDesc(wxWindow):
  def __init__(self, parent, listChoices, select=None, id=-1):
    wxWindow.__init__(self, parent, -1)
    self.choices=listChoices
    self.keys=map(lambda x: x[0], listChoices)
    self.C=wxChoice(self, -1, choices=self.keys)
    if select==None or select not in self.keys:
      select=self.keys[0]
    self.C.SetStringSelection(select)
    self.T=wxStaticText(self, -1, self.goto(select))
    EVT_CHOICE(self, self.C.GetId(), self.evt_select)
    s=wxBoxSizer(wxHORIZONTAL)
    s.Add(self.C); s.Add(self.T)
    s.Layout()
    self.SetSizer(s)
    s.Fit(self)
    self.SetAutoLayout(true)
  def evt_select(self, event):
    element=event.GetString()
    self.T.SetLabel(self.goto(element))
  def goto(self, element):
    i=self.keys.index(element)
    return self.choices[i][1]

a=wxPySimpleApp()
d=wxDialog(None, -1, title="test",
  style=wxDEFAULT_DIALOG_STYLE|wxDIALOG_NO_PARENT)
t1=wxTextCtrl(d, -1); t2=wxTextCtrl(d, -1)
t3=ChoiceDesc(d, (('1', 'one'), ('2', 'two')))
t1.SetFocus()
s=wxBoxSizer(wxVERTICAL)
s.Add(t1); s.Add(t2); s.Add(t3)
d.SetSizer(s)
s.Fit(d)
d.Layout()
d.SetAutoLayout(true)
d.ShowModal()
d.Destroy()
a.MainLoop()

derive it from wxPanel instead of wxWindows and it works as expected

Horst

···

On Sun, 15 Sep 2002 06:55 am, Gabriele wrote:

from wxPython.wx import *
class ChoiceDesc(wxWindow):

I've tried it, I also tried to derive from wxControl, but it doesn't work,
at least under windows.
The solution that I've found (thanks to Alberto Griggio) is to put all the
controls in a wxPanel instead to add them directly to wxDialog.
In this way all works correctly, but is there a bug in wxDialog under
windows?

Thanks.
Gabriele.

···

On Sun, 15 Sep 2002, Horst Herb wrote:

From: Horst Herb <subscriptions@gnumed.net>
To: wxpython-users@lists.wxwindows.org
Date: Sun, 15 Sep 2002 17:41:46 +1000
Subject: Re: [wxPython] custom control
Reply-To: wxpython-users@lists.wxwindows.org

On Sun, 15 Sep 2002 06:55 am, Gabriele wrote:
> from wxPython.wx import *
> class ChoiceDesc(wxWindow):

derive it from wxPanel instead of wxWindows and it works as expected

Gabriele wrote:

···

On Sun, 15 Sep 2002, Horst Herb wrote:

From: Horst Herb <subscriptions@gnumed.net>
To: wxpython-users@lists.wxwindows.org
Date: Sun, 15 Sep 2002 17:41:46 +1000
Subject: Re: [wxPython] custom control
Reply-To: wxpython-users@lists.wxwindows.org

On Sun, 15 Sep 2002 06:55 am, Gabriele wrote:

from wxPython.wx import *
class ChoiceDesc(wxWindow):

derive it from wxPanel instead of wxWindows and it works as expected

I've tried it, I also tried to derive from wxControl, but it doesn't work,
at least under windows.
The solution that I've found (thanks to Alberto Griggio) is to put all the
controls in a wxPanel instead to add them directly to wxDialog.
In this way all works correctly, but is there a bug in wxDialog under
windows?

IIRC on windows dialogs query controls about theyr wishes - do they want focus, enter key, etc. Your control must respond to these messages.

HTH
Niki Spahiev

Thanks Niki,

the problem is solved. I just have to submit self instead of -1 as the
parent.
It was right in front of my eyes ... :wink:

Bye,
Harald

···

-----Ursprüngliche Nachricht-----
Von: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org] Im Auftrag
von Niki Spahiev
Gesendet: Dienstag, 17. September 2002 09:26
An: wxpython-users@lists.wxwindows.org
Betreff: Re: [wxPython] custom control

Gabriele wrote:
> On Sun, 15 Sep 2002, Horst Herb wrote:
>
>
>>From: Horst Herb <subscriptions@gnumed.net>
>>To: wxpython-users@lists.wxwindows.org
>>Date: Sun, 15 Sep 2002 17:41:46 +1000
>>Subject: Re: [wxPython] custom control
>>Reply-To: wxpython-users@lists.wxwindows.org
>>
>>On Sun, 15 Sep 2002 06:55 am, Gabriele wrote:
>>
>>>from wxPython.wx import *
>>>class ChoiceDesc(wxWindow):
>>
>>derive it from wxPanel instead of wxWindows and it works as expected
>>
>
> I've tried it, I also tried to derive from wxControl, but
it doesn't work,
> at least under windows.
> The solution that I've found (thanks to Alberto Griggio) is
to put all the
> controls in a wxPanel instead to add them directly to wxDialog.
> In this way all works correctly, but is there a bug in
wxDialog under
> windows?

IIRC on windows dialogs query controls about theyr wishes -
do they want
focus, enter key, etc. Your control must respond to these messages.

HTH
Niki Spahiev

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users