예제 #1
0
    def build(self):
        buf = StringIO()
        buf.write(_RCT_TOP)
        gramps_rf = RecentFiles()

        count = 0

        if self.active != DISABLED:
            self.uimanager.remove_ui(self.active)
            self.uimanager.remove_action_group(self.action_group)
            self.action_group = Gtk.ActionGroup(name='RecentFiles')
            self.active = DISABLED

        actions = []
        rfiles = gramps_rf.gramps_recent_files
        rfiles.sort(key=lambda x: x.get_time(), reverse=True)

        new_menu = Gtk.Menu()

        for item in rfiles:
            try:
                title = item.get_name()
                filename = os.path.basename(item.get_path())
                action_id = "RecentMenu%d" % count
                buf.write('<menuitem action="%s"/>' % action_id)
                actions.append((action_id, None, title, None, None,
                                make_callback(item, self.load)))
                mitem = Gtk.MenuItem(label=title, use_underline=False)
                mitem.connect('activate', make_callback(item, self.load))
                mitem.show()
                new_menu.append(mitem)
            except RuntimeError:
                _LOG.info("Ignoring the RecentItem %s (%s)" %
                          (title, filename))
                pass  # ignore no longer existing files

            count += 1
        buf.write(_RCT_BTM)
        self.action_group.add_actions(actions)
        self.uimanager.insert_action_group(self.action_group, 1)
        self.active = self.uimanager.add_ui_from_string(buf.getvalue())
        self.uimanager.ensure_update()
        buf.close()

        if len(rfiles) > 0:
            new_menu.show()
            self.uistate.set_open_recent_menu(new_menu)
예제 #2
0
    def build(self, update_menu=True):
        gramps_rf = RecentFiles()

        count = 0

        if self.active != DISABLED:
            self.uimanager.remove_ui(self.ui_xml)
            self.uimanager.remove_action_group(self.action_group)
            self.active = DISABLED

        actionlist = []
        menu = _RCT_TOP
        bar = _RCT_BAR_TOP
        rfiles = gramps_rf.gramps_recent_files
        rfiles.sort(key=lambda x: x.get_time(), reverse=True)

        #new_menu = Gtk.Menu()
        #new_menu.set_tooltip_text(_("Connect to a recent database"))

        for item in rfiles:
            try:
                title = html.escape(item.get_name())
                filename = os.path.basename(item.get_path())
                action_id = "RecentMenu%d" % count
                # add the menuitem for this file
                menu += _RCT_MENU % (action_id, title)
                # add the action for this file
                actionlist.append((action_id, make_callback(item, self.load)))
                # add the toolbar menuitem
                bar += _RCT_BAR % (action_id, title)
            except RuntimeError:
                # ignore no longer existing files
                _LOG.info("Ignoring the RecentItem %s (%s)" %
                          (title, filename))

            count += 1
        menu += _RCT_BTM
        bar += _RCT_BAR_BTM
        self.ui_xml = [menu, bar]
        self.action_group.add_actions(actionlist)
        self.uimanager.insert_action_group(self.action_group)
        self.active = self.uimanager.add_ui_from_string(self.ui_xml)
        if update_menu:
            self.uimanager.update_menu()