def reloadRecentWorlds(self): recentWorlds = RecentFilesSetting.value() self.recentWorldsMenu = QtGui.QMenu() def _triggered(f): def triggered(): self.accept() self.editWorldClicked.emit(f) return triggered dead = [] for filename in recentWorlds: if not os.path.exists(filename): dead.append(filename) continue try: displayName, lastPlayed, versionInfo = getWorldInfo(filename) action = self.recentWorldsMenu.addAction(displayName) action._editWorld = _triggered(filename) action.triggered.connect(action._editWorld) except EnvironmentError as e: log.exception("Failed to load world info") if len(dead): for f in dead: recentWorlds.remove(f) RecentFilesSetting.setValue(recentWorlds) self.recentWorldsButton.setMenu(self.recentWorldsMenu)
def reloadRecentWorlds(self): recentWorlds = RecentFilesSetting.value() self.recentWorldsMenu = QtGui.QMenu() def _triggered(f): def triggered(): self.accept() self.editWorldClicked.emit(f) return triggered dead = [] for filename in recentWorlds: if not os.path.exists(filename): dead.append(filename) continue try: displayName, lastPlayed, versionInfo = WorldEditor.getWorldInfo(filename) action = self.recentWorldsMenu.addAction(displayName) action._editWorld = _triggered(filename) action.triggered.connect(action._editWorld) except EnvironmentError as e: log.exception("Failed to load world info") if len(dead): for f in dead: recentWorlds.remove(f) RecentFilesSetting.setValue(recentWorlds) self.recentWorldsButton.setMenu(self.recentWorldsMenu)
def addRecentFile(self, filename): recentFiles = RecentFilesSetting.value() if filename in recentFiles: recentFiles.remove(filename) recentFiles.insert(0, filename) if len(recentFiles) > self.recentFileLimit: recentFiles = recentFiles[:-1] RecentFilesSetting.setValue(recentFiles) self.updateRecentFilesMenu()
def updateRecentFilesMenu(self): recentFiles = RecentFilesSetting.value() recentWorldsMenu = self.mainWindow.menuRecent_Worlds for i, child in enumerate(recentWorldsMenu.children()): if i < 2: continue # Skip "clear" and separator child.setParent(None) log.info("Updating recent files menu: (%d) %s", len(recentFiles), recentFiles) filenames = [] displayNames = collections.Counter() for filename in recentFiles: text = util.displayName(filename) filenames.append((text, filename)) displayNames[text] += 1 displayFilenames = [] for text, path in filenames: if displayNames[text] > 1: text += " (%s)" % path displayFilenames.append((text, path)) for text, path in displayFilenames: log.info("Adding %s", text) action = recentWorldsMenu.addAction(text) def _triggered(p): def _f(): self.loadFile(p) return _f triggered = _triggered(path) action.triggered.connect(triggered) action.__triggered = triggered
def reloadRecentWorlds(self): recentWorlds = RecentFilesSetting.value() self.recentWorldsMenu = QtGui.QMenu() def _triggered(f): def triggered(): self.accept() self.editWorldClicked.emit(f) return triggered for filename in recentWorlds: try: displayName, lastPlayed = getWorldInfo(filename) action = self.recentWorldsMenu.addAction(displayName) action._editWorld = _triggered(filename) action.triggered.connect(action._editWorld) except EnvironmentError as e: log.exception("Failed to load world info") self.recentWorldsButton.setMenu(self.recentWorldsMenu)