예제 #1
0
파일: main.py 프로젝트: m0003r/frescobaldi
def main():
    """Main function."""
    options, files = parse_commandline()
    urls = list(map(url, files))
    
    if not app.qApp.isSessionRestored():
        if not options.new and remote.enabled():
            api = remote.get()
            if api:
                api.command_line(options, urls)
                api.close()
                sys.exit(0)
    
        if QSettings().value("splash_screen", True) not in ("false", False):
            import splashscreen
            splashscreen.show()

    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
    import document         # contains Document class

    # boot Frescobaldi-specific stuff that should be running on startup
    import viewhighlighter  # highlight arbitrary ranges in text
    import matcher          # matches braces etc in active text window
    import progress         # creates progress bar in view space
    import autocomplete     # auto-complete input
    
    if app.qApp.isSessionRestored():
        # Restore session, we are started by the session manager
        session.restoreSession()
        return

    # load specified session
    doc = None
    if options.session and options.session != "none":
        doc = sessions.loadSession(options.session)
        
    # Just create one MainWindow
    win = mainwindow.MainWindow()
    win.show()
    
    if urls:
        for u in urls:
            doc = win.openUrl(u, options.encoding)
    elif not options.session:
        # no docs, load default session
        doc = sessions.loadDefaultSession()
    win.setCurrentDocument(doc or document.Document())
    if urls and options.line is not None:
        # set the last loaded document active and apply navigation if requested
        pos = doc.findBlockByNumber(options.line - 1).position() + options.column
        cursor = QTextCursor(doc)
        cursor.setPosition(pos)
        win.currentView().setTextCursor(cursor)
        win.currentView().centerCursor()
예제 #2
0
 def loadSettings(self):
     s = QSettings()
     lang = s.value("language", "", type(""))
     try:
         index = self._langs.index(lang)
     except ValueError:
         index = 1
     self.lang.setCurrentIndex(index)
     style = s.value("guistyle", "", type("")).lower()
     styles = [name.lower() for name in QStyleFactory.keys()]
     try:
         index = styles.index(style) + 1
     except ValueError:
         index = 0
     self.styleCombo.setCurrentIndex(index)
     self.systemIcons.setChecked(s.value("system_icons", True, bool))
     self.splashScreen.setChecked(s.value("splash_screen", True, bool))
     self.allowRemote.setChecked(remote.enabled())
예제 #3
0
 def loadSettings(self):
     s = QSettings()
     lang = s.value("language", "", type(""))
     try:
         index = self._langs.index(lang)
     except ValueError:
         index = 1
     self.lang.setCurrentIndex(index)
     style = s.value("guistyle", "", type("")).lower()
     styles = [name.lower() for name in QStyleFactory.keys()]
     try:
         index = styles.index(style) + 1
     except ValueError:
         index = 0
     self.styleCombo.setCurrentIndex(index)
     self.systemIcons.setChecked(s.value("system_icons", True, bool))
     self.splashScreen.setChecked(s.value("splash_screen", True, bool))
     self.allowRemote.setChecked(remote.enabled())
예제 #4
0
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()
예제 #5
0
def main():
    """Main function."""
    args = parse_commandline()

    if args.version_debug:
        import debuginfo
        sys.stdout.write(debuginfo.version_info_string() + '\n')
        sys.exit(0)

    check_ly()
    patch_pyqt()

    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.Document(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()
예제 #6
0
def main():
    """Main function."""
    options, files = parse_commandline()

    if options.list_sessions:
        import sessions
        for name in sessions.sessionNames():
            sys.stdout.write(name + '\n')
        sys.exit(0)

    urls = list(map(url, files))

    if not app.qApp.isSessionRestored():
        if not options.new and remote.enabled():
            api = remote.get()
            if api:
                api.command_line(options, 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

    if app.qApp.isSessionRestored():
        # Restore session, we are started by the session manager
        session.restoreSession()
        return

    # load specified session?
    doc = None
    if options.session and options.session != "-":
        doc = sessions.loadSession(options.session)

    # Just create one MainWindow
    win = mainwindow.MainWindow()
    win.show()

    # load documents given as arguments
    for u in urls:
        doc = win.openUrl(u, options.encoding)

    # were documents loaded?
    if not doc:
        if app.documents:
            doc = app.documents[-1]
        elif not options.session:
            # no docs, load default session
            doc = sessions.loadDefaultSession()

    if doc:
        win.setCurrentDocument(doc)
    else:
        win.cleanStart()

    if urls and options.line is not None:
        # set the last loaded document active and apply navigation if requested
        pos = doc.findBlockByNumber(options.line -
                                    1).position() + options.column
        cursor = QTextCursor(doc)
        cursor.setPosition(pos)
        win.currentView().setTextCursor(cursor)
        win.currentView().centerCursor()
예제 #7
0
def main():
    """Main function."""
    options, files = parse_commandline()
    
    if options.list_sessions:
        import sessions
        for name in sessions.sessionNames():
            sys.stdout.write(name + '\n')
        sys.exit(0)
        
    urls = list(map(url, files))
    
    if not app.qApp.isSessionRestored():
        if not options.new and remote.enabled():
            api = remote.get()
            if api:
                api.command_line(options, 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
    import document         # contains Document class

    # 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 autocomplete     # auto-complete input
    import wordboundary     # better wordboundary behaviour for the editor
    
    # on Mac OS X, handle FileOpen requests (e.g. double-clicking a file in the
    # Finder), these events also can occur right on application start.
    # We do this just before creating the window, so that when multiple files
    # are opened on startup (I don't know whether that really could happen),
    # they are not made the current document, as that slows down loading
    # multiple documents drastically.
    if sys.platform.startswith('darwin'):
        import file_open_eventhandler
        import icon_drag_eventhandler   # handle window icon drag events
    
    if app.qApp.isSessionRestored():
        # Restore session, we are started by the session manager
        session.restoreSession()
        return

    # load specified session?
    doc = None
    if options.session and options.session != "-":
        doc = sessions.loadSession(options.session)
    
    # Just create one MainWindow
    win = mainwindow.MainWindow()
    win.show()
    
    # load documents given as arguments
    for u in urls:
        doc = win.openUrl(u, options.encoding)
    
    # were documents loaded?
    if not doc:
        if app.documents:
            doc = app.documents[-1]
        elif not options.session:
            # no docs, load default session
            doc = sessions.loadDefaultSession()
    
    win.setCurrentDocument(doc or document.Document())
    
    if urls and options.line is not None:
        # set the last loaded document active and apply navigation if requested
        pos = doc.findBlockByNumber(options.line - 1).position() + options.column
        cursor = QTextCursor(doc)
        cursor.setPosition(pos)
        win.currentView().setTextCursor(cursor)
        win.currentView().centerCursor()