Exemplo n.º 1
0
    def add(self, recent):
        remove_action = None
        for a in self.qactions:
            if a.recent == recent:
                remove_action = a
                break

        a = QAction("1: " + recent, self.filemenu, triggered=(lambda r=recent : lambda :self.open_wrapper(r))())
        a.recent = recent
        self.filemenu.insertAction (self.next_element, a)
        self.qactions.insert(0, a)
        self.next_element = a
        if remove_action:
            self.qactions.remove(remove_action)
            self.filemenu.removeAction(remove_action)

        for i, a in enumerate(self.qactions, 1):
            a.setText("%d: %s" % (i, a.recent))

        recent_lst = self.parent.load_setting('recent_lst', "").split(";")
        recent_lst.insert(0, recent)
        self.parent.save_setting('recent_lst', ";".join(recent_lst[:3]))
        if len(self.qactions) > self.max:
            a = self.qactions.pop()
            self.filemenu.removeAction(a)
Exemplo n.º 2
0
 def __init__(self, parent, filemenu, open_func, next_element, max=10):
     self.parent = parent
     self.filemenu = filemenu
     self.open_func = open_func
     self.next_element = next_element
     self.max = max
     self.qactions = []
     for i, recent in enumerate([r for r in self.parent.load_setting('recent_lst', "").split(";") if r], 1):
         a = QAction("%d: %s" % (i, recent), self.filemenu, triggered=(lambda r=recent : lambda :self.open_wrapper(r))())
         a.recent = recent
         self.qactions.append(a)
         self.filemenu.insertAction (self.next_element, a)
     if self.qactions:
         self.next_element = self.qactions[0]