add recent events to file menu

This commit is contained in:
Sebastian Wehling-Benatelli 2015-01-20 13:44:35 +01:00
parent 2961867c10
commit 9bbbe89b36

View File

@ -113,15 +113,21 @@ class MainWindow(QMainWindow):
def updateFileMenu(self): def updateFileMenu(self):
self.fileMenu.clear() self.fileMenu.clear()
self.addActions(self.fileMenu, self.fileMenuActions[:-1]) for action in self.fileMenuActions[:-1]:
current = self.data.evtdata.getID() if action is None:
self.fileMenu.addSeparator()
else:
self.fileMenu.addAction(action)
try:
current = self.data.evtdata.getID()
except AttributeError:
current = None
recentEvents = [] recentEvents = []
for eventID in self.recentEvents: for eventID in self.recentEvents:
fname = fnConstructor(eventID) fname = fnConstructor(eventID)
if eventID != current and QFile.exists(fname): if eventID != current and QFile.exists(fname):
recentEvents.append(eventID) recentEvents.append(eventID)
if recentEvents: if recentEvents:
self.fileMenu.addSeparator()
for i, eventID in enumerate(recentEvents): for i, eventID in enumerate(recentEvents):
fname = fnConstructor(eventID) fname = fnConstructor(eventID)
action = QAction(QIcon(":/icon.png"), action = QAction(QIcon(":/icon.png"),
@ -231,7 +237,10 @@ class MainWindow(QMainWindow):
self.fileMenuActions = (openEventAction, saveEventAction, None, self.fileMenuActions = (openEventAction, saveEventAction, None,
prefsEventAction, None, prefsEventAction, None,
quitAction) quitAction)
self.fileMenuActions = (openEventAction, saveEventAction,
prefsEventAction, quitAction)
self.fileMenu.aboutToShow.connect(self.updateFileMenu) self.fileMenu.aboutToShow.connect(self.updateFileMenu)
self.updateFileMenu()
self.editMenu = self.menuBar().addMenu('&Edit') self.editMenu = self.menuBar().addMenu('&Edit')
for action in (filterAction, filterEditAction, None, selectPAction, for action in (filterAction, filterEditAction, None, selectPAction,