Beispiel #1
0
    def _finalize_text(self, widget, textview):
        # get the Gdk.Window of the TextWindow child of the TextView
        window = textview.get_window(Gtk.TextWindowType.TEXT)
        window.ensure_native()

        # paint the TextView TextWindow onto a surface and destroy it
        # FIXME: theoretically unnecessary, but empirically prevents
        # use of the window underneath the activity.
        width, height = window.get_width(), window.get_height()
        surface = Gdk.Window.create_similar_surface(window,
                                                    cairo.CONTENT_COLOR,
                                                    width, height)
        ctx = cairo.Context(surface)
        Gdk.cairo_set_source_window(ctx, window, 0, 0)
        ctx.paint()
        surface = None  # destroy the copy

        # paint the Gtk.TextView TextWindow onto the drawing
        ctx = widget.drawing_ctx
        tv_alloc = textview.get_allocation()
        Gdk.cairo_set_source_window(ctx, window, tv_alloc.x, tv_alloc.y)
        ctx.paint()

        widget.activity.textview.hide()
        widget.drawing_canvas.flush()

        textview.get_buffer().set_text('')

        widget.enable_undo()
        widget.queue_draw()
Beispiel #2
0
    def take_screenshot(self, capture_count=1):
        ''' Take a screenshot and save to the Journal '''
        tmp_file_path = os.path.join(
            os.environ['SUGAR_ACTIVITY_ROOT'], 'instance',
            'screen_capture_' + str(capture_count) + '.png')

        window = self.activity.wave.get_window()
        width, height = window.get_width(), window.get_height()
        surface = Gdk.Window.create_similar_surface(window,
                                                    cairo.CONTENT_COLOR,
                                                    width, height)
        cr = cairo.Context(surface)
        Gdk.cairo_set_source_window(cr, window, 0, 0)
        cr.paint()
        surface.write_to_png(tmp_file_path)

        if os.path.exists(tmp_file_path):
            dsobject = datastore.create()
            try:
                dsobject.metadata['title'] = '%s %d' % (_('Waveform'),
                                                        capture_count)
                dsobject.metadata['keep'] = '0'
                dsobject.metadata['buddies'] = ''
                dsobject.metadata['preview'] = self._get_preview_data(surface)
                dsobject.metadata['icon-color'] = self.activity.icon_colors
                dsobject.metadata['mime_type'] = 'image/png'
                dsobject.set_file_path(tmp_file_path)
                datastore.write(dsobject)
            finally:
                dsobject.destroy()
                del dsobject
            os.remove(tmp_file_path)
            return True
        return False
Beispiel #3
0
    def take_screenshot(self, capture_count=1):
        ''' Take a screenshot and save to the Journal '''
        tmp_file_path = os.path.join(
            os.environ['SUGAR_ACTIVITY_ROOT'], 'instance',
            'screen_capture_' + str(capture_count) + '.png')

        window = self.activity.wave.get_window()
        width, height = window.get_width(), window.get_height()
        surface = Gdk.Window.create_similar_surface(window,
                                                    cairo.CONTENT_COLOR, width,
                                                    height)
        cr = cairo.Context(surface)
        Gdk.cairo_set_source_window(cr, window, 0, 0)
        cr.paint()
        surface.write_to_png(tmp_file_path)

        if os.path.exists(tmp_file_path):
            dsobject = datastore.create()
            try:
                dsobject.metadata['title'] = '%s %d' % (_('Waveform'),
                                                        capture_count)
                dsobject.metadata['keep'] = '0'
                dsobject.metadata['buddies'] = ''
                dsobject.metadata['preview'] = self._get_preview_data(surface)
                dsobject.metadata['icon-color'] = self.activity.icon_colors
                dsobject.metadata['mime_type'] = 'image/png'
                dsobject.set_file_path(tmp_file_path)
                datastore.write(dsobject)
            finally:
                dsobject.destroy()
                del dsobject
            os.remove(tmp_file_path)
            return True
        return False
Beispiel #4
0
    def _finalize_text(self, widget, textview):
        # get the Gdk.Window of the TextWindow child of the TextView
        window = textview.get_window(Gtk.TextWindowType.TEXT)
        window.ensure_native()

        # paint the TextView TextWindow onto a surface and destroy it
        # FIXME: theoretically unnecessary, but empirically prevents
        # use of the window underneath the activity.
        width, height = window.get_width(), window.get_height()
        surface = Gdk.Window.create_similar_surface(window,
                                                    cairo.CONTENT_COLOR, width,
                                                    height)
        ctx = cairo.Context(surface)
        Gdk.cairo_set_source_window(ctx, window, 0, 0)
        ctx.paint()
        surface = None  # destroy the copy

        # paint the Gtk.TextView TextWindow onto the drawing
        ctx = widget.drawing_ctx
        tv_alloc = textview.get_allocation()
        Gdk.cairo_set_source_window(ctx, window, tv_alloc.x, tv_alloc.y)
        ctx.paint()

        widget.activity.textview.hide()
        widget.drawing_canvas.flush()

        textview.get_buffer().set_text('')

        widget.enable_undo()
        widget.queue_draw()
Beispiel #5
0
def widget_pixbuf(widget, maxsize=None):
    """Generate a pixbuf of a widget"""
    # FIXME: Can this be changed from using "import cairo" to "from gi.repository import cairo"?
    window = widget.get_window()
    width, height = window.get_width(), window.get_height()

    longest = max(width, height)

    if maxsize is not None:
        factor = float(maxsize) / float(longest)

    if not maxsize or (width * factor) > width or (height * factor) > height:
        factor = 1

    preview_width, preview_height = int(width * factor), int(height * factor)

    preview_surface = Gdk.Window.create_similar_surface(window,
        cairo.CONTENT_COLOR, preview_width, preview_height)

    cairo_context = cairo.Context(preview_surface)
    cairo_context.scale(factor, factor)
    Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
    cairo_context.paint()

    scaledpixbuf = Gdk.pixbuf_get_from_surface(preview_surface, 0, 0, preview_width, preview_height);

    return scaledpixbuf
Beispiel #6
0
def widget_pixbuf(widget, maxsize=None):
    """Generate a pixbuf of a widget"""
    # FIXME: Can this be changed from using "import cairo" to "from gi.repository import cairo"?
    window = widget.get_window()
    width, height = window.get_width(), window.get_height()

    longest = max(width, height)

    if maxsize is not None:
        factor = float(maxsize) / float(longest)

    if not maxsize or (width * factor) > width or (height * factor) > height:
        factor = 1

    preview_width, preview_height = int(width * factor), int(height * factor)

    preview_surface = Gdk.Window.create_similar_surface(window,
        cairo.CONTENT_COLOR, preview_width, preview_height)

    cairo_context = cairo.Context(preview_surface)
    cairo_context.scale(factor, factor)
    Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
    cairo_context.paint()

    scaledpixbuf = Gdk.pixbuf_get_from_surface(preview_surface, 0, 0, preview_width, preview_height);
    
    return(scaledpixbuf)
Beispiel #7
0
def take_screenshot():
    tmp_dir = os.path.join(env.get_profile_path(), 'data')
    fd, file_path = tempfile.mkstemp(dir=tmp_dir)
    os.close(fd)

    window = Gdk.get_default_root_window()
    width, height = window.get_width(), window.get_height()

    screenshot_surface = Gdk.Window.create_similar_surface(
        window, cairo.CONTENT_COLOR, width, height)

    cr = cairo.Context(screenshot_surface)
    Gdk.cairo_set_source_window(cr, window, 0, 0)
    cr.paint()
    screenshot_surface.write_to_png(file_path)

    settings = Gio.Settings('org.sugarlabs.user')
    color = settings.get_string('color')

    content_title = None
    shell_model = shell.get_model()
    zoom_level = shell_model.zoom_level

    # TRANS: Nouns of what a screenshot contains
    if zoom_level == shell_model.ZOOM_MESH:
        content_title = _('Mesh')
    elif zoom_level == shell_model.ZOOM_GROUP:
        content_title = _('Group')
    elif zoom_level == shell_model.ZOOM_HOME:
        content_title = _('Home')
    elif zoom_level == shell_model.ZOOM_ACTIVITY:
        activity = shell_model.get_active_activity()
        if activity is not None:
            content_title = activity.get_title()
            if content_title is None:
                content_title = _('Activity')

    if content_title is None:
        title = _('Screenshot')
    else:
        title = _('Screenshot of \"%s\"') % content_title

    jobject = datastore.create()
    try:
        jobject.metadata['title'] = title
        jobject.metadata['keep'] = '0'
        jobject.metadata['buddies'] = ''
        jobject.metadata['preview'] = _get_preview_data(screenshot_surface)
        jobject.metadata['icon-color'] = color
        jobject.metadata['mime_type'] = 'image/png'
        jobject.file_path = file_path
        datastore.write(jobject, transfer_ownership=True)
    finally:
        jobject.destroy()
        del jobject

    return title
Beispiel #8
0
def take_screenshot():
    tmp_dir = os.path.join(env.get_profile_path(), 'data')
    fd, file_path = tempfile.mkstemp(dir=tmp_dir)
    os.close(fd)

    window = Gdk.get_default_root_window()
    width, height = window.get_width(), window.get_height()

    screenshot_surface = Gdk.Window.create_similar_surface(
        window, cairo.CONTENT_COLOR, width, height)

    cr = cairo.Context(screenshot_surface)
    Gdk.cairo_set_source_window(cr, window, 0, 0)
    cr.paint()
    screenshot_surface.write_to_png(file_path)

    settings = Gio.Settings('org.sugarlabs.user')
    color = settings.get_string('color')

    content_title = None
    shell_model = shell.get_model()
    zoom_level = shell_model.zoom_level

    # TRANS: Nouns of what a screenshot contains
    if zoom_level == shell_model.ZOOM_MESH:
        content_title = _('Mesh')
    elif zoom_level == shell_model.ZOOM_GROUP:
        content_title = _('Group')
    elif zoom_level == shell_model.ZOOM_HOME:
        content_title = _('Home')
    elif zoom_level == shell_model.ZOOM_ACTIVITY:
        activity = shell_model.get_active_activity()
        if activity is not None:
            content_title = activity.get_title()
            if content_title is None:
                content_title = _('Activity')

    if content_title is None:
        title = _('Screenshot')
    else:
        title = _('Screenshot of \"%s\"') % content_title

    jobject = datastore.create()
    try:
        jobject.metadata['title'] = title
        jobject.metadata['keep'] = '0'
        jobject.metadata['buddies'] = ''
        jobject.metadata['preview'] = _get_preview_data(screenshot_surface)
        jobject.metadata['icon-color'] = color
        jobject.metadata['mime_type'] = 'image/png'
        jobject.file_path = file_path
        datastore.write(jobject, transfer_ownership=True)
    finally:
        jobject.destroy()
        del jobject

    return title
Beispiel #9
0
 def make_screenshot(self):
     gdk_win = self.get_window()
     width = gdk_win.get_width()
     height = gdk_win.get_height()
     ims = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
     cr = cairo.Context(ims)
     Gdk.cairo_set_source_window(cr, gdk_win, 0, 0)
     cr.paint()
     ims.write_to_png("screenshot-%.4d.png" % self.current_round)
Beispiel #10
0
    def after_draw(win, e):
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
        cr = cairo.Context(surface)
        Gdk.cairo_set_source_window(cr, get_window(widget), 0, 0)
        cr.paint()
        surface.write_to_png(output)
        logger.warn("Screenshot captured to %s", output)

        widget.disconnect(handler)
        # Reparent back
        temp.remove(widget)
        old.add(widget)
        temp.destroy()
        return False
Beispiel #11
0
    def _finalize_text(self, widget, textview):
        window = textview.get_window(Gtk.TextWindowType.TEXT)
        ctx = widget.drawing_ctx
        tv_alloc = textview.get_allocation()
        Gdk.cairo_set_source_window(ctx, window, tv_alloc.x, tv_alloc.y)
        ctx.paint()

        widget.activity.textview.hide()
        widget.drawing_canvas.flush()

        textview.get_buffer().set_text('')

        widget.enable_undo()
        widget.queue_draw()
Beispiel #12
0
    def after_draw(win, e):
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
        cr = cairo.Context(surface)
        Gdk.cairo_set_source_window(cr, get_window(widget), 0, 0)
        cr.paint()
        surface.write_to_png(output)
        logger.warning("Screenshot captured to %s", output)

        widget.disconnect(handler)
        # Reparent back
        temp.remove(widget)
        old.add(widget)
        temp.destroy()
        return False
Beispiel #13
0
    def _finalize_text(self):
        textview = self.textview
        window = textview.get_window(Gtk.TextWindowType.TEXT)

        # create a temporary surface with a print of the text in the textview
        tv_alloc = textview.get_allocation()
        self._text_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                                tv_alloc.width,
                                                tv_alloc.height)
        ctx = cairo.Context(self._text_surface)
        Gdk.cairo_set_source_window(ctx, window, 0, 0)
        ctx.paint()

        self.textviewbox.hide()
        self._box.redraw()
Beispiel #14
0
    def _finalize_text(self):
        textview = self.textview
        window = textview.get_window(Gtk.TextWindowType.TEXT)

        # create a temporary surface with a print of the text in the textview
        tv_alloc = textview.get_allocation()
        self._text_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                                tv_alloc.width,
                                                tv_alloc.height)
        ctx = cairo.Context(self._text_surface)
        Gdk.cairo_set_source_window(ctx, window, 0, 0)
        ctx.paint()

        self.textviewbox.hide()
        self._box.redraw()
Beispiel #15
0
def take_screen_shot():
    tmp_dir = os.path.join(env.get_profile_path(), 'data')
    fd, file_path = tempfile.mkstemp(dir=tmp_dir, suffix='.png')
    os.close(fd)

    window = Gdk.get_default_root_window()
    width, height = window.get_width(), window.get_height()

    screenshot_surface = Gdk.Window.create_similar_surface(
        window, cairo.CONTENT_COLOR, width, height)

    cr = cairo.Context(screenshot_surface)
    Gdk.cairo_set_source_window(cr, window, 0, 0)
    cr.paint()
    screenshot_surface.write_to_png(file_path)
    return file_path
Beispiel #16
0
def take_screen_shot():
    tmp_dir = os.path.join(env.get_profile_path(), 'data')
    fd, file_path = tempfile.mkstemp(dir=tmp_dir, suffix='.png')
    os.close(fd)

    window = Gdk.get_default_root_window()
    width, height = window.get_width(), window.get_height()

    screenshot_surface = Gdk.Window.create_similar_surface(
        window, cairo.CONTENT_COLOR, width, height)

    cr = cairo.Context(screenshot_surface)
    Gdk.cairo_set_source_window(cr, window, 0, 0)
    cr.paint()
    screenshot_surface.write_to_png(file_path)
    return file_path
Beispiel #17
0
    def _get_screenshot(self):
        browser = self._tabbed_view.props.current_browser
        window = browser.get_window()
        width, height = window.get_width(), window.get_height()

        thumb_surface = Gdk.Window.create_similar_surface(
            window, cairo.CONTENT_COLOR, THUMB_WIDTH, THUMB_HEIGHT)

        cairo_context = cairo.Context(thumb_surface)
        thumb_scale_w = THUMB_WIDTH * 1.0 / width
        thumb_scale_h = THUMB_HEIGHT * 1.0 / height
        cairo_context.scale(thumb_scale_w, thumb_scale_h)
        Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
        cairo_context.paint()

        thumb_str = StringIO.StringIO()
        thumb_surface.write_to_png(thumb_str)
        return thumb_str.getvalue()
    def _get_screenshot(self):
        browser = self._tabbed_view.props.current_browser
        window = browser.get_window()
        width, height = window.get_width(), window.get_height()

        thumb_surface = Gdk.Window.create_similar_surface(
            window, cairo.CONTENT_COLOR, THUMB_WIDTH, THUMB_HEIGHT)

        cairo_context = cairo.Context(thumb_surface)
        thumb_scale_w = THUMB_WIDTH * 1.0 / width
        thumb_scale_h = THUMB_HEIGHT * 1.0 / height
        cairo_context.scale(thumb_scale_w, thumb_scale_h)
        Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
        cairo_context.paint()

        thumb_str = StringIO.StringIO()
        thumb_surface.write_to_png(thumb_str)
        return thumb_str.getvalue()
Beispiel #19
0
    def _finalize_text(self, widget, textview):
        buf = textview.get_buffer()
        window = textview.get_window(Gtk.TextWindowType.TEXT)
        ctx = widget.drawing_ctx
        tv_alloc = textview.get_allocation()
        Gdk.cairo_set_source_window(ctx, window, tv_alloc.x, tv_alloc.y)
        ctx.paint()

        widget.activity.textview.hide()
        widget.drawing_canvas.flush()

        try:
            widget.activity.textview.set_text('')
        except AttributeError:
            buf.set_text('')

        widget.enable_undo()
        widget.queue_draw()
Beispiel #20
0
    def get_widget_image(self):
        # Gets an image for use as an icon in the WidgetChooser
        # Need to implement some way to call from a GUI menu.

        window = self.window.get_window()

        if window is None:
            return

        width, height = window.get_width(), window.get_height()

        surface = Gdk.Window.create_similar_surface(window,
                                                    cairo.CONTENT_COLOR, width,
                                                    height)
        cairo_context = cairo.Context(surface)
        Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
        cairo_context.paint()

        surface.write_to_png(os.path.join(self.widget_dir, 'widget.png'))
Beispiel #21
0
    def __init__(self, widget, browser, tray_widget):
        Animation.__init__(self, 0, 3)
        self._draw_hid = None
        self._widget = widget
        self._browser = browser
        self._tray_widget = tray_widget
        self._tray_widget.hide_thumb()

        self._balloc = browser.get_allocation()
        self._center = ((self._balloc.width) / 2.0,
                        (self._balloc.height) / 2.0)

        window = browser.get_window()
        width, height = window.get_width(), window.get_height()

        self._snap = Gdk.Window.create_similar_surface(
            window, cairo.CONTENT_COLOR, width, height)
        cairo_context = cairo.Context(self._snap)
        Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
        cairo_context.paint()
    def __init__(self, widget, browser, tray_widget):
        Animation.__init__(self, 0, 3)
        self._draw_hid = None
        self._widget = widget
        self._browser = browser
        self._tray_widget = tray_widget
        self._tray_widget.hide_thumb()

        self._balloc = browser.get_allocation()
        self._center = ((self._balloc.width) / 2.0,
                        (self._balloc.height) / 2.0)

        window = browser.get_window()
        width, height = window.get_width(), window.get_height()

        self._snap = Gdk.Window.create_similar_surface(
            window, cairo.CONTENT_COLOR, width, height)
        cairo_context = cairo.Context(self._snap)
        Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
        cairo_context.paint()
Beispiel #23
0
def thumbshot(width, height):
    """Return a thumbshot of the current screen as bytes."""
    root = Gdk.get_default_root_window()
    if root is None:
        raise RuntimeError('Cannot find the root window, is xorg running?')
    geometry = root.get_geometry()
    surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
    ctx = cairo.Context(surface)
    # TODO: check if this actually does client-size resizing
    ctx.scale(float(width) / geometry.width, float(height) / geometry.height)
    Gdk.cairo_set_source_window(ctx, root, 0, 0)
    ctx.paint()

    # TODO: is a pixbuf necessary, or can we get the bytes from the surface?
    pixbuf = Gdk.pixbuf_get_from_surface(surface, 0, 0, width, height)
    rowst = pixbuf.get_rowstride()
    pixels = pixbuf.get_pixels()

    return (b"%i\n%ix%i\n" % (rowst, width, height) + pixels
            # TODO: the last padding isn't included, so do it manually
            + b"\0" * (rowst * height - len(pixels)))