获取 Windows 上 gtk.StatusIcon 的位置
我正在协助 Windows 支持 PyGTK 应用程序,该应用程序显示为系统托盘小程序,但我对 GTK+ 粘糊糊的东西不太感兴趣......
我们有它,所以当您左键单击系统托盘图标时,窗口会出现在您的右侧无论您的系统托盘位于何处,托盘图标都可以使用 gtk.StatusIcon.get_geometry() 的结果来计算大小和位置,这在 Linux 上效果很好。
当然,gtk.StatusIcon.get_geometry() 的文档指出“某些平台不提供此信息”——这包括 MS Windows,因为我得到 NoneType 作为结果。
我可以猜测并将窗口放置在屏幕的右下角,距底部 30 像素处,因为这会吸引大多数未移动任务栏的 Windows 用户。 但对于那些有过这种经历的人来说,这一切看起来都是错误的。
那么有没有一种 Windows 友好的方法来获取系统托盘图标的位置,以便我可以将窗口放置在那里?
请注意:我已经将 gtk_menu_popup()
与 gtk_status_icon_position_menu
一起使用,以获得可以正常工作的弹出菜单。
但我试图定位的是一个单独的 gtk.Window,它不接受 gtk_status_icon_position_menu (因为它不是菜单)。
任何其他想法将不胜感激......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Gtk 提供了函数 gtk_status_icon_position_menu ,可以将其作为 GtkPositionFunc 传递到 gtk_menu_popup 中。
这似乎提供了所需的功能。
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.
我也在寻找这个问题的答案,但发现了一些可能有帮助的东西。
在我看来,GTK 找出了从鼠标位置调出 PopupMenu 的位置。 不知何故,它发现鼠标按钮是在 StatusIcon 上单击的。 据推测,要么来自窗口系统发送的鼠标事件,要么来自对 StatusIcon 所在位置的某种了解。
我的意思是,GTK 必须 1)知道 StatusIcon 的实际位置,或者 2)当鼠标单击 StatusIcon 时从窗口系统获取事件。 所以它必须知道这些信息。
我还有一个想要在 StatusIcon 附近升起的弹出窗口,并且我还有一个工作正常的 PopupMenu。 所以我在 pygtk 中尝试了这个:
我传入 PopupMenu 来尝试找到 StatusIcon,即使我没有尝试弹出菜单。 这确实获得了靠近 StatusIcon 的位置,但奇怪的是它只有在 PopupMenu 弹出一次后才起作用。
不管怎样,这让我更接近了一点,可能会帮助您或其他人找到完整的解决方案。
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:
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.
我在使用 gtk_status_icon_position_menu 的窗口中经历的行为是,它在用户在状态图标中单击的位置生成窗口
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