コード例 #1
0
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent parent widget of this lexer
        """
        QsciLexerJavaScript.__init__(self, parent)
        Lexer.__init__(self)

        self.commentString = "//"
        self.streamCommentString = {'start': '/* ', 'end': ' */'}
        self.boxCommentString = {'start': '/* ', 'middle': ' * ', 'end': ' */'}
コード例 #2
0
    def createCodeGroupBox(self, parent):
        yPos = const.GROUP_BOX_MARGIN_TOP
        width = AlgorithmDescDialog.WINDOW_WIDTH - const.PADDING * 4

        box = WidgetUtil.createGroupBox(parent, title="代码实现",
                                        minSize=QSize(width, AlgorithmDescDialog.DESC_GROUP_BOX_HEIGHT))

        # sizePolicy = WidgetUtil.createSizePolicy()
        splitter = WidgetUtil.createSplitter(box, geometry=QRect(const.PADDING, yPos, width - const.PADDING * 2, 330))

        tabWidget = WidgetUtil.createTabWidget(splitter)
        if self.javaCode:
            tabWidget.addTab(self.createTabWidget(self.javaCode, QsciLexerJava()), "Java")
        if self.javaScriptCode:
            tabWidget.addTab(self.createTabWidget(self.javaScriptCode, QsciLexerJavaScript()), "JavaScript")
        if self.pythonCode:
            tabWidget.addTab(self.createTabWidget(self.pythonCode, QsciLexerPython()), "Python")
        if self.cCode:
            tabWidget.addTab(self.createTabWidget(self.cCode, QsciLexerCPP()), "C")
        if self.cppCode:
            tabWidget.addTab(self.createTabWidget(self.cppCode, QsciLexerCPP()), "C++")
        if self.swiftCode:
            tabWidget.addTab(self.createTabWidget(self.swiftCode, QsciLexerCPP()), "Swift")

        return box
コード例 #3
0
 def defaultKeywords(self, kwSet):
     """
     Public method to get the default keywords.
     
     @param kwSet number of the keyword set (integer)
     @return string giving the keywords (string) or None
     """
     return QsciLexerJavaScript.keywords(self, kwSet)
コード例 #4
0
ファイル: LexerJavaScript.py プロジェクト: testmana2/test
 def defaultKeywords(self, kwSet):
     """
     Public method to get the default keywords.
     
     @param kwSet number of the keyword set (integer)
     @return string giving the keywords (string) or None
     """
     return QsciLexerJavaScript.keywords(self, kwSet)
コード例 #5
0
ファイル: LexerJavaScript.py プロジェクト: testmana2/test
 def __init__(self, parent=None):
     """
     Constructor
     
     @param parent parent widget of this lexer
     """
     QsciLexerJavaScript.__init__(self, parent)
     Lexer.__init__(self)
     
     self.commentString = "//"
     self.streamCommentString = {
         'start': '/* ',
         'end': ' */'
     }
     self.boxCommentString = {
         'start': '/* ',
         'middle': ' * ',
         'end': ' */'
     }
コード例 #6
0
    def _initCodeEdit(self):
        # 初始化编辑器的工作
        self.codeEdit.setUtf8(True)
        self.codeEdit.linesChanged.connect(self.onLinesChanged)  # 行改变
        # 代码高亮
        self.codeEdit.setLexer(QsciLexerJavaScript(self))
        # 自动折叠
        self.codeEdit.setMarginType(3, QsciScintilla.SymbolMargin)
        self.codeEdit.setMarginLineNumbers(3, False)
        self.codeEdit.setMarginWidth(3, 15)
        self.codeEdit.setMarginSensitivity(3, True)
        # 显示行号
        #self.codeEdit.setMarginType(0, QsciScintilla.NumberMargin)
        self.codeEdit.setMarginLineNumbers(0, True)
        self.onLinesChanged()
        # 代码提示
        sciApi = QsciAPIs(self.codeEdit.lexer())
        sciApi.prepare()
        self.codeEdit.setAutoCompletionSource(QsciScintilla.AcsAll)  # 设置源
        self.codeEdit.setAutoCompletionCaseSensitivity(True)  # 设置自动补全大小写敏感
        self.codeEdit.setAutoCompletionThreshold(1)  # 设置每输入一个字符就会出现自动补全的提示
        # 设置字体
        self.codeEdit.setFont(QFont('Consolas', 16))
        self.codeEdit.setMarginsFont(self.codeEdit.font())
        # 设置编码
        self.codeEdit.SendScintilla(QsciScintilla.SCI_SETCODEPAGE,
                                    QsciScintilla.SC_CP_UTF8)

        self.codeEdit.setBraceMatching(QsciScintilla.StrictBraceMatch)

        # 设置当前行高亮
        self.codeEdit.setCaretLineVisible(True)
        self.codeEdit.setCaretLineBackgroundColor(Qt.lightGray)
        self.codeEdit.setCaretForegroundColor(Qt.white)

        # tab
        # table relative
        self.codeEdit.setIndentationsUseTabs(True)
        self.codeEdit.setIndentationWidth(4)
        self.codeEdit.setTabIndents(True)
        self.codeEdit.setAutoIndent(True)
        self.codeEdit.setBackspaceUnindents(True)
        self.codeEdit.setTabWidth(4)

        # indentation guides
        self.codeEdit.setIndentationGuides(True)

        # folding margin
        self.codeEdit.setFolding(QsciScintilla.PlainFoldStyle)
        self.codeEdit.setMarginWidth(2, 12)

        # 自动换行
        self.codeEdit.setWrapMode(QsciScintilla.WrapWord)
コード例 #7
0
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent parent widget of this lexer
        """
        QsciLexerJavaScript.__init__(self, parent)
        Lexer.__init__(self)

        self.commentString = "//"
        self.streamCommentString = {'start': '/* ', 'end': ' */'}
        self.boxCommentString = {'start': '/* ', 'middle': ' * ', 'end': ' */'}

        self.keywordSetDescriptions = [
            self.tr("Primary keywords and identifiers"),
            self.tr("Secondary keywords and identifiers"),
            self.tr("Documentation comment keywords"),
            self.tr("Global classes and typedefs"),
            self.tr("Preprocessor definitions"),
            self.tr("Task marker and error marker keywords"),
        ]
コード例 #8
0
    def __init__(self, path, name, label_name, json, parent=None):
        super(JsonEditorDlg, self).__init__(parent)
        self.setWindowTitle("Json Editor")
        self._path = path
        self._name = name
        self._label_name = label_name
        self.orig_text = json

        self._label_file = QtWidgets.QLabel(label_name + ": " + name, self)
        self._save_button = QtWidgets.QPushButton("Save ...", self)
        self._save_button.clicked.connect(self._save_file)
        self._save_as_button = QtWidgets.QPushButton("Save as...", self)
        self._save_as_button.clicked.connect(self._save_as_file)
        self._cancel_button = QtWidgets.QPushButton("Cancel", self)
        self._cancel_button.clicked.connect(self._cancel)

        self._editor = QsciScintilla(self)

        # Set Yaml lexer
        self._editor.lexer = QsciLexerJavaScript()
        self._editor.setLexer(self._editor.lexer)
        self._editor.setMinimumSize(600, 450)
        self._editor.setText(json)

        appearance.set_default_appearence(self._editor)

        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addWidget(self._label_file)
        button_layout.addWidget(self._save_button)
        button_layout.addWidget(self._save_as_button)
        button_layout.addWidget(self._cancel_button)

        layout = QtWidgets.QVBoxLayout(self)
        layout.addLayout(button_layout)
        layout.addWidget(self._editor)
        self.setLayout(layout)
コード例 #9
0
ファイル: codeViewer.py プロジェクト: Zingam/PyQtApps
    def __init__(self, qsciScintillaWidget,  parent=None):
        super().__init__(parent)

        self.qsciScintillaWidget = qsciScintillaWidget

        self.qsciScintillaWidget.setReadOnly(True)

        # Set default font
        font = QFont()
        font.setFamily("Courier New")
        font.setFixedPitch(True)
        font.setPointSize(14)

        self.qsciScintillaWidget.setFont(font)

        # Set margin 0 - used for line numbers
        self.fontMetrics = QFontMetrics(font)
        self.qsciScintillaWidget.setMarginsFont(font)
        self.qsciScintillaWidget.setMarginLineNumbers(0, True)
        self.qsciScintillaWidget.setMarginsBackgroundColor(QColor("#444444"))
        self.qsciScintillaWidget.setMarginsForegroundColor(QColor("#A9B7C6"))
        self.qsciScintillaWidget.setMarginWidth(1, 0)

        self.qsciScintillaWidget.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        lexer = QsciLexerJavaScript()

        lexer.setFont(font)
        # Background color
        lexer.setPaper(QColor("#333333"))
        lexer.setDefaultPaper(QColor("#333333"))
        # Text color
        lexer.setDefaultColor(QColor("#00CCCC"))
        # Text colorization
        # Colorization for: 'some string'
        lexer.setColor(QColor("#A5C261"), QsciLexerJavaScript.SingleQuotedString)
        # Colorization for: "some string"
        lexer.setColor(QColor("#A5C261"), QsciLexerJavaScript.DoubleQuotedString)
        # Colorization for: 13 33 45
        lexer.setColor(QColor("#6897BB"), QsciLexerJavaScript.Number)
        # Colorization for: {} + = ; :
        lexer.setColor(QColor("#A9B7C6"), QsciLexerJavaScript.Operator)
        # Colorization for: true, false
        lexer.setColor(QColor("#FF00BB"), QsciLexerJavaScript.Keyword)
        # Colorization for: valueOfSomething, functionAdd()
        lexer.setColor(QColor("#FF00BB"), QsciLexerJavaScript.Identifier)

        self.qsciScintillaWidget.setLexer(lexer)

        self.qsciScintillaWidget.textChanged.connect(self.on_qsciScintillaWidget_textChanged)