kaStevie
kaStevie

Reputation: 93

Determining the location of a GTK widget on-screen to create a relevant popup window

I have a button labeled import (down arrow) and I am trying to determine it's location so I can create a popup menu to say 1. from device 2. from folder.

I can't seem to find anymore than allocation in the api docs, which is relative to the application window. Please help, I will send imaginary cookies ^_^.

using PyGI if it matters.

Upvotes: 1

Views: 1203

Answers (2)

kaStevie
kaStevie

Reputation: 93

I figured out the answer before but couldn't self answer yet.

The process is as follows:

  1. determine the location of the GdkWindow, which does not contain the window decorations. : gdk_window_x, gdk_window_y
  2. determine the location of the widget relative to it's GdkWindow : widget_x, widget_y

    x = gdk_window_x + widget_x

    y = gdk_window_y + widget_y

as everything in the graphics world measures from top left (unless your weird :-)), you now have the location of the top left pixel of your widget.

Upvotes: 1

Jong Bor Lee
Jong Bor Lee

Reputation: 3855

You can get the position of the window relative to the screen using window.get_position(). Since you already know how to get the position of the button relative to the window, it should be a matter of adding up both to get the coordinates (relative to the screen) in which to place the popup.

Upvotes: 0

Related Questions