On Sun, 2013-06-23 at 00:08 +0200, David Nečas wrote:
> 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.  

Hey David. I had posted my cairo drawing code a couple posts ago, but
this thread is getting long and you may have missed it:

        <http://pastebin.com/Mj7bTJLh>

Before that, I had posted several times code using GtkImage as well. In
any case, they didn't work properly, it doesn't matter now, and I'm
grateful for your help.

> 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...

Yes, your code is similar to what I had tried before with GtkImage,
only you're subclassing the DrawingArea instead which is probably a
better idea, except it still doesn't work properly either. My code
draws the image correctly, but it doesn't resize as the parent window is
resized...

        <http://pastebin.com/6LEzFk8A>

> 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.

Yup.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
_______________________________________________
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