简体   繁体   English

MacOSX,Windows和Linux(Gnome)和python上的GTK +中的状态图标

[英]Status icon in GTK+ on MacOSX, Windows, and Linux(Gnome) and python

I'm developing an application in python and it will be used in Windows MacOsX and Linux, and now i'm developing system (status icon) icon (and the menu when you click) in Mac OSX bar. 我正在使用python开发一个应用程序,它将在Windows MacOsX和Linux中使用,现在我正在Mac OSX栏中开发系统(状态图标)图标(以及单击时的菜单)。 Can I use PyGTK in windows, mac and linux and use the same code for show status icon in status bar (macosx), system tray(windows), or linux? 我可以在windows,mac和linux中使用PyGTK,并在状态栏(macosx),系统托盘(windows)或linux中使用相同的代码来显示状态图标吗?

Thanks in advance. 提前致谢。 This is the code: 这是代码:

import gtk


class SystrayIconApp:
    def __init__(self):
        self.tray = gtk.StatusIcon()
        self.tray.set_from_stock(gtk.STOCK_ABOUT) 
        self.tray.connect('popup-menu', self.on_right_click)
        self.tray.set_tooltip(('Sample tray app'))


        def on_right_click(self, icon, event_button, event_time):
          self.make_menu(event_button, event_time)

        def make_menu(self, event_button, event_time):
          menu = gtk.Menu()

          # show about dialog
          about = gtk.MenuItem("About")
          about.show()
          menu.append(about)
          about.connect('activate', self.show_about_dialog)

          # add quit item
          quit = gtk.MenuItem("Quit")
          quit.show()
          menu.append(quit)
          quit.connect('activate', gtk.main_quit)

          menu.popup(None, None, gtk.status_icon_position_menu,
                   event_button, event_time, self.tray)

    def  show_about_dialog(self, widget):
        about_dialog = gtk.AboutDialog()
        about_dialog.set_destroy_with_parent (True)
        about_dialog.set_icon_name ("SystrayIcon")
        about_dialog.set_name('SystrayIcon')
        about_dialog.set_version('0.1')
        about_dialog.set_copyright("(C) 2010 João Pinto")
        about_dialog.set_comments(("Program to demonstrate a system tray icon"))
        about_dialog.set_authors(['João Pinto <joao.pinto@getdeb.net>'])
        about_dialog.run()
        about_dialog.destroy()

if __name__ == "__main__":
    SystrayIconApp()
    gtk.main()

This is de tray in MAC OS X (the star from gtk+): 这是MAC OS X中的de tray(来自gtk +的星):

这是MAC OS X中的系统托盘

This is the tray in WINDOWS (the star from gtk+): 这是WINDOWS中的托盘(来自gtk +的星形):

这是WINDOWS中的托盘

On windows no problem, menu is visible when you click the icon, but in Mac OX, icos is showed but menu is not displayed. 在Windows上没有问题,单击图标时菜单可见,但在Mac OX中,显示icos但不显示菜单。

What is the problem with the code? 代码有什么问题?

Short answer: Yes ! 简答:是的!

Qt manages the status icons integration in all compatible operating systems. Qt管理所有兼容操作系统中的状态图标集成。

You just have to use the QSystemTrayIcon class in order to do that. 您只需使用QSystemTrayIcon类即可。

The QSystemTrayIcon class provides an icon for an application in the system tray. QSystemTrayIcon类为系统托盘中的应用程序提供图标。 Modern operating systems usually provide a special area on the desktop, called the system tray or notification area, where long-running applications can display icons and short messages. 现代操作系统通常在桌面上提供一个称为系统托盘或通知区域的特殊区域,其中长时间运行的应用程序可以显示图标和短消息。

More information on the Qt Documentation . 有关Qt文档的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM