Is there a simple way to use pygame to switch to an OS-defined cursor? For example, switching to the windows loading circle or apple beach-ball when loading, or changing to arrows when hovering over a draggable object?
Pygame provides the cursor module for loading a bitmap to replace the cursor, but I'd like to defer to the OS-defined cursors instead.
From: link, if anyone still finds it useful:
you can use the pygame.mouse.set_cursor method with e. g. pygame.SYSTEM_CURSOR_WAIT as the first argument.
Related
What I'd like to do is find out the type of cursor (ie. pointer, normal, insert) currently active in Linux using python.
I've found one post mentioning that for windows using win32gui: The way to detect the current mouse cursor type from bash or python
win32gui is Windows-specific and this library will not work in Linux. Any other solutions?
Use this library PyXCursor to get the image of cursor/mouse-pointer for an arbitrary application window in Linux - in Python using ctypes
Update: I have come up with three solutions, but they are rather effort and resource-intensive. And I haven't tested them out, so I don't know about any roadblocks. So at this point, I would still appreciate alternative solutions to this problem.
(1) You could find out the location of the mouse pointer using pyautogui and then take a snapshot of the pointer. Then you could compare this image with a test image of a cursor and calculate how similar both images look like using OpenCV.
(2) Run win32gui via Wine like service and send cursor data to linux application.
(3) Use python's ctype module to call XFixes C library's XFixesGetCursorImage(display) function.
Is it possible and how do I set my own cursor in Python using pygame modules?
The point is, I wrote a pygame (python) game and would like to change the cursor to my own, which I painted myself in RealWordCursorEditor.
I know there is a "set_cursor" function and I don't know if I can set my own cursor with it?
If so, how, but if it can't be pygame, can it be pure Python or some other module?
Please help!
Have a look HERE, these are the docs for setting the mouse cursor using pygame.
I'd like to write a screenshot tool in Python. Right now i'm studying how I could do. I've got a script making a screenshot using win32 api like here, but want to include the mouse pointer in the screenshot.
With win32gui.GetCursorInfo() i get its state (shown/hidden), its handle and its position. My goal is to use the handle to access the actual bitmap of the cursor, copy it, and add it to my screenshot at the right coordinates. However, I can't seem to find any doc saying what I can do with that handle once I got it.
I'm thinking i might have to do like the screenshot itself, i.e. get a DC of the cursor, create a bitmap compatible with it and copy into it with BitBlt. Am I on the right track?
Does the python win32 api include DrawIconEx:
http://msdn.microsoft.com/en-us/library/ms648065%28v=vs.85%29.aspx
you need to make a drawable context to write it on, and then pass that and the cursor handle...
(or plain DrawIcon)
Anther option is to actually use Python Imaging Library (PIL)
you can easily edit bitmap with it.
(much simpler then actually using win32 apis.)
you can use ImageGrab, and ImageDraw
Once you get the cursor's icon handle from GetCursorInfo, you can draw it with DrawIcon or DrawIconEx, which I presume the Win32 API module you're using supports. You will need to create a DC for the screenshot bitmap to render the icon to, yes, but I don't think you'll need to create a DC for the cursor icon itself -- DrawIcon should be sufficient.
I want to use the google maps hand cursor in Python but I don't know how to do it.
I've downloaded the cursor but I only get to use the hand open, I also have a event that "closes" the hand when clicked but I don't know how can I change the style cursor on it.
I say this because the google maps hand cursor has two style (the open and the closed hand).
If you don't know how to use the other style you can also tell me how can I create another cursor where the close hand is the default style. If I have that, I only change the cursor and it's done.
Thanks in advance :)
Use two cursors and change them on events as they need to be.
Did you try just changing the cursor, i.e:
myFrame.SetCursor(closedCursor)
In the event handler for mouse-down? Then for mouse-up change it back again. myFrame is your container wx.Frame, and I suppose you already know how to load a cursor from a file.
It's likely that this is just a general Python Tkinter question, not necessarily a matplotlib one.
So I'm in the midst of developing a rather large suite of plotting functionality on top of matplotlib using the Matplotlib "TkAgg" backend (Agg rendering to a Tk canvas using TkInter). I'm using some of the default zooming functionality provided by matplotlib out of the box...specifically the "Zoom to box" button on the default matplotlib toolbar. I am creating my own toolbar by subclassing the existing "matplotlib.backends.backend_tkagg.NavigationToolbar2TkAgg" class.
Pretty much, the issue here is that I hate the default icon that "Zoom to box" uses (the Tkinter "tcross"). I've figured out how to use a different Tkinter built-in cursor (e.g. this changes the cursor to "plus" instead of "tcross"):
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.backend_bases
import matplotlib.backends.backend_tk_agg
matplotlib.backends.backend_tkagg.cursord[matplotlib.backend_bases.cursors.SELECT_REGION] = "plus"
And in general, I know that to change the current mouse cursor to one of the built-in Tkinter ones from the toolbar class, I can just call:
self.window.configure(cursor="cursor_name")
So what I would really, really like is to be able to use a magnifying glass icon for when the user is in "zoom mode". I already have a .ppm of the magnifying glass icon I'd like to use and everything, but I can't figure out for the life of me how to use my magnifying glass as the mouse cursor icon. Is it possible to use a custom image as a mouse cursor in Python Tkinter? Help!
Platform note: This needs to be workable on Mac OS X 10.5+, RedHat Enterprise Linux 5, and possibly Solaris 10, so a platform-specific solution is undesirable.
Something like this works with unix X11 XBM files:
import Tkinter
t = Tkinter.Tk()
t.configure(cursor=('#/usr/include/X11/bitmaps/star', '/usr/include/X11/bitmaps/starMask', 'black', 'white'))
t.mainloop()
As for the Macs, from the man page for "Tk_GetCursorFromData":
The Macintosh version of Tk supports all of the X cursors
and
will also accept any of the standard Mac cursors
including
ibeam, crosshair, watch, plus, and arrow. In addition, Tk
will
load Macintosh cursor resources of the types crsr (color)
and
CURS (black and white) by the name of the of the resource.
The
application and all its open dynamic library's resource
files
will be searched for the named cursor. If there are
conflicts
color cursors will always be loaded in preference to
black and
white cursors.