Re: Invisible GtkImage

2013-06-22 Thread אנטולי קרסנר
The code looks fine. I think the problem is that scaling images are
rarely used in GUI. Usually, they scale to fixed sizes and not directly
depend on a container scaling to arbitrary size. This is probably why
getting the result you want is not easy.

Try the canvas idea. You can probably use any simple drawing area widget
(I never used one personally) from Gtk or Cairo.

On ו', 2013-06-21 at 21:30 -0700, Kip Warner wrote:
 On Fri, 2013-06-21 at 11:46 +0300, אנטולי קרסנר wrote:
  Hey Kip,
 
 Hey Tom.
 
  You can try to place your image into a 1x1 GtkGrid and see if it works.
  If not... hmmm... I'm trying to think of an existing Gnome app which has
  scaling images. Hmmm... probably none. Scaling images (unless in
  Gimp/Inkspace) to containing widget size is probably rarely done.
 
 Ok, I tried it with GtkGrid containing the image widget with the parent
 of the former being the AspectFrame. No love. It behaves the same as
 without it.
 
  Anyway, here's another idea: You can try to solve the recursive scaling
  problem by not using all the available space. Try to make the image fit,
  say 90% of the aspect frame. Then the image is not big enough to cause
  the aspect frame to rescale (which probably would cause the recursive
  scaling). You may get a little bit of screen space wasted, but if you
  don't mind the 10% (maybe you can reduce it to 5% or less) it's okay.
 
 I think that's a good idea, but I'll try that as a last resort.
 
 So I've almost got it working. It resizes properly when I make the
 window larger, but the window's width can never be made smaller
 (including after maximization).
 
   http://pastebin.com/q76RJ4UH
 
 Can you see anything broken in that?
 
  Another idea: Image editing software usually uses a custom canvas and
  draws things on it, including scaled SVG images. Maybe you can put such
  a canvas in the aspect frame, possible also inside a 1x1 GtkGrid, and
  scale the image within the canvas. Then, the image scaling is just a
  canvas drawing operation and has no effect on the AspectFrame size, and
  shouldn't cause recursive scaling.
 
 I don't know much about the canvas. But I'll try it and get back to you.
 
 Thank you for your help,
 


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

Re: Invisible GtkImage

2013-06-22 Thread Kip Warner
On Sat, 2013-06-22 at 11:33 +0300, אנטולי קרסנר wrote:
 The code looks fine. I think the problem is that scaling images are
 rarely used in GUI. Usually, they scale to fixed sizes and not directly
 depend on a container scaling to arbitrary size. This is probably why
 getting the result you want is not easy.

Hey Tom. Yes, definitely the resizing is the difficulty. It's amazing
how much time I've spent on just trying to get the image to resize.

 Try the canvas idea. You can probably use any simple drawing area widget
 (I never used one personally) from Gtk or Cairo.

This is what I've come up with so far. The image paints on the
DrawingArea properly, but it doesn't resize at all when I resize the
parent window.

http://pastebin.com/Mj7bTJLh

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

Re: Invisible GtkImage

2013-06-22 Thread אנטולי קרסנר
I never used drawing areas, but here are my suggestions.

First, does the drawing area resize? If it does, all you need to do is
to change the code which draws the image to use the drawing area's
dimensions, and scale the image accordingly (I don't know how to do
that, but I'm sure Cairo can help. In the worst case, from personal
experience I know OpenGL can do that, if you have no choice...).

If the drawing area doesn't resize, try to put it in a GtkGrid.

If it doesn't help - maybe you can removing the aspect frame and
calculating the image dimensions manually.

If it still doesn't work, I suggest you try asking on gtk-l...@gnome.org
and have some GTK experts give you ideas.

On ש', 2013-06-22 at 08:49 -0700, Kip Warner wrote:
 On Sat, 2013-06-22 at 11:33 +0300, אנטולי קרסנר wrote:
  The code looks fine. I think the problem is that scaling images are
  rarely used in GUI. Usually, they scale to fixed sizes and not directly
  depend on a container scaling to arbitrary size. This is probably why
  getting the result you want is not easy.
 
 Hey Tom. Yes, definitely the resizing is the difficulty. It's amazing
 how much time I've spent on just trying to get the image to resize.
 
  Try the canvas idea. You can probably use any simple drawing area widget
  (I never used one personally) from Gtk or Cairo.
 
 This is what I've come up with so far. The image paints on the
 DrawingArea properly, but it doesn't resize at all when I resize the
 parent window.
 
 http://pastebin.com/Mj7bTJLh
 


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

Re: Invisible GtkImage

2013-06-22 Thread Kip Warner
On Sat, 2013-06-22 at 19:18 +0300, אנטולי קרסנר wrote:
 I never used drawing areas, but here are my suggestions.
 
 First, does the drawing area resize? If it does, all you need to do is
 to change the code which draws the image to use the drawing area's
 dimensions, and scale the image accordingly (I don't know how to do
 that, but I'm sure Cairo can help. In the worst case, from personal
 experience I know OpenGL can do that, if you have no choice...).

That was my first line of inquiry, except it doesn't seem to resize. I
can see this because if I leave a frame border on the parent
AspectFrame, it doesn't resize.

 If the drawing area doesn't resize, try to put it in a GtkGrid.

I tried putting the DrawingArea into a 1x1 Grid, in turn inside of an
AspectFrame, but it still doesn't resize.

 If it doesn't help - maybe you can removing the aspect frame and
 calculating the image dimensions manually.

Even if I remove the aspect frame and calculate the image dimensions
myself, there still seems to be no way I can find to reliably resize it
dynamically.

I can't believe resizing a widget in Gtk+ is this difficult. I think
I've tried everything by now. Viewports, AspectFrame, cairo, Gdk pixbuf,
subclassing and overrides. You'd think something like this would be
really straightforward. =(

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

Re: Invisible GtkImage

2013-06-22 Thread David Nečas
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


Re: Invisible GtkImage

2013-06-22 Thread Kip Warner
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

Re: Invisible GtkImage

2013-06-22 Thread Colomban Wendling
Le 23/06/2013 00:30, Kip Warner a écrit :
 On Sun, 2013-06-23 at 00:08 +0200, David Nečas wrote:
 [...]
 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

1) you don't need an AspectFrame if the drwaing takes care of not
messing up the ratio.

2) you say it doesn't expand: check your packing flags.  You have:
page.pack_start(page._bannerAspectFrame, False, False, 0)
   the 2 False mean don't expand and don't fill the available space.
   Change this to True, True and you'll be happy.


Regards,
Colomban
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list