Exemplo n.º 1
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.lexer = QsciLexerJSON(self)
        # # Default text settings
        # self.lexer.setDefaultColor(QColor("#cccccc"))
        # self.lexer.setDefaultPaper(QColor("#cccccc"))
        # self.lexer.setDefaultFont(QFont("Consolas", 14))

        self.setLexer(QsciLexerJSON(self))
        self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
        self.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        # Set the default font
        font = QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(14)
        self.setFont(font)
        self.setMarginsFont(font)

        # Margin 0 is used for line numbers
        fontmetrics = QFontMetrics(font)
        self.setMarginsFont(font)
        self.setMarginWidth(0, fontmetrics.width("00000") + 6)
        self.setMarginLineNumbers(0, True)
        self.setMarginsBackgroundColor(QColor("#cccccc"))
Exemplo n.º 2
0
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent parent widget of this lexer
        """
        QsciLexerJSON.__init__(self, parent)
        Lexer.__init__(self)

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

        self.keywordSetDescriptions = [
            self.tr("JSON Keywords"),
            self.tr("JSON-LD Keywords"),
        ]
Exemplo n.º 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 QsciLexerJSON.keywords(self, kwSet)
Exemplo n.º 4
0
 def init(self):
     self.setUtf8(True)
     lexer = QsciLexerJSON(self)
     self.setLexer(lexer)
     self.setAutoCompletionCaseSensitivity(False)  # 忽略大小写
     self.setAutoCompletionSource(self.AcsAll)
     self.setAutoCompletionThreshold(1)  # 一个字符就弹出补全
     self.setAutoIndent(True)  # 自动缩进
     self.setBackspaceUnindents(True)
     self.setBraceMatching(self.StrictBraceMatch)
     self.setIndentationGuides(True)
     self.setIndentationsUseTabs(False)
     self.setIndentationWidth(4)
     self.setTabIndents(True)
     self.setTabWidth(4)
     self.setWhitespaceSize(1)
     self.setWhitespaceVisibility(self.WsVisible)
     self.setWhitespaceForegroundColor(Qt.gray)
     self.setWrapIndentMode(self.WrapIndentFixed)
     self.setWrapMode(self.WrapWord)
     # 折叠
     self.setFolding(self.BoxedTreeFoldStyle, 2)
     self.setFoldMarginColors(QColor("#676A6C"), QColor("#676A6D"))
     font = self.font() or QFont()
     font.setFamily("Consolas")
     font.setFixedPitch(True)
     font.setPointSize(13)
     self.setFont(font)
     self.setMarginsFont(font)
     self.fontmetrics = QFontMetrics(font)
     lexer.setFont(font)
     self.setMarginWidth(0, self.fontmetrics.width(str(self.lines())) + 6)
     self.setMarginLineNumbers(0, True)
     self.setMarginsBackgroundColor(QColor("gainsboro"))
     self.setMarginWidth(1, 0)
     self.setMarginWidth(2, 14)  # 折叠区域
     # 绑定自动补齐热键Alt+/
     completeKey = QShortcut(QKeySequence(Qt.ALT + Qt.Key_Slash), self)
     completeKey.setContext(Qt.WidgetShortcut)
     completeKey.activated.connect(self.autoCompleteFromAll)
Exemplo n.º 5
0
    def __init__(self):
        super().__init__()
        self.broker = const.BROKER
        self.brokerEdit = QLineEdit(self.broker)
        self.brokerEdit.setPlaceholderText("Input mq broker, for example: {}".format(const.BROKER))
        self.timeout = const.TIMEOUT
        self.timeoutEdit = QLineEdit(str(self.timeout))
        self.timeoutEdit.setPlaceholderText("Input timeout")
        self.timeoutEdit.setMaximumWidth(100)
        self.timeoutEdit.setValidator(QIntValidator(1, 1000))
        self.sendButton = QPushButton(const.SEND_BUTTON_SEND_TEXT)
        self.serviceEdit = QLineEdit()
        self.serviceEdit.setFocusPolicy(QtCoreQt.NoFocus)
        self.serviceEdit.setPlaceholderText("Input service name, for example: {}".format(const.SERVICE_INPUT))
        self.methodEdit = QLineEdit()
        self.methodEdit.setFocusPolicy(QtCoreQt.NoFocus)
        self.methodEdit.setMinimumWidth(400)
        self.methodEdit.setPlaceholderText("Input method name, for example: {}".format(const.METHOD_INPUT))

        # 初始化输出日志组件
        self.logTextBox = QTextEditLogger(self)
        self.logTextBox.widget.setMinimumHeight(150)
        self.logTextBox.widget.setMaximumHeight(300)
        self.logTextBox.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
        logging.getLogger().addHandler(self.logTextBox)
        logging.getLogger().setLevel(logging.DEBUG)

        # 初始化代码编辑控件
        lexer = QsciLexerJSON()
        lexer.setHighlightComments(False)
        lexer.setHighlightEscapeSequences(False)
        self.paramsEdit = NamekoManQsciScintilla()
        self.paramsEdit.setLexer(lexer)
        self.paramsEdit.setUtf8(True)
        self.paramsEdit.setMarginLineNumbers(0, True)
        self.paramsEdit.setAutoIndent(True)
        self.paramsEdit.setTabWidth(4)
        self.paramsEdit.setFolding(QsciScintilla.BoxedTreeFoldStyle)
        self.paramsEdit.setFoldMarginColors(QtCoreQt.gray, QtCoreQt.lightGray)
        self.paramsEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
        self.paramsEdit.setIndentationGuides(QsciScintilla.SC_IV_LOOKBOTH)

        # 初始化结果显示控件,支持滚动
        self.scrollArea = QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        self.resultLabel = QLabel("")
        self.resultLabel.setAlignment(QtCoreQt.AlignCenter)
        self.resultLabel.adjustSize()
        self.resultLabel.setWordWrap(True)
        self.resultLabel.setAlignment(QtCoreQt.AlignLeft)
        self.resultLabel.setTextInteractionFlags(QtCoreQt.TextSelectableByMouse)
        self.resultLabel.setText(const.README)
        self.scrollArea.setWidget(self.resultLabel)
        self.scrollArea.setMinimumSize(500, 600)

        # 初始化文件夹树
        self.folderBar = FolderWidget()

        # 使用网格布局进行布局
        self.layout = QGridLayout()
        self.layout.setContentsMargins(10, 0, 10, 0)
        self.layout.addWidget(self.folderBar, 0, 0, 25, 1)
        self.layout.addWidget(self.brokerEdit, 0, 1, 1, 1)
        self.layout.addWidget(self.timeoutEdit, 0, 2, 1, 1)
        self.layout.addWidget(self.serviceEdit, 1, 1, 1, 2)
        self.layout.addWidget(self.methodEdit, 2, 1, 1, 2)
        self.layout.addWidget(self.paramsEdit, 3, 1, 22, 2)
        self.layout.addWidget(self.sendButton, 0, 3, 1, 1)
        self.layout.addWidget(self.scrollArea, 1, 3, 24, 1)
        self.layout.addWidget(self.logTextBox.widget, 25, 0, 1, 4)
        self.setLayout(self.layout)

        self.sendButton.clicked.connect(self.onSendRpc)
        self.folderBar.clickNodeSingal.connect(self.onClickedNode)

        # 初始化nameko client
        self.initNameko()

        self.rpcThread = None

        self.nodeInfo = None
Exemplo n.º 6
0
    def __init__(
            self,
            parent=None,
            font_family: str = None,
            font_point_size: float = 10.0,
            margins_background_color: str = None,
            marker_background_color: str = None,
            caret_line_background_color: str = None,
            caret_line_visible: bool = True,
            language: str = None,
            **kwargs
    ):
        """

        :param parent:
        :param font_family:
        :param font_point_size:
        :param margins_background_color:
        :param marker_background_color:
        :param caret_line_background_color:
        :param caret_line_visible:
        :param language: a string that is set to select the lexer of the
        editor (either Python or JSON) the default lexer is a YAML lexer
        :param kwargs:
        """
        super().__init__(parent)
        if font_point_size is None:
            font_point_size = chisurf.settings.gui['editor']['font_size']
        if font_family is None:
            font_family = chisurf.settings.gui['editor']['font_family']
        if margins_background_color is None:
            margins_background_color = chisurf.settings.gui[
                'editor'
            ]['margins_background_color']
        if marker_background_color is None:
            marker_background_color = chisurf.settings.gui[
                'editor'
            ]['marker_background_color']
        if caret_line_background_color is None:
            caret_line_background_color = chisurf.settings.gui[
                'editor'
            ]['caret_line_background_color']

        # Set the default font
        font = QFont()
        font.setFamily(font_family)
        font.setFixedPitch(True)
        font.setPointSize(font_point_size)

        self.setFont(font)
        self.setMarginsFont(font)

        # Margin 0 is used for line numbers
        fontmetrics = QFontMetrics(font)
        self.setMarginsFont(font)
        self.setMarginWidth(0, fontmetrics.width("0000") + 6)
        self.setMarginLineNumbers(0, True)
        self.setMarginsBackgroundColor(
            QColor(margins_background_color)
        )

        # Clickable margin 1 for showing markers
        self.setMarginSensitivity(1, True)
#        self.connect(self,
#            SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),
#            self.on_margin_clicked)
        self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM)

        self.setMarkerBackgroundColor(
            QColor(marker_background_color),
            self.ARROW_MARKER_NUM
        )

        # Brace matching: enable for a brace immediately before or after
        # the current position
        #
        self.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        # Current line visible with special background color
        self.setCaretLineVisible(caret_line_visible)
        self.setCaretLineBackgroundColor(
            QColor(caret_line_background_color)
        )

        # Set Python lexer
        # Set style for Python comments (style number 1) to a fixed-width
        # courier.
        if language.lower() == "python":
            lexer = QsciLexerPython()
        elif language.lower() == "json":
            lexer = QsciLexerJSON()
        else:
            lexer = QsciLexerYAML()
        lexer.setDefaultFont(font)
        self.setLexer(lexer)

        text = bytearray(str.encode("Arial"))
        # 32, "Courier New"
        self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text)

        # Don't want to see the horizontal scrollbar at all
        # Use raw message to Scintilla here (all messages are documented
        # here: http://www.scintilla.org/ScintillaDoc.html)
        self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
Exemplo n.º 7
0
 def json_highlighter(self):
     lexer = QsciLexerJSON()
     self.setDefaultSettings(lexer)