On, Fri Sep 08, 2006, Christian Pohlmann wrote:
> Hi,
>=20
> I'm very new to ocempgui, so here's my sort of newbie'ish question:
> I can't figure out how to connect a SIG_CLICKED with a HFrame *and*
> have it supply the coordinates where the click occured.
First of all the Frame does not support signals, so that you'll have to
implement this features by subclassing.
Second, SIG_CLICKED is definitely something you should not use because
of its general intention. A click consists of a SIG_MOUSEDOWN followed
by SIG_MOUSEUP event combination while it is indifferent whether the
mouse was moved or not (as long as it stays in the bounds of the widget).
I'd thus recommend to use another signal type which is raised upon
SIG_MOUSEUP, but only if the mouse did not move between
SIG_MOUSEDOWN and SIGMOUSEUP (you could use e.g. a certain delta, which
is allowed to be moved to compensate the inaccuracy of a user's hand :-).
=20
> It'll be great if somebody could post a simple example.
I'll just cover the basic things without getting into detail here (or
having rechecked the code). Most is explained in the docs so you might
want to take a look at them as well.
class UserFrame (HFrame):=20
def __init__ (self, widget=3DNone):
HFrame.__init__ (self, widget)
# Do not let the user connect to SIG_MOUSEDOWN and SIG_MOUSEUP,
# they're only for internal listening purposes so the widget
# receives the events.
self._signals[SIG_MOUSEDOWN] =3D None=20
self._signals[SIG_MOUSEUP] =3D None
# Misuse SIG_CLICKED :-)
self._signals[SIG_CLICKED] =3D {}
# The mouse position to pass to SIG_CLICKED callbacks.
self.__mousepos =3D None
def notify (self, event):
if event.signal =3D=3D SIG_MOUSEDOWN:
# Get the occupied area on the screen.
eventarea =3D self.rect_to_client ()
=20
if eventarea.collidepoint (event.data.pos):
# Mouse is in the bounds, store its position.
self.__mousepos =3D event.data.pos
=20
elif event.signal =3D=3D SIG_MOUSEUP:
# Get the occupied area on the screen.
eventarea =3D self.rect_to_client ()
if eventarea.collidepoint (event.data.pos):
# Mouse is in the bounds, check its current position
# and assure that it is near the SIG_MOUSEDOWN position.
# _check_position must be implemented, if wanted.
if self._check_position (event.data.pos):
# Invoke the SIG_CLICKED callbacks and pass the
# position as first argument to them.
self.run_signal_handlers (SIG_CLICKED, self.__mousepos)
Callbacks for the SIG_CLICKED handler of this class then must have the
signature
def FUNCNAME (position[, user_defined_arguments]):
...
because run_signal_handlers() passes any argument supplied to it at
first to the callbacks while their arguments, which were passed with
connect_signal() are concatenated to it/them.
You might also want to take a look at the ImageMap class code and the
BaseObject and EventCallback documentations for argument passing to
callbacks.
I hope that helps a bit.
Regards
Marcus
|