def restoreSession(key): """Restore a session specified by key, previously saved by the session manager.""" settings = sessionSettings(key) ## restore current named session name session_name = settings.value('session_name', "", str) if session_name: import sessions sessions.setCurrentSession(session_name) ## restore documents numdocuments = settings.value('numdocuments', 0, int) doc = None for index in range(numdocuments): settings.beginGroup("document{0}".format(index)) url = settings.value("url", QUrl(), QUrl) if url.isEmpty(): import document doc = document.EditorDocument() else: try: doc = app.openUrl(url) except IOError: pass settings.endGroup() # open at least one if doc is None: doc = app.openUrl(QUrl()) ## restore windows numwindows = settings.value('numwindows', 0, int) if numwindows > 0: for index in range(numwindows): settings.beginGroup("mainwindow{0}".format(index)) win = mainwindow.MainWindow() win.readSessionSettings(settings) win.show() app.qApp.processEvents() # init (re)size dock tools u = settings.value("active_document", QUrl(), QUrl) # we don't use app.findDocument because it does not allow empty url for d in app.documents: if u == d.url(): win.setCurrentDocument(d) break else: win.setCurrentDocument(app.documents[0]) settings.endGroup() else: win = mainwindow.MainWindow() win.show() app.qApp.processEvents() # init (re)size dock tools
def main(): """Main function.""" args = parse_commandline() if args.version_debug: import debuginfo sys.stdout.write(debuginfo.version_info_string() + '\n') sys.exit(0) if args.python_ly: # The python-ly path has to be inserted at the *second* position # because the first element in sys.path is the directory of the invoked # script (an information we need in determining if Frescobaldi is run # from its Git repository) sys.path.insert(1, args.python_ly) check_ly() if args.list_sessions: import sessions for name in sessions.sessionNames(): sys.stdout.write(name + '\n') sys.exit(0) urls = list(map(url, args.files)) if not app.qApp.isSessionRestored(): if not args.new and remote.enabled(): api = remote.get() if api: api.command_line(args, urls) api.close() sys.exit(0) if QSettings().value("splash_screen", True, bool): import splashscreen splashscreen.show() # application icon import icons QApplication.setWindowIcon(icons.get("frescobaldi")) QTimer.singleShot(0, remote.setup) # Start listening for IPC import mainwindow # contains MainWindow class import session # Initialize QSessionManager support import sessions # Initialize our own named session support # boot Frescobaldi-specific stuff that should be running on startup import viewhighlighter # highlight arbitrary ranges in text import progress # creates progress bar in view space import musicpos # shows music time in statusbar import autocomplete # auto-complete input import wordboundary # better wordboundary behaviour for the editor if sys.platform.startswith('darwin'): import macosx.setup macosx.setup.initialize() if app.qApp.isSessionRestored(): # Restore session, we are started by the session manager session.restoreSession(app.qApp.sessionKey()) return # load specified session? doc = None if args.session and args.session != "-": doc = sessions.loadSession(args.session) # Just create one MainWindow win = mainwindow.MainWindow() win.show() win.activateWindow() # load documents given as arguments import document for u in urls: doc = win.openUrl(u, args.encoding, ignore_errors=True) if not doc: doc = document.EditorDocument(u, args.encoding) # were documents loaded? if not doc: if app.documents: doc = app.documents[-1] elif not args.session: # no docs, load default session doc = sessions.loadDefaultSession() if doc: win.setCurrentDocument(doc) else: win.cleanStart() if urls and args.line is not None: # set the last loaded document active and apply navigation if requested pos = doc.findBlockByNumber(args.line - 1).position() + args.column cursor = QTextCursor(doc) cursor.setPosition(pos) win.currentView().setTextCursor(cursor) win.currentView().centerCursor()