SugarPreview API improvements
This commit is contained in:
parent
cd4cb6bd67
commit
cd61c52c7b
@ -173,11 +173,24 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-method save
|
||||
(define-method set_size
|
||||
(of-object "SugarPreview")
|
||||
(c-name "sugar_preview_save")
|
||||
(return-type "gboolean")
|
||||
(c-name "sugar_preview_set_size")
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("const-char*" "key")
|
||||
'("int" "width")
|
||||
'("int" "height")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method clear
|
||||
(of-object "SugarPreview")
|
||||
(c-name "sugar_preview_clear")
|
||||
(return-type "none")
|
||||
)
|
||||
|
||||
(define-method get_pixbuf
|
||||
(of-object "SugarPreview")
|
||||
(c-name "sugar_preview_get_pixbuf")
|
||||
(return-type "GdkPixbuf*")
|
||||
)
|
||||
|
@ -27,13 +27,20 @@ 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)
|
||||
void
|
||||
sugar_preview_set_size(SugarPreview *preview, int width, int height)
|
||||
{
|
||||
preview->width = width;
|
||||
preview->height = height;
|
||||
}
|
||||
|
||||
GdkPixbuf *
|
||||
sugar_preview_get_pixbuf(SugarPreview *preview)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
|
||||
if (preview->image != NULL) {
|
||||
return FALSE;
|
||||
if (preview->image == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pixbuf = gdk_pixbuf_get_from_image(NULL, preview->image, NULL,
|
||||
@ -41,14 +48,16 @@ sugar_preview_save(SugarPreview *preview, const char *file_name)
|
||||
preview->image->width,
|
||||
preview->image->height);
|
||||
|
||||
gdk_pixbuf_save(pixbuf, file_name, "png", NULL);
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_preview_clear(SugarPreview *preview)
|
||||
{
|
||||
if (preview->image != NULL) {
|
||||
g_object_unref(G_OBJECT(preview->image));
|
||||
preview->image = NULL;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -59,16 +68,14 @@ sugar_preview_take_screenshot(SugarPreview *preview, GdkDrawable *drawable)
|
||||
GdkColormap *colormap;
|
||||
gint width, height;
|
||||
|
||||
sugar_preview_clear(preview);
|
||||
|
||||
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);
|
||||
|
||||
@ -82,13 +89,8 @@ 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;
|
||||
sugar_preview_clear(preview);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
sugar_preview_class_init(SugarPreviewClass *preview_class)
|
||||
|
@ -38,6 +38,8 @@ struct _SugarPreview {
|
||||
GObject base_instance;
|
||||
|
||||
GdkImage *image;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct _SugarPreviewClass {
|
||||
@ -45,10 +47,13 @@ struct _SugarPreviewClass {
|
||||
};
|
||||
|
||||
GType sugar_preview_get_type (void);
|
||||
void sugar_preview_take_screenshot (SugarPreview *menu,
|
||||
void sugar_preview_take_screenshot (SugarPreview *preview,
|
||||
GdkDrawable *drawable);
|
||||
gboolean sugar_preview_save (SugarPreview *menu,
|
||||
const char *file_name);
|
||||
void sugar_preview_set_size (SugarPreview *preview,
|
||||
int width,
|
||||
int height);
|
||||
GdkPixbuf *sugar_preview_get_pixbuf (SugarPreview *preview);
|
||||
void sugar_preview_clear (SugarPreview *preview);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -28,7 +28,8 @@ import common
|
||||
def _preview_timeout_cb():
|
||||
preview = _sugarext.Preview()
|
||||
preview.take_screenshot(button.window)
|
||||
preview.save('/home/marco/test.png')
|
||||
preview.get_pixbuf().save('/home/marco/test.png','png')
|
||||
preview.clear()
|
||||
|
||||
test = common.Test()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user