On Sat, Jun 22, 2013 at 01:09:17PM -0700, Kip Warner wrote:
> I can't believe resizing a widget in Gtk+ is this difficult.

Frankly, I don't quite understand what you are trying to achieve since
you have never posted anything runnable and your examples have never
included any actual drawing code.  Anyway, it is trivial to create a
scaleable widget (whether it draws an image or anything else):

-----------------------------------------------------------------------
from gi.repository import Gtk, GdkPixbuf, Gdk

class ScalableImage(Gtk.DrawingArea):
    def __init__(self, filename):
        super(ScalableImage, self).__init__()
        self.pb = GdkPixbuf.Pixbuf.new_from_file(filename)

    def do_get_preferred_width(self):
        pw = self.pb.get_width()
        return (pw, pw)

    def do_get_preferred_height(self):
        ph = self.pb.get_height()
        return (ph, ph)

    def do_draw(self, cr):
        alloc = self.get_allocation()
        pw, ph = self.pb.get_width(), self.pb.get_height()
        aw, ah = float(alloc.width), float(alloc.height)
        r = min(aw/pw, ah/ph)
        cr.scale(r, r)
        Gdk.cairo_set_source_pixbuf(cr, self.pb, 0.0, 0.0)
        cr.paint()
        return False

w = Gtk.Window(Gtk.WindowType.TOPLEVEL)
w.connect('destroy', Gtk.main_quit)

b = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
w.add(b)

b.pack_start(Gtk.Label(label='Test'), False, False, 0)
d = ScalableImage('/usr/share/icons/HighContrast/48x48/stock/gtk-ok.png')
b.pack_start(d, True, True, 0)
b.pack_start(Gtk.Label(label='Somewhat longer test'), False, False, 0)

w.show_all()

Gtk.main()
-----------------------------------------------------------------------

This might not be exactly what you need but as I noted I don't get where
the problem is...

If you need your widget to be a GtkImage subclass things will likely
turn hairy because GtkImage is not scaleable, all its methods think it
is not scaleable so you will end up fighting the implementation of the
widget.

Yeti

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to