def make_cursor(self, cursor_data): #if present, try cursor ny name: if len(cursor_data)>=9 and cursor_names: cursor_name = cursor_data[8] if cursor_name: gdk_cursor = cursor_names.get(cursor_name.upper()) if gdk_cursor is not None: log("setting new cursor by name: %s=%s", cursor_name, gdk_cursor) return gdk.Cursor(gdk_cursor) else: log("cursor name '%s' not found", cursor_name) #create cursor from the pixel data: w, h, xhot, yhot, serial, pixels = cursor_data[2:8] if len(pixels)<w*h*4: import binascii log.warn("not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)", w*h*4, len(pixels), binascii.hexlify(pixels)[:100]) return pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8, w, h, w * 4) x = max(0, min(xhot, w-1)) y = max(0, min(yhot, h-1)) size = gdk.display_get_default().get_default_cursor_size() log("new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s, default cursor size is %s", xhot,yhot, serial, w,h, len(pixels), size) if size>0 and (size<w or size<h) and False: ratio = float(max(w,h))/size log("downscaling cursor by %.2f", ratio) pixbuf = pixbuf.scale_simple(int(w/ratio), int(h/ratio), gdk.INTERP_BILINEAR) x = int(x/ratio) y = int(y/ratio) return gdk.Cursor(gdk.display_get_default(), pixbuf, x, y)
def make_cursor(self, cursor_data): #if present, try cursor ny name: if len(cursor_data) >= 9 and cursor_names: cursor_name = cursor_data[8] if cursor_name: gdk_cursor = cursor_names.get(cursor_name.upper()) if gdk_cursor is not None: log("setting new cursor by name: %s=%s", cursor_name, gdk_cursor) return gdk.Cursor(gdk_cursor) else: global missing_cursor_names if cursor_name not in missing_cursor_names: log.warn("cursor name '%s' not found", cursor_name) missing_cursor_names.add(cursor_name) #create cursor from the pixel data: w, h, xhot, yhot, serial, pixels = cursor_data[2:8] if len(pixels) < w * h * 4: import binascii log.warn( "not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)", w * h * 4, len(pixels), binascii.hexlify(pixels)[:100]) return pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8, w, h, w * 4) x = max(0, min(xhot, w - 1)) y = max(0, min(yhot, h - 1)) display = gdk.display_get_default() csize = display.get_default_cursor_size() cmaxw, cmaxh = display.get_maximal_cursor_size() if len(cursor_data) >= 11: ssize = cursor_data[9] smax = cursor_data[10] log("server cursor sizes: default=%s, max=%s", ssize, smax) log( "new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s, default cursor size is %s, maximum=%s", xhot, yhot, serial, w, h, len(pixels), csize, (cmaxw, cmaxh)) ratio = 1 if w > cmaxw or h > cmaxh or (csize > 0 and (csize < w or csize < h)): ratio = max( float(w) / cmaxw, float(h) / cmaxh, float(max(w, h)) / csize) log("downscaling cursor by %.2f", ratio) pixbuf = pixbuf.scale_simple(int(w / ratio), int(h / ratio), gdk.INTERP_BILINEAR) x = int(x / ratio) y = int(y / ratio) return gdk.Cursor(gdk.display_get_default(), pixbuf, x, y)
def make_cursor(self, cursor_data): #if present, try cursor ny name: if len(cursor_data)>=9 and cursor_names: cursor_name = cursor_data[8] if cursor_name: gdk_cursor = cursor_names.get(cursor_name.upper()) if gdk_cursor is not None: log("setting new cursor by name: %s=%s", cursor_name, gdk_cursor) return gdk.Cursor(gdk_cursor) else: global missing_cursor_names if cursor_name not in missing_cursor_names: log.warn("cursor name '%s' not found", cursor_name) missing_cursor_names.add(cursor_name) #create cursor from the pixel data: w, h, xhot, yhot, serial, pixels = cursor_data[2:8] if len(pixels)<w*h*4: import binascii log.warn("not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)", w*h*4, len(pixels), binascii.hexlify(pixels)[:100]) return pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8, w, h, w * 4) x = max(0, min(xhot, w-1)) y = max(0, min(yhot, h-1)) display = gdk.display_get_default() csize = display.get_default_cursor_size() cmaxw, cmaxh = display.get_maximal_cursor_size() if len(cursor_data)>=11: ssize = cursor_data[9] smax = cursor_data[10] log("server cursor sizes: default=%s, max=%s", ssize, smax) log("new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s, default cursor size is %s, maximum=%s", xhot,yhot, serial, w,h, len(pixels), csize, (cmaxw, cmaxh)) ratio = 1 if w>cmaxw or h>cmaxh or (csize>0 and (csize<w or csize<h)): ratio = max(float(w)/cmaxw, float(h)/cmaxh, float(max(w,h))/csize) log("downscaling cursor by %.2f", ratio) pixbuf = pixbuf.scale_simple(int(w/ratio), int(h/ratio), gdk.INTERP_BILINEAR) x = int(x/ratio) y = int(y/ratio) return gdk.Cursor(gdk.display_get_default(), pixbuf, x, y)
def make_cursor(self, cursor_data): #if present, try cursor ny name: if len(cursor_data) >= 9 and cursor_names: cursor_name = cursor_data[8] if cursor_name: gdk_cursor = cursor_names.get(cursor_name.upper()) if gdk_cursor is not None: log("setting new cursor by name: %s=%s", cursor_name, gdk_cursor) return gdk.Cursor(gdk_cursor) else: log("cursor name '%s' not found", cursor_name) #create cursor from the pixel data: w, h, xhot, yhot, serial, pixels = cursor_data[2:8] if len(pixels) < w * h * 4: import binascii log.warn( "not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)", w * h * 4, len(pixels), binascii.hexlify(pixels)[:100]) return pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8, w, h, w * 4) x = max(0, min(xhot, w - 1)) y = max(0, min(yhot, h - 1)) size = gdk.display_get_default().get_default_cursor_size() log( "new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s, default cursor size is %s", xhot, yhot, serial, w, h, len(pixels), size) if size > 0 and (size < w or size < h) and False: ratio = float(max(w, h)) / size log("downscaling cursor by %.2f", ratio) pixbuf = pixbuf.scale_simple(int(w / ratio), int(h / ratio), gdk.INTERP_BILINEAR) x = int(x / ratio) y = int(y / ratio) return gdk.Cursor(gdk.display_get_default(), pixbuf, x, y)
def set_windows_cursor(self, gtkwindows, new_cursor): cursor = None if len(new_cursor)>0: cursor = None if len(new_cursor)>=9 and cursor_names: cursor_name = new_cursor[8] if cursor_name: gdk_cursor = cursor_names.get(cursor_name.upper()) if gdk_cursor is not None: try: from xpra.x11.gtk_x11.error import trap log("setting new cursor: %s=%s", cursor_name, gdk_cursor) cursor = trap.call_synced(gdk.Cursor, gdk_cursor) except: pass if cursor is None: w, h, xhot, yhot, serial, pixels = new_cursor[2:8] log("new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s" % (xhot,yhot, serial, w,h, len(pixels))) pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8, w, h, w * 4) x = max(0, min(xhot, w-1)) y = max(0, min(yhot, h-1)) size = gdk.display_get_default().get_default_cursor_size() if size>0 and (size<w or size<h): ratio = float(max(w,h))/size pixbuf = pixbuf.scale_simple(int(w/ratio), int(h/ratio), gdk.INTERP_BILINEAR) x = int(x/ratio) y = int(y/ratio) cursor = gdk.Cursor(gdk.display_get_default(), pixbuf, x, y) for gtkwindow in gtkwindows: if gtk.gtk_version>=(2,14): gdkwin = gtkwindow.get_window() else: gdkwin = gtkwindow.window #trays don't have a gdk window if gdkwin: gdkwin.set_cursor(cursor)
def change_cursor(*args): name = cursor_combo.get_active_text() print(name) gdk_cursor = cursor_names.get(name) cursor = gdk.Cursor(gdk_cursor) window.get_window().set_cursor(cursor)