Example #1
0
 def validate(self):
     """Checks if the input is acceptable.
     
     If this method returns True, the dialog is accepted when OK is clicked.
     Otherwise a messagebox could be displayed, and the dialog will remain
     visible.
     """
     name = self.name.text().strip()
     self.name.setText(name)
     if not name:
         self.name.setFocus()
         QMessageBox.warning(self, app.caption(_("Warning")),
             _("Please enter a session name."))
         if self._originalName:
             self.name.setText(self._originalName)
         return False
     
     elif name == 'none':
         self.name.setFocus()
         QMessageBox.warning(self, app.caption(_("Warning")),
             _("Please do not use the name '{name}'.".format(name="none")))
         return False
     
     elif self._originalName != name and name in sessions.sessionNames():
         self.name.setFocus()
         box = QMessageBox(QMessageBox.Warning, app.caption(_("Warning")),
             _("Another session with the name {name} already exists.\n\n"
               "Do you want to overwrite it?").format(name=name),
             QMessageBox.Discard | QMessageBox.Cancel, self)
         box.button(QMessageBox.Discard).setText(_("Overwrite"))
         result = box.exec_()
         if result != QMessageBox.Discard:
             return False
         
     return True
Example #2
0
def menu_sessions(parent):
    m = QMenu(parent)
    m.setTitle(_('menu title', '&Session'))
    m.triggered.connect(slot_session_action)
    import sessions
    for name in sessions.sessionNames():
        a = m.addAction(name.replace('&', '&&'))
        a.setObjectName(name)
    qutil.addAccelerators(m.actions())
    return m
Example #3
0
    def populate(self):
        groups = {}
        tl_sessions = []

        def add_session(menu, name, group=None):
            name = name.replace('&', '&&')
            fullname = group + '/' + name if group else name
            a = menu.addAction(name)
            a.setCheckable(True)
            if fullname == sessions.currentSession():
                a.setChecked(True)
                if group:
                    menu.setTitle('* ' + menu.title())
            a.setObjectName(fullname)
            self._actionGroup.addAction(a)

        def add_sessions():
            for name in tl_sessions:
                add_session(self, name)

        def add_groups():
            for k in sorted(groups.keys()):
                m = self.addMenu(k)
                self.groupMenus.append(m)
                for name in groups[k]:
                    add_session(m, name, k)
                qutil.addAccelerators(m.actions())

        def reset_menu():
            for m in self.groupMenus:
                m.deleteLater()
            self.groupMenus = []
            ac = manager.get(self.parentWidget()).actionCollection
            ag = self._actionGroup
            for a in ag.actions():
                if a is not ac.session_none:
                    self.removeAction(a)
                    ag.removeAction(a)
            ac.session_none.setChecked(not sessions.currentSession())

        reset_menu()
        for name in sessions.sessionNames():
            if '/' in name:
                group, name = name.split('/')
                if group in groups:
                    groups[group].append(name)
                else:
                    groups[group] = [name]
            else:
                tl_sessions.append(name)
        add_groups()
        if groups:
            self.addSeparator()
        add_sessions()
        qutil.addAccelerators(self.actions())
Example #4
0
    def populate(self):
        groups = {}
        tl_sessions = []

        def add_session(menu, name, group=None):
            name = name.replace('&', '&&')
            fullname = group + '/' + name if group else name
            a = menu.addAction(name)
            a.setCheckable(True)
            if fullname == sessions.currentSession():
                a.setChecked(True)
                if group:
                    menu.setTitle('* ' + menu.title())
            a.setObjectName(fullname)
            self._actionGroup.addAction(a)

        def add_sessions():
            for name in tl_sessions:
                add_session(self, name)

        def add_groups():
            for k in sorted(groups.keys()):
                m = self.addMenu(k)
                self.groupMenus.append(m)
                for name in groups[k]:
                    add_session(m, name, k)
                qutil.addAccelerators(m.actions())

        def reset_menu():
            for m in self.groupMenus:
                m.deleteLater()
            self.groupMenus = []
            ac = manager.get(self.parentWidget()).actionCollection
            ag = self._actionGroup
            for a in ag.actions():
                if a is not ac.session_none:
                    self.removeAction(a)
                    ag.removeAction(a)
            ac.session_none.setChecked(not sessions.currentSession())

        reset_menu()
        for name in sessions.sessionNames():
            if '/' in name:
                group, name = name.split('/')
                if group in groups:
                    groups[group].append(name)
                else:
                    groups[group] = [name]
            else:
                tl_sessions.append(name)
        add_groups()
        if groups:
            self.addSeparator()
        add_sessions()
        qutil.addAccelerators(self.actions())
Example #5
0
 def populate(self):
     ac = manager.get(self.parentWidget()).actionCollection
     ag = self._actionGroup
     for a in ag.actions():
         if a is not ac.session_none:
             self.removeAction(a)
             ag.removeAction(a)
     ac.session_none.setChecked(not sessions.currentSession())
     for name in sessions.sessionNames():
         a = self.addAction(name.replace('&', '&&'))
         a.setCheckable(True)
         if name == sessions.currentSession():
             a.setChecked(True)
         a.setObjectName(name)
         ag.addAction(a)
     qutil.addAccelerators(self.actions())
Example #6
0
 def loadSettings(self):
     s = QSettings()
     s.beginGroup("session")
     startup = s.value("startup", "none", type(""))
     if startup == "lastused":
         self.lastused.setChecked(True)
     elif startup == "custom":
         self.custom.setChecked(True)
     else:
         self.none.setChecked(True)
     sessionNames = sessions.sessionNames()
     self.combo.clear()
     self.combo.addItems(sessionNames)
     custom = s.value("custom", "", type(""))
     if custom in sessionNames:
         self.combo.setCurrentIndex(sessionNames.index(custom))
Example #7
0
 def loadSettings(self):
     s = QSettings()
     s.beginGroup("session")
     startup = s.value("startup", "none", type(""))
     if startup ==  "lastused":
         self.lastused.setChecked(True)
     elif startup == "custom":
         self.custom.setChecked(True)
     else:
         self.none.setChecked(True)
     sessionNames = sessions.sessionNames()
     self.combo.clear()
     self.combo.addItems(sessionNames)
     custom = s.value("custom", "", type(""))
     if custom in sessionNames:
         self.combo.setCurrentIndex(sessionNames.index(custom))
Example #8
0
 def populate(self):
     ac = manager.get(self.parentWidget()).actionCollection
     ag = self._actionGroup
     for a in ag.actions():
         if a is not ac.session_none:
             self.removeAction(a)
             ag.removeAction(a)
     ac.session_none.setChecked(not sessions.currentSession())
     for name in sessions.sessionNames():
         a = self.addAction(name.replace('&', '&&'))
         a.setCheckable(True)
         if name == sessions.currentSession():
             a.setChecked(True)
         a.setObjectName(name)
         ag.addAction(a)
     qutil.addAccelerators(self.actions())
Example #9
0
    def loadSettings(self):
        s = QSettings()
        self.verbose_toolbuttons.setChecked(
            s.value("verbose_toolbuttons", False, bool))

        # New Documents Tab
        ndoc = s.value("new_document", "empty", str)
        template = s.value("new_document_template", "", str)
        if template in self._names:
            self.new_combo.setCurrentIndex(self._names.index(template))
        if ndoc == "template":
            self.template.setChecked(True)
        elif ndoc == "version":
            self.lilyVersion.setChecked(True)
        else:
            self.emptyDocument.setChecked(True)

        # Saving Files Tab
        self.stripwsp.setChecked(
            s.value("strip_trailing_whitespace", False, bool))
        self.backup.setChecked(s.value("backup_keep", False, bool))
        self.metainfo.setChecked(s.value("metainfo", True, bool))
        self.basedir.setPath(s.value("basedir", "", str))
        self.customFilename.setChecked(
            s.value("custom_default_filename", False, bool))
        self.filenameTemplate.setText(
            s.value("default_filename_template", "{composer}-{title}", str))
        self.filenameTemplate.setEnabled(self.customFilename.isChecked())

        # Sessions Tab
        s.beginGroup("session")
        startup = s.value("startup", "none", str)
        if startup == "lastused":
            self.session_lastused.setChecked(True)
        elif startup == "custom":
            self.session_custom.setChecked(True)
        else:
            self.session_none.setChecked(True)
        sessionNames = sessions.sessionNames()
        self.session_combo.clear()
        self.session_combo.addItems(sessionNames)
        custom = s.value("custom", "", str)
        if custom in sessionNames:
            self.session_combo.setCurrentIndex(sessionNames.index(custom))
        s.endGroup()
        self.tabs.setCurrentIndex(
            s.value("prefs_general_file_tab_index", 0, int))
Example #10
0
    def validate(self):
        """Checks if the input is acceptable.
        
        If this method returns True, the dialog is accepted when OK is clicked.
        Otherwise a messagebox could be displayed, and the dialog will remain
        visible.
        """
        name = self.name.text().strip()
        self.name.setText(name)
        if not name:
            self.name.setFocus()
            QMessageBox.warning(self, app.caption(_("Warning")),
                                _("Please enter a session name."))
            if self._originalName:
                self.name.setText(self._originalName)
            return False

        elif name == '-':
            self.name.setFocus()
            QMessageBox.warning(
                self, app.caption(_("Warning")),
                _("Please do not use the name '{name}'.".format(name="-")))
            return False

        elif self._originalName != name and name in sessions.sessionNames():
            self.name.setFocus()
            box = QMessageBox(
                QMessageBox.Warning, app.caption(_("Warning")),
                _("Another session with the name {name} already exists.\n\n"
                  "Do you want to overwrite it?").format(name=name),
                QMessageBox.Discard | QMessageBox.Cancel, self)
            box.button(QMessageBox.Discard).setText(_("Overwrite"))
            result = box.exec_()
            if result != QMessageBox.Discard:
                return False

        return True
Example #11
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()
Example #12
0
 def load(self):
     names = sessions.sessionNames()
     current = sessions.currentSession()
     self.setValue(names)
     if current in names:
         self.setCurrentRow(names.index(current))
Example #13
0
 def slotSessionsAction(self, action):
     if action.objectName() in sessions.sessionNames():
         manager.get(self.parentWidget()).startSession(action.objectName())
Example #14
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()
Example #15
0
 def slotSessionsAction(self, action):
     if action.objectName() in sessions.sessionNames():
         manager.get(self.parentWidget()).startSession(action.objectName())
Example #16
0
 def load(self):
     names = sessions.sessionNames()
     current = sessions.currentSession()
     self.setValue(names)
     if current in names:
         self.setCurrentRow(names.index(current))
Example #17
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
    
    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()
Example #18
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()
Example #19
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()