| FAQ Index - Search - Recent Changes - Everything - Add entry |
23.32. How to get coordinates relative to X11 for a widget that has no window of its own?
Try this code:
# here I get the coordinates of the button relative to # window (self.window) button_x, button_y = self.actions_button.allocation.x, self.actions_button.allocation.y # now convert them to X11-relative window_x, window_y = self.window.window.get_origin() x = window_x + button_x y = window_y + button_ynow x, y hold the top-left corner of button and those x, y are X11 and not window-relative.
Something more advanced but hopefully useful:
menu.popup(None, None, self.position_actions_menu, 1, 0) menu.show_all() def position_actions_menu(self, menu): # here I get the coordinates of the button relative to # window (self.window) button_x, button_y = self.actions_button.allocation.x, self.actions_button.allocation.y # now convert them to X11-relative window_x, window_y = self.window.window.get_origin() x = window_x + button_x y = window_y + button_y # now move the menu below the button y += self.actions_button.allocation.height push_in = True # push_in is True so all menu is always inside screen return (x, y, push_in)
