def on_list_right_click(self, item):
     if item == -1:
         return
     item = self.list.model[item]
     menu = Menu()
     menu.append(Command('Delete', 'delete', object, 'stock_delete.png'))
     menu.append(None)
     menu.append(Command('Preview PostScript', 'Preview PostScript', 
                 lambda: self.on_preview_ps(item), 'stock_print-preview.png'))
     menu.append(Command('Export...', 'Export', object, 'stock_export.png'))
     self.list._widget.PopupMenu(menu._menu)
    def __init__(self):
#        print >>sys.stderr, "creating main window"
        Window.__init__(self, statusbar=True, size=(800, 600))
        self.title = 'Grafit'

        # for example
        self.main = MainPanel(self)

        self.shell = ScriptWindow(self.main.bottom_panel,
                                  page_label='console', page_pixmap='console.png')
        self.shell.locals['mainwin'] = self

        try:
            self.shell._widget.history = settings.get('script', 'history').split('\n')
        except:
            self.shell._widget.history = []
            pass
        self.explorer = ProjectExplorer(self.main.left_panel,
                                        page_label='project', page_pixmap='stock_navigator.png')
        self.actionlist = ActionList(action_list, self.main.left_panel,
                                        page_label='actions', page_pixmap='stock_undo.png')
        self.explorer.connect('item-activated', self.on_item_activated)

        self.project = Project()
        self.open_project(self.project)

        self.book = Notebook(self.main)
#        self.book.connect('page-changed', self.on_page_changed)

        self.main.left_panel.open(self.explorer)

        global_connect('status-message', self.on_status_message)
        action_list.connect('added', self.on_action)
        action_list.connect('removed', self.on_action)
        action_list.connect('modified', self.on_action)

        self.actions = actions = {
            'file-new': Command('New', 'Create a new project', self.on_project_new, 'new.png', 'Ctrl+N'),
            'file-open': Command('Open...', 'Open a project', self.on_project_open, 'open.png', 'Ctrl+O'),
            'file-save': Command('Save', 'Save the project', 
                                self.on_project_save, 'save.png', 'Ctrl+S'),
            'file-saveas': Command('Save As...', 'Save the project with a new name', 
                                  self.on_project_saveas, 'saveas.png'),
            'file-quit': Command('Quit', 'Quit grafit', self.on_quit, 'stock_exit.png', 'Ctrl+Q'),

            'edit-undo': Command('Undo', 'Undo the last action', undo, 'stock_undo.png', 'Ctrl+Z'),
            'edit-redo': Command('Redo', 'Redo the last action', redo, 'stock_redo.png', 'Shift+Ctrl+Z'),
            'edit-copy': Command('Copy', 'Undo the last action', object, 'stock_copy.png', 'Ctrl+C'),
            'edit-cut': Command('Cut', 'Undo the last action', object, 'stock_cut.png', 'Ctrl+X'),
            'edit-paste': Command('Paste', 'Undo the last action', 'stock_paste.png', None, 'Ctrl+V'),
            'edit-delete': Command('Delete', 'Undo the last action', 'stock_delete.png', None),

            'import-ascii': Command('Import ASCII...', 'Import and ASCII file', 
                                   self.on_import_ascii, 'import_ascii.png', 'Ctrl+I'),
            'object-new-worksheet': Command('New Worksheet', 'Create a new worksheet', 
                                           self.on_new_worksheet, 'new-worksheet.png'),
            'object-new-graph': Command('New Graph', 'Create a new worksheet', 
                                       self.on_new_graph, 'new-graph.png'),
            'object-new-folder': Command('New Folder', 'Create a new worksheet', 
                                        self.on_new_folder, 'new-folder.png'),
            'functions': Command('Functions...', '', object),
            'filters': Command('Filters...', '', object),
            'scripts': Command('Scripts...', '', object),
            'run-script': Command('Run script...', '', self.on_run_script),
            'integrate': Command('Integrate', '', self.on_integrate),
            'close-active-page': Command('Close', 'Close this worksheet',
                                         lambda: self.book.active_page.on_close(), 'close.png', 'Ctrl+W'),
            None: None
        }

        self.menubar = Menubar(self)
        for title, items in [
            ('&File', ['file-new', 'file-open', None, 
                       'file-save', 'file-saveas', None, 
                       'file-quit']),
            ('&Edit', ['edit-undo', 'edit-redo', None, 
                       'edit-cut', 'edit-copy', 'edit-paste', None, 'edit-delete']),
            ('&Tools', ['functions', 'filters', 'scripts', None, 'run-script']),
            ('&Analysis', ['integrate']),
            ('&Help', []),
        ]:
            menu = Menu(self.menubar, title)
            for item in items:
                menu.append(actions[item])

        self.toolbar = Toolbar(self)
        for item in [
            'file-new', 'file-open', 'file-save', 'file-saveas', None,
            'object-new-folder', 'object-new-worksheet', 'object-new-graph', None,
            'edit-undo', 'edit-redo', None,
            'import-ascii', None,
            'close-active-page',
        ]:
            self.toolbar.append(actions[item])
        self.toolbar._widget.Realize()
        
        self.connect('close', self.on_quit)

        self.main.bottom_panel._widget.toolbar.Realize()
        self.main.left_panel._widget.toolbar.Realize()
        self.main.right_panel._widget.toolbar.Realize()

        # preload
        wx.xrc.XmlResource(os.path.join(DATADIR, 'data', 'resources.xrc'))

        self.on_action()
        self.on_project_modified(False)

        if len(self.args) > 0:
            name = self.args[0]
            if ':' in name:
                prj, obj = name.split(':')
                self.open_project(Project(prj))
                self.on_item_activated(self.project.top[obj])
            else:
                self.open_project(Project(name))