widget suggestion / question

I wonder if I am missing something already in wxPython. If not, consider
this a suggestion for future versions.

In Borland Delphi, the individual widgets (components) had a spare field
that could be used to store an integer for whatever purpose the
developer wanted. I would like to see something like this in wx. Here's
where I could use something like this. I designed a form with a series
of buttons. Several of the buttons could share the same event handler if
the event handler could figure out which button invoked it. I supposed
I could use reflection to figure out which button, but it would be nice
if the event handler could check this spare field in the button.

I'm using wxGlade for the design. The latest version allows you to
attach properties to the widgets which it implements by calling a SetXXX
method. To get this to work, I had to derive a button from wxButton that
had a SetXXX method.

Thanks,
Mark

In Borland Delphi, the individual widgets (components) had a spare field
that could be used to store an integer for whatever purpose the

developer wanted. I would like to see something like this in wx. Here’s
where I could use something like this. I designed a form with a series
of buttons. Several of the buttons could share the same event handler if

the event handler could figure out which button invoked it. I supposed
I could use reflection to figure out which button, but it would be nice
if the event handler could check this spare field in the button.

Since every button has it’s own ID, isn’t .GetID() enough to find which is which?

I’m using wxGlade for the design. The latest version allows you to
attach properties to the widgets which it implements by calling a SetXXX
method. To get this to work, I had to derive a button from wxButton that

had a SetXXX method.

As I find it more efficient to do all my GUI design by hand, I don’t know what wxGlade’s capabilities are. Does it let you enter arbitrary code? As all the wxPython objects are regular python objects, you can set any arbitrary attribute on them if you want. I personally find that “poor practice”, but that’s me.

You could do ‘button.whichButton = 5’ if you wanted. Even though ‘whichButton’ doesn’t exist before.

Mark Erbaugh wrote:

In Borland Delphi, the individual widgets (components) had a spare field
that could be used to store an integer for whatever purpose the
developer wanted. I would like to see something like this in wx. Here's
where I could use something like this. I designed a form with a series
of buttons. Several of the buttons could share the same event handler if
the event handler could figure out which button invoked it. I supposed
I could use reflection to figure out which button, but it would be nice
if the event handler could check this spare field in the button.
  

You could do something like this (using a number keypad, as an example):

import wx

class Keypad(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, wx.ID_ANY)
        self.text_ctrl = wx.TextCtrl(self, wx.ID_ANY, '')
        button_sizer = wx.GridSizer(cols = 3, hgap = 3, vgap = 3)
        for rows in ( ('7', '8', '9'), ('4', '5', '6'), ('1', '2', '3'), ('00', '0', '.') ):
            for label in rows:
                button = wx.Button(self, wx.ID_ANY, label)
                button.SetMinSize((30,30))
                self.Bind(wx.EVT_BUTTON, self.button_handler, button)
                button_sizer.Add(button)
        pad_sizer = wx.BoxSizer(wx.VERTICAL)
        pad_sizer.Add(self.text_ctrl, 1, wx.EXPAND)
        pad_sizer.Add(button_sizer)

        self.SetSizer(pad_sizer)
        pad_sizer.Fit(self)
        pad_sizer.SetSizeHints(self)
        self.Layout()

    def button_handler(self, event):
        label = event.GetEventObject().GetLabel()
        self.text_ctrl.AppendText(label)

Hi Laurent,

Hi,
I'm using a wx.TextCtrl with a black background.
Let say my TextCtrl instance is 't'.
When I do t.Remove(t.GetLastPosition()-10, t.GetLastPosition())
The text is selected THEN it is deleted.
As the selection color is Blue it makes a graphical glitch.

Is there a way to set selection color to background color or perhaps another
way to avoid the glitch??

You could try to use something like:

yourTextCtrl.Freeze()

# your code to delete text and whatever you want here

yourTextCtrl.Thaw()

and see if it does what you want :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On Dec 2, 2007 11:28 PM, Laurent Dufrechou wrote:

Zach,

···

On Mon, 2007-12-03 at 01:18 -0600, Zach Heilig wrote:

> In Borland Delphi, the individual widgets (components) had a spare field
> that could be used to store an integer for whatever purpose the
> developer wanted. I would like to see something like this in wx. Here's
> where I could use something like this. I designed a form with a series
> of buttons. Several of the buttons could share the same event handler if
> the event handler could figure out which button invoked it. I supposed
> I could use reflection to figure out which button, but it would be nice
> if the event handler could check this spare field in the button.
>
You could do something like this (using a number keypad, as an example):

Thanks for the example. I think it should work, but I was hoping to
avoid using the widget's label. It's possible that you might want to
change the label text (say for internationalization) without changing
the underlying code.

Thanks,
Mark

Mark Erbaugh wrote:

Chris,

Mark Erbaugh wrote:

Thanks for the example. I think it should work, but I was hoping to
avoid using the widget's label. It's possible that you might want to
change the label text (say for internationalization) without changing
the underlying code.

right, the label isn't necessarily the best key. yous can use the Label, you can use the ID (which you can get by .getID(), after creating the object with the default).

Most importantly though -- this is Python! it's been said before in this thread, but it bears repeating: you can any attribute you want to any object, no problem at all. For instance, using the previous example, I might do:

Yes, I understand this and have used it. I still think it would be nice
if there were an 'official' data member that the user could use for
whatever was needed.

Actually, there is one in C++ but wxPython is already using it to store a pointer to the PyObject which is the Python proxy of the C++ object. This is what allows you to be able to assign arbitrary attributes to the original proxy instance and then later when something like event.GetEventObject() returns a proxy it is the same one that you assigned attributes to instead of a new instance that proxies the same C++ object.

···

On Mon, 2007-12-03 at 11:19 -0800, Christopher Barker wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!