最近我开始学习pygtk。作为练习,我计划建立一个小型的阅读器。目前我有以下(工作)代码:
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
class FeedbarWindow():
prop_file = 'feedbar.prop' #Properties File
menu_bar_ui = """
<ui>
<menubar name="MenuBar">
<menu action="Feeds">
<menuitem action="RefreshAll"/>
<menuitem action="MarkAllAsRead"/>
</menu>
<menu action="About" name="AboutMenu">
<menuitem action="Version"/>
<menuitem action="ShowAbout"/>
</menu>
</menubar>
</ui>
"""
#INITIALIZERS
def __init__(self):
""" Initialize all the components in the Feedbar GUI """
#MAIN WINDOW
self.window = gtk.Window()
self.window.set_title("Feedbar")
self.window.set_size_request(500, 400)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.connect("destroy", self.window_destroy)
self.window.connect("delete-event", self.window_delete_event)
#MAIN VERTICAL BOX
self.main_vbox = gtk.VBox(False, 2)
self.window.add(self.main_vbox)
#ACTION GROUP (FOR MAIN MENU)
self.action_group = gtk.ActionGroup("MenuBarActionGroup")
self.action_group.add_actions([
("About", None, "_About"),
("Feeds", None, "_Feeds"),
("RefreshAll", gtk.STOCK_REFRESH, "_Refresh All", None, "Refresh all feeds", self.menu_refresh_all),
("MarkAllAsRead", gtk.STOCK_APPLY, "_Mark All As Read", None, "Mark all feeds as read", self.menu_mark_all_as_read),
("Version", gtk.STOCK_INDEX, "_Version", None, "Show current FeedBar version", self.menu_show_version),
("ShowAbout", gtk.STOCK_ABOUT, "_About", None, "About FeedBar", self.menu_show_about)
])
#UI MANAGER
self.ui_manager = gtk.UIManager()
accel_group = self.ui_manager.get_accel_group()
self.window.add_accel_group(accel_group)
self.ui_manager.insert_action_group(self.action_group, 0)
self.ui_manager.add_ui_from_string(self.menu_bar_ui)
#MENUBAR
self.menu_bar = self.ui_manager.get_widget("/MenuBar")
self.main_vbox.pack_start(self.menu_bar, expand=False, fill=False)
#SHOW COMPONENTS
self.window.show_all()
#CALLBACKS
def window_delete_event(self, widget, event, data=None):
""" CALLBACK --> gtk.Window.'delete-event' """
return False
def window_destroy(self, widget, data=None):
""" CALLBACK --> gtk.Window.'destroy' """
gtk.main_quit()
def menu_refresh_all(self, menu_item, data=None):
""" CALLBACK --> gtk.MenuItem."activate" - Refresh all """
return
def menu_mark_all_as_read(self, menu_item, data=None):
""" CALLBACK --> gtk.MenuItem."activate" - Mark all as read """
return
def menu_show_version(self, menu_item, data=None):
""" CALLBACK --> gtk.MenuItem."activate" - Show Version """
return
def menu_show_about(self, menu_item, data=None):
""" CALLBACK --> gtk.MenuItem."activate" - Show About """
return
#OTHER
def main(self):
""" Starts the GTK Loop, should be called
after the FeedbarFrame object is created"""
gtk.main();
if __name__ == "__main__":
feedbar = FeedbarWindow()
feedbar.main()
一切正常,但菜单中的图片没有显示出来。你有任何提示吗?这是一个程序员的失明之类的东西,我在路上失去了一些东西吗?
答案 0 :(得分:1)
图标显示在菜单中,确保您启用了菜单图标。
来自终端:gconftool-2 --type bool --set /desktop/gnome/interface/menus_have_icons True