wxCursor questions:

Hi all,

I've been working on implementing custom Cursors for FloatCanvas, and have come up with a few questions:

1) It looks like the cursor implementation is platform dependent:
Macs want 16X16 cursors
Windows wants 32X32 cursors
GTK takes whatever you give it (yea, GTK!)

I know they get auto-re-scaled, but that just doesn't look very good.

Also, the docs say:

"In MSW the cursor is resized to 32x32 if it was larger."

What if it's smaller? I don't have a Windows box to easily test on at the moment.

So far, I have not one line of platform dependent code in FloatCanvas. Am I going to have to write some now? If so, how can you tell which wxPlatform you are on? sys.platform is not really safe, as you can have both wxMac or wxGTK on 'darwin' and GTK runs on a lot more than 'linux', and in theory, you could have GTK on Windows (at least some day). How would I determine which wxPlatform I'm running?

2) How do I set the hotspot for a Cursor? It looks like I can do it if I load the cursor form a file, but not if I load it from a wx.Image. I start with a PNG, and use img2py to put it in a python file, then get the image from there. Is it possible to set the hotspot this way? It looks to me like there should be SetHotspot method to wxCursor, or a hotspot parameters to wxCursorFrom Image

3) There is an apparent bug in wxMac, so that when you set the cursor, it doesn' re-set itself when it leaves the Window. It doews if you pass over the right part of the window border, but not if you move off the side. This strikes me as something the syustem should be doing, but in any case, it's a problem. It's been recently reported on wx-users, but I haven't seen anyone comment on it yet.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker wrote:

Hi all,

I've been working on implementing custom Cursors for FloatCanvas, and have come up with a few questions:

1) It looks like the cursor implementation is platform dependent:
Macs want 16X16 cursors
Windows wants 32X32 cursors
GTK takes whatever you give it (yea, GTK!)

I know they get auto-re-scaled, but that just doesn't look very good.

Also, the docs say:

"In MSW the cursor is resized to 32x32 if it was larger."

What if it's smaller? I don't have a Windows box to easily test on at the moment.

I think that it stays at the smaller size, but I don't remember for sure.

So far, I have not one line of platform dependent code in FloatCanvas. Am I going to have to write some now? If so, how can you tell which wxPlatform you are on? sys.platform is not really safe, as you can have
both wxMac or wxGTK on 'darwin' and GTK runs on a lot more than 'linux', and in theory, you could have GTK on Windows (at least some day). How would I determine which wxPlatform I'm running?

Interesting choice of words, because it is wx.Platform or wx.PlatformInfo. The former is a string like "__WXMAC__" that coresponds to the preprocessor macros used in the C++ code. wx.PlatformInfo is a tuple that includes this and other values that are build dependent, so you can check for options like this:

  if somevalue in wx.PlatformInfo:
    # do something

2) How do I set the hotspot for a Cursor? It looks like I can do it if I load the cursor form a file, but not if I load it from a wx.Image. I start with a PNG, and use img2py to put it in a python file, then get the image from there. Is it possible to set the hotspot this way? It looks to me like there should be SetHotspot method to wxCursor, or a hotspot parameters to wxCursorFrom Image

Ah Chris, you disappoint me. You should know by now that the first thing to do is to look at the demo. :wink: From Cursor.py:

         if cnum == CUSTOMID:
             image = images.getPointyImage()

             # since this image didn't come from a .cur file, tell it where the hotspot is
             image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 1)
             image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 1)

             # make the image into a cursor
             cursor = wx.CursorFromImage(image)

3) There is an apparent bug in wxMac, so that when you set the cursor, it doesn' re-set itself when it leaves the Window. It doews if you pass over the right part of the window border, but not if you move off the side. This strikes me as something the syustem should be doing, but in any case, it's a problem. It's been recently reported on wx-users, but I haven't seen anyone comment on it yet.

I've seen this too, and I think I've seen it in non-wx apps as well, although I can't find it now. I think it may have something to do with when the top-level windows are activated or deactivated. But in any case it will probably have to wait for Stefan to get back from WWDC before anything happens with it.

···

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

Robin Dunn wrote:

What if it's smaller? I don't have a Windows box to easily test on at the moment.

I think that it stays at the smaller size, but I don't remember for sure.

Then I'll just wait and see if anybody complains about how ugly the cursors are before I do anything about it.

Interesting choice of words, because it is wx.Platform or wx.PlatformInfo. The former is a string like "__WXMAC__" that coresponds to the preprocessor macros used in the C++ code. wx.PlatformInfo is a tuple that includes this and other values that are build dependent, so you can check for options like this:

    if somevalue in wx.PlatformInfo:
        # do something

Perfect! thanks, I figure it would be there, I'm not sure why I didn't find it.

Ah Chris, you disappoint me. You should know by now that the first thing to do is to look at the demo. :wink:

AARGG!! And to think how many times I tell people on this list to look there. While I'm confessing, I now realize I didn't look in the Wiki either! Thanks for helping me anyway.

From Cursor.py:

        if cnum == CUSTOMID:
            image = images.getPointyImage()

            # since this image didn't come from a .cur file, tell it where the hotspot is
            image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 1)
            image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 1)

            # make the image into a cursor
            cursor = wx.CursorFromImage(image)

I was so close. I had tried wx.Image.SetOption, but it kept wanting a string, and I had no idea what string to pass!

3) There is an apparent bug in wxMac, so that when you set the cursor, it doesn' re-set itself when it leaves the Window. It doews if you pass over the right part of the window border, but not if you move off the side. This strikes me as something the syustem should be doing, but in any case, it's a problem. It's been recently reported on wx-users, but I haven't seen anyone comment on it yet.

I've seen this too, and I think I've seen it in non-wx apps as well, although I can't find it now. I think it may have something to do with when the top-level windows are activated or deactivated. But in any case it will probably have to wait for Stefan to get back from WWDC before anything happens with it.

I'm just trying to decide whether I want to deal with the EVT_ENTER and EVT_LEAVE events myself to fix it, and I don't think so, it's not fatal.

thanks,

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov