views:

13

answers:

1

Recently I've started to learn pygtk . As an exercise, I am planing to build a small feed reader. Currently I have the following (working) code:

#!/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()

Everything works fine, but the pictures in the menu's aren't showing up. Have you any tips on that ? Is it a programmer's blindness kind of thing, and I am loosing something in the way ?

+1  A: 

The icons show up in the menus for me, make sure you have menu icons enabled. From a terminal: gconftool-2 --type bool --set /desktop/gnome/interface/menus_have_icons True

DoR
It's silly but this was the problem. Thanks!
Andrei Ciobanu