Re: this is interesting, when "running" eval

Lich Lee said:
$entry->signal_connect(key_press_event => \&caller);
sub caller{
      my($self, $event) = @_;
      if( $event->keyval == $Gtk2::Gdk::Keysyms{'Return'}){

Gtk2::Entry emits the "activate" signal when the user presses Return/Enter --
that might be a little easier for you.

              $text = $self->get_text;
              print "$text\n";
              eval $text;

out of curiosity, what is this program?  just a graphical perl code tester?  i
posted to the list a while back a gtk2-perl interactive shell called "gish"...

i've also played with using the ReadLine implementation in gish inside the
perl debugger, which is a little more friendly.

problem is in sub caller when I eval $text;
$text is " $window->set_size_request(x, y);"
if x and y are bigger than the original size of $window, It can execute
normally, but if they are smaller, It seem never be executed,
for example;
when $text is "$window->set_size_request(1024, 768);"
now the window cover whole my desktop; but when I eval $text is
"$window->set_size_request(500, 500);"
window never gets smaller, it's still 1024*768;

the size request is the widget's desired *minimum* size.  if a widget requests
to be 1024 by 768 and it is currently 640 by 480, gtk+ will resize the window
to give that widget its requested size.

if, however, the widget is already 1024 by 768 and requests 500 by 500, it
already has considerably more than 500 by 500, so gtk+ doesn't change the
size.  the size request *is* stored, though.

the size request is used as a minimum size for resizable widget.  when your
widget is set to 1024 by 768, it can't be resized smaller than that, but you
can make it bigger.  after you change it to 500 by 500, the window doesn't
resize itself, but you can try resizing it --- it will shrink as far as 500 by
500 and will not go any smaller.

you can prove this to yourself by adding the line

    print "request: ".join(",",$window->get_size_request)."\n";

after your "eval $text;".

so, it's not that gtk+ is not executing your statements, it's that they don't
do what you were thinking they do.  :-)

but if I use:
eval \$window->set_size_request(1024, 768);
eval \$window->set_size_request(500, 500);
instead of:
eval $text;
everything is ok, window is 500*500;
can anyone tell me what happen?

i would imagine that here you're executing both of these before the idle runs,
and thus by the time gtk+ actually tries to talk to the window server to say
"resize this window, would you?", the request is only 500x500.

muppet <scott at asofyet dot org>

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