> data -> widget is easy with proper and liberal use of
> properties. With a bit of work, you can generate a set of
> automatic wrappers to handle the widget -> data transfer.
> Want to combine them all together? Well, hack a custom
> metaclass and you can use a Python class/subclass to handle
> the automatic wrapping, set up your event handlers, etc.I'm sure it can be done with a bit of work. But it sort of
violates the "batteries included" attitude of which we are so
fond.
Batteries are only inlcuded if someone has taken the time to make them.
If no one has taken the time to make the batteries, then it is
impossible for them to be included. Don't get me wrong, being able to
use properly named methods without having to define callbacks sounds
like a great idea, as does the automatic binding of a value with a
control and vv, but I have a hard time asking for a feature if I am
unwilling to implement (or help implement) it myself. But hey, that's
just me. Feel free to demand anything you want of wxPython development,
I hope you get what you want.
> On the one hand, I agree. On the other hand, what about those cases
> where a user wants to add more than one event handler?Don't know. I don't recall ever having to do that. The
objective (IMO) should be to make the 95% use-case as simple
and obvious as possible. I don't mind jumping through a hoop
the other 5% of the time, but don't make me jump through a hoop
all of the time for the benefit of the 5% case.
Here is an example that I have used myself in real code (see plugins/findbar.py
in the PyPE source distribution).
box1.Bind(wx.EVT_TEXT, self.OnChar)
box1.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
box1.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
box1.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
box1.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
Some of those can probably be merged, but I prefer simple callbacks
whenever possible.
> They'll start asking "why can't I pass 10?" I think that it's
> easier and more consistant to support none than to support
> 1...? in a usable fashion.[1]There's no reason to disallow explicit connection of handlers
to particular events, but why not make it easy to attach a
single handler to the most commonly used event? It seems to
work great for Tk.
And who decides what is the most commonly used event? For some controls,
the answer is obvious, but on other controls, the default event may not
be quite as clear-cut.
Me, I bypass those worries and write object factories to suit my task
whenever I need to create multiple objects of similar type. I like to
have them handle object creation, sizer addition, and event binding.
But hey, what goes in CPython core development (not all 5 line functions
should become a builtin), may not be applicable in the case of wxPython.
I would offer that if someone wants such default event bindings, that
one should sit down with the wxPython source and hack a patch together
to make such a thing happen, and remember to modify the documentation to
note the new argument, etc. Maybe it's not quite as easy as one would
expect.
- Josiah
···
Grant Edwards <grante@visi.com> wrote:
On 2005-11-07, Josiah Carlson <jcarlson@uci.edu> wrote: