Exemplo n.º 1
0
 def do_init_new_backing_instance(self):
     w, h = self.size
     self._backing = None
     assert w < 32768 and h < 32768, "dimensions too big: %sx%s" % (w, h)
     if w == 0 or h == 0:
         #this can happen during cleanup
         return
     if w < 0 or h < 0:
         log.warn("Warning: invalid backing dimensions %ix%i", w, h)
         w = max(1, w)
         h = max(1, h)
     try:
         if self._alpha_enabled:
             self._backing = gdk.Pixmap(None, w, h, 32)
             screen = self._backing.get_screen()
             rgba = screen.get_rgba_colormap()
             if rgba is not None:
                 self._backing.set_colormap(rgba)
             else:
                 #cannot use transparency
                 log.warn(
                     "Warning: cannot display transparency, no RGBA colormap"
                 )
                 self._alpha_enabled = False
                 self._backing = gdk.Pixmap(gdk.get_default_root_window(),
                                            w, h)
         else:
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     except RuntimeError as e:
         log("do_init_new_backing_instance()", exc_info=True)
         log.error("Error creating pixmap backing of size %ix%i", w, h)
         log.error(" %s", e)
         self._backing = None
Exemplo n.º 2
0
 def init(self, ww, wh, bw, bh):
     #use window size as backing size:
     self.render_size = ww, wh
     self.size = bw, bh
     w, h = bw, bh
     old_backing = self._backing
     self._backing = None
     assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h)
     if w==0 or h==0:
         #this can happen during cleanup
         return
     if self._alpha_enabled:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             log.warn("cannot use transparency: no RGBA colormap!")
             self._alpha_enabled = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = self._backing.cairo_create()
     cr.set_source_rgb(1, 1, 1)
     if old_backing is not None:
         # Really we should respect bit-gravity here but... meh.
         old_w, old_h = old_backing.get_size()
         if w>old_w and h>old_h:
             #both width and height are bigger:
             cr.rectangle(old_w, 0, w-old_w, h)
             cr.fill()
             cr.new_path()
             cr.rectangle(0, old_h, old_w, h-old_h)
             cr.fill()
         elif w>old_w:
             #enlarged in width only
             cr.rectangle(old_w, 0, w-old_w, h)
             cr.fill()
         if h>old_h:
             #enlarged in height only
             cr.rectangle(0, old_h, w, h-old_h)
             cr.fill()
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.set_source_pixmap(old_backing, 0, 0)
         cr.paint()
     else:
         cr.rectangle(0, 0, w, h)
         cr.fill()
Exemplo n.º 3
0
 def init(self, ww, wh, bw, bh):
     #use window size as backing size:
     self.render_size = ww, wh
     self.size = bw, bh
     w, h = bw, bh
     old_backing = self._backing
     self._backing = None
     assert w < 32768 and h < 32768, "dimensions too big: %sx%s" % (w, h)
     if w == 0 or h == 0:
         #this can happen during cleanup
         return
     if self._alpha_enabled:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             log.warn("cannot use transparency: no RGBA colormap!")
             self._alpha_enabled = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = self._backing.cairo_create()
     cr.set_source_rgb(1, 1, 1)
     if old_backing is not None:
         # Really we should respect bit-gravity here but... meh.
         old_w, old_h = old_backing.get_size()
         if w > old_w and h > old_h:
             #both width and height are bigger:
             cr.rectangle(old_w, 0, w - old_w, h)
             cr.fill()
             cr.new_path()
             cr.rectangle(0, old_h, old_w, h - old_h)
             cr.fill()
         elif w > old_w:
             #enlarged in width only
             cr.rectangle(old_w, 0, w - old_w, h)
             cr.fill()
         if h > old_h:
             #enlarged in height only
             cr.rectangle(0, old_h, w, h - old_h)
             cr.fill()
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.set_source_pixmap(old_backing, 0, 0)
         cr.paint()
     else:
         cr.rectangle(0, 0, w, h)
         cr.fill()
Exemplo n.º 4
0
def dump_windows():
    root = gdk.get_default_root_window()
    log("root window: %s" % root)
    children = get_children(root)
    log("%s windows" % len(children))
    for window in get_children(root):
        log("found window: %s", window_info(window))
Exemplo n.º 5
0
Arquivo: tray.py Projeto: cattaka/Xpra
    def cleanup(self):
        log("SystemTray.cleanup()")
        root = gdk.get_default_root_window()

        def undock(window):
            log("undocking %s", window)
            X11Window.Unmap(window.xid)
            X11Window.Reparent(window.xid, root.xid, 0, 0)

        with xswallow:
            owner = X11Window.XGetSelectionOwner(SELECTION)
            if owner == self.tray_window.xid:
                X11Window.XSetSelectionOwner(0, SELECTION)
                log("SystemTray.cleanup() reset %s selection owner to %#x",
                    SELECTION, X11Window.XGetSelectionOwner(SELECTION))
            else:
                log.warn("Warning: we were no longer the tray selection owner")
        remove_event_receiver(self.tray_window, self)
        tray_windows = self.tray_windows
        self.tray_windows = {}
        for window, tray_window in tray_windows.items():
            with xswallow:
                undock(window)
            tray_window.destroy()
        self.tray_window.destroy()
        self.tray_window = None
        log("SystemTray.cleanup() done")
Exemplo n.º 6
0
 def __init__(self):
     self.statusicon = gtk.StatusIcon()
     self.counter = 0
     self.statusicon.connect("activate", self.quit_cb)
     self.statusicon.connect("popup-menu", self.quit_cb)
     self.statusicon.set_tooltip("StatusIcon Example")
     #generate tray image:
     s = 64
     w, h = s * 2, s * 2
     pixmap = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = pixmap.cairo_create()
     cr.set_operator(cairo.OPERATOR_CLEAR)
     cr.fill()
     cr.set_operator(cairo.OPERATOR_SOURCE)
     for i, color in enumerate([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)]):
         cr.set_source_rgba(*color)
         cr.new_path()
         x = (i % 2) * s
         y = (i / 2) * s
         cr.move_to(x, y)
         cr.line_to(x + s, y)
         cr.line_to(x + s, y + s)
         cr.line_to(x, y + s)
         cr.close_path()
         cr.fill()
     pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h)
     pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, w,
                              h)
     self.statusicon.set_from_pixbuf(pixbuf)
Exemplo n.º 7
0
  def pick_immediate(self, x, y, magnifier):
    """
    Select the color at the specified pixel

    The coordinates are relative to the screen.
    """

    if self.flags() & gtk.REALIZED == False: return

    if magnifier:
      r,g,b = self.mag.raw_pixbuf.get_pixels_array()[y,x]
    else:
      # grab raw screen data
      self.raw_pixbuf.get_from_drawable(
          gdk.get_default_root_window(),
          gdk.colormap_get_system(),
          x, y,
          0, 0,
          self.raw_width, self.raw_height)

      #pull out rgb value
      #XXX first time this is called generates a warning and doesn't work.
      #    all subsequent times are fine. why?
      r,g,b = self.raw_pixbuf.get_pixels_array()[0,0]

    self.color.set_rgb(r,g,b)
Exemplo n.º 8
0
    def cb_motion_notify(self, widget, event):
        """ Callback from mouse motion notify events """
        if (self.picking):
            # check if we are over the magnified image. if so, select from it
            a = self.allocation
            r = self.mag.allocation
            ox, oy = self.mag.origin()
            x = a.x + event.x - r.x
            y = a.y + event.y - r.y
            zx = int((x - ox) / self.mag.zoom)
            zy = int((y - oy) / self.mag.zoom)

            if (self.mag.has_data and (x >= 0 and x < r.width)
                    and (y >= 0 and y < r.height)
                    and (zx >= 0 and zx < self.mag.raw_width)
                    and (zy >= 0 and zy < self.mag.raw_height)):
                self.pick(zx, zy, True)

            # otherwise, select from screen
            else:
                root_w, root_h = gdk.get_default_root_window().get_size()
                x = event.x_root
                y = event.y_root

                if (x < 0): x = 0
                if (x >= root_w): x = root_w - 1
                if (y < 0): y = 0
                if (y >= root_h): y = root_h - 1

                self.pick(x, y, False)
Exemplo n.º 9
0
	def init(self, w, h):
		old_backing = self._backing
		self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
		cr = self._backing.cairo_create()
		cr.set_source_rgb(1, 1, 1)
		if CRASH and old_backing is not None:
			cr.set_operator(cairo.OPERATOR_SOURCE)
			cr.set_source_pixmap(old_backing, 0, 0)
			cr.paint()
			old_w, old_h = old_backing.get_size()
			if w>old_w:
				cr.new_path()
				cr.move_to(old_w, 0)
				cr.line_to(w, 0)
				cr.line_to(w, h)
				cr.line_to(old_w, h)
				cr.close_path()
				cr.fill()
			if h>old_h:
				cr.new_path()
				cr.move_to(0, old_h)
				cr.line_to(0, h)
				cr.line_to(w, h)
				cr.line_to(w, old_h)
				cr.close_path()
				cr.fill()
		else:
			cr.rectangle(0, 0, w, h)
			cr.fill()
Exemplo n.º 10
0
 def set_icon():
     #generate window icon image:
     if not self.rotate:
         return True
     s = 64
     w, h = s * 2, s * 2
     pixmap = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = pixmap.cairo_create()
     cr.set_operator(cairo.OPERATOR_CLEAR)
     cr.fill()
     cr.set_operator(cairo.OPERATOR_SOURCE)
     v = (self.counter % 256 / 255.0)
     self.counter += 10
     for i, color in enumerate([(1, 0, 0, 1), (0, 1, 0, 1),
                                (0, 0, 1, 1), (v, v, v, v)]):
         cr.set_source_rgba(*color)
         cr.new_path()
         x = (i % 2) * s
         y = (i / 2) * s
         cr.move_to(x, y)
         cr.line_to(x + s, y)
         cr.line_to(x + s, y + s)
         cr.line_to(x, y + s)
         cr.close_path()
         cr.fill()
     pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h)
     pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0,
                              w, h)
     self.set_icon(pixbuf)
     print("set icon to %s" % int(255 * v))
     return True
Exemplo n.º 11
0
 def set_icon():
     #generate window icon image:
     if not self.rotate:
         return True
     s = 64
     w, h = s*2, s*2
     pixmap = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = pixmap.cairo_create()
     cr.set_operator(cairo.OPERATOR_CLEAR)
     cr.fill()
     cr.set_operator(cairo.OPERATOR_SOURCE)
     v = (self.counter % 256 / 255.0)
     self.counter += 10
     for i, color in enumerate([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1), (v, v, v, v)]):
         cr.set_source_rgba(*color)
         cr.new_path()
         x = (i % 2) * s
         y = (i / 2) * s
         cr.move_to(x, y)
         cr.line_to(x + s, y)
         cr.line_to(x+s, y+s)
         cr.line_to(x, y+s)
         cr.close_path()
         cr.fill()
     pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h)
     pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, w, h)
     self.set_icon(pixbuf)
     print("set icon to %s" % int(255*v))
     return True
Exemplo n.º 12
0
 def do_unmanaged(self, wm_exiting):
     log("unmanaging window: %s (%s - %s)", self, self.corral_window, self.client_window)
     self._internal_set_property("owner", None)
     if self.corral_window:
         remove_event_receiver(self.corral_window, self)
         with xswallow:
             for prop in WindowModel.SCRUB_PROPERTIES:
                 X11Window.XDeleteProperty(self.xid, prop)
         if self.client_reparented:
             self.client_window.reparent(gdk.get_default_root_window(), 0, 0)
             self.client_reparented = False
         self.client_window.set_events(self.client_window_saved_events)
         #it is now safe to destroy the corral window:
         self.corral_window.destroy()
         self.corral_window = None
         # It is important to remove from our save set, even after
         # reparenting, because according to the X spec, windows that are
         # in our save set are always Mapped when we exit, *even if those
         # windows are no longer inferior to any of our windows!* (see
         # section 10. Connection Close).  This causes "ghost windows", see
         # bug #27:
         if self.in_save_set:
             with xswallow:
                 X11Window.XRemoveFromSaveSet(self.xid)
             self.in_save_set = False
         with xswallow:
             X11Window.sendConfigureNotify(self.xid)
         if wm_exiting:
             self.client_window.show_unraised()
     BaseWindowModel.do_unmanaged(self, wm_exiting)
Exemplo n.º 13
0
 def __init__(self):
     self.statusicon = gtk.StatusIcon()
     self.counter = 0
     self.statusicon.connect("activate", self.quit_cb)
     self.statusicon.connect("popup-menu", self.quit_cb)
     self.statusicon.set_tooltip("StatusIcon Example")
     #generate tray image:
     s = 64
     w, h = s*2, s*2
     pixmap = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = pixmap.cairo_create()
     cr.set_operator(cairo.OPERATOR_CLEAR)
     cr.fill()
     cr.set_operator(cairo.OPERATOR_SOURCE)
     for i, color in enumerate([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)]):
         cr.set_source_rgba(*color)
         cr.new_path()
         x = (i % 2) * s
         y = (i / 2) * s
         cr.move_to(x, y)
         cr.line_to(x + s, y)
         cr.line_to(x+s, y+s)
         cr.line_to(x, y+s)
         cr.close_path()
         cr.fill()
     pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h)
     pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, w, h)
     self.statusicon.set_from_pixbuf(pixbuf)
Exemplo n.º 14
0
 def init(self, w, h):
     old_backing = self._backing
     self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = self._backing.cairo_create()
     cr.set_source_rgb(1, 1, 1)
     if CRASH and old_backing is not None:
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.set_source_pixmap(old_backing, 0, 0)
         cr.paint()
         old_w, old_h = old_backing.get_size()
         if w > old_w:
             cr.new_path()
             cr.move_to(old_w, 0)
             cr.line_to(w, 0)
             cr.line_to(w, h)
             cr.line_to(old_w, h)
             cr.close_path()
             cr.fill()
         if h > old_h:
             cr.new_path()
             cr.move_to(0, old_h)
             cr.line_to(0, h)
             cr.line_to(w, h)
             cr.line_to(w, old_h)
             cr.close_path()
             cr.fill()
     else:
         cr.rectangle(0, 0, w, h)
         cr.fill()
Exemplo n.º 15
0
    def __init__ (self):
        super(LanguageBar, self).__init__()
        self.__show = 1
        self.__enabled = False
        self.__has_focus = False
        self.__show_im_name = False
        self.__im_name = None
        self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
        self.set_show_arrow(False)
        self.set_property("icon-size", ICON_SIZE)
        self.__create_ui()

        self.__properties = []
        self.__toplevel = gtk.Window(gtk.WINDOW_POPUP)
        self.__toplevel.connect("size-allocate", self.__toplevel_size_allocate_cb)
        self.__toplevel.add(self)

        root = gdk.get_default_root_window()
        try:
            self.__work_area = root.property_get("_NET_WORKAREA")[2]
        except:
            w, h = root.get_size()
            self.__work_area = 0, 0, w, h
        self.__position = self.__work_area[0] + self.__work_area[2] - 20, self.__work_area[1] + self.__work_area[3] - 20
        self.__toplevel.move(*self.__position)
Exemplo n.º 16
0
  def cb_motion_notify(self, widget, event):
    """ Callback from mouse motion notify events """
    if (self.picking):
      # check if we are over the magnified image. if so, select from it
      a = self.allocation
      r = self.mag.allocation
      ox,oy = self.mag.origin()
      x = a.x + event.x - r.x
      y = a.y + event.y - r.y
      zx = int((x-ox)/self.mag.zoom)
      zy = int((y-oy)/self.mag.zoom)

      if (self.mag.has_data and
          (x >= 0 and x < r.width) and
          (y >= 0 and y < r.height) and
          (zx >= 0 and zx < self.mag.raw_width) and
          (zy >= 0 and zy < self.mag.raw_height)):
        self.pick(zx, zy, True)

      # otherwise, select from screen
      else:
        root_w, root_h = gdk.get_default_root_window().get_size()
        x = event.x_root
        y = event.y_root

        if (x < 0): x = 0
        if (x >= root_w): x = root_w - 1
        if (y < 0): y = 0
        if (y >= root_h): y = root_h - 1

        self.pick(x, y, False)
    def _get_root_bbox(self):
        root_window = gdk.get_default_root_window()
        args = root_window.get_position() + root_window.get_size()

        root_bbox = gdk.Rectangle(*args)

        current_screen = gtk.gdk.screen_get_default().get_number()
        for panel in self._gconf_client.all_dirs('/apps/panel/toplevels'):
            orientation = self._gconf_client.get_string(panel + '/orientation')
            size = self._gconf_client.get_int(panel + '/size')
            screen = self._gconf_client.get_int(panel + '/screen')
            if screen != current_screen:
                continue
            if orientation == 'top':
                root_bbox.y += size
                root_bbox.height -= size
            elif orientation == 'bottom':
                root_bbox.height -= size
            elif orientation == 'right':
                root_bbox.x += size
                root_bbox.width -= size
            elif orientation == 'left':
                root_bbox.x -= size

        return root_bbox
    def _get_root_bbox(self):
        root_window = gdk.get_default_root_window()
        args = root_window.get_position() + root_window.get_size()

        root_bbox = gdk.Rectangle(*args)

        current_screen = gtk.gdk.screen_get_default().get_number()
        for panel in self._gconf_client.all_dirs('/apps/panel/toplevels'):
            orientation = self._gconf_client.get_string(panel+'/orientation')
            size = self._gconf_client.get_int(panel+'/size')
            screen = self._gconf_client.get_int(panel+'/screen')
            if screen != current_screen:
                continue
            if orientation == 'top':
                root_bbox.y += size
                root_bbox.height -= size
            elif orientation == 'bottom':
                root_bbox.height -= size
            elif orientation == 'right':
                root_bbox.x += size
                root_bbox.width -= size
            elif orientation == 'left':
                root_bbox.x -= size
        
        return root_bbox
Exemplo n.º 19
0
def dump_windows():
    root = gdk.get_default_root_window()
    log("root window: %s" % root)
    children = get_children(root)
    log("%s windows" % len(children))
    for window in get_children(root):
        log("found window: %s", window_info(window))
Exemplo n.º 20
0
 def do_unmanaged(self, wm_exiting):
     log("unmanaging window: %s (%s - %s)", self, self.corral_window,
         self.client_window)
     self._internal_set_property("owner", None)
     if self.corral_window:
         remove_event_receiver(self.corral_window, self)
         geom = None
         #use a new context so we will XSync right here
         #and detect if the window is already gone:
         with XSwallowContext():
             geom = X11Window.getGeometry(self.xid)
         if geom is not None:
             if self.client_reparented:
                 self.client_window.reparent(gdk.get_default_root_window(),
                                             0, 0)
             self.client_window.set_events(self.client_window_saved_events)
         self.client_reparented = False
         #it is now safe to destroy the corral window:
         self.corral_window.destroy()
         self.corral_window = None
         # It is important to remove from our save set, even after
         # reparenting, because according to the X spec, windows that are
         # in our save set are always Mapped when we exit, *even if those
         # windows are no longer inferior to any of our windows!* (see
         # section 10. Connection Close).  This causes "ghost windows", see
         # bug #27:
         if self.in_save_set:
             with xswallow:
                 X11Window.XRemoveFromSaveSet(self.xid)
             self.in_save_set = False
         with xswallow:
             X11Window.sendConfigureNotify(self.xid)
         if wm_exiting:
             self.client_window.show_unraised()
     BaseWindowModel.do_unmanaged(self, wm_exiting)
Exemplo n.º 21
0
def set_background(path):
	# Note that the path is not unlinked, because gconf and xfconf set bg
	#  asynchronously, so there's no way of knowing when the image will
	#  actually be used

	if 'gsettings' in conf.bg_set_methods:
		## GSettings - newer GNOME, Unity
		# Using gi.repository.Gio here directly is tricky alongside gimp's gtk2
		from subprocess import call
		from urllib import quote
		call([ 'gsettings', 'set',
			'org.gnome.desktop.background', 'picture-uri',
			'file://{0}'.format(quote(path)) ])

	if 'gconf' in conf.bg_set_methods:
		## Gconf - older GNOME, XFCE/nautilus and such
		try:
			import gconf
			gconf = gconf.client_get_default()
			gconf.set_string(
				'/desktop/gnome/background/picture_filename', path )
		except ImportError: pass

	if 'xfconf' in conf.bg_set_methods:
		## Xfconf (via dbus interface) - XFCE/xfdesktop
		try: import dbus
		except ImportError: pass
		else:
			try:
				xfconf = dbus.Interface(
					dbus.SessionBus().get_object(
						'org.xfce.Xfconf', '/org/xfce/Xfconf' ),
					dbus_interface='org.xfce.Xfconf' )
				for k,v in xfconf.GetAllProperties('xfce4-desktop', '/backdrop').iteritems():
					if k.endswith('/image-path'): xfconf.SetProperty('xfce4-desktop', k, path)
			except dbus.exceptions.DBusException: pass # no property/object/interface/etc

	if 'enlightenment' in conf.bg_set_methods:
		## E17+ edbus interface
		try: import dbus
		except ImportError: pass
		else:
			try:
				edbus = dbus.SessionBus().get_object(
						'org.enlightenment.wm.service', '/org/enlightenment/wm/RemoteObject' )
				dxc, dyc = edbus.GetVirtualCount(dbus_interface='org.enlightenment.wm.Desktop')
				edbus = dbus.Interface( edbus,
					dbus_interface='org.enlightenment.wm.Desktop.Background' )
				for dx, dy in it.product(xrange(dxc), xrange(dyc)): edbus.Add(0, dx, dy, path)
			except dbus.exceptions.DBusException: pass # no property/object/interface/etc

	if 'x-root-window' in conf.bg_set_methods:
		## Paint X root window via pygtk
		pb = gdk.pixbuf_new_from_file(path)
		pm, mask = pb.render_pixmap_and_mask()
		win = gdk.get_default_root_window()
		win.set_back_pixmap(pm, False)
		win.clear()
		win.draw_pixbuf(gdk.GC(win), pb, 0, 0, 0, 0, -1, -1)
Exemplo n.º 22
0
def take_screenshot(win=None):
    if win is None:
        win = gdk.get_default_root_window()
    sz = win.get_size()
    pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, sz[0], sz[1])
    pb = pb.get_from_drawable(win, win.get_colormap(), 0, 0, 0, 0, sz[0],
                              sz[1])
    return pb.get_pixels_array()
Exemplo n.º 23
0
 def init(self, w, h):
     old_backing = self._backing
     assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h)
     if self._has_alpha and HAS_RGBA:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             self._has_alpha = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = self._backing.cairo_create()
     cr.set_source_rgb(1, 1, 1)
     if old_backing is not None:
         # Really we should respect bit-gravity here but... meh.
         old_w, old_h = old_backing.get_size()
         #note: we may paint the rectangle (old_w, old_h) to (w, h) twice - no big deal
         if w>old_w:
             cr.new_path()
             cr.move_to(old_w, 0)
             cr.line_to(w, 0)
             cr.line_to(w, h)
             cr.line_to(old_w, h)
             cr.close_path()
             cr.fill()
         if h>old_h:
             cr.new_path()
             cr.move_to(0, old_h)
             cr.line_to(0, h)
             cr.line_to(w, h)
             cr.line_to(w, old_h)
             cr.close_path()
             cr.fill()
         cr.new_path()
         cr.move_to(0, 0)
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.set_source_pixmap(old_backing, 0, 0)
         cr.paint()
     else:
         cr.rectangle(0, 0, w, h)
         cr.fill()
Exemplo n.º 24
0
 def init(self, w, h):
     old_backing = self._backing
     assert w < 32768 and h < 32768, "dimensions too big: %sx%s" % (w, h)
     if self._has_alpha and HAS_RGBA:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             self._has_alpha = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = self._backing.cairo_create()
     cr.set_source_rgb(1, 1, 1)
     if old_backing is not None:
         # Really we should respect bit-gravity here but... meh.
         old_w, old_h = old_backing.get_size()
         #note: we may paint the rectangle (old_w, old_h) to (w, h) twice - no big deal
         if w > old_w:
             cr.new_path()
             cr.move_to(old_w, 0)
             cr.line_to(w, 0)
             cr.line_to(w, h)
             cr.line_to(old_w, h)
             cr.close_path()
             cr.fill()
         if h > old_h:
             cr.new_path()
             cr.move_to(0, old_h)
             cr.line_to(0, h)
             cr.line_to(w, h)
             cr.line_to(w, old_h)
             cr.close_path()
             cr.fill()
         cr.new_path()
         cr.move_to(0, 0)
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.set_source_pixmap(old_backing, 0, 0)
         cr.paint()
     else:
         cr.rectangle(0, 0, w, h)
         cr.fill()
Exemplo n.º 25
0
def f(t,width,height):
    time.sleep(t)
    w = g.get_default_root_window()
    sz = (width,height)
    pb = g.Pixbuf(g.COLORSPACE_RGB, False, 8,*sz)
    cm = w.get_colormap()
    pb = pb.get_from_drawable(w,cm,58,141,0,0,*sz)
    im = Image(pb.get_pixels_array()) #creates simplecv image from pixbuf
    return im
Exemplo n.º 26
0
Arquivo: tray.py Projeto: cattaka/Xpra
 def dock_tray(self, xid):
     log("dock_tray(%#x)", xid)
     root = gdk.get_default_root_window()
     window = gdk.window_foreign_new(xid)
     if window is None:
         log.warn("could not find gdk window for tray window %#x", xid)
         return
     log("dock_tray: root=%s, window=%s", root, window)
     w, h = window.get_geometry()[2:4]
     log("dock_tray: geometry=%s", (w, h))
     if w == 0 and h == 0:
         log("dock_tray: invalid tray geometry, ignoring this request")
         return
     event_mask = gdk.STRUCTURE_MASK | gdk.EXPOSURE_MASK | gdk.PROPERTY_CHANGE_MASK
     window.set_events(event_mask=event_mask)
     add_event_receiver(window, self)
     w = max(1, min(128, w))
     h = max(1, min(128, h))
     title = prop_get(window, "_NET_WM_NAME", "utf8", ignore_errors=True)
     if title is None:
         title = prop_get(window, "WM_NAME", "latin1", ignore_errors=True)
     if title is None:
         title = ""
     log(
         "dock_tray(%#x) gdk window=%#x, geometry=%s, title=%s, visual.depth=%s",
         xid, window.xid, window.get_geometry(), title,
         window.get_visual().depth)
     event_mask = gdk.STRUCTURE_MASK | gdk.EXPOSURE_MASK | gdk.PROPERTY_CHANGE_MASK
     tray_window = gdk.Window(root,
                              width=w,
                              height=h,
                              window_type=gdk.WINDOW_TOPLEVEL,
                              event_mask=event_mask,
                              wclass=gdk.INPUT_OUTPUT,
                              title=title,
                              x=-200,
                              y=-200,
                              override_redirect=True,
                              visual=window.get_visual(),
                              colormap=window.get_colormap())
     log("dock_tray(%#x) setting tray properties", xid)
     set_tray_window(tray_window, window)
     tray_window.show()
     self.tray_windows[window] = tray_window
     self.window_trays[tray_window] = window
     log("dock_tray(%#x) resizing and reparenting", xid)
     window.resize(w, h)
     xwin = window.xid
     xtray = tray_window.xid
     X11Window.Withdraw(xwin)
     X11Window.Reparent(xwin, xtray, 0, 0)
     X11Window.MapRaised(xwin)
     log("dock_tray(%#x) new tray container window %#x", xid, xtray)
     tray_window.invalidate_rect(gdk.Rectangle(width=w, height=h), True)
     X11Window.send_xembed_message(xwin, XEMBED_EMBEDDED_NOTIFY, 0, xtray,
                                   XEMBED_VERSION)
Exemplo n.º 27
0
 def do_init_new_backing_instance(self):
     w, h = self.size
     self._backing = None
     assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h)
     if w==0 or h==0:
         #this can happen during cleanup
         return
     if self._alpha_enabled:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             log.warn("cannot use transparency: no RGBA colormap!")
             self._alpha_enabled = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
Exemplo n.º 28
0
 def _gtk_screenshot(self, path):
     window = gdk.get_default_root_window()
     if not window:
         raise RuntimeError('Taking screenshot failed')
     width, height = window.get_size()
     pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height)
     pb = pb.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0,
                               width, height)
     if not pb:
         raise RuntimeError('Taking screenshot failed')
     pb.save(path, 'jpeg')
Exemplo n.º 29
0
 def _gtk_screenshot(self, path):
     window = gdk.get_default_root_window()
     if not window:
         raise RuntimeError('Taking screenshot failed')
     width, height = window.get_size()
     pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height)
     pb = pb.get_from_drawable(window, window.get_colormap(),
                               0, 0, 0, 0, width, height)
     if not pb:
         raise RuntimeError('Taking screenshot failed')
     pb.save(path, 'jpeg')
Exemplo n.º 30
0
def _grab_screenshot_gtk_py2():
    window = gdk.get_default_root_window()
    if not window:
        raise RuntimeError('Taking screenshot failed.')
    width, height = window.get_size()
    pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height)
    pb = pb.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0, width,
                              height)
    if not pb:
        raise RuntimeError('Taking screenshot failed.')
    return pb
Exemplo n.º 31
0
 def do_init_new_backing_instance(self):
     w, h = self.size
     self._backing = None
     assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h)
     if w==0 or h==0:
         #this can happen during cleanup
         return
     if self._alpha_enabled:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             log.warn("cannot use transparency: no RGBA colormap!")
             self._alpha_enabled = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
Exemplo n.º 32
0
def get_workarea():
    """
    List with x-offset, y-offset, width and height in pixel of the first desktop
    workarea relative to the root window.
    TODO: take not the first, but the current desktop (right now, all
    desktops are the same size, so it doesn't bother me)
    """
    root_win = gdk.get_default_root_window()
    win_property = gdk.atom_intern("_NET_WORKAREA")
    wa_list = root_win.property_get(win_property)[2]
    return ([wa_list[0], wa_list[1], wa_list[2], wa_list[3]])
Exemplo n.º 33
0
 def init(self, w, h):
     old_backing = self._backing
     assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h)
     if self._has_alpha and HAS_ALPHA:
         self._backing = gdk.Pixmap(None, w, h, 32)
         screen = self._backing.get_screen()
         rgba = screen.get_rgba_colormap()
         if rgba is not None:
             self._backing.set_colormap(rgba)
         else:
             #cannot use transparency
             self._has_alpha = False
             self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     else:
         self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
     cr = self._backing.cairo_create()
     cr.set_source_rgb(1, 1, 1)
     if old_backing is not None:
         # Really we should respect bit-gravity here but... meh.
         old_w, old_h = old_backing.get_size()
         if w>old_w and h>old_h:
             #both width and height are bigger:
             cr.rectangle(old_w, 0, w-old_w, h)
             cr.fill()
             cr.new_path()
             cr.rectangle(0, old_h, old_w, h-old_h)
             cr.fill()
         elif w>old_w:
             #enlarged in width only
             cr.rectangle(old_w, 0, w-old_w, h)
             cr.fill()
         if h>old_h:
             #enlarged in height only
             cr.rectangle(0, old_h, w, h-old_h)
             cr.fill()
         cr.set_operator(cairo.OPERATOR_SOURCE)
         cr.set_source_pixmap(old_backing, 0, 0)
         cr.paint()
     else:
         cr.rectangle(0, 0, w, h)
         cr.fill()
Exemplo n.º 34
0
 def motion_notify_event(self, win, event):
     """Mouse motion_notify_event handler"""
     pixbuf = Pixbuf(COLORSPACE_RGB, False, 8, 1, 1)
     root = get_default_root_window()
     xcoord, ycoord = event.get_root_coords()
     from_draw = pixbuf.get_from_drawable(root, root.get_colormap(),
                                          int(xcoord), int(ycoord),
                                          0, 0, 1, 1)
     pixel = from_draw.get_pixels_array()[0][0]
     self.rgb = (pixel[0], pixel[1], pixel[2])
     self.draw_color()
     self.label.set_label(rgb_to_string(self.rgb).upper())
Exemplo n.º 35
0
def get_screenshot(x=0, y=0, w=None, h=None, grayscale=True):
    window = gg.get_default_root_window()
    if not (w and h):
        w, h = window.get_size()
    pixbuf = gg.Pixbuf(gg.COLORSPACE_RGB, False, 8, w, h)
    pixbuf = pixbuf.get_from_drawable(window, window.get_colormap(),x,y,0,0,w,h)
    pixbuf.save('sc.png', 'png')
    if grayscale:
        img = cv2.imread('sc.png',0)
    else:
        img = cv2.imread('sc.png')
    os.remove('sc.png')
    return img
Exemplo n.º 36
0
Arquivo: handle.py Projeto: iwaim/ibus
    def __init__ (self):
        super(Handle, self).__init__()
        self.set_visible_window(False)
        self.set_size_request(10, -1)
        self.set_events(
            gdk.EXPOSURE_MASK | \
            gdk.BUTTON_PRESS_MASK | \
            gdk.BUTTON_RELEASE_MASK | \
            gdk.BUTTON1_MOTION_MASK)

        self.__move_begined = False

        root = gdk.get_default_root_window()
Exemplo n.º 37
0
 def _bell_signaled(self, wm, event):
     log("bell signaled on window %#x", get_xwindow(event.window))
     if not self.bell:
         return
     wid = 0
     if event.window!=gdk.get_default_root_window() and event.window_model is not None:
         try:
             wid = self._window_to_id[event.window_model]
         except:
             pass
     log("_bell_signaled(%s,%r) wid=%s", wm, event, wid)
     for ss in self._server_sources.values():
         ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, event.bell_name or "")
Exemplo n.º 38
0
    def __init__(self):
        super(Handle, self).__init__()
        self.set_visible_window(False)
        self.set_size_request(10, -1)
        self.set_events(
            gdk.EXPOSURE_MASK | \
            gdk.BUTTON_PRESS_MASK | \
            gdk.BUTTON_RELEASE_MASK | \
            gdk.BUTTON1_MOTION_MASK)

        self.__move_begined = False

        root = gdk.get_default_root_window()
Exemplo n.º 39
0
def _get_window_by_title(title):
    root = gdk.get_default_root_window()
    if not root:
        return
    extents = _get_win_property(root, '_NET_CLIENT_LIST')
    if not extents:
        return

    for id in extents:
        w = gdk.window_foreign_new(id)
        if w:
            wm_name = w.property_get("WM_NAME")
            if wm_name and title == wm_name[2]:
                return w
Exemplo n.º 40
0
    def activate():
        screen = gdk.screen_get_default()

        screenWidth  = screen.get_width()
        screenHeight = screen.get_height()

        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, screenWidth, screenHeight)
        screenshot = gdk.Pixbuf.get_from_drawable(pixbuf, gdk.get_default_root_window(), gdk.colormap_get_system(), 0, 0, 0, 0, screenWidth, screenHeight)
        screenshot.save(os.path.join(tempfile.gettempdir(), 'perdyselection.png'), 'png')

        areaWindow = AreaWindow(screenWidth, screenHeight)
        areaWindow.move(0, 0)
        areaWindow.setFixedSize(screenWidth, screenHeight)
        areaWindow.show()
Exemplo n.º 41
0
def _get_window_by_title(title):
    root = gdk.get_default_root_window()
    if not root:
        return
    extents = _get_win_property(root, '_NET_CLIENT_LIST')
    if not extents:
        return

    for id in extents:
        w = gdk.window_foreign_new(id)
        if w:
            wm_name = w.property_get("WM_NAME")
            if wm_name and title == wm_name[2]:
                return w
Exemplo n.º 42
0
def _get_window_by_pid(pid):
    root = gdk.get_default_root_window()
    if not root:
        return
    extents = _get_win_property(root, '_NET_CLIENT_LIST')
    if not extents:
        return

    for id in extents:
        w = gdk.window_foreign_new(id)
        if w:
            wm_pids = w.property_get("_NET_WM_PID")
            if pid in wm_pids[2]:
                return w
Exemplo n.º 43
0
def _get_window_by_pid(pid):
    root = gdk.get_default_root_window()
    if not root:
        return
    extents = _get_win_property(root, '_NET_CLIENT_LIST')
    if not extents:
        return

    for id in extents:
        w = gdk.window_foreign_new(id)
        if w:
            wm_pids = w.property_get("_NET_WM_PID")
            if pid in wm_pids[2]:
                return w
Exemplo n.º 44
0
    def cb_motion_notify(self, widget, event):
        """
    Callback for mouse motion notify events

    If magnifying, calculates the size of a region centered on the
    mouse cursor that is just large enough to fill the widget when
    scaled up by the zoom factor. Then queues a grab of this region.

    If measuring, updates measurement rectangle.

    If panning, updates pan.
    """
        if self.grabbing:
            root_w, root_h = gdk.get_default_root_window().get_size()
            w = int(math.ceil(float(self.allocation.width) / self.zoom))
            h = int(math.ceil(float(self.allocation.height) / self.zoom))
            x = event.x_root - int(w / 2)
            y = event.y_root - int(h / 2)

            if x < 0:
                x = 0
            if x > root_w - w:
                x = root_w - w
            if y < 0:
                y = 0
            if y > root_h - h:
                y = root_h - h

            self.grab(x, y, w, h)

        elif self.panning:
            pan_x = int(event.x - self.pan_start_x)
            pan_y = int(event.y - self.pan_start_y)

            self.pan(pan_x, pan_y)

        elif self.measuring:
            x0, y0 = self.coord_widget_to_pixbuf(*self.measure_start)
            x1, y1 = self.coord_widget_to_pixbuf(event.x, event.y)

            if x0 > x1:
                x0, x1 = x1, x0
            if y0 > y1:
                y0, y1 = y1, y0

            rect = gdk.Rectangle(x0, y0, x1 - x0 + 1, y1 - y0 + 1)
            if rect != self.measure_rect:
                self.measure_rect = rect
                self.emit("measure-changed")
                self.queue_draw()
Exemplo n.º 45
0
 def do_button_press_event(self, widget, event, data=None):
     if event.button == 1:
         root = gdk.get_default_root_window()
         try:
             desktop = root.property_get("_NET_CURRENT_DESKTOP")[2][0]
             self.__workarea = root.property_get("_NET_WORKAREA")[2][desktop * 4: (desktop + 1) * 4]
         except:
             self.__workarea = None
         self.__move_begined = True
         toplevel = self.get_toplevel()
         x, y = toplevel.get_position()
         self.__press_pos = event.x_root - x, event.y_root - y
         self.window.set_cursor(gdk.Cursor(gdk.FLEUR))
         return True
     return False
Exemplo n.º 46
0
def get_x11_property(atom_name):
    if sys.platform.startswith("win"):
        return ""
    try:
        from gtk import gdk
        root = gdk.get_default_root_window()
        pulse_server_atom = gdk.atom_intern(atom_name)
        p = root.property_get(pulse_server_atom)
        if p is None:
            return ""
        v = p[2]
        log("%s=%s", atom_name, v)
        return v
    except:
        return ""
Exemplo n.º 47
0
def get_x11_property(atom_name):
    if sys.platform.startswith("win"):
        return ""
    try:
        from gtk import gdk
        root = gdk.get_default_root_window()
        pulse_server_atom = gdk.atom_intern(atom_name)
        p = root.property_get(pulse_server_atom)
        if p is None:
            return ""
        v = p[2]
        debug("get_x11_property(%s)=%s", atom_name, v)
        return v
    except:
        return ""
Exemplo n.º 48
0
def dump_windows():
    from xpra.log import Logger
    log = Logger("x11", "window")
    from gtk import gdk
    root = gdk.get_default_root_window()
    log("root window: %s" % root)
    try:
        from xpra.x11.gtk2.gdk_bindings import get_children #@UnresolvedImport
    except ImportError:
        pass
    else:
        children = get_children(root)
        log("%s windows" % len(children))
        for window in get_children(root):
            log("found window: %s", window_info(window))
Exemplo n.º 49
0
def _record_gtk_py2(path, fps, stop):
    window = gdk.get_default_root_window()
    fourcc = cv2.VideoWriter_fourcc(*'VP08')
    width, height = window.get_size()
    with suppress_stderr():
        vid = cv2.VideoWriter('%s' % path, fourcc, fps, (width, height))
    while not stop.isSet():
        pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height)
        pb = pb.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0,
                                  width, height)
        numpy_array = pb.get_pixels_array()
        frame = cv2.cvtColor(numpy_array, cv2.COLOR_RGB2BGR)
        vid.write(frame)
    vid.release()
    cv2.destroyAllWindows()
Exemplo n.º 50
0
Arquivo: tray.py Projeto: cattaka/Xpra
 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
Exemplo n.º 51
0
def get_x11_property(atom_name):
    from xpra.os_util import WIN32, OSX
    if WIN32 or OSX:
        return ""
    try:
        from gtk import gdk
        root = gdk.get_default_root_window()
        atom = gdk.atom_intern(atom_name)
        p = root.property_get(atom)
        if p is None:
            return ""
        v = p[2]
        log("get_x11_property(%s)=%s", atom_name, v)
        return v
    except:
        return ""
Exemplo n.º 52
0
 def _bell_signaled(self, wm, event):
     log("bell signaled on window %#x", get_xwindow(event.window))
     if not self.bell:
         return
     wid = 0
     if event.window != gdk.get_default_root_window(
     ) and event.window_model is not None:
         try:
             wid = self._window_to_id[event.window_model]
         except:
             pass
     log("_bell_signaled(%s,%r) wid=%s", wm, event, wid)
     for ss in self._server_sources.values():
         ss.bell(wid, event.device, event.percent, event.pitch,
                 event.duration, event.bell_class, event.bell_id,
                 event.bell_name or "")
Exemplo n.º 53
0
def _take_gtk_screen_size():
    if not gdk and not Gdk:
        raise RuntimeError('PyGTK not installed/supported on this platform.')
    if gdk:
        window = gdk.get_default_root_window()
        if not window:
            raise RuntimeError('Taking screenshot failed.')
        width, height = window.get_size()
        return width, height
    elif Gdk:
        window = Gdk.get_default_root_window()
        if not window:
            raise RuntimeError('Taking screenshot failed.')
        width = window.get_width()
        height = window.get_height()
        return width, height
Exemplo n.º 54
0
 def serverlist(self):
     ''' get the serverlist from the X root window '''
     rootwindow = gdk.get_default_root_window()
     # Read the property
     propval = rootwindow.property_get("VimRegistry")
     res = {}
     if propval:
         prop = propval[-1].split('\0')
         for r in prop:
             if r:
                 rs = r.split()
                 id = long(int(rs[0], 16))
                 name = rs[1]
                 w = self.server_exists(id)
                 if w and not (name in self.bad_servers):
                     res[name] = id
     return res
Exemplo n.º 55
0
def peek_gtk():
    """Takes a screenshot using gtk."""
    from gtk import gdk
    window = gdk.get_default_root_window()
    size = window.get_size()
    buff = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, size[0], size[1])
    buff = buff.get_from_drawable(window, window.get_colormap(),
                                  0, 0, 0, 0, size[0], size[1])
    if buff is None:
        raise PeekUnableToPeek()

    path = _gettempfile()
    buff.save(path, "png")
    screenshot = _file2screen(path)
    screenshot.fmt = "png"

    return screenshot
Exemplo n.º 56
0
 def __get_xkb_layout(self):
     root_window = get_default_root_window()
     if not root_window:
         return 0
     prop = root_window.property_get("_XKB_RULES_NAMES")[2]
     list = prop.split('\0')
     layout = 0
     for data in list:
         if data == "jp":
             layout = 0
         elif data == "us":
             layout = 1
         elif data.find("japan:nicola_f_bs") >= 0:
             layout = 2
         elif data.find("japan:") >= 0:
             layout = 0
     return layout
Exemplo n.º 57
0
    def __check_position(self):
        bx = self.__cursor_location[0] + self.__toplevel.allocation.width
        by = self.__cursor_location[1] + self.__toplevel.allocation.height

        root_window = gdk.get_default_root_window()
        sx, sy = root_window.get_size()

        if bx > sx:
            x = sx - self.__toplevel.allocation.width
        else:
            x = self.__cursor_location[0]

        if by > sy:
            y = sy - self.__toplevel.allocation.height
        else:
            y = self.__cursor_location[1]

        self.move(x, y)