예제 #1
0
파일: api.py 프로젝트: AlexSchr/frescobaldi
 def command(self, command):
     """Perform one command."""
     command = command.split()
     cmd = command[0]
     args = command[1:]
     
     win = app.activeWindow()
     if not win:
         import mainwindow
         win = mainwindow.MainWindow()
         win.show()
     
     if cmd == b'open':
         url = QUrl.fromEncoded(args[0])
         win.openUrl(url, self.encoding)
             
     elif cmd == b'encoding':
         self.encoding = str(args[0])
     elif cmd == b'activate_window':
         win.activateWindow()
         win.raise_()
     elif cmd == b'set_current':
         url = QUrl.fromEncoded(args[0])
         try:
             win.setCurrentDocument(app.openUrl(url)) # already loaded
         except IOError:
             pass
     elif cmd == b'set_cursor':
         line, column = map(int, args)
         cursor = win.textCursor()
         pos = cursor.document().findBlockByNumber(line - 1).position() + column
         cursor.setPosition(pos)
         win.currentView().setTextCursor(cursor)
     elif cmd == b'bye':
         self.close()
예제 #2
0
파일: api.py 프로젝트: zsalch/frescobaldi
    def command(self, command):
        """Perform one command."""
        command = command.split()
        cmd = command[0]
        args = command[1:]

        win = app.activeWindow()
        if not win:
            import mainwindow
            win = mainwindow.MainWindow()
            win.show()

        if cmd == b'open':
            url = QUrl.fromEncoded(args[0])
            win.openUrl(url, self.encoding)

        elif cmd == b'encoding':
            self.encoding = str(args[0])
        elif cmd == b'activate_window':
            win.activateWindow()
            win.raise_()
        elif cmd == b'set_current':
            url = QUrl.fromEncoded(args[0])
            try:
                win.setCurrentDocument(app.openUrl(url)) # already loaded
            except IOError:
                pass
        elif cmd == b'set_cursor':
            line, column = map(int, args)
            cursor = win.textCursor()
            pos = cursor.document().findBlockByNumber(line - 1).position() + column
            cursor.setPosition(pos)
            win.currentView().setTextCursor(cursor)
        elif cmd == b'bye':
            self.close()
예제 #3
0
 def __init__(self, parent=None):
     super(TemplateMenu, self).__init__(parent)
     import scorewiz
     self._scorewizAction =  scorewiz.ScoreWizard.instance(
         app.activeWindow()
     ).actionCollection.scorewiz
     self.addAction(self._scorewizAction)
     self.addAction(self.tool().actionCollection.templates_manage)
예제 #4
0
def openUrl(url):
    """Open Url.

    If there is an active MainWindow, the document is made the current
    document in that window. If there is no MainWindow at all, it is
    created.

    """
    win = app.activeWindow()
    if not win:
        import mainwindow
        win = mainwindow.MainWindow()
        win.show()
    d = win.openUrl(url)
    if d:
        win.setCurrentDocument(d)
def openUrl(url):
    """Open Url.
    
    If there is an active MainWindow, the document is made the current
    document in that window. If there is no MainWindow at all, it is
    created.
    
    """
    win = app.activeWindow()
    if not win:
        import mainwindow
        win = mainwindow.MainWindow()
        win.show()
    d = win.openUrl(url)
    if d:
        win.setCurrentDocument(d)
예제 #6
0
    def cursor(self, load):
        """Returns a QTextCursor for this reference.

        load should be True or False and determines if a not-loaded document should be loaded.
        Returns None if the document could not be loaded.

        """
        if self._cursor:
            return self._cursor
        if load:
            win = app.activeWindow()
            if win:
                try:
                    win.openUrl(QUrl.fromLocalFile(self._filename)) # also calls bind
                except IOError:
                    pass
                if self._cursor:
                    return self._cursor
예제 #7
0
 def cursor(self, load):
     """Returns a QTextCursor for this reference.
     
     load should be True or False and determines if a not-loaded document should be loaded.
     Returns None if the document could not be loaded.
     
     """
     if self._cursor:
         return self._cursor
     if load:
         win = app.activeWindow()
         if win:
             try:
                 win.openUrl(QUrl.fromLocalFile(self._filename)) # also calls bind
             except IOError:
                 pass
             if self._cursor:
                 return self._cursor
예제 #8
0
        def load_content():
            """
            Load the content to be engraved as sample,
            either from the active editor or from a file.
            """
            nonlocal sample_content, base_dir
            nonlocal cache_persistently
            custom_file = self.custom_sample_url.path()

            # target will be one out of
            # 0: provided sample file
            # 1: custom file
            # 2: active document (unsaved state)
            target = self.sample_button_group.checkedId()
            if target == 1 and not custom_file:
                # Custom file selected but no file provided
                target = 0

            # Provided sample files will be cached persistently
            cache_persistently = target == 0

            if target == 2:
                # Engrave active document
                import engrave
                current_doc = engrave.engraver(app.activeWindow()).document()
                sample_content = current_doc.toPlainText()
                if not current_doc.url().isEmpty():
                    base_dir = os.path.dirname(current_doc.url().toLocalFile())
            else:
                if target == 1:
                    print("Custom file:", custom_file)
                    sample_file = custom_file
                else:
                    # Engrave from a file
                    import fonts
                    template_dir = os.path.join(fonts.__path__[0], 'templates')
                    sample_file = os.path.join(
                        template_dir,
                        'musicfont-' + self.cb_default_sample.currentData())
                    print("Default:", sample_file)
                base_dir = os.path.dirname(sample_file)
                with open(sample_file, 'r') as f:
                    sample_content = f.read()
예제 #9
0
        def load_content():
            """
            Load the content to be engraved as sample,
            either from the active editor or from a file.
            """
            nonlocal sample_content, base_dir
            nonlocal cache_persistently, target
            custom_file = self.custom_sample_url.path()

            if target == "<CUSTOM>" and not custom_file:
                target = self.cb_samples.itemData(0)

            # Provided sample files will be cached persistently
            cache_persistently = target not in ("<CUSTOM>", "<CURRENT>")

            if target == "<CURRENT>":
                # Engrave active document
                import engrave
                current_doc = engrave.engraver(app.activeWindow()).document()
                sample_content = current_doc.toPlainText()
                if not current_doc.url().isEmpty():
                    base_dir = os.path.dirname(current_doc.url().toLocalFile())
            else:
                if target == "<CUSTOM>":
                    print("Custom file:", custom_file)
                    sample_file = custom_file
                else:
                    # Engrave from a file
                    import fonts
                    template_dir = os.path.join(fonts.__path__[0], 'templates')
                    sample_file = os.path.join(template_dir,
                                               'musicfont-' + target)
                    print("Default:", sample_file)
                base_dir = os.path.dirname(sample_file)
                with open(sample_file, 'r') as f:
                    sample_content = f.read()