Re: "changed" signal



muppet wrote:


In my custom widget I have an image, which I make on the fly. I also can't seem to make the widget support flexible resizing of the window, this also works in ScrolledWindow.


"flexible resizing"?


I mean basically the widget is an image viewer. The use has to be able to

zoom in - I can do this with a VScale widget (external) or keypress (+/-) within the widget

pan - works with the Scrollbars of the ScrolledWindow or keypress (arrow keys), should work also with drag and drop, but I have not implemented that yet

resize the window which contains the image viewer - I respond to this with hooking to changed signals of the adjustments of the ScrolledWindow

The custom widget inherits from ScrolledWindow and contains an EventBox, which contains the Image. A strange thing is that I can hook up to button_press-event and motion_notify_event of the EventBox, but I need to connect the key_press_event to $self (ScrolledWindow) to catch it.


do you mean scaling the image to whatever size the window is? hook into the size-allocate signal and use Gtk2::Gdk::Pixbuf::scale_simple and Gtk2::Gtk::Image::set_from_pixbuf to show the image at the size of the window.


I'm making the pixbuf myself from a raster data maintained by another perl object but yes. The pixbuf I put into a pixmap because I want to be able to draw on the image.


do you mean shrink the widget below the size of the image? in size-allocate, set the size request to be something small, e.g. 0,0.


I do this initially when I create the Image but in my render method (when the image is done by set_from_pixmap) I say set_size_request(zoom*native_size) otherwise the scrollbars do not show correctly and set_alignment(value/(upper-page_size)) (value, upper and page_size are from the adjustments).

Anyway the widget seems to work now. The code is public (it is already now in cvs.sourceforge.net:/cvsroot/libral as Gtk2-Geo-Raster) it could be of interest also outside my use with Geo-Raster (which is also in sourceforge and in CPAN), with normal image files. Maybe such widget already exists, I did not check, I have to admit.

Ari


--
If I lived in Teletubby Land, the homicide rate would be four.
  -- elysse





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