Experimental preview implementation using XShmGetImage.

Not hooked up yet.
master
Marco Pesenti Gritti 17 years ago
parent 2907b10dbb
commit eaef1eb015

@ -32,7 +32,9 @@ _sugarext_la_SOURCES = \
sugar-key-grabber.c \
sugar-key-grabber.h \
sugar-menu.h \
sugar-menu.c
sugar-menu.c \
sugar-preview.h \
sugar-preview.c
BUILT_SOURCES = \
_sugarext.c \

@ -22,6 +22,13 @@
(gtype-id "SUGAR_TYPE_MENU")
)
(define-object Preview
(in-module "Sugar")
(parent "GObject")
(c-name "SugarPreview")
(gtype-id "SUGAR_TYPE_PREVIEW")
)
(define-object IconEntry
(in-module "Sexy")
(parent "GtkEntry")
@ -150,3 +157,27 @@
(return-type "none")
)
;; From sugar-preview.h
(define-function sugar_preview_get_type
(c-name "sugar_preview_get_type")
(return-type "GType")
)
(define-method take_screenshot
(of-object "SugarPreview")
(c-name "sugar_preview_take_screenshot")
(return-type "none")
(parameters
'("GdkDrawable" "drawable")
)
)
(define-method save
(of-object "SugarPreview")
(c-name "sugar_preview_save")
(return-type "gboolean")
(parameters
'("const-char*" "key")
)
)

@ -7,6 +7,7 @@ headers
#include "sugar-address-entry.h"
#include "sugar-key-grabber.h"
#include "sugar-menu.h"
#include "sugar-preview.h"
#include "sexy-icon-entry.h"
#include <pygtk/pygtk.h>
@ -20,6 +21,7 @@ import gtk.Entry as PyGtkEntry_Type
import gtk.Menu as PyGtkMenu_Type
import gtk.Container as PyGtkContainer_Type
import gtk.gdk.Window as PyGdkWindow_Type
import gtk.gdk.Drawable as PyGdkDrawable_Type
import gtk.Image as PyGtkImage_Type
%%
ignore-glob

@ -0,0 +1,105 @@
/*
* Copyright (C) 2007, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gdk/gdkx.h>
#include <gtk/gtkwindow.h>
#include "sugar-preview.h"
static void sugar_preview_class_init (SugarPreviewClass *menu_class);
static void sugar_preview_init (SugarPreview *menu);
G_DEFINE_TYPE(SugarPreview, sugar_preview, G_TYPE_OBJECT)
gboolean
sugar_preview_save(SugarPreview *preview, const char *file_name)
{
GdkPixbuf *pixbuf;
if (preview->image != NULL) {
return FALSE;
}
pixbuf = gdk_pixbuf_get_from_image(NULL, preview->image, NULL,
0, 0, 0, 0,
preview->image->width,
preview->image->height);
gdk_pixbuf_save(pixbuf, file_name, "png", NULL);
if (preview->image != NULL) {
g_object_unref(G_OBJECT(preview->image));
preview->image = NULL;
}
return TRUE;
}
void
sugar_preview_take_screenshot(SugarPreview *preview, GdkDrawable *drawable)
{
GdkScreen *screen;
GdkVisual *visual;
GdkColormap *colormap;
gint width, height;
gdk_drawable_get_size(drawable, &width, &height);
screen = gdk_drawable_get_screen(drawable);
visual = gdk_drawable_get_visual(drawable);
colormap = gdk_drawable_get_colormap(drawable);
if (preview->image != NULL) {
g_object_unref(G_OBJECT(preview->image));
}
preview->image = gdk_image_new(GDK_IMAGE_SHARED, visual, width, height);
gdk_image_set_colormap(preview->image, colormap);
XShmGetImage(GDK_SCREEN_XDISPLAY(screen),
GDK_DRAWABLE_XID(drawable),
gdk_x11_image_get_ximage(preview->image),
0, 0, AllPlanes, ZPixmap);
}
static void
sugar_preview_dispose (GObject *object)
{
SugarPreview *preview = SUGAR_PREVIEW(object);
if (preview->image != NULL) {
g_object_unref(G_OBJECT(preview->image));
preview->image = NULL;
}
}
static void
sugar_preview_class_init(SugarPreviewClass *preview_class)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (preview_class);
g_object_class->dispose = sugar_preview_dispose;
}
static void
sugar_preview_init(SugarPreview *preview)
{
preview->image = NULL;
}

@ -0,0 +1,55 @@
/*
* Copyright (C) 2007, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __SUGAR_PREVIEW_H__
#define __SUGAR_PREVIEW_H__
#include <gdk/gdkdrawable.h>
G_BEGIN_DECLS
typedef struct _SugarPreview SugarPreview;
typedef struct _SugarPreviewClass SugarPreviewClass;
#define SUGAR_TYPE_PREVIEW (sugar_preview_get_type())
#define SUGAR_PREVIEW(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_PREVIEW, SugarPreview))
#define SUGAR_PREVIEW_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), SUGAR_TYPE_PREVIEW, SugarPreviewClass))
#define SUGAR_IS_PREVIEW(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_PREVIEW))
#define SUGAR_IS_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_PREVIEW))
#define SUGAR_PREVIEW_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_PREVIEW, SugarPreviewClass))
struct _SugarPreview {
GObject base_instance;
GdkImage *image;
};
struct _SugarPreviewClass {
GObjectClass base_class;
};
GType sugar_preview_get_type (void);
void sugar_preview_take_screenshot (SugarPreview *menu,
GdkDrawable *drawable);
gboolean sugar_preview_save (SugarPreview *menu,
const char *file_name);
G_END_DECLS
#endif /* __SUGAR_PREVIEW_H__ */

@ -1,376 +0,0 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-10-30 23:51+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../shell/intro/intro.py:67
msgid "Name:"
msgstr ""
#: ../shell/intro/intro.py:96
msgid "Click to change color:"
msgstr ""
#: ../shell/intro/intro.py:146
msgid "Back"
msgstr ""
#: ../shell/intro/intro.py:160
msgid "Done"
msgstr ""
#: ../shell/intro/intro.py:163
msgid "Next"
msgstr ""
#: ../shell/view/BuddyMenu.py:83
msgid "Remove friend"
msgstr ""
#: ../shell/view/BuddyMenu.py:86
msgid "Make friend"
msgstr ""
#: ../shell/view/BuddyMenu.py:92
msgid "Invite"
msgstr ""
#: ../shell/view/clipboardmenu.py:59 ../shell/view/frame/activitybutton.py:58
msgid "Remove"
msgstr ""
#: ../shell/view/clipboardmenu.py:64
msgid "Open"
msgstr ""
#. self._stop_item = MenuItem(_('Stop download'), 'stock-close')
#. TODO: Implement stopping downloads
#. self._stop_item.connect('activate', self._stop_item_activate_cb)
#. self.append_menu_item(self._stop_item)
#: ../shell/view/clipboardmenu.py:74
msgid "Add to journal"
msgstr ""
#: ../shell/view/clipboardmenu.py:200
#, python-format
msgid "Clipboard object: %s."
msgstr ""
#: ../shell/hardware/keydialog.py:149
msgid "Key Type:"
msgstr ""
#: ../shell/hardware/keydialog.py:169
msgid "Authentication Type:"
msgstr ""
#: ../shell/hardware/keydialog.py:250
msgid "Encryption Type:"
msgstr ""
#: ../shell/view/home/activitiesdonut.py:90
msgid "Starting..."
msgstr ""
#: ../shell/view/home/activitiesdonut.py:104
msgid "Resume"
msgstr ""
#: ../shell/view/home/activitiesdonut.py:111
#: ../lib/sugar/activity/activity.py:124
msgid "Stop"
msgstr ""
#: ../shell/view/Shell.py:267
msgid "Screenshot"
msgstr ""
#: ../shell/view/home/HomeBox.py:157
msgid "Reboot"
msgstr ""
#: ../shell/view/home/HomeBox.py:162
msgid "Shutdown"
msgstr ""
#: ../shell/view/home/HomeBox.py:168
msgid "Register"
msgstr ""
#. Only show disconnect when there's a mesh device, because mesh takes
#. priority over the normal wireless device. NM doesn't have a "disconnect"
#. method for a device either (for various reasons) so this doesn't
#. have a good mapping
#: ../shell/view/home/MeshBox.py:87 ../shell/view/home/MeshBox.py:186
#: ../shell/view/devices/network/wireless.py:113
#: ../shell/view/devices/network/mesh.py:83
msgid "Disconnect..."
msgstr ""
#: ../shell/view/home/MeshBox.py:184 ../shell/view/devices/network/mesh.py:37
#: ../shell/view/devices/network/mesh.py:62
#: ../shell/view/devices/network/mesh.py:66
msgid "Mesh Network"
msgstr ""
#: ../shell/view/devices/battery.py:38
msgid "My Battery life"
msgstr ""
#: ../shell/view/devices/battery.py:94
msgid "Battery charging"
msgstr ""
#: ../shell/view/devices/battery.py:96
msgid "Battery discharging"
msgstr ""
#: ../shell/view/devices/battery.py:98
msgid "Battery fully charged"
msgstr ""
#: ../shell/view/devices/network/wireless.py:61
msgid "Disconnected"
msgstr ""
#: ../shell/view/devices/network/wireless.py:131
msgid "Channel"
msgstr ""
#: ../shell/view/frame/zoomtoolbar.py:42
msgid "Neighborhood"
msgstr ""
#: ../shell/view/frame/zoomtoolbar.py:54
msgid "Group"
msgstr ""
#: ../shell/view/frame/zoomtoolbar.py:66
msgid "Home"
msgstr ""
#: ../shell/view/frame/zoomtoolbar.py:78
msgid "Activity"
msgstr ""
#: ../lib/sugar/activity/activity.py:107
msgid "Share with:"
msgstr ""
#: ../lib/sugar/activity/activity.py:109
msgid "Private"
msgstr ""
#: ../lib/sugar/activity/activity.py:110
msgid "My Neighborhood"
msgstr ""
#: ../lib/sugar/activity/activity.py:118
msgid "Keep"
msgstr ""
#: ../lib/sugar/activity/activity.py:237
msgid "Undo"
msgstr ""
#: ../lib/sugar/activity/activity.py:242
msgid "Redo"
msgstr ""
#: ../lib/sugar/activity/activity.py:252
msgid "Copy"
msgstr ""
#: ../lib/sugar/activity/activity.py:257
msgid "Paste"
msgstr ""
#: ../lib/sugar/activity/activity.py:445
#, python-format
msgid "%s Activity"
msgstr ""
#: ../lib/sugar/graphics/alert.py:164 ../lib/sugar/graphics/alert.py:206
msgid "Cancel"
msgstr ""
#: ../lib/sugar/graphics/alert.py:168
msgid "Ok"
msgstr ""
#: ../lib/sugar/graphics/alert.py:216
msgid "Continue"
msgstr ""
#: ../lib/sugar/graphics/alert.py:244
msgid "OK"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:175
#, python-format
msgid "%d year"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:175
#, python-format
msgid "%d years"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:176
#, python-format
msgid "%d month"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:176
#, python-format
msgid "%d months"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:177
#, python-format
msgid "%d week"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:177
#, python-format
msgid "%d weeks"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:178
#, python-format
msgid "%d day"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:178
#, python-format
msgid "%d days"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:179
#, python-format
msgid "%d hour"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:179
#, python-format
msgid "%d hours"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:180
#, python-format
msgid "%d minute"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:180
#, python-format
msgid "%d minutes"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:181
#, python-format
msgid "%d second"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:181
#, python-format
msgid "%d seconds"
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:191
msgid " and "
msgstr ""
#: ../lib/sugar/graphics/objectchooser.py:193
msgid ", "
msgstr ""
#: ../shell/controlpanel/control.py:254
msgid "Error in specified color modifiers."
msgstr ""
#: ../shell/controlpanel/control.py:257
msgid "Error in specified colors."
msgstr ""
#: ../shell/controlpanel/control.py:306
msgid "Error in specified radio argument use on/off."
msgstr ""
#: ../shell/controlpanel/control.py:323 ../shell/controlpanel/control.py:325
#, python-format
msgid "get_timezone: %s"
msgstr ""
#: ../shell/controlpanel/control.py:331
msgid "Error in reading timezone"
msgstr ""
#: ../shell/controlpanel/control.py:344
#, python-format
msgid "Error copying timezone (from %s): %s"
msgstr ""
#: ../shell/controlpanel/control.py:349
#, python-format
msgid "Changing permission of timezone: %s"
msgstr ""
#: ../shell/controlpanel/control.py:360
msgid "Error timezone does not exist."
msgstr ""
#: ../shell/controlpanel/control.py:379
#, python-format
msgid "Could not access %s"
msgstr ""
#: ../shell/controlpanel/control.py:415
#, python-format
msgid "Language for code=%s could not be determined."
msgstr ""
#: ../shell/controlpanel/control.py:424
#, python-format
msgid "Sorry I do not speak '%s'."
msgstr ""
#: ../shell/view/devices/network/mesh.py:105
msgid "Connected to a School Mesh Portal"
msgstr ""
#: ../shell/view/devices/network/mesh.py:107
msgid "Looking for a School Mesh Portal..."
msgstr ""
#: ../shell/view/devices/network/mesh.py:110
msgid "Connected to an XO Mesh Portal"
msgstr ""
#: ../shell/view/devices/network/mesh.py:112
msgid "Looking for an XO Mesh Portal..."
msgstr ""
#: ../shell/view/devices/network/mesh.py:115
msgid "Connected to a Simple Mesh"
msgstr ""
#: ../shell/view/devices/network/mesh.py:117
msgid "Starting a Simple Mesh"
msgstr ""
#: ../shell/view/devices/network/mesh.py:124
msgid "Unknown Mesh"
msgstr ""

@ -0,0 +1,42 @@
# Copyright (C) 2007, Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
"""
"""
import gtk
import gobject
from sugar import _sugarext
import common
def _preview_timeout_cb():
preview = _sugarext.Preview()
preview.take_screenshot(button.window)
preview.save('/home/marco/test.png')
test = common.Test()
button = gtk.Button('Hello')
test.pack_start(button)
button.show()
gobject.timeout_add(2000, _preview_timeout_cb)
if __name__ == "__main__":
common.main(test)
Loading…
Cancel
Save