X gurus?

Randall Hopper aa8vb at yahoo.com
Thu Mar 2 20:24:07 CET 2000


Mike Sabin:
 |I am beginning a small project which I am afraid may have to end up being
 |written in C (I say afraid, because I will have to LEARN C first, if this
 |is the case).  I am programming for the X Windows environment on Linux,
 |and need to accomplish the following two things:
 |
 |1. At a certain time, I need to get the x-y coordinates of my mouse
 |pointer, no matter where my pointer is at the time (it could be over the
 |window for some other application, but I want a function call to return
 |the coordinates to my application)

Yes, you can do this in X.  But don't dispair.  You can do this in Tk too,
so Python/Tkinter should be able to handle it.

There are several approaches you can take depending on your requirements.
One is to initiate a global pointer grab for the entire screen (I won't
soap box on how annoying this is; rarely, but sometimes, this is
appropriate; you be the judge).  Then all pointer events will be passed to
your app no matter where the cursor is.  In Xlib-land, see XGrabPointer.
In Python/Tkinter, see the grab* functions (grab_current, grab_set,
grab_set_global, grab_release, grab_status).

Other approaches involve creating a transparent (InputOnly) window of the
appropriate size and raising it.  You may need to make it OverrideRedirect
to request the window manager let you put it on top of "all" windows.  For
X, see questions 171 (How do I make a "busy cursor") in the X FAQ for the
basic technique and tweak to taste.  The same topic in the Motif FAQ might
be helpful as well:

    http://ftp.x.org/contrib/faqs/FAQ
    http://www.faqs.org/faqs/motif-faq/part9/section-8.html

In pure Python, I don't think you can get at X's InputOnly functionality
directly.  comp.lang.tcl postings indicate that the BLT widget set provides
for InputOnly windows coexisting peacably with Tk, so it can probably be
done.  Just not out-of-the-box.

I believe you can do all option #1 completely in Python/Tkinter.  Option #2
might require a little more craftiness to do in Python.

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list