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 send_initial_cursors(self, ss, sharing=False): #cursors: get sizes and send: display = gdk.display_get_default() self.cursor_sizes = display.get_default_cursor_size( ), display.get_maximal_cursor_size() cursorlog("send_initial_cursors() cursor_sizes=%s", self.cursor_sizes) ss.send_cursor()
def test_window_lookup_for_display_id0(): ''' There should be no window with system ID 0 on the default display. ''' display = gdk.display_get_default() window = gdk.window_lookup_for_display(display, 0) assert not window
def on_drawarea_keypress(self, wid, e, data=None): # block all keyboard events if panning or selecting if self.panning or self.selecting: return True elif self.kbselect_state is not None: key = GG.keyval_name(e.keyval) if e.state & ALLMODS != 0: return True elif key in ('space', 'KP_Space'): self.on_key_space(wid) elif key in ('Return', 'KP_Enter'): self.on_key_return() elif key in ('Insert', 'KP_Insert'): self.on_key_insert() elif key in ('Delete', 'KP_Delete'): self.on_key_delete() elif key in self.select_keymap: dsp = GG.display_get_default() screen , x , y , mods = dsp.get_pointer() shift = self.select_keymap[key] x, y = x + shift[0], y + shift[1] dsp.warp_pointer(screen, x , y) if self.kbselect_state == 'extending': xw, yw = wid.get_pointer() w, h = self.doc.get_page(self.current_page).get_size() self.view.continue_ptr_selection(xw, yw, self.zoom, self.rotation, h) self.view.invalidate() return True else: return False
def get_cursor_data(self): #must be called from the UI thread! try: with xsync: cursor_data = X11Keyboard.get_cursor_image() except Exception as e: cursorlog.error("Error getting cursor data:") cursorlog.error(" %s", e) return None, [] if cursor_data is None: cursorlog("get_cursor_data() failed to get cursor image") return None, [] self.last_cursor_data = cursor_data pixels = self.last_cursor_data[7] cursorlog( "get_cursor_data() cursor=%s", cursor_data[:7] + ["%s bytes" % len(pixels)] + cursor_data[8:]) if self.default_cursor_data is not None and str(pixels) == str( self.default_cursor_data[7]): cursorlog("get_cursor_data(): default cursor - clearing it") cursor_data = None display = gdk.display_get_default() cursor_sizes = display.get_default_cursor_size( ), display.get_maximal_cursor_size() return (cursor_data, cursor_sizes)
def test_default_attributes(): display = gdk.display_get_default() assert isinstance(display.get_name(), str) assert isinstance(display.get_n_screens(), int) assert isinstance(display.get_default_screen(), gdk.Screen) assert isinstance(display.list_devices(), list) assert isinstance(display.get_core_pointer(), gdk.Device) assert display.supports_cursor_alpha() in (True, False) assert display.supports_cursor_color() in (True, False)
def get_ui_info(self, proto, *args): info = ServerBase.get_ui_info(self, proto, *args) info.setdefault("server", {}).update({ "display": gdk.display_get_default().get_name(), "root_window_size": self.get_root_window_size(), }) info.setdefault("cursor", {}).update(self.get_ui_cursor_info()) return info
def x11_init(self): X11ServerBase.x11_init(self) assert init_x11_filter() is True display = gdk.display_get_default() screens = display.get_n_screens() for n in range(screens): screen = display.get_screen(n) root = screen.get_root_window() add_event_receiver(root, self) add_catchall_receiver("xpra-motion-event", self) add_catchall_receiver("xpra-xkb-event", self) X11Keyboard.selectBellNotification(True)
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 __get_pos(self): display = gdk.display_get_default() screen, x, y, mask = display.get_pointer() w = screen.get_width() h = screen.get_height() if (x + 320 + 5) > w: x = (w - 320 - 8) if (y + 240 + 5) > h: y = (y - 240 - 2) return (x+8), (y+2)
def get_ui_cursor_info(self): #(from UI thread) #now cursor size info: display = gdk.display_get_default() pos = display.get_default_screen().get_root_window().get_pointer()[:2] cinfo = {"position": pos} for prop, size in { "default": display.get_default_cursor_size(), "max": display.get_maximal_cursor_size() }.items(): if size is None: continue cinfo["%s_size" % prop] = size return cinfo
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 continue_panning(self): dsp = GG.display_get_default() scr, x, y , mods = dsp.get_pointer() x0, y0 = self.panning_pos dx, dy = x-x0, y-y0 ha = self.scrollw.get_hadjustment() va = self.scrollw.get_vadjustment() hs, vs = (ha.get_value(), va.get_value()) hmax = max(1, ha.get_upper() - ha.get_page_size()) hs = min(max(0, hs-dx), hmax) vmax = max(1, va.get_upper() - va.get_page_size()) vs = min(max(0, vs-dy), vmax) ha.set_value(hs) va.set_value(vs) self.panning_pos = (x, y)
def make_hello(self, source): capabilities = ServerBase.make_hello(self, source) if source.wants_display: display = gdk.display_get_default() capabilities.update({ "display": display.get_name(), "cursor.default_size": display.get_default_cursor_size(), "cursor.max_size": display.get_maximal_cursor_size(), }) if source.wants_versions: capabilities.update(flatten_dict(get_gtk_version_info())) return capabilities
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 setup_tray_window(self): display = gdk.display_get_default() root = gdk.get_default_root_window() screen = root.get_screen() if TRANSPARENCY: colormap, visual = screen.get_rgba_colormap( ), screen.get_rgba_visual() if colormap is None or visual is None: log.warn("setup tray: using rgb visual fallback") colormap, visual = screen.get_rgb_colormap( ), screen.get_rgb_visual() assert colormap is not None and visual is not None, "failed to obtain visual or colormap" owner = X11Window.XGetSelectionOwner(SELECTION) log("setup tray: current selection owner=%#x", owner) if owner != XNone: raise Exception("%s already owned by %s" % (SELECTION, owner)) self.tray_window = gdk.Window(root, width=1, height=1, window_type=gdk.WINDOW_TOPLEVEL, event_mask=0, wclass=gdk.INPUT_OUTPUT, title="Xpra-SystemTray", visual=visual, colormap=colormap) xtray = self.tray_window.xid set_tray_visual(self.tray_window, visual) set_tray_orientation(self.tray_window, TRAY_ORIENTATION_HORZ) log("setup tray: tray window %#x", xtray) display.request_selection_notification(SELECTION) try: with xsync: setsel = X11Window.XSetSelectionOwner(xtray, SELECTION) log("setup tray: set selection owner returned %s, owner=%#x", setsel, X11Window.XGetSelectionOwner(SELECTION)) event_mask = StructureNotifyMask log("setup tray: sending client message") X11Window.sendClientMessage(root.xid, root.xid, False, event_mask, "MANAGER", CurrentTime, SELECTION, xtray) owner = X11Window.XGetSelectionOwner(SELECTION) assert owner == xtray, "we failed to get ownership of the tray selection" add_event_receiver(self.tray_window, self) log("setup tray: done") except Exception: log("setup_tray failure", exc_info=True) self.cleanup() raise
def __on_timer_timeout(self): if self.timer == 0: return False display = gdk.display_get_default() screen, x, y, mask = display.get_pointer() mask = mask & ((1<<13)-1) if mask & self.conf.get_mod_key(): if self.spy_view.get_property("visible") is False: self.clipboard.request_text(self.__on_clipboard_text_received) else: if self.spy_view.get_property("visible"): self.spy_view.hide() return True
def load_existing_windows(self): #at present, just one window is forwarded: #the root window covering the whole display display = gdk.display_get_default() screens = display.get_n_screens() with xsync: for n in range(screens): screen = display.get_screen(n) root = screen.get_root_window() model = DesktopModel(root, self.randr_exact_size) model.setup() windowlog("adding root window model %s", model) X11ServerBase._add_new_window_common(self, model) model.managed_connect("client-contents-changed", self._contents_changed) model.managed_connect("resized", self._window_resized_signaled)
def init_randr(self): self.randr = RandR.has_randr() if self.randr and len(RandR.get_screen_sizes())<=1: #disable randr when we are dealing with a Xvfb #with only one resolution available #since we don't support adding them on the fly yet self.randr = False if self.randr: display = gdk.display_get_default() i=0 while i<display.get_n_screens(): screen = display.get_screen(i) screen.connect("size-changed", self._screen_size_changed) i += 1 log("randr enabled: %s", self.randr) else: log.warn("Warning: no X11 RandR support on %s", os.environ.get("DISPLAY"))
def process_ui_capabilities(self, capabilities): GTKXpraClient.process_ui_capabilities(self, capabilities) if self.server_randr: display = gdk.display_get_default() i=0 while i<display.get_n_screens(): screen = display.get_screen(i) screen.connect("size-changed", self._screen_size_changed) i += 1 #if server supports it, enable UI thread monitoring workaround when needed: if self.suspend_resume and (sys.platform.startswith("darwin") or FAKE_UI_LOCKUPS>0): self.start_UI_thread_polling() if FAKE_UI_LOCKUPS>0: def sleep_in_ui_thread(*args): time.sleep(FAKE_UI_LOCKUPS) return True gobject.timeout_add((10+FAKE_UI_LOCKUPS)*1000, sleep_in_ui_thread)
def init_randr(self): self.randr = RandR.has_randr() if self.randr and len(RandR.get_screen_sizes()) <= 1: #disable randr when we are dealing with a Xvfb #with only one resolution available #since we don't support adding them on the fly yet self.randr = False if self.randr: display = gdk.display_get_default() i = 0 while i < display.get_n_screens(): screen = display.get_screen(i) screen.connect("size-changed", self._screen_size_changed) i += 1 log("randr enabled: %s", self.randr) else: log.warn("Warning: no X11 RandR support on %s", os.environ.get("DISPLAY"))
def process_ui_capabilities(self, capabilities): GTKXpraClient.process_ui_capabilities(self, capabilities) if self.server_randr: display = gdk.display_get_default() i=0 while i<display.get_n_screens(): screen = display.get_screen(i) screen.connect("size-changed", self.screen_size_changed) i += 1 global UI_watcher UI_watcher.start() #if server supports it, enable UI thread monitoring workaround when needed: if self.suspend_resume: def UI_resumed(): self.send("resume", True, self._id_to_window.keys()) def UI_failed(): self.send("suspend", True, self._id_to_window.keys()) UI_watcher.add_resume_callback(UI_resumed) UI_watcher.add_fail_callback(UI_failed)
def __init__(self, cb): """ Constructor. The Window is instantiated, the properties are correctly set, the event mask is modified, and the instance variables are initialized. @param cb: An instance of the main Application class. @type cb: pida.main.Application. """ gtk.Window.__init__(self) self.cb = cb # Window needs to be realized to do anything useful with it. Realizing # does not show the window to the user, so we can use it, but not have # an ugly blank frame while it loads. self.realize() # The "Vim" property self.window.property_change("Vim", gdk.SELECTION_TYPE_STRING, 8, gdk.PROP_MODE_REPLACE, "6.0") # Set the correct event mask and connect the notify event self.add_events(gtk.gdk.PROPERTY_CHANGE_MASK) self.connect('property-notify-event', self.cb_notify) # The serial number used for sending synchronous messages self.serial = 1 # A dictionary of callbacks for synchronous messages. The key is the # serial number, and the value is a callable that will be called with # the result of the synchronous evaluation. self.callbacks = {} # A dictionary to store the working directories for each Vim so they # only have to be fetched once. self.server_cwds = {} # An instance of the root window, so it only has to be fetched once. dpy = gdk.display_get_default() if not dpy: raise Exception('Unable to get default display') screen = dpy.get_screen(0) self.root_window = screen.get_root_window() # fetch the serverlist to begin with to know when we are started self.oldservers = None self.keep_fetching_serverlist = True gobject.timeout_add(250, self.fetch_serverlist)
def get_cursor_data(self): #must be called from the UI thread! try: with xsync: cursor_data = X11Keyboard.get_cursor_image() except Exception as e: cursorlog.error("Error getting cursor data:") cursorlog.error(" %s", e) return None, [] if cursor_data is None: cursorlog("get_cursor_data() failed to get cursor image") return None, [] self.last_cursor_data = cursor_data pixels = self.last_cursor_data[7] cursorlog("get_cursor_data() cursor=%s", cursor_data[:7]+["%s bytes" % len(pixels)]+cursor_data[8:]) if self.default_cursor_data is not None and str(pixels)==str(self.default_cursor_data[7]): cursorlog("get_cursor_data(): default cursor - clearing it") cursor_data = None display = gdk.display_get_default() cursor_sizes = display.get_default_cursor_size(), display.get_maximal_cursor_size() return (cursor_data, cursor_sizes)
def get_screen_sizes(self): display = gdk.display_get_default() i = 0 screen_sizes = [] while i < display.get_n_screens(): screen = display.get_screen(i) j = 0 monitors = [] while j < screen.get_n_monitors(): geom = screen.get_monitor_geometry(j) plug_name = "" if hasattr(screen, "get_monitor_plug_name"): plug_name = screen.get_monitor_plug_name(j) or "" wmm = -1 if hasattr(screen, "get_monitor_width_mm"): wmm = screen.get_monitor_width_mm(j) hmm = -1 if hasattr(screen, "get_monitor_height_mm"): hmm = screen.get_monitor_height_mm(j) monitor = plug_name, geom.x, geom.y, geom.width, geom.height, wmm, hmm monitors.append(monitor) j += 1 work_x, work_y = 0, 0 work_width, work_height = screen.get_width(), screen.get_height() if not sys.platform.startswith("win"): try: p = gtk.gdk.atom_intern('_NET_WORKAREA') root = screen.get_root_window() work_x, work_y, work_width, work_height = root.property_get( p)[2][:4] except: pass item = (screen.make_display_name(), screen.get_width(), screen.get_height(), screen.get_width_mm(), screen.get_height_mm(), monitors, work_x, work_y, work_width, work_height) screen_sizes.append(item) i += 1 return screen_sizes
def process_ui_capabilities(self, capabilities): GTKXpraClient.process_ui_capabilities(self, capabilities) if self.server_randr: display = gdk.display_get_default() i = 0 while i < display.get_n_screens(): screen = display.get_screen(i) screen.connect("size-changed", self.screen_size_changed) i += 1 global UI_watcher UI_watcher.start() #if server supports it, enable UI thread monitoring workaround when needed: if self.suspend_resume: def UI_resumed(): self.send("resume", True, self._id_to_window.keys()) def UI_failed(): self.send("suspend", True, self._id_to_window.keys()) UI_watcher.add_resume_callback(UI_resumed) UI_watcher.add_fail_callback(UI_failed)
def get_screen_sizes(self): display = gdk.display_get_default() i=0 screen_sizes = [] while i<display.get_n_screens(): screen = display.get_screen(i) j = 0 monitors = [] while j<screen.get_n_monitors(): geom = screen.get_monitor_geometry(j) plug_name = "" if hasattr(screen, "get_monitor_plug_name"): plug_name = screen.get_monitor_plug_name(j) or "" wmm = -1 if hasattr(screen, "get_monitor_width_mm"): wmm = screen.get_monitor_width_mm(j) hmm = -1 if hasattr(screen, "get_monitor_height_mm"): hmm = screen.get_monitor_height_mm(j) monitor = plug_name, geom.x, geom.y, geom.width, geom.height, wmm, hmm monitors.append(monitor) j += 1 root = screen.get_root_window() work_x, work_y = 0, 0 work_width, work_height = screen.get_width(), screen.get_height() if not sys.platform.startswith("win"): try: p = gtk.gdk.atom_intern('_NET_WORKAREA') work_x, work_y, work_width, work_height = root.property_get(p)[2][:4] except: pass item = (screen.make_display_name(), screen.get_width(), screen.get_height(), screen.get_width_mm(), screen.get_height_mm(), monitors, work_x, work_y, work_width, work_height) screen_sizes.append(item) i += 1 log("get_screen_sizes()=%s", screen_sizes) return screen_sizes
def __handler(self): """ Emite la señal de estado cada 60 segundos. """ try: display, posx, posy = gdk.display_get_default( ).get_window_at_pointer() except: return True if posx > 0 and posy > 0: if posx != self.mouse_pos[0] or posy != self.mouse_pos[1]: self.mouse_pos = (posx, posy) self.emit("estado", "moviendose") else: self.emit("estado", "detenido") else: self.emit("estado", "fuera") return True
def __init__(self): self.screen_number = gdk.display_get_default().get_default_screen().get_number() self.root_window = gdk.get_default_root_window() self.last_mouse_user = None GTKServerBase.__init__(self)
def test_create_without_socket_id(): try: gtk.Plug(display = gdk.display_get_default()) assert False except TypeError: assert True
def test_create_with_display(): plug = gtk.Plug(socket_id = 0L, display = gdk.display_get_default()) print plug.get_id() assert plug.get_id() == 0
def get_cursor_sizes(self): display = gdk.display_get_default() return display.get_default_cursor_size( ), display.get_maximal_cursor_size()
def __init__(self): self.screen_number = gdk.display_get_default().get_default_screen( ).get_number() self.root_window = gdk.get_default_root_window() self.last_mouse_user = None GTKServerBase.__init__(self)
def set_accion(self, accion, valor=True): """ Ejecuta acciones sobre el código. """ buffer = self.get_buffer() if accion == "Deshacer": if buffer.can_undo(): buffer.undo() elif accion == "Rehacer": if buffer.can_redo(): buffer.redo() elif accion == "Seleccionar Todo": inicio, fin = buffer.get_bounds() buffer.select_range(inicio, fin) elif accion == "Copiar": clipboard = gtk.Clipboard(display=gdk.display_get_default(), selection="CLIPBOARD") if buffer.get_selection_bounds(): inicio, fin = buffer.get_selection_bounds() texto = buffer.get_text(inicio, fin, 0) clipboard.set_text(texto, -1) elif accion == "Pegar": clipboard = gtk.Clipboard(display=gdk.display_get_default(), selection="CLIPBOARD") texto = clipboard.wait_for_text() if texto != None: if buffer.get_selection_bounds(): start, end = buffer.get_selection_bounds() texto_seleccion = buffer.get_text(start, end, 0) # Texto selección buffer.delete(start, end) buffer.insert_at_cursor(texto) elif accion == "Cortar": clipboard = gtk.Clipboard(display=gdk.display_get_default(), selection="CLIPBOARD") if buffer.get_selection_bounds(): start, end = buffer.get_selection_bounds() texto_seleccion = buffer.get_text(start, end, 0) # Texto selección buffer.delete(start, end) clipboard.set_text(texto_seleccion, -1) elif accion == "Buscar Texto": try: inicio, fin = buffer.get_selection_bounds() texto = buffer.get_text(inicio, fin, 0) except: texto = None dialogo = DialogoBuscar(self, parent_window=self.get_toplevel(), title="Buscar Texto", texto=texto) dialogo.run() dialogo.destroy() elif accion == "Reemplazar Texto": texto = "" try: inicio, fin = buffer.get_selection_bounds() texto = buffer.get_text(inicio, fin, 0) except: texto = None dialogo = DialogoReemplazar(self, parent_window=self.get_toplevel(), title="Reemplazar Texto", texto=texto) dialogo.run() dialogo.destroy() elif accion == "Cerrar Archivo": if buffer.get_modified(): dialog = DialogoAlertaSinGuardar( parent_window=self.get_toplevel()) respuesta = dialog.run() dialog.destroy() if respuesta == gtk.RESPONSE_ACCEPT: self.guardar() elif respuesta == gtk.RESPONSE_CANCEL: return elif respuesta == gtk.RESPONSE_CLOSE: self.__cerrar() else: self.__cerrar() elif accion == "Numeracion": self.set_show_line_numbers(valor) elif accion == "Identar": self.__identar() elif accion == "Identar con Espacios": # FIXME: convertir . . . self.tab = ' ' #self.__identar() elif accion == "Identar con Tabulaciones": # FIXME: convertir . . . self.tab = '\t' #self.__identar() elif accion == "De Identar": self.__de_identar() elif accion == "Valorar": if self.lenguaje: if self.lenguaje.get_name() == "Python": numeracion = self.get_show_line_numbers() self.set_show_line_numbers(True) dialogo = DialogoErrores(self, parent_window=self.get_toplevel(), tipo="pep8") dialogo.run() dialogo.destroy() self.set_show_line_numbers(numeracion) else: dialogo = gtk.Dialog(parent=self.get_toplevel(), flags=gtk.DIALOG_MODAL, buttons=("OK", gtk.RESPONSE_ACCEPT)) dialogo.set_size_request(300, 100) dialogo.set_border_width(15) label = gtk.Label("El archivo no contiene código python.") label.show() dialogo.vbox.pack_start(label, True, True, 0) dialogo.run() dialogo.destroy() else: dialogo = gtk.Dialog(parent=self.get_toplevel(), flags=gtk.DIALOG_MODAL, buttons=("OK", gtk.RESPONSE_ACCEPT)) dialogo.set_size_request(300, 100) dialogo.set_border_width(15) label = gtk.Label("El archivo no contiene código python.") label.show() dialogo.vbox.pack_start(label, True, True, 0) dialogo.run() dialogo.destroy() elif accion == "Chequear": if self.lenguaje: if self.lenguaje.get_name() == "Python": numeracion = self.get_show_line_numbers() self.set_show_line_numbers(True) # HACK: No se debe permitir usar la interfaz de la aplicación. self.get_toplevel().set_sensitive(False) dialogo = DialogoErrores(self, parent_window=self.get_toplevel()) dialogo.run() dialogo.destroy() self.set_show_line_numbers(numeracion) # HACK: No se debe permitir usar la interfaz de la aplicación. self.get_toplevel().set_sensitive(True) return dialogo = gtk.Dialog(parent=self.get_toplevel(), flags=gtk.DIALOG_MODAL, buttons=("OK", gtk.RESPONSE_ACCEPT)) dialogo.set_size_request(300, 100) dialogo.set_border_width(15) label = gtk.Label( "El archivo no contiene código python\no todavía no ha sido guardado." ) label.show() dialogo.vbox.pack_start(label, True, True, 0) dialogo.run() dialogo.destroy()
def start_panning(self): dsp = GG.display_get_default() scr, x, y , mods = dsp.get_pointer() self.panning_pos = (x, y)
def _move_pointer(self, wid, pos, *args): x, y = pos display = gdk.display_get_default() display.warp_pointer(display.get_default_screen(), x, y)
def set_accion(self, accion, valor=True): """ Ejecuta acciones sobre el código. """ buffer = self.get_buffer() if accion == "Deshacer": if buffer.can_undo(): buffer.undo() elif accion == "Rehacer": if buffer.can_redo(): buffer.redo() elif accion == "Seleccionar Todo": inicio, fin = buffer.get_bounds() buffer.select_range(inicio, fin) elif accion == "Copiar": clipboard = gtk.Clipboard( display=gdk.display_get_default(), selection="CLIPBOARD") if buffer.get_selection_bounds(): inicio, fin = buffer.get_selection_bounds() texto = buffer.get_text(inicio, fin, 0) clipboard.set_text(texto, -1) elif accion == "Pegar": clipboard = gtk.Clipboard( display=gdk.display_get_default(), selection="CLIPBOARD") texto = clipboard.wait_for_text() if texto != None: if buffer.get_selection_bounds(): start, end = buffer.get_selection_bounds() texto_seleccion = buffer.get_text(start, end, 0) # Texto selección buffer.delete(start, end) buffer.insert_at_cursor(texto) elif accion == "Cortar": clipboard = gtk.Clipboard( display=gdk.display_get_default(), selection="CLIPBOARD") if buffer.get_selection_bounds(): start, end = buffer.get_selection_bounds() texto_seleccion = buffer.get_text(start, end, 0) # Texto selección buffer.delete(start, end) clipboard.set_text(texto_seleccion, -1) elif accion == "Buscar Texto": try: inicio, fin = buffer.get_selection_bounds() texto = buffer.get_text(inicio, fin, 0) except: texto = None dialogo = DialogoBuscar(self, parent_window=self.get_toplevel(), title="Buscar Texto", texto=texto) dialogo.run() dialogo.destroy() elif accion == "Reemplazar Texto": texto = "" try: inicio, fin = buffer.get_selection_bounds() texto = buffer.get_text(inicio, fin, 0) except: texto = None dialogo = DialogoReemplazar(self, parent_window=self.get_toplevel(), title="Reemplazar Texto", texto=texto) dialogo.run() dialogo.destroy() elif accion == "Cerrar Archivo": if buffer.get_modified(): dialog = DialogoAlertaSinGuardar( parent_window=self.get_toplevel()) respuesta = dialog.run() dialog.destroy() if respuesta == gtk.RESPONSE_ACCEPT: self.guardar() elif respuesta == gtk.RESPONSE_CANCEL: return elif respuesta == gtk.RESPONSE_CLOSE: self.__cerrar() else: self.__cerrar() elif accion == "Numeracion": self.set_show_line_numbers(valor) elif accion == "Identar": self.__identar() elif accion == "Identar con Espacios": # FIXME: convertir . . . self.tab = ' ' #self.__identar() elif accion == "Identar con Tabulaciones": # FIXME: convertir . . . self.tab = '\t' #self.__identar() elif accion == "De Identar": self.__de_identar() elif accion == "Valorar": if self.lenguaje: if self.lenguaje.get_name() == "Python": numeracion = self.get_show_line_numbers() self.set_show_line_numbers(True) dialogo = DialogoErrores(self, parent_window=self.get_toplevel(), tipo="pep8") dialogo.run() dialogo.destroy() self.set_show_line_numbers(numeracion) else: dialogo = gtk.Dialog( parent=self.get_toplevel(), flags=gtk.DIALOG_MODAL, buttons=("OK", gtk.RESPONSE_ACCEPT)) dialogo.set_size_request(300, 100) dialogo.set_border_width(15) label = gtk.Label("El archivo no contiene código python.") label.show() dialogo.vbox.pack_start(label, True, True, 0) dialogo.run() dialogo.destroy() else: dialogo = gtk.Dialog( parent=self.get_toplevel(), flags=gtk.DIALOG_MODAL, buttons=("OK", gtk.RESPONSE_ACCEPT)) dialogo.set_size_request(300, 100) dialogo.set_border_width(15) label = gtk.Label("El archivo no contiene código python.") label.show() dialogo.vbox.pack_start(label, True, True, 0) dialogo.run() dialogo.destroy() elif accion == "Chequear": if self.lenguaje: if self.lenguaje.get_name() == "Python": numeracion = self.get_show_line_numbers() self.set_show_line_numbers(True) # HACK: No se debe permitir usar la interfaz de la aplicación. self.get_toplevel().set_sensitive(False) dialogo = DialogoErrores(self, parent_window=self.get_toplevel()) dialogo.run() dialogo.destroy() self.set_show_line_numbers(numeracion) # HACK: No se debe permitir usar la interfaz de la aplicación. self.get_toplevel().set_sensitive(True) return dialogo = gtk.Dialog( parent=self.get_toplevel(), flags=gtk.DIALOG_MODAL, buttons=("OK", gtk.RESPONSE_ACCEPT)) dialogo.set_size_request(300, 100) dialogo.set_border_width(15) label = gtk.Label("El archivo no contiene código python\no todavía no ha sido guardado.") label.show() dialogo.vbox.pack_start(label, True, True, 0) dialogo.run() dialogo.destroy()
def test_window_foreign_new_for_display_id0(): display = gdk.display_get_default() window = gdk.window_foreign_new_for_display(display, 0) assert not window
def _init_from_image_and_hotspot(self, image, hotspot): #print "Cursor._init_from_image_and_hotspot:", image, hotspot ### x, y = hotspot gdk_display = gdk.display_get_default() self._gtk_cursor = gdk.Cursor(gdk_display, image._gdk_pixbuf, x, y)
def setup_init(self): """ Se crea la interfaz grafica, se setea y se empaqueta todo. """ self.get_toplevel().set_sensitive(False) from Widgets import Visor from Widgets import BarraProgreso from Widgets import ControlVolumen from PlayerList import Lista from PlayerControls import PlayerControl #from GstreamerWidgets.Widgets import WidgetsGstreamerEfectos from Toolbars import ToolbarSalir from Toolbars import Toolbar from Toolbars import ToolbarAccion from Toolbars import ToolbarConfig from Toolbars import ToolbarGrabar from Toolbars import ToolbarInfo from Toolbars import ToolbarAddStream self.pantalla = Visor() self.barradeprogreso = BarraProgreso() self.volumen = ControlVolumen() self.lista_de_reproduccion = Lista() self.controlesrepro = PlayerControl() self.toolbar = Toolbar() self.toolbar_config = ToolbarConfig() #self.widget_efectos = WidgetsGstreamerEfectos() self.toolbar_accion = ToolbarAccion() self.toolbar_grabar = ToolbarGrabar() self.toolbar_info = ToolbarInfo() self.toolbaraddstream = ToolbarAddStream() self.toolbar_salir = ToolbarSalir() basebox = gtk.VBox() hpanel = gtk.HPaned() hpanel.modify_bg(0, get_colors("window")) eventbox = gtk.EventBox() # FIXME: Para poder pintar el fondo eventbox.modify_bg(0, get_colors("barradeprogreso")) eventbox.add(self.toolbar) basebox.pack_start(eventbox, False, False, 3) basebox.pack_start(self.toolbar_salir, False, False, 0) basebox.pack_start(self.toolbar_accion, False, False, 0) basebox.pack_start(self.toolbaraddstream, False, False, 0) basebox.pack_start(hpanel, True, True, 0) # Area Izquierda del Panel # Efectos que se están aplicando. #eventbox = gtk.EventBox() # FIXME: Para poder pintar el fondo #eventbox.modify_bg(0, get_colors("drawingplayer")) #self.hbox_efectos_en_pipe = gtk.HBox() #self.hbox_efectos_en_pipe.set_size_request(-1, 24) #eventbox.add(self.hbox_efectos_en_pipe) #scroll = gtk.ScrolledWindow() #scroll.set_policy( # gtk.POLICY_AUTOMATIC, # gtk.POLICY_NEVER) #scroll.add_with_viewport(eventbox) # Barra de Progreso + Volúmen ev_box = gtk.EventBox() # FIXME: Para poder pintar el fondo ev_box.modify_bg(0, get_colors("barradeprogreso")) hbox_barra_progreso = gtk.HBox() hbox_barra_progreso.pack_start( self.barradeprogreso, True, True, 0) hbox_barra_progreso.pack_start( self.volumen, False, False, 0) ev_box.add(hbox_barra_progreso) # Todo vbox = gtk.VBox() vbox.pack_start(self.toolbar_grabar, False, False, 0) vbox.pack_start(self.pantalla, True, True, 0) #vbox.pack_start(scroll, False, False, 0) eventbox = gtk.EventBox() # FIXME: Para poder pintar el fondo eventbox.modify_bg(0, get_colors("barradeprogreso")) eventbox.add(self.toolbar_info) vbox.pack_start(eventbox, False, False, 3) vbox.pack_start(ev_box, False, True, 0) hpanel.pack1(vbox, resize=True, shrink=True) # Area Derecha del Panel self.derecha_vbox = gtk.VBox() # Configuración de balanace y efectos self.vbox_config = gtk.VBox() self.scroll_config = gtk.ScrolledWindow() self.scroll_config.set_policy( gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.scroll_config.add_with_viewport(self.vbox_config) self.scroll_config.get_child().modify_bg(0, get_colors("window")) self.vbox_config.pack_start( self.toolbar_config, False, False, 0) #self.vbox_config.pack_start(self.widget_efectos, False, False, 0) # Lista de Reproducción # FIXME: Para poder pintar el fondo self.evnt_box_lista_reproduccion = gtk.EventBox() self.evnt_box_lista_reproduccion.modify_bg( 0, get_colors("barradeprogreso")) self.vbox_lista_reproduccion = gtk.VBox() self.scroll_list = gtk.ScrolledWindow() self.scroll_list.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scroll_list.add(self.lista_de_reproduccion) # Lista + Controles de Reproducción self.__pack_vbox_lista_reproduccion() self.evnt_box_lista_reproduccion.add( self.vbox_lista_reproduccion) # Configuración + Lista de Reproducción. self.derecha_vbox.pack_start( self.scroll_config, True, True, 0) self.derecha_vbox.pack_start( self.evnt_box_lista_reproduccion, True, True, 0) hpanel.pack2(self.derecha_vbox, resize=False, shrink=True) self.controles_dinamicos = [ hbox_barra_progreso, self.derecha_vbox, self.toolbar, self.toolbar_info, #self.hbox_efectos_en_pipe.get_parent().get_parent( # ).get_parent(), ] basebox.show_all() map(self.__ocultar, [self.toolbar_salir, self.scroll_config, self.toolbar_accion, self.toolbar_grabar, self.toolbaraddstream, self.toolbar_info.descarga]) self.add(basebox) self.lista_de_reproduccion.connect( "nueva-seleccion", self.__cargar_reproducir) self.lista_de_reproduccion.connect( "button-press-event", self.__click_derecho_en_lista) self.controlesrepro.connect( "activar", self.__activar) self.barradeprogreso.connect( "user-set-value", self.__user_set_value) self.pantalla.connect( "ocultar_controles", self.__ocultar_controles) self.pantalla.connect( "button_press_event", self.__clicks_en_pantalla) self.toolbar.connect('salir', self.confirmar_salir) self.toolbar.connect('config', self.__mostrar_config) self.toolbar_salir.connect( 'salir', self.__emit_salir) self.toolbar_config.connect( 'valor', self.__set_balance) self.toolbar_info.connect( 'rotar', self.__set_rotacion) self.toolbar_info.connect( 'actualizar_streamings', self.__actualizar_streamings) self.toolbar_accion.connect( "Grabar", self.__grabar_streaming) self.toolbar_accion.connect( "accion-stream", self.__accion_stream) self.toolbar_grabar.connect( "stop", self.__detener_grabacion) self.volumen.connect( "volumen", self.__set_volumen) self.toolbaraddstream.connect( "add-stream", self.__ejecutar_add_stream) #self.widget_efectos.connect( # "click_efecto", self.__click_efecto) #self.widget_efectos.connect( # 'configurar_efecto', self.__configurar_efecto) # Controlador del mouse. # http://www.pygtk.org/pygtk2reference/class-gdkdisplay.html # #function-gdk--display-get-default icono = os.path.join(BASE_PATH, "Iconos", "jamedia_cursor.svg") pixbuf = gdk.pixbuf_new_from_file_at_size(icono, -1, 24) self.jamedia_cursor = gdk.Cursor( gdk.display_get_default(), pixbuf, 0, 0) self.cursor_root = self.get_parent_window().get_cursor() self.get_parent_window().set_cursor(self.jamedia_cursor) from Widgets import MouseSpeedDetector self.mouse_listener = MouseSpeedDetector(self) self.mouse_listener.connect( "estado", self.__set_mouse) self.mouse_listener.new_handler(True) self.get_parent().connect( "hide", self.__hide_show_parent) self.get_parent().connect( "show", self.__hide_show_parent) #self.hbox_efectos_en_pipe.get_parent().get_parent( # ).get_parent().hide() self.get_toplevel().set_sensitive(True) self.derecha_vbox.set_size_request(169, -1)