Re: How to create a popup?



muppet schrieb:

On Saturday, November 22, 2003, at 10:19 AM, Thomas Bayen wrote:

* How can I make that my popup behaves like a real one?

i would love to know. for a few years now, i've had a gtk-perl date-combo that just doesn't pop down correctly. i'm missing something simple-yet-important. but i've looked at it a lot and can give you some hints, so maybe you'll figure out what i've missed.


For example if I move my main window around with the mouse the popup stays on the old screen position :-(

erm, most popups go away when you click outside of them. think of optionmenus, menus in general, and comboboxen -- they're open until you click anywhere outside them, which means you can't grab the window border without the popup popping down.

to get this popup-moves-when-the-parent-moves behavior, you'd have to connect to something that tells you the window has been moved so you can move your child --- the only way to move two together (unless you're a window manager) is to have one be a child of the other, which popup windows aren't.

I dont need really the "move-with-it". After more thinking I made a connection to the "focus-out-event"-signal and close the popup. It feels like a real popup. :-)


if I use "$self->{win}->set_property('type','popup')" the input focus does not go into the popup widget but stays in the main window.

you have to explicitly set the focus to be in that new popup window.

This does not work. I can not set the focus into the popup window. Not with the focus_grab method and not with the mouse clicking into it. :-(

Inbetween my popup is working better. But I do not use the "popup" type. Is there somewhere an explanation for this type or an example or am I true that it is useless...


  Can't locate object method "get_root_window" via package ...

Is this method not implemented, if it is how can I call it or how can I find out the root coordinates of my widget in another way?

erm... well, no, that's not bound. it's a 2.2 method that appears to have slipped through the cracks. GtkWidget.xs was one of the first files created in gtk2-perl-xs, and came from the gtkwidget.h in my 2.0.6 installation which doesn't have that method and a few others.

As I read the xs-Source, I saw that the next called method "get_frame_extents" is not bound too, so I looked for another way to do it. For the mailing list archive here is my (working!) solution to find the screen position of a widget:

  my($winx,$winy)=$self->get_parent_window->get_position;
  my($x,$y)=($self->allocation->x,$self->allocation->y);
  $self->{win}->move($winx+$x,$winy+$y);


* I use the "allocation" function to get the coordinates of the widget. I can not find documentation to this function. I found it only with indirect mention. If this is a "documentation bug" I want to report it here...

it's an accessor for a member variable, not a *real* function. the allocation describes how much space was actually allocated to the widget, which asked for the amount of space in the requisition. i have no idea what the x and y in the allocation actually are -- i presume that they are the coordinates of the widget's origin relative to its parent, but i can't prove that.

You are true. I tested it and it works. But I can't find any documentation about this function/member variable in the C documentation. This can not be true! Please can someone more experienced than me tell me what I did wrong. This one costed me a long time, I want to be better next time. :-)


sub callback_openpopup{
  my($self)= _;
  $self->{win}->destroy if defined $self->{win};

why destroy it if it already exists? usually you'd want just to show it again to keep from having to re-create it. (but destroying works, just a thought)

A good thought. Thanks. I just wanted "clean everything", but is is not really necessacy.


  $self->{win}=Gtk2::Window->new;
  # What's this for?!?:
  # $self->{win}->set_property('type','popup');

type is a construct-only property.  you want instead to do

   $self->{win} = Gtk2::Window->new ('popup')

Both ways give the same result (described above) that gives no focus to the popup window.


  $self->{win}->set_destroy_with_parent(1);
  $self->{win}->set_decorated(0);

these are not necessary if you create the window correctly.

What is "correctly"? with "popup"? I tried it and yes - the "popup" type window was without decorations. But it gets no focus. :-(


  my ($x, $y) = $self->window->get_origin;

Please can you tell me why this works? Where in the world is the information hidden that there is a "window" function? I searched about two hours how to become a GdkWindow out of an GtkWindow. Something is really weird in this documentation. :-( Let me guess: "it's an accessor for a member variable, not a *real* function."


muppet <scott at asofyet dot org>


Thanks, Thomas




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