Scaling an image with Gtk2::Gdk::Pixbuf->scale

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Scaling an image with Gtk2::Gdk::Pixbuf->scale

Les Trol
I'm implementing a spec in which an image is displayed in a Gtk2::Textview. Simple enough to do, but the spec requires optional extras, such as displaying padding around the image and detecting clicks on it.
 
Taking one problem at a time:
 
1. Sometimes the image must be displayed its original size. Sometimes it must be its original size, but surrounded by some empty 'padding'.
 
The script below is the closest I've been able to get so far. It uses Gtk2::Gdk::Pixbuf->scale to create the 'padding'.
 
However, the 'padding' is not empty space, as I'd hoped, but a blur of pixels from the edges of the original image. I see the same effect for many different images in different sizes (such as this cat image: https://i.imgur.com/unoDgq7.png - I see https://imgur.com/a/iqe2t )
 
Is there a simple way to remove the blur, or does this call for a different approach entirely?
 
#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'change_this_directory/cat.bmp';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
    Gtk2->main_quit();
    exit;
});
            
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');     
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display a photo of a cat face
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
 
    # Make the overall image 20% bigger, but the cat's face is its
    #   original size (and centred in the middle)
    my $factor = 0.2;   
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
 
    my $pixbuf2 = Gtk2::Gdk::Pixbuf->new(
        'GDK_COLORSPACE_RGB',
        FALSE,
        $pixbuf->get_bits_per_sample(),
        ($w * (1 + $factor)),
        ($h * (1 + $factor)),
    );
 
    $pixbuf->scale(
        # $dest
        $pixbuf2,
        # $destx, $desty
        0,
        0,
        # $dest_width, $dest_height
        ($w * (1 + $factor)),
        ($h * (1 + $factor)),
        # $offset_x, $offset_y
        ($w * ($factor / 2)),
        ($h * ($factor / 2)),
        # $scale_x, $scale_y
        1,
        1,
        # $interp_type
        'GDK_INTERP_NEAREST',
     );
 
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf2,
    );
}
 
$window->show_all();   
Gtk2->main();
    
 

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Dov Grobgeld-2
Try creating a new (empty) image of the required size and then use cairo to fill it with the desired contents. The following link may help you (though it is in C and not perl, but the API is the same):


Regards,
Dov


On Thu, Oct 26, 2017 at 11:18 AM, Les Trol <[hidden email]> wrote:
I'm implementing a spec in which an image is displayed in a Gtk2::Textview. Simple enough to do, but the spec requires optional extras, such as displaying padding around the image and detecting clicks on it.
 
Taking one problem at a time:
 
1. Sometimes the image must be displayed its original size. Sometimes it must be its original size, but surrounded by some empty 'padding'.
 
The script below is the closest I've been able to get so far. It uses Gtk2::Gdk::Pixbuf->scale to create the 'padding'.
 
However, the 'padding' is not empty space, as I'd hoped, but a blur of pixels from the edges of the original image. I see the same effect for many different images in different sizes (such as this cat image: https://i.imgur.com/unoDgq7.png - I see https://imgur.com/a/iqe2t )
 
Is there a simple way to remove the blur, or does this call for a different approach entirely?
 
#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'change_this_directory/cat.bmp';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
    Gtk2->main_quit();
    exit;
});
            
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');     
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display a photo of a cat face
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
 
    # Make the overall image 20% bigger, but the cat's face is its
    #   original size (and centred in the middle)
    my $factor = 0.2;   
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
 
    my $pixbuf2 = Gtk2::Gdk::Pixbuf->new(
        'GDK_COLORSPACE_RGB',
        FALSE,
        $pixbuf->get_bits_per_sample(),
        ($w * (1 + $factor)),
        ($h * (1 + $factor)),
    );
 
    $pixbuf->scale(
        # $dest
        $pixbuf2,
        # $destx, $desty
        0,
        0,
        # $dest_width, $dest_height
        ($w * (1 + $factor)),
        ($h * (1 + $factor)),
        # $offset_x, $offset_y
        ($w * ($factor / 2)),
        ($h * ($factor / 2)),
        # $scale_x, $scale_y
        1,
        1,
        # $interp_type
        'GDK_INTERP_NEAREST',
     );
 
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf2,
    );
}
 
$window->show_all();   
Gtk2->main();
    
 

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list



_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Les Trol
In reply to this post by Les Trol
 
Try creating a new (empty) image of the required size and then use cairo to fill it with the desired contents. The following link may help you (though it is in C and not perl, but the API is the same):
 
 
I don't know any C, but as far as I can tell, the Perl equivalent of draw_in_a_GdkPixbuf.c should be something like this. (I can't tell how to make it work.)
 
 
 
#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
use Cairo;
 
# Display this image
my $path = 'change_this_directory/cat.bmp';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
    Gtk2->main_quit();
    exit;
});
            
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');     
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
 
    my $surface = Cairo::ImageSurface->create('argb32', $w, $h);
    my $cr = Cairo::Context->create($surface);

    # Neither of the following two lines work
#   $cr->set_source_pixbuf($pixbuf, 0, 0);
    Gtk2::Gdk::Cairo->set_source_pixbuf($cr, $pixbuf, 0, 0);
    # Continuing...
    $cr->paint();
    
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $surface,
    );
 
    Gtk2::Gdk::Cairo->surface_destroy($surface);
    Gtk2::Gdk::Cairo->destroy($cr);
}
 
$window->show_all();   
Gtk2->main();
   

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Les Trol
In reply to this post by Les Trol
Ok, second intractable problem:
 
2. The spec also wants to detect mouse clicks on the displayed image. With this I've barely made any progress at all.
 
I tried some obvious things. However, Gtk2::TextIter->get_pixbuf() only detects mouse motion of the left half of the image (for no obvious reason).  
 
The Gtk docs say: "The image will be counted as one character in character counts...". Alas, Gtk2::TextIter->get_line_offset() seems to count it as two characters - one for the left half of the image, one for the right half.
 
The script below demonstrates those two quirks. I also tried inserting Gtk2::TextMarks before and after the image, and for some reason that only applies to the right-hand half of the image.
 
I'm lost now. Any ideas?
 
---
 
#!/usr/bin/perl
package scaleme2;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'change_this_directory/cat.bmp';
my $count = 0;
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
 
    Gtk2->main_quit();
    exit;
});
            
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');     
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display an image
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
}
 
# Detect mouse motion over the image
$textView->signal_connect(motion_notify_event => sub {
 
    my ($widget, $event) = @_;
 
    # Get mouse position over the textview buffer
    my ($xPos, $yPos) = $textView->window_to_buffer_coords(
        'widget',
        $event->x,
        $event->y,
    );
 
    my $iter = $textView->get_iter_at_location($xPos, $yPos);
 
    print "mouse position " . $iter->get_line_offset . " y " . $iter->get_line . "\n";
    if ($iter->get_pixbuf()) {
 
        print "mouse is hovering over the image! " . $count++ . "\n";
    }
});
 
$window->show_all();   
Gtk2->main();

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Gtk+ - Perl mailing list
In reply to this post by Les Trol

Hi Les,

See if this works better for the cat.

Eric

#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'cat.png';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
    Gtk2->main_quit();
    exit;
});
           
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');    
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display a photo of a cat face
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
 
    # Make the overall image 20% bigger, but the cat's face is its
    #   original size (and centred in the middle)
    my $factor = 0.2;  
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
    my $scale_w1 = $w * 1.2;
    my $scale_h1 = $h * 1.2;
 
    my $pixbuf2 = $pixbuf->scale_simple($scale_w1, $scale_h1, 'GDK_INTERP_BILINEAR');

    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf2,
    );

   my $pixbuf3 = Gtk2::Gdk::Pixbuf->new(
        'GDK_COLORSPACE_RGB',
        FALSE,
        $pixbuf->get_bits_per_sample(),
        $scale_w1,
        $scale_h1,
    );
   $pixbuf3->fill(0xFF00FFFF);

   my $move_x = ($scale_w1 - $w) / 2;
   my $move_y = ($scale_h1 - $h) / 2;

   $pixbuf->composite($pixbuf3, $move_x, $move_y, $w, $h, $move_x, $move_y, 1, 1, 'GDK_INTERP_BILINEAR', 255);

   $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf3,
    );

}
 
$window->show_all();  
Gtk2->main();



_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Gtk+ - Perl mailing list
In reply to this post by Les Trol

Hi Les,

If you put the pixbuf in an image widget and the image widget in an event box then you can get your mouse clicks from the pixbuf. The event box can then be added to the textview widget.

Eric




_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Les Trol
In reply to this post by Les Trol
>The event box can then be added to the textview widget.
 
How, exactly?
 
We have Gtk2::TextBuffer->insert for inserting text, Gtk2::TextBuffer->insert_pixbuf for inserting pixbufs, but no equivalent method for inserting an event box (something like Gtk2::TextBuffer->insert_event_box ).
 
Perhaps you meant: put the pixbuf in an event box, ->insert_pixbuf as before, and monitor signals for the event box. Something like:
 
    $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
    $image = Gtk2::Image->new_from_pixbuf($pixbuf);
    $ebox = Gtk2::EventBox->new();
    $ebox->add($image);
 
    $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
 
    ...
 
   $ebox->signal_connect(motion_notify_event => sub {
 
        # Some stuff here
    });
 
...but that doesn't seem to be the right approach, either.
 
 

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Jeremy Volkening-2
In reply to this post by Les Trol
On Wed, Nov 01, 2017 at 08:10:29PM +0100, Les Trol wrote:
>Ok, second intractable problem:
>
>2. The spec also wants to detect mouse clicks on the displayed image. With this
>I've barely made any progress at all.
>
>I tried some obvious things. However, Gtk2::TextIter->get_pixbuf() only detects
>mouse motion of the left half of the image (for no obvious reason).  

Short answer: use 'Gtk2::TextView::get_iter_at_position' instead of
'::get_iter_at_location'
>
>The Gtk docs say: "The image will be counted as one character in character
>counts...". Alas, Gtk2::TextIter->get_line_offset() seems to count it as two
>characters - one for the left half of the image, one for the right half.

Long answer: the rest of that sentence reads "[and] will be represented
by the Unicode 'object replacement character' 0xFFFC". So, a two-byte
character, which explains all of your observed behavior.
'Gtk2::TextView::window_to_buffer_coords' returns byte coordinates and
not character coordinates. When you call 'get_iter_at_location' on these
coords, it returns an iter to the byte at that location (more or less),
while you want an iter pointing to the character. This is what
'::get_iter_at_position' provides.

Regards,
Jeremy
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Gtk+ - Perl mailing list
In reply to this post by Les Trol

Try inserting a widget into the textview and capture the clicks on the widget. In this case, an event box with an image widget and pixbuf.

Eric

#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'cat.png';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(400, 400);
$window->signal_connect('delete-event' => sub {
    Gtk2->main_quit();
    exit;
});
           
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');    
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display a photo of a cat face
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
    my $scale_w1 = $w * 0.3;
    my $scale_h1 = $h * 0.3;
 
    my $pixbuf2 = $pixbuf->scale_simple($scale_w1, $scale_h1, 'GDK_INTERP_BILINEAR');

    my $image = Gtk2::Image->new_from_pixbuf($pixbuf2);
    my $ebox = Gtk2::EventBox->new();
    $ebox->signal_connect('button-press-event' => \&click_pixbuf);
    $ebox->add($image);

    my $buffer = $textView->get_buffer();
    my $anchor = $buffer->create_child_anchor($buffer->get_end_iter());
    $textView->add_child_at_anchor($ebox, $anchor);

}
 
$window->show_all();  
Gtk2->main();

sub click_pixbuf
{
  print "Click Pixbuf\n";
}



_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Les Trol
In reply to this post by Les Trol
Two down, one to go!
 
3. The spec wants the image to be displayable on the left or right of the textview, with any accompanying text at the top, middle or bottom of the image.
 
I used Gtk2::TextTags with the 'justification' and 'rise' properties set. 'justification' works just fine when there is only text on the line, but it stops working the minute an image is added to the same line. 'rise' doesn't work at all.
 
I could handle left-justification by inserting the image at the first iter in the line (instead of at the end of the line, as usual). But I can't think of any workaround for the 'rise' property.
 
---
 
#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'change_this_directory/cat.bmp';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
 
    Gtk2->main_quit();
    exit;
});
            
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');     
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display an image
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
 
    # Create some text tags for modifying how text on the same line
    #   as the image is displayed. (I have specified colours so we
    #   can be sure which tag is displayed)
    $buffer->create_tag(
        'rise_tag',
        'rise'          => '100',
        'rise-set'      => TRUE,
        'foreground'    => '#FF0000',
    );
 
    $buffer->create_tag(
        'justify_tag',
        'justification' => 'right',
        'foreground'    => '#FF00FF',
    );
 
    # Test the tags with some innocuous text
    $buffer->insert_with_tags_by_name(
        $buffer->get_end_iter(),
        'Here is some text to look at',
        'rise_tag',
    );
}
 
$window->show_all();   
Gtk2->main();
   

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Gtk+ - Perl mailing list

It sounds like some tricky layout features for the textview. Maybe wrapping text around images?

Not sure how to go about doing this. One thing to try is putting another textview in there with the image. Then you can size it to the image height and could resize it based on the overall window width.

Eric

#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'cat.png';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(400, 400);
$window->signal_connect('delete-event' => sub {
    Gtk2->main_quit();
    exit;
});
           
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');    
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display a photo of a cat face
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
    my $scale_w1 = $w * 0.3;
    my $scale_h1 = $h * 0.3;
 
    my $pixbuf2 = $pixbuf->scale_simple($scale_w1, $scale_h1, 'GDK_INTERP_BILINEAR');

    my $textView2 = Gtk2::TextView->new;
    $textView2->set_size_request(400, $scale_h1);
    my $table = Gtk2::Table->new(1, 2, FALSE);
    my $image = Gtk2::Image->new_from_pixbuf($pixbuf2);
    my $ebox = Gtk2::EventBox->new();
    $ebox->signal_connect('button-press-event' => \&click_pixbuf);
    $ebox->add($image);
    $table->attach_defaults($ebox, 0, 1, 0, 1);
    $table->attach_defaults($textView2, 1, 2, 0, 1);

    my $buffer = $textView->get_buffer();
    my $buffer2 = $textView2->get_buffer();
    $buffer->set_text("Top of the cat\n");
    my $anchor = $buffer->create_child_anchor($buffer->get_end_iter());
    $textView->add_child_at_anchor($table, $anchor);
    $buffer2->insert_at_cursor("\nA few\nlines to the right\n of the cat\n");
    $buffer->insert_at_cursor("\nBottom of the cat\n");

}
 
$window->show_all();  
Gtk2->main();

sub click_pixbuf
{
  print "Click Pixbuf\n";
}



_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list