views:

391

answers:

3

I am assisting with Windows support for a PyGTK app that appears as a system tray applet, but am not so strong on the GTK+ gooey stuff...

We have it so when you left-click the systray icon, the window appears right by your tray icon no matter where your system tray is--and on Linux this works great, using the results of gtk.StatusIcon.get_geometry() to calculate the size and position.

Of course, the docs for gtk.StatusIcon.get_geometry() point out that "some platforms do not provide this information"--and this includes MS Windows, as I get NoneType as the result.

I can make a guess and position the window in the bottom-right corner of the screen, 30 pixels up from the bottom--as this will catch the majority of Windows users who haven't moved the taskbar. But for those that have, it looks all wrong.

So is there a Windows-friendly way to get the position of the systray icon so I can place my window there?


Please note: I am already using gtk_menu_popup() with gtk_status_icon_position_menu for a pop-up menu which works correctly.

But what I am trying to position is a separate gtk.Window, which will not accept gtk_status_icon_position_menu (because it's not a menu).

Any other ideas would be appreciated...

+1  A: 

Gtk provides function gtk_status_icon_position_menu that can be passed into gtk_menu_popup as a GtkPositionFunc. This seems to provide the requested functionality.

dmitry_vk
gtk_status_icon_position_menu seems appropriate for a popup menu, but will it work for a child gtk.Window? We are currently using gtk.Windows.move(x,y) to position it manually after the calculation.If I assume that most Windoze systrays are on the bottom-right of the screen (a bad assumption, I know), set the gravity to South-East and display there, then it shows underneath the taskbar. Ideally, if I could detect where the systray/gtk.StatusIcon really is on Windows, then I could position the window relative to that.Or maybe there's yet another better way?
ewall
A: 

The behavior i experienced in windows with gtk_status_icon_position_menu was that it spawns the window at the location the user clicked in the statusicon

aiwarrior
A: 

I am also looking for an answer to this but have found something that might help.

It seems to me that GTK figures out where to bring up the PopupMenu from the mouse position. Somehow it figures out that the mouse button was clicked over the StatusIcon. Presumably either from mouse events sent by the windowing system or from some sort of knowledge of where the StatusIcon is.

What I am getting at is that GTK must either 1) know the actual location of the StatusIcon or 2) get events from the windowing system when the mouse is clicked on the StatusIcon. So it must know the information.

I also have a popup window I want to raise near the StatusIcon and I also have a PopupMenu that is working fine. So I tried this, in pygtk:

x, y, push = gtk.status_icon_position_menu(popup_menu, status_icon)

I passed in the PopupMenu to try to find the StatusIcon even though I'm not trying to popup the menu. This does get a position near the StatusIcon but the weird thing is that it only works after the PopupMenu has been popped up once.

Anyway, that got me a little closer and might help you or someone else find a complete solution.

jcoffland