GtkStyleContext issues



Hi,

I am working on a GTK mockup application, in which I need to render GTK
widgets onto a Cairo.Context

To do this, I obtain a GtkStyleContext from the GtkDrawingArea (which is
my 'canvas') and then connect to the 'draw' signal of this GtkDrawingArea

In this callback, I then use the gtk_render_* functions, however I seem
to have a problem.

In the example below, I am trying to render a Progressbar, however the
rendered progressbar doesn't look like the real progressbar (in this
case in Glade) (http://i.imgur.com/BMhdr.png)

This issue is not restricted to just ProgressBars either, it is shown in
other widgets. For example here is the same demo with a GtkButton,
however the difference is only shown when using the Ambiance/Radiance
GTK3 themes, not Adawaita (http://i.imgur.com/ADNnt.png)

My code is listed at the end of this message (I have wrote it in Python
to ease testing, however the same behaviour is shown in Vala and C) and
the drawing parts are ported from gtkprogressbar.c

What is going wrong and can someone please help?

Thanks

--
Andrew




#!/usr/bin/env python

from gi.repository import Gtk

def on_draw(widget, cairo_cx) :
    style_cx = widget.get_style_context()

    x = 50
    y = 100
    width = 200
    height = 32

    ######################################
    # Ported from from gtkprogressbar.c
    style_cx.save()

    style_cx.add_class(Gtk.STYLE_CLASS_TROUGH);
    Gtk.render_background(style_cx, cairo_cx, x, y, width, height);
    Gtk.render_frame(style_cx, cairo_cx, x, y, width, height);

    style_cx.restore();

    style_cx.save()

    style_cx.add_class(Gtk.STYLE_CLASS_PROGRESSBAR);
    Gtk.render_activity(style_cx, cairo_cx, x, y, width/2, height);

    style_cx.restore();
    ####################################


drawingarea = Gtk.DrawingArea()
drawingarea.connect("draw", on_draw)
drawingarea.set_size_request(300, 200)

window = Gtk.Window()
window.set_default_size(300, 200)
window.connect("delete-event", Gtk.main_quit)

window.add(drawingarea)
window.show_all()
Gtk.main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]