Fix all black and white wx cursors on windows

The following code demonstrates the problem with some wx cursors on Windows (OSX cursors have a white outline) ... namely, they are all black and therefore completely invisible against a black background.

import wx
app = wx.PySimpleApp()
f = wx.Frame(None)
f.SetBackgroundColour(wx.Color(0))
f.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
f.Show()
app.MainLoop()

I wonder if anyone found a way to fix the window icons, or if there is a fix for it that I don't know about.

A more specific problem that I encountered is that wft.wm.wc.cURSOR_CROSS is for scaling on imshow charts, which I use to display images that are mostly black. I have not yet found a way to configure the cursors that mpl selects, but I decided that I would pose the question while I dig.

Thanks Adam

Note. Using wxPython version 2.8.10.1 and matplotlib version 0.99 and 1.0

PROGRESS: , , , , , , , . .

import numpy as np
buf = np.ones((16,16,3), dtype='uint8') * 127   # pixels untouched by the following operations will outline the crosshair shape (wish they could be white)
buf[7,:,:] = 0        # horizontal black line
buf[:,7,:] = 0        # vertical black line
buf[:6,:6, :] = 255   # evidently values > 127 are interpreted as alpha
buf[9:,:6, :] = 255
buf[9:, 9:, :] = 255
buf[:6, 9:, :] = 255
im = wx.ImageFromBuffer(16, 16, buf.tostring()) # passing a separate alpha buffer just gets ignored
im.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 7)
im.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 7)
cursor = wx.CursorFromImage(im)
+3
3

, . mouse_enter mouse_leave , matplotlib , .

, . .

# Bind mouse motion events in the canvas
self.figure.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)

# ...

def on_mouse_move(self, evt):
    #
    # LAAAME SAUCE -- Crosshair cursor is all black on Windows making it
    #    virtually invisible on dark images. Use custom cursor instead.
    #
    if (sys.platform.lower().startswith('win') and 
        evt.inaxes and
        self.navtoolbar.mode == 'Zoom to rect mode'):  # NOTE: There are no constants for the navbar modes
        #
        # Build the crosshair cursor image as a numpy array.
        # Sadly I can't figure out how to make a white outline since every
        # value above 127 is apparently transparent.
        # Soooo the outline is yellow.
        #
        # Best docs I could find: http://wxruby.rubyforge.org/doc/cursor.html
        #
        buf = np.ones((16,16,3), dtype='uint8') * 255
        buf[:,:,2] = 1
        buf[7,1:-1,:] = buf[1:-1,7,:] = 0
        buf[:6,:6,:] = buf[9:,:6,:] = buf[9:,9:,:] = buf[:6,9:,:] = 255
        #
        # NOTE: I tried making an alpha channel and doing 
        #  wx.ImageFromBuffer(16, 16, buf.tostring(), alpha_buffer.to_string())
        # ...no good. wx just ignores the channel.
        #
        im = wx.ImageFromBuffer(16, 16, buf.tostring())
        im.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 7)
        im.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 7)
        cursor = wx.CursorFromImage(im)
        self.figure.canvas.SetCursor(cursor)
+1

, , "" , , .

: \matplotlib\backends\backend_wx.py 1593 ( matplotlib 1.3.1) , :

cursord = {
    cursors.MOVE : wx.CURSOR_HAND,
    cursors.HAND : wx.CURSOR_HAND,
    cursors.POINTER : wx.CURSOR_ARROW,
    cursors.SELECT_REGION : wx.CURSOR_ARROW, #wx.CURSOR_CROSS, change here!!!
    }

.

+1

I am working on the same thing, I have success by creating a custom navigation toolbar and redirecting the set_cursor callback ...

class CustomNavigationToolbar(NavigationToolbar2WxAgg):
    """
    Extend the default wx toolbar with your own event handlers
    """
    ON_CUSTOM = wx.NewId()
    def __init__(self, canvas):
        NavigationToolbar2WxAgg.__init__(self, canvas)
        self.set_cursor = self.customSetCursor


    def customSetCursor(self, event):
        self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
0
source

Source: https://habr.com/ru/post/1769784/


All Articles