Beispiel #1
0
 def setupEditor(self):
     self.editor.setFont(QFont("Times New Roman", 12))
     self.editor.setMargins(2)
     self.editor.setMarginType(0, QsciScintilla.NumberMargin)
     self.editor.setMarginType(1, QsciScintilla.SymbolMargin)
     self.editor.setMarginWidth(0, "000")
     self.editor.setMarginWidth(1, "00")
     self.editor.markerDefine(QsciScintilla.RightTriangle, 1)
     if system() == "Windows":
         self.editor.setEolMode(QsciScintilla.EolWindows)
     elif system() == "Linux":
         self.editor.setEolMode(QsciScintilla.EolUnix)
     elif system() == "Mac":
         self.editor.setEolMode(QsciScintilla.EolMac)
     else:
         print("Using Windows EOL")
         self.editor.setEolMode(QsciScintilla.EolWindows)
     self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)
     self.editor.setIndentationsUseTabs(True)
     self.editor.setTabWidth(4)
     self.editor.setIndentationGuides(True)
     self.editor.setTabIndents(True)
     self.editor.setAutoIndent(True)
     self.editor.setCaretForegroundColor(QColor("#ff11214b"))
     self.editor.setCaretLineVisible(True)
     self.editor.setCaretLineBackgroundColor(QColor("#1f0000ff"))
     self.editor.setUtf8(True)
     self.editor.setMarginSensitivity(1, True)
     self.editor.marginClicked.connect(self.margin_clicked)
     self.editor.marginRightClicked.connect(self.margin_right_clicked)
     self.lexer = QsciLexerPython()
     self.lexer.setFont(QFont("Times New Roman", 12))
     self.editor.setLexer(self.lexer)
     self.editor.textChanged.connect(self.fileChanged)
Beispiel #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
Beispiel #3
0
    def onSet(self):
        #from subprocess import call
        #call("notepad ./Project/Sequences/DefaultSequence.py")

        self.editor = QsciScintilla()

        # define the font to use
        font = QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(10)
        # the font metrics here will help
        # building the margin width later
        fm = QFontMetrics(font)

        ## set the default font of the editor
        ## and take the same font for line numbers
        self.editor.setFont(font)
        self.editor.setMarginsFont(font)

        ## Line numbers
        # conventionnaly, margin 0 is for line numbers
        self.editor.setMarginWidth(0, fm.width("00000") + 5)
        self.editor.setMarginLineNumbers(0, True)

        ## Edge Mode shows a red vetical bar at 80 chars
        self.editor.setEdgeMode(QsciScintilla.EdgeLine)
        self.editor.setEdgeColumn(80)
        self.editor.setEdgeColor(QColor("#FF0000"))

        ## Folding visual : we will use boxes
        self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)

        ## Braces matching
        self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        ## Editing line color
        self.editor.setCaretLineVisible(True)
        self.editor.setCaretLineBackgroundColor(QColor("#CDA869"))

        ## Margins colors
        # line numbers margin
        self.editor.setMarginsBackgroundColor(QColor("#333333"))
        self.editor.setMarginsForegroundColor(QColor("#CCCCCC"))

        # folding margin colors (foreground,background)
        self.editor.setFoldMarginColors(QColor("#99CC66"), QColor("#333300"))

        ## Choose a lexer
        lexer = QsciLexerPython()
        lexer.setDefaultFont(font)
        api = QsciStrictAPIs(lexer)
        api.prepare()
        lexer.setDefaultFont(font)
        self.editor.setLexer(lexer)
        self.editor.setMinimumSize(1024, 768)
        self.editor.show()
        ## Show this file in the editor
        text = open("./Project/Sequences/DefaultSequence.py").read()
        self.editor.setText(text)
Beispiel #4
0
    def set_lexer(self, language):
        r"""
            多语法代码高亮
        :param language:
        :return:
        """
        font = self.font_content['font']
        size = int(self.font_content['size'])
        lexer_font = QFont(font, size)
        if language == 'py':
            self.lxr = QsciLexerPython()
            self.lxr.setFont(lexer_font)
            self.setLexer(self.lxr)
            self.__pythonCompletion()

        elif language == 'c':
            self.lxr = QsciLexerCPP()
            self.lxr.setFont(lexer_font)
            self.setLexer(self.lxr)
            self.__cCompletion()
        elif language == 'md':
            self.lxr = QsciLexerMarkdown()
            self.lxr.setFont(lexer_font)
            self.setLexer(self.lxr)
        else:
            self.setLexer(None)
            self.setText(self.text())
Beispiel #5
0
    def lock(self):
        """
        Sets the default properties for the Python lexer.
        """
        # Lexer Initialization
        lexer = QsciLexerPython(self.ui.code_editor)
        lexer.setDefaultFont(self.font)
        self.ui.code_editor.setLexer(lexer)

        # Auto Completion
        api = QsciAPIs(lexer)
        for var in dir(builtins):
            if not (var[0] == "_"):
                api.add(var)
        api.prepare()

        self.ui.code_editor.setAutoCompletionThreshold(1)
        self.ui.code_editor.setAutoCompletionSource(QsciScintilla.AcsAPIs)

        # Auto Indentation
        self.ui.code_editor.setAutoIndent(True)
        self.ui.code_editor.setIndentationGuides(True)
        self.ui.code_editor.setIndentationsUseTabs(True)
        self.ui.code_editor.setIndentationWidth(4)

        # Font Settings
        font_metrics = QFontMetrics(self.font)
        self.ui.code_editor.setMinimumSize(int(font_metrics.width("0" * 80)),
                                           0)
Beispiel #6
0
    def Setup(self):
        # Setting the size to be fixed
        self.setFixedSize(800, 800)
        # adding the the custom editor of QsciScintilla
        self.editor = QsciScintilla()
        self.editor.setGeometry(25, 25, 750, 750)
        # adding text to the ditro
        self.editor.append("print('Hello World!') # this is just a test")
        # this is i am not sure yet but i think its for the syntax
        self.python_syntax = QsciLexerPython()
        self.editor.setLexer(self.python_syntax)
        self.editor.setUtf8(True)  # Set encoding to UTF-8
        # setting editor position

        # adding font
        self.Font = QFont()
        # adding text size
        self.Font.setPointSize(16)
        # applying font
        self.editor.setFont(self.Font)  # Will be overridden by lexer!
        # adding the editor to te form
        self.layout().addWidget(self.editor)

        # showing ui
        self.show()
    def __init__(self, code):
        super(QDialog, self).__init__()

        self.codeEdit = QsciScintilla()
        self.codeEdit.setText(code)
        fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
        self.codeEdit.setFont(fixedWidthFont)
        fontmetrics = QFontMetrics(fixedWidthFont)
        self.codeEdit.setMarginWidth(0, fontmetrics.width("000"))
        self.codeEdit.setMarginLineNumbers(0, True)
        self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc"))

        self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
        self.codeEdit.setCaretLineVisible(True)
        self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4"))
        lexer = QsciLexerPython()
        lexer.setDefaultFont(fixedWidthFont)
        self.codeEdit.setLexer(lexer)
        self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
        self.codeEdit.setUtf8(True)

        self.codeEdit.setTabWidth(4)
        self.codeEdit.setIndentationsUseTabs(True)
        self.codeEdit.setIndentationGuides(True)
        self.codeEdit.setTabIndents(True)
        self.codeEdit.setAutoIndent(True)

        verticalLayout = QVBoxLayout()
        verticalLayout.addWidget(self.codeEdit)
        self.setLayout(verticalLayout)

        self.codeEdit.textChanged.connect(self.changeCode)
Beispiel #8
0
    def __init__(self, name, currentValue):
        super(QDialog, self).__init__()
        self.setWindowTitle(name)
        self.resize(800, 600)
        self.codeEdit = QsciScintilla()
        self.codeEdit.setText(currentValue)
        fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
        self.codeEdit.setFont(fixedWidthFont)
        fontmetrics = QFontMetrics(fixedWidthFont)
        self.codeEdit.setMarginWidth(0, fontmetrics.width("000"))
        self.codeEdit.setMarginLineNumbers(0, True)
        self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc"))

        self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
        self.codeEdit.setCaretLineVisible(True)
        self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4"))
        lexer = QsciLexerPython()
        lexer.setDefaultFont(fixedWidthFont)
        self.codeEdit.setLexer(lexer)
        self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
        self.codeEdit.setUtf8(True)

        self.codeEdit.setTabWidth(4)
        self.codeEdit.setIndentationsUseTabs(True)
        self.codeEdit.setIndentationGuides(True)
        self.codeEdit.setTabIndents(True)
        self.codeEdit.setAutoIndent(True)

        self.cancelButton = QPushButton('Cancel')
        self.cancelButton.clicked.connect(self.cancel)
        self.acceptButton = QPushButton('Accept')
        self.acceptButton.clicked.connect(self.accept)

        self.pythonButton = QRadioButton('Python')
        self.pythonButton.setChecked(True)
        self.pythonButton.clicked.connect(self.pythonClicked)
        self.cppButton = QRadioButton('C++')
        self.cppButton.clicked.connect(self.cppClicked)

        hLayout0 = QHBoxLayout()
        hLayout0.addWidget(self.pythonButton)
        hLayout0.addWidget(self.cppButton)
        container0 = QWidget()
        container0.setLayout(hLayout0)

        verticalLayout = QVBoxLayout()
        verticalLayout.addWidget(container0)
        verticalLayout.addWidget(self.codeEdit)

        container = QWidget()
        hLayout = QHBoxLayout()
        hLayout.addWidget(self.cancelButton)
        hLayout.addWidget(self.acceptButton)
        container.setLayout(hLayout)

        verticalLayout.addWidget(container)
        self.setLayout(verticalLayout)

        self.language = 'python'
Beispiel #9
0
 def _init_lexer(self):
     """
     初始化语法解析器
     Returns:
     """
     self._lexer = QsciLexerPython(self.textEdit)
     self._lexer.setFont(self.textEdit.font())
     self.textEdit.setLexer(self._lexer)
 def __init__(self):
     super().__init__()
     self.dir = path.join(path.dirname(__file__), "../data/custompreview")
     self.file = path.join(self.dir, "__init__.py")
     self.cachedir = path.join(self.dir, "../cache")
     self.cachefile = path.join(self.cachedir, "custom.py")
     self.setLexer(QsciLexerPython(self))
     self.load(self.file)
     self.custom = None
Beispiel #11
0
 def __init__(self):
     self.lexer = QsciLexerPython()
     self.apis = QsciAPIs(self.lexer)
     self.lexer.setAPIs(self.apis)
     self.apis.apiPreparationFinished.connect(
         self.slotApiPreparationFinished)
     for fn in API_FILES:
         ok = self.apis.load(PATH + '/api_raw/' + fn)
     self.apis.prepare()
Beispiel #12
0
    def __init__(self, parent=None):
        super().__init__(parent)

        # Set the default font
        font = QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(12)
        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"))
        self.setMarginLineNumbers(0, True)
        self.setMarginsBackgroundColor(QColor("#cccccc"))

        self.setTabWidth(4)

        # # Clickable margin 1 for showing markers
        # self.setMarginSensitivity(1, True)
        # self.marginClicked.connect(self.on_margin_clicked)
        # self.markerDefine(QsciScintilla.RightArrow,
        #     self.ARROW_MARKER_NUM)
        # self.setMarkerBackgroundColor(QColor("#ee1111"),
        #     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(True)
        self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

        # Set Python lexer
        # Set style for Python comments (style number 1) to a fixed-width
        # courier.
        #

        lexer = QsciLexerPython()
        lexer.setDefaultFont(font)
        self.setLexer(lexer)
        text = bytearray(str.encode("Courier"))
        self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text)
        self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, 1, 12)

        # 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)
        self.setScrollWidth(1)
Beispiel #13
0
    def __init__(self, parent=None):
        super(PMPythonEditor, self).__init__(parent, comment_string='#')
        self._extension_names.append('.py')
        self._init_editor()
        self._init_lexer(QsciLexerPython(self.textEdit))
        self._init_apis()
        self._init_actions()
        self._init_signals()
        # 编辑器主题
        self.slot_set_theme(self._theme)

        self.last_hint = ''
Beispiel #14
0
    def checkExtensionToHighlight(self, path, editor):
        _, extension = os.path.splitext(path)

        if extension == '.py':
            editor.setLexer(QsciLexerPython(self))
        elif extension == '.html':
            editor.setLexer(QsciLexerHTML(self))
        elif extension == '.java':
            editor.setLexer(QsciLexerJava(self))
        elif extension == '.cs':
            editor.setLexer(QsciLexerCSharp(self))
        elif extension == '.bat':
            editor.setLexer(QsciLexerBatch(self))
Beispiel #15
0
def create_qscintilla_code_view():
    """ Create a QScintilla based view containing a copy of this source code.
    """

    from PyQt5.Qsci import QsciLexerPython, QsciScintilla

    view = QsciScintilla()
    view.setReadOnly(True)
    view.setUtf8(True)
    view.setLexer(QsciLexerPython())
    view.setFolding(QsciScintilla.PlainFoldStyle)
    view.setText(get_source_code())

    return view
Beispiel #16
0
    def __init__(self):
        """ Invoked to return the default editor widget. """

        from PyQt5.Qsci import QsciLexerPython, QsciScintilla

        editor = QsciScintilla()

        # Configure the editor for Python.
        editor.setUtf8(True)
        editor.setLexer(QsciLexerPython(editor))
        editor.setFolding(QsciScintilla.PlainFoldStyle, 1)
        editor.setIndentationGuides(True)
        editor.setIndentationWidth(4)

        self.editor = editor
    def __init__(self):
        super(PyOneScript, self).__init__()

        self.setAttribute(Qt.WA_DeleteOnClose)
        self.isUntitled = True

        font = QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        self.setMarginsFont(font)

        self.setMarginSensitivity(1, True)
        self.marginClicked.connect(self.on_margin_clicked)
        self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM)
        self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)
        self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
        self.setEolMode(Qsci.QsciScintilla.EolUnix)
        self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll)
        self.setAutoCompletionThreshold(1)
        self.setAutoIndent(True)
        self.setIndentationsUseTabs(True)
        self.setTabWidth(4)
        self.setAutoCompletionFillupsEnabled(True)
        self.setBraceMatching(Qsci.QsciScintilla.StrictBraceMatch)
        self.setMarginLineNumbers(1, 1)
        self.setMarginWidth(1, 35)
        self.setUtf8(True)
        self.setEolVisibility(False)
        self.setMinimumSize(600, 450)
        self.setCaretLineVisible(True)
        self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

        self.lexer = QsciLexerPython()
        self.lexer.setDefaultFont(font)

        self.setLexer(self.lexer)
        self.sense = Qsci.QsciAPIs(self.lexer)
        self.sense.prepare()

        self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
    def __init__(self, parent=None):
        super(CodeEditor, self).__init__(parent)

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

        # 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("#90FF90"))

        # Clickable margin 1 for showing markers
        self.setMarginSensitivity(1, True)
        self.marginClicked.connect(self.on_margin_clicked)

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

        # Set Python lexer
        # Set style for Python comments (style number 1) to a fixed-width courier.
        lexer = QsciLexerPython()
        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
        self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
Beispiel #19
0
    def __init__(self,
                 layout_dir: str,
                 title: str,
                 initial_value: str = '',
                 lexer=''):
        super().__init__(layout_dir)
        self.on_check_callback = None

        self.prefix = QLabel(text=title)

        entryLayout = QHBoxLayout()
        entryLayout.setContentsMargins(0, 0, 0, 0)
        self.ctrl = QsciScintilla()
        if lexer == 'python':
            self.ctrl.setLexer(QsciLexerPython())
        self.ctrl.setText(initial_value)
        # self.ctrl.textChanged.connect(self.ontext)

        # self.postfix = lab_unit = QLabel(text=unit)

        self.central_layout.addWidget(self.prefix)
        self.central_layout.addLayout(entryLayout)
        entryLayout.addWidget(self.ctrl)
        self.set_value(initial_value)
Beispiel #20
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(640, 480)
        self.vindu = QtWidgets.QWidget(MainWindow)
        self.vindu.setStyleSheet(_fromUtf8('notusedasyet'))
        #MainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
        self.filename = ""
        self.vindu.setObjectName(_fromUtf8("vindu"))
        self.verticalLayout = PyQt5.QtWidgets.QVBoxLayout(self.vindu)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/ico/python.png")), QtGui.QIcon.Normal, QtGui.QIcon.On)
        MainWindow.setWindowIcon(icon)
        self.verticalLayout.setContentsMargins(0,0,0,0)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName(_fromUtf8('verticalLayout'))
        self.codebox = Qsci.QsciScintilla(self.vindu)
        self.codebox.setToolTip(_fromUtf8(""))
        self.codebox.setWhatsThis(_fromUtf8(""))
        self.codebox.setAutoFillBackground(False)
        self.codebox.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.codebox.setObjectName(_fromUtf8("codebox"))
        self.verticalLayout.addWidget(self.codebox)
        MainWindow.setCentralWidget(self.vindu)
        #toolbar
        self.toolBar = QtWidgets.QToolBar(MainWindow)
        self.toolBar.setAutoFillBackground(False)
        self.toolBar.setIconSize(QtCore.QSize(32, 32))
        self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.toolBar.setObjectName(_fromUtf8("toolBar2"))
        MainWindow.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolBar)
        self.toolBar.addSeparator()
        #toolbar2 debugger
        #self.toolBar2 = QtGui.QToolBar(MainWindow)
        #self.toolBar2.setAutoFillBackground(False)
        #self.toolBar2.setIconSize(QtCore.QSize(32, 32))
        #self.toolBar2.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        #self.toolBar2.setObjectName(_fromUtf8("toolBar"))
       # MainWindow.addToolBar(QtCore.Qt.RightToolBarArea, self.toolBar2)
#        self.toolBar2.addSeparator()
        #getting ready for debugger
        self.codebox.setMarginSensitivity(1, True)
        self.codebox.marginClicked.connect(self.on_margin_clicked)
        self.codebox.markerDefine(QsciScintilla.FullRectangle, self.ARROW_MARKER_NUM)
        self.codebox.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)
        #first action Newfile
        self.toolBar.newAction = QtWidgets.QAction(QtGui.QIcon(":/ico/new.png"),"New",self.toolBar)
        self.toolBar.newAction.setStatusTip("Clear TextBox or make new document.")
        self.toolBar.newAction.setShortcut("Ctrl+N")
        self.toolBar.newAction.triggered.connect(self.newfile)
        #second Action OpenFile
        self.toolBar.secondAction = QtWidgets.QAction(QtGui.QIcon(":/ico/open.png"),"Open",self.toolBar)
        self.toolBar.secondAction.setStatusTip("Create a new document from scratch.")
        self.toolBar.secondAction.setShortcut("Ctrl+O")
        self.toolBar.secondAction.triggered.connect(self.open)
        # action 3 save file
        self.toolBar.Action3 = QtWidgets.QAction(QtGui.QIcon(":/ico/save.png"),"Save",self.toolBar)
        self.toolBar.Action3.setStatusTip("Save Your File.")
        self.toolBar.Action3.setShortcut("Ctrl+S")
        self.toolBar.Action3.triggered.connect(self.savefile)
        #action 4 run file
        self.toolBar.Action4 = QtWidgets.QAction(QtGui.QIcon(":/ico/run32.png"),"Run",self.toolBar)
        self.toolBar.Action4.setStatusTip("Run")
        self.toolBar.Action4.setShortcut("Ctrl+E")
        self.toolBar.Action4.triggered.connect(self.runto)
        #action 21 debug
        #self.toolBar2.Action21 = QtGui.QAction(QtGui.QIcon(":/ico/run32.png"),"Debug",self.toolBar)
        #self.toolBar2.Action21.setStatusTip("Debug File.")
        #self.toolBar2.Action21.setShortcut("Ctrl+7")
        #self.toolBar2.Action21.triggered.connect(self.debugto)
        #action 6 undo
        self.toolBar.Action6 =  QtWidgets.QAction(QtGui.QIcon(":/ico/undo.png"),"Redo",self.toolBar)
        self.toolBar.Action6.setStatusTip("Undo.")
        self.toolBar.Action6.setShortcut("Ctrl+Z")
        self.toolBar.Action6.triggered.connect(self.codebox.undo)
        #action 7 redo
        self.toolBar.Action7 = QtWidgets.QAction(QtGui.QIcon(":/ico/redo.png"),"Redo",self.toolBar)
        self.toolBar.Action7.setStatusTip("Redo.")
        self.toolBar.Action7.setShortcut("Ctrl+Y")
        self.toolBar.Action7.triggered.connect(self.codebox.redo)
        #action8 rerset Folding
        self.toolBar.Action8 = QtWidgets.QAction(QtGui.QIcon(":/ico/align-justify.png"),"Reset Folding",self.toolBar)
        self.toolBar.Action8.setStatusTip("Reset Folding.")
        self.toolBar.Action8.setShortcut("Ctrl+R")
        self.toolBar.Action8.triggered.connect(self.nofoldingl)
        #actions9 CircledTreeFoldStyle
        self.toolBar.Action9 = QtWidgets.QAction(QtGui.QIcon(":/ico/bullet.png"),"Circled Tree Folding",self.toolBar)
        self.toolBar.Action9.setStatusTip("Circled Tree Folding.")
        self.toolBar.Action9.setShortcut("Ctrl+C")
        self.toolBar.Action9.triggered.connect(self.Circledfold)
        #actions10 plainFoldStyle
        self.toolBar.Action10 = QtWidgets.QAction(QtGui.QIcon(":/ico/number.png"),"Plain Folding",self.toolBar)
        self.toolBar.Action10.setStatusTip("Plain Folding")
        self.toolBar.Action10.setShortcut("Ctrl+P")
        self.toolBar.Action10.triggered.connect(self.plainfold)
        # fonts
        self.toolBar.Action21 = QtWidgets.QAction(QtGui.QIcon(":/ico4/font.png"), "Fonts", self.toolBar)
        self.toolBar.Action21.setStatusTip("Fonts")
        self.toolBar.Action21.setShortcut("Ctrl+F")
        self.toolBar.Action21.triggered.connect(self.font_choice)
        #web baby
        self.toolBar.Action11 = QtWidgets.QAction(QtGui.QIcon(":/ico/web.png"),"Hex-rays Homepage",self.toolBar)
        self.toolBar.Action11.setStatusTip("Home of Hex-rays")
        self.toolBar.Action11.setShortcut("Ctrl+W")
        self.toolBar.Action11.triggered.connect(self.webopen)
        #irc
        self.toolBar.Action12 = QtWidgets.QAction(QtGui.QIcon(":/ico3/settings.png"),"Open Ida Pro Python SDK",self.toolBar)
        self.toolBar.Action12.setStatusTip("Ida Pro Python SDK")
        self.toolBar.Action12.setShortcut("Ctrl+I")
        self.toolBar.Action12.triggered.connect(self.sdkopen)
        #github Python
        self.toolBar.Action14 = QtWidgets.QAction(QtGui.QIcon(":/ico/github.png"),"Open git python",self.toolBar)
        self.toolBar.Action14.setStatusTip("Open git python")
        self.toolBar.Action14.setShortcut("Ctrl+G")
        self.toolBar.Action14.triggered.connect(self.gitopen)
        #auther me :)
        self.toolBar.Action15 = QtWidgets.QAction(QtGui.QIcon(":/ico/auth.png"),"Author",self.toolBar)
        self.toolBar.Action15.setStatusTip("Author")
        self.toolBar.Action15.setShortcut("Ctrl+B")
        self.toolBar.Action15.triggered.connect(self.Author)
        #toggle off code regonision
        self.toolBar.Action16 = QtWidgets.QAction(QtGui.QIcon(":/ico2/pythonminus.png"),"Disable Code recognition",self.toolBar)
        self.toolBar.Action16.setStatusTip("Disable Code recognition")
        self.toolBar.Action16.setShortcut("Alt+D")
        self.toolBar.Action16.triggered.connect(self.Diablecode)
        #toogle on
        self.toolBar.Action17 = QtWidgets.QAction(QtGui.QIcon(":/ico2/pypluss.png"),"Enable Code recognition",self.toolBar)
        self.toolBar.Action17.setStatusTip("Enable Code recognition")
        self.toolBar.Action17.setShortcut("Alt+E")
        self.toolBar.Action17.triggered.connect(self.Reiablecode)
        # zoom in
        self.toolBar.Action18 = QtWidgets.QAction(QtGui.QIcon(":/ico3/in.png"),"Zoom In",self.toolBar)
        self.toolBar.Action18.setStatusTip("Zoom In")
        self.toolBar.Action18.setShortcut("CTRL+SHIFT++")
        self.toolBar.Action18.triggered.connect(self.udder)
        #zoom out
        self.toolBar.Action19 = QtWidgets.QAction(QtGui.QIcon(":/ico3/out.png"),"Zoom Out",self.toolBar)
        self.toolBar.Action19.setStatusTip("Zoom Out")
        self.toolBar.Action19.setShortcut("CTRL+SHIFT+-")
        self.toolBar.Action19.triggered.connect(self.odder)

        self.toolBar.Action20 = QtWidgets.QAction(QtGui.QIcon(":/ico3/10.png"),"Profile Code",self.toolBar)
        self.toolBar.Action20.setStatusTip("Profile Code")
        self.toolBar.Action20.setShortcut("CTRL+SHIFT+E")
        self.toolBar.Action20.triggered.connect(self.runtoprob)

        #actions
        self.toolBar.addAction(self.toolBar.newAction)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.secondAction)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action3)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action4)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action6)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action7)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action8)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action9)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action10)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action21)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action11)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action12)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action14)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action15)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action16)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action17)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action18)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action19)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.toolBar.Action20)

        #self.toolBar2.addAction(self.toolBar.Action21)
        #self.toolBar2.addSeparator()
        #font
        self.skrift = QFont()
        self.skrift.setFamily('Consolas')
        self.skrift.setFixedPitch(True)
        self.skrift.setPointSize(12)
        self.codebox.setFont(self.skrift)

        #python style
        self.lexer = QsciLexerPython(self.codebox)
        self.lexer.setFont(self.skrift)
        self.lexer.setEolFill(True)
        #api test not working
        api = Qsci.QsciAPIs(self.lexer)
        API_FILE = dn+'\\Python.api'
        API_FILE2 = dn+'\\idc.api'
        API_FILE3 = dn+'\\idaapi.api'
        api.load(API_FILE)
        api.load(API_FILE2)
        api.load(API_FILE3)

        api.prepare()
        self.codebox.setAutoCompletionThreshold(0)
        self.codebox.setAutoCompletionThreshold(6)
        self.codebox.setAutoCompletionThreshold(8)
        self.codebox.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs)
        self.lexer.setDefaultFont(self.skrift)
        self.codebox.setLexer(self.lexer)
        self.codebox.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Consolas')

        #line numbers
        fontmetrics = QFontMetrics(self.skrift)
        self.codebox.setMarginsFont(self.skrift)
        self.codebox.setMarginWidth(0, fontmetrics.width("00000") + 6)
        self.codebox.setTabWidth(4)

        #brace
        self.codebox.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        #auto line tab =4
        self.codebox.setAutoIndent(True)

        #scroolbar
        self.codebox.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Beispiel #21
0
 def set_python_lexer(self):
     self.lexer = QsciLexerPython()
     self.lexer.setDefaultFont(self.font)
     self.setLexer(self.lexer)
     self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')
Beispiel #22
0
    def __init__(self, name, transition):
        super(QDialog, self).__init__()
        self.transition = transition
        self.setWindowTitle(name)
        self.resize(800, 600)

        self.codeEdit = QsciScintilla()
        self.codeEdit.setText(self.transition.getCode())
        fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
        self.codeEdit.setFont(fixedWidthFont)
        fontmetrics = QFontMetrics(fixedWidthFont)
        self.codeEdit.setMarginWidth(0, fontmetrics.width("000"))
        self.codeEdit.setMarginLineNumbers(0, True)
        self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc"))

        self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
        self.codeEdit.setCaretLineVisible(True)
        self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4"))
        lexer = QsciLexerPython()
        lexer.setDefaultFont(fixedWidthFont)
        self.codeEdit.setLexer(lexer)
        self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
        self.codeEdit.setUtf8(True)

        self.codeEdit.setTabWidth(4)
        self.codeEdit.setIndentationsUseTabs(True)
        self.codeEdit.setIndentationGuides(True)
        self.codeEdit.setTabIndents(True)
        self.codeEdit.setAutoIndent(True)

        self.cancelButton = QPushButton('Cancel')
        self.cancelButton.clicked.connect(self.cancel)
        self.acceptButton = QPushButton('Accept')
        self.acceptButton.clicked.connect(self.accept)

        self.language = 'python'
        self.pythonButton = QRadioButton('Python')
        self.pythonButton.setChecked(True)
        self.pythonButton.clicked.connect(self.pythonClicked)
        self.cppButton = QRadioButton('C++')
        self.cppButton.clicked.connect(self.cppClicked)

        codeLanguageContainer = QWidget()
        hLayout0 = QHBoxLayout()
        hLayout0.addWidget(self.pythonButton)
        hLayout0.addWidget(self.cppButton)
        codeLanguageContainer.setLayout(hLayout0)

        self.temporalButton = QRadioButton('Temporal', self)
        self.temporalButton.toggled.connect(self.temporalToggled)
        self.conditionalButton = QRadioButton('Conditional', self)
        self.conditionalButton.toggled.connect(self.conditionalToggled)

        radioButtonContainer = QGroupBox()
        radioButtonContainer.setTitle('Transition Type')
        vLayout = QVBoxLayout()
        vLayout.addWidget(self.temporalButton)
        vLayout.addWidget(self.conditionalButton)
        radioButtonContainer.setLayout(vLayout)

        self.transitionTypeCode = QTextEdit()
        self.transitionTypeCode.setFont(fixedWidthFont)
        self.transitionGroupBox = QGroupBox()
        self.transitionGroupBox.setTitle('Temporal (number in ms)')
        h3Layout = QHBoxLayout()
        h3Layout.addWidget(self.transitionTypeCode)
        self.transitionGroupBox.setLayout(h3Layout)

        typeContainer = QWidget()
        h2Layout = QHBoxLayout()
        h2Layout.addWidget(radioButtonContainer)
        h2Layout.addWidget(self.transitionGroupBox)
        typeContainer.setLayout(h2Layout)

        verticalLayout = QVBoxLayout()
        verticalLayout.addWidget(typeContainer)
        verticalLayout.addWidget(codeLanguageContainer)
        verticalLayout.addWidget(self.codeEdit)

        container = QWidget()
        hLayout =QHBoxLayout()
        hLayout.addWidget(self.cancelButton)
        hLayout.addWidget(self.acceptButton)
        container.setLayout(hLayout)

        verticalLayout.addWidget(container)
        self.setLayout(verticalLayout)

        if self.transition.getType() == TransitionType.CONDITIONAL:
            self.conditionalButton.setChecked(True)
            self.conditionalToggled()
        elif self.transition.getType() == TransitionType.TEMPORAL:
            self.temporalButton.setChecked(True)
            self.temporalToggled()
    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)
Beispiel #24
0
    def __init__(self, parent=None):
        super(EditWindow, self).__init__(parent)

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

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

        self.setIndentationsUseTabs(False)
        self.setIndentationWidth(4)

        # Clickable margin 1 for showing markers
        self.setMarginSensitivity(1, True)
        self.marginClicked.connect(self.on_margin_clicked)

        # debug marker
        self.markerDefine(QsciScintilla.Circle, self.DEBUG_MARKER_NUM)
        self.setMarkerBackgroundColor(QtGui.QColor("#1111ee"),
                                      self.DEBUG_MARKER_NUM)

        # execute marker
        self.markerDefine(QsciScintilla.Circle, self.EXEC_MARKER_NUM)
        self.setMarkerBackgroundColor(QtGui.QColor("#11ee11"),
                                      self.EXEC_MARKER_NUM)

        # crash marker
        self.markerDefine(QsciScintilla.Circle, self.CRASH_MARKER_NUM)
        self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"),
                                      self.CRASH_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(True)
        self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4"))

        # Set Python lexer
        lexer = QsciLexerPython()
        lexer.setDefaultFont(font)
        self.setLexer(lexer)

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

        # not too small
        self.setMinimumSize(600, 450)

        self.last_exec_line = 0
Beispiel #25
0
    def __init__(self, sequencePath, errline, parent=None):
        super(Editor, self).__init__(parent)
        #Set the default font
        self.sequencePath = sequencePath
        #self.polyMaskGenWnd = PolymaskGeneratorWindow()
        font = QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        self.setMarginsFont(font)
        self.file = open(self.sequencePath)
        self.setTabWidth(4)
        self.setText(self.file.read())
        self.file.close()
        self.sequenceErrorIndicator = self.indicatorDefine(
            QsciScintilla.SquiggleIndicator)
        self.setIndicatorForegroundColor(Qt.magenta,
                                         self.sequenceErrorIndicator)
        if errline > 0:
            self.fillIndicatorRange(errline - 1, 0, errline, 0,
                                    self.sequenceErrorIndicator)
        self.previewTrackIndicator = self.indicatorDefine(
            QsciScintilla.DotBoxIndicator)
        self.setIndicatorForegroundColor(Qt.blue, self.previewTrackIndicator)

        # 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"))

        # Clickable margin 1 for showing markers
        self.setMarginSensitivity(1, True)
        self.marginClicked.connect(self.on_margin_clicked)
        self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM)
        self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)

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

        self.setAutoIndent(True)

        # Current line visible with special background color
        self.setCaretLineVisible(True)
        self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

        # Set Python lexer
        # Set style for Python comments (style number 1) to a fixed-width
        # courier.
        #
        lexer = QsciLexerPython(self)

        api = QsciStrictAPIs(lexer)
        self.counter = 0
        self.modules = []
        #print('Processing components for calltips at path:')
        #print(Components.__path__)
        #print('1-')
        #print(Components.__file__)
        #print('2-')
        #print(Components.__spec__)
        #print('4-')
        #print(inspect.getfile(Components))
        #print('--')
        #print(AppData.appDataDir)
        #print(AppData.appDataDir + '\\Project\\Components')
        #print('@@')
        self.addPackageFuncs(api, Components, 'Components')
        #self.addModuleFuncs(api, Project.Components, 'Project.Components')

        api.prepare()

        lexer.setDefaultFont(font)
        self.setLexer(lexer)
        self.setAutoCompletionThreshold(1)
        self.setAutoCompletionCaseSensitivity(False)
        self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
        self.setCallTipsStyle(QsciScintilla.CallTipsContext)
        #self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')

        # 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)
        self.SendScintilla(QsciScintilla.SCI_SETEOLMODE,
                           QsciScintilla.SC_EOL_LF)
        self.SendScintilla(QsciScintilla.SCI_SETPASTECONVERTENDINGS, True)

        #self.SCN_CALLTIPCLICK.connect(self.calltipClicked)
        # not too small
        self.setMinimumSize(1024, 768)

        self.calltip = None
Beispiel #26
0
    def __init__(self, interpreter, message="", log='', parent=None):
        """Constructor.
        @param interpreter : InteractiveInterpreter in which
        the code will be executed

        @param message : welcome message string
        
        @param  'parent' : specifies the parent widget.
        If no parent widget has been specified, it is possible to
        exit the interpreter by Ctrl-D.
        """

        QsciScintilla.__init__(self, parent)
        self.interpreter = interpreter

        # user interface setup
        self.setAutoIndent(True)
        self.setAutoCompletionThreshold(4)
        self.setAutoCompletionSource(QsciScintilla.AcsDocument)
        # Lexer
        self.setLexer(QsciLexerPython(self))

        # Search
        self.incrementalSearchString = ""
        self.incrementalSearchActive = False
        self.inRawMode = False
        self.echoInput = True

        # Initialize history
        self.historyLists = {}
        self.maxHistoryEntries = 1000
        self.H = History("%s/.ghist" % os.environ['HOME'])  # Added by vb
        self.history = self.H.load(self.maxHistoryEntries)  # Added by vb
        #        self.history = []
        self.histidx = -1

        # # capture all interactive input/output
        sys.stdout = self
        sys.stderr = MultipleRedirection((sys.stderr, self))
        sys.stdin = self

        self.reading = 0
        # interpreter prompt.
        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ">>> "
        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = "... "

        #self.completionText = ""
        # Excecution Status
        self.more = False
        # Multi line execution Buffer
        self.execlines = []

        # interpreter banner
        self.write('The shell running Python %s on %s.\n' %
                   (sys.version, sys.platform))
        self.write('Type "copyright", "credits" or "license"'
                   ' for more information on Python.\n')
        self.write(message + '\n\n')
        self.write(sys.ps1)

        #self.standardCommands().clearKeys()
        self.keymap = {
            Qt.Key_Backspace: self.__QScintillaDeleteBack,
            Qt.Key_Delete: self.__QScintillaDelete,
            Qt.Key_Return: self.__QScintillaNewline,
            Qt.Key_Enter: self.__QScintillaNewline,
            Qt.Key_Tab: self.__QScintillaTab,
            Qt.Key_Left: self.__QScintillaCharLeft,
            Qt.Key_Right: self.__QScintillaCharRight,
            Qt.Key_Up: self.__QScintillaLineUp,
            Qt.Key_Down: self.__QScintillaLineDown,
            Qt.Key_Home: self.__QScintillaVCHome,
            Qt.Key_End: self.__QScintillaLineEnd,
        }

        self.connect(self,
                     QtCore.SIGNAL('userListActivated(int, const QString)'),
                     self.__completionListSelected)
Beispiel #27
0
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.Qsci import QsciScintilla, QsciLexerPython

if __name__ == "__main__":
    app = QApplication(sys.argv)
    font = QFont()
    font.setFamily('Courier')
    font.setFixedPitch(True)
    editor = QsciScintilla()
    editor.setFont(font)
    lexer = QsciLexerPython()
    lexer.setFont(font)
    editor.setLexer(lexer)
    editor.show()
    editor.setText(open(sys.argv[0]).read())
    app.exec_()
Beispiel #28
0
 def set_python_lexer(self):
     self.lexer = QsciLexerPython()
     self.lexer.setDefaultFont(self.font)
     self.setLexer(self.lexer)
Beispiel #29
0
    def __init__(self, parent=None):
        super(Ui_Wizard, self).__init__(parent=None)
        Wizard.setObjectName("Wizard")
        Wizard.resize(762, 500)
        font = QtGui.QFont()
        font.setFamily("Calibri Light")
        Wizard.setFont(font)
        Wizard.setOptions(QtWidgets.QWizard.HelpButtonOnRight)
        self.wizardPage1 = QtWidgets.QWizardPage()
        font = QtGui.QFont()
        font.setFamily("Calibri Light")
        font.setPointSize(20)
        self.wizardPage1.setFont(font)
        self.wizardPage1.setObjectName("wizardPage1")
        self.textBrowser_2 = QtWidgets.QTextBrowser(self.wizardPage1)
        self.textBrowser_2.setGeometry(QtCore.QRect(130, 140, 421, 131))
        self.textBrowser_2.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.textBrowser_2.setObjectName("textBrowser_2")
        Wizard.addPage(self.wizardPage1)
        self.wizardPage = QtWidgets.QWizardPage()
        self.wizardPage.setTitle("")
        self.wizardPage.setSubTitle("")
        self.wizardPage.setObjectName("wizardPage")
        self.textBrowser_4 = QtWidgets.QTextBrowser(self.wizardPage)
        self.textBrowser_4.setGeometry(QtCore.QRect(130, 140, 499, 239))
        self.textBrowser_4.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.textBrowser_4.setObjectName("textBrowser_4")
        Wizard.addPage(self.wizardPage)
        self.tempwizardPage = QtWidgets.QWizardPage()
        self.tempwizardPage.setObjectName("tempwizardPage")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.tempwizardPage)
        self.verticalLayout.setObjectName("verticalLayout")
        self.TemptextEdit = Qsci.QsciScintilla(self.tempwizardPage)
        self.TemptextEdit.setToolTip("")
        self.TemptextEdit.setWhatsThis("")
        self.TemptextEdit.setObjectName("TemptextEdit")
        self.verticalLayout.addWidget(self.TemptextEdit)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.temppushButtonopen = QtWidgets.QPushButton(self.tempwizardPage)
        self.temppushButtonopen.setObjectName("temppushButtonopen")
        self.horizontalLayout.addWidget(self.temppushButtonopen)
        self.temppushButtonsave = QtWidgets.QPushButton(self.tempwizardPage)
        self.temppushButtonsave.setObjectName("temppushButtonsave")
        self.horizontalLayout.addWidget(self.temppushButtonsave)
        self.verticalLayout.addLayout(self.horizontalLayout)
        Wizard.addPage(self.tempwizardPage)
        self.scriptwizardPage = QtWidgets.QWizardPage()
        self.scriptwizardPage.setObjectName("scriptwizardPage")
        self.textBrowser_5 = QtWidgets.QTextBrowser(self.scriptwizardPage)
        self.textBrowser_5.setGeometry(QtCore.QRect(120, 130, 499, 239))
        self.textBrowser_5.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.textBrowser_5.setObjectName("textBrowser_5")
        Wizard.addPage(self.scriptwizardPage)
        self.wizardPage_3 = QtWidgets.QWizardPage()
        self.wizardPage_3.setObjectName("wizardPage_3")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.wizardPage_3)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.script_textEdit = Qsci.QsciScintilla(self.wizardPage_3)
        self.script_textEdit.setToolTip("")
        self.script_textEdit.setWhatsThis("")
        self.script_textEdit.setObjectName("script_textEdit")
        self.verticalLayout_2.addWidget(self.script_textEdit)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem1)
        self.scriptGrabpushButton = QtWidgets.QPushButton(self.wizardPage_3)
        self.scriptGrabpushButton.setObjectName("scriptGrabpushButton")
        self.horizontalLayout_2.addWidget(self.scriptGrabpushButton)
        self.scriptpushButtonopen = QtWidgets.QPushButton(self.wizardPage_3)
        self.scriptpushButtonopen.setObjectName("scriptpushButtonopen")
        self.horizontalLayout_2.addWidget(self.scriptpushButtonopen)
        self.scriptpushButtonsave = QtWidgets.QPushButton(self.wizardPage_3)
        self.scriptpushButtonsave.setObjectName("scriptpushButtonsave")
        self.horizontalLayout_2.addWidget(self.scriptpushButtonsave)
        self.verticalLayout_2.addLayout(self.horizontalLayout_2)
        Wizard.addPage(self.wizardPage_3)
        self.wizardPage_2 = QtWidgets.QWizardPage()
        font = QtGui.QFont()
        font.setPointSize(20)
        self.wizardPage_2.setFont(font)
        self.wizardPage_2.setObjectName("wizardPage_2")
        self.textBrowser_6 = QtWidgets.QTextBrowser(self.wizardPage_2)
        self.textBrowser_6.setGeometry(QtCore.QRect(170, 140, 411, 191))
        self.textBrowser_6.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.textBrowser_6.setObjectName("textBrowser_6")
        Wizard.addPage(self.wizardPage_2)
        #font textedit
        self.skrift = QFont()
        self.skrift.setFamily('Consolas')
        self.skrift.setFixedPitch(True)
        self.skrift.setPointSize(11)
        self.TemptextEdit.setFont(self.skrift)
        self.script_textEdit.setFont(self.skrift)

        #python style temp
        self.lexer = QsciLexerPython(self.TemptextEdit)
        self.lexer.setFont(self.skrift)
        self.lexer.setEolFill(True)
        #Python style scritps
        self.lexer = QsciLexerPython(self.script_textEdit)
        self.lexer.setFont(self.skrift)
        self.lexer.setEolFill(True)
        self.filename = ""
        #python style temp
        self.TemptextEdit.setAutoCompletionThreshold(0)
        self.TemptextEdit.setAutoCompletionThreshold(6)
        self.TemptextEdit.setAutoCompletionThreshold(8)
        self.TemptextEdit.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs)
        #        self.TemptextEdit.setDefaultFont(self.skrift)
        self.TemptextEdit.setLexer(self.lexer)
        self.TemptextEdit.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1,
                                        'Consolas')
        #python style script
        self.script_textEdit.setAutoCompletionThreshold(0)
        self.script_textEdit.setAutoCompletionThreshold(6)
        self.script_textEdit.setAutoCompletionThreshold(8)
        self.script_textEdit.setAutoCompletionSource(
            Qsci.QsciScintilla.AcsAPIs)
        #        self.script_textEdit.setDefaultFont(self.skrift)
        self.script_textEdit.setLexer(self.lexer)
        self.script_textEdit.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1,
                                           'Consolas')

        #line numbers temp
        fontmetrics = QFontMetrics(self.skrift)
        self.TemptextEdit.setMarginsFont(self.skrift)
        self.TemptextEdit.setMarginWidth(0, fontmetrics.width("00000") + 6)
        self.TemptextEdit.setTabWidth(4)
        #line numbers script
        fontmetrics = QFontMetrics(self.skrift)
        self.script_textEdit.setMarginsFont(self.skrift)
        self.script_textEdit.setMarginWidth(0, fontmetrics.width("00000") + 6)
        self.script_textEdit.setTabWidth(4)

        #brace temp
        self.TemptextEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
        #brace script
        self.script_textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        #auto line tab =4 temp
        self.TemptextEdit.setAutoIndent(True)
        #auto line tab =4 script
        self.TemptextEdit.setAutoIndent(True)

        #scroolbar
        self.script_textEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1)
        try:
            bs = open(TemplateFile).read()
            bba = QtCore.QByteArray(bs)
            self.bts = QtCore.QTextStream(bba)
            self.bheysa = self.bts.readAll()
            self.TemptextEdit.setText(self.bheysa)
            self.TemptextEdit.setMarkerBackgroundColor((QColor(66, 66, 255)))
            marker = self.TemptextEdit.markerDefine(
                PyQt5.Qsci.QsciScintilla.Rectangle, 2)

            self.TemptextEdit.markerAdd(7, 2)
            self.TemptextEdit.markerAdd(11, 2)
            self.TemptextEdit.markerAdd(12, 2)
            self.TemptextEdit.markerAdd(13, 2)
            self.TemptextEdit.markerAdd(14, 2)
            self.TemptextEdit.markerAdd(15, 2)
            self.TemptextEdit.markerAdd(19, 2)
            self.TemptextEdit.markerAdd(27, 2)
            self.TemptextEdit.markerAdd(34, 2)
            self.TemptextEdit.markerAdd(35, 2)
            self.TemptextEdit.markerAdd(40, 2)
            self.TemptextEdit.markerAdd(41, 2)
            self.TemptextEdit.markerAdd(42, 2)
            self.TemptextEdit.markerAdd(43, 2)
            self.TemptextEdit.markerAdd(44, 2)
            self.TemptextEdit.markerAdd(45, 2)

            self.TemptextEdit.markerAdd(48, 2)
            self.TemptextEdit.markerAdd(50, 2)
            self.TemptextEdit.markerAdd(51, 2)
            self.TemptextEdit.markerAdd(52, 2)
            self.TemptextEdit.markerAdd(53, 2)
            self.TemptextEdit.markerAdd(54, 2)
            self.TemptextEdit.markerAdd(55, 2)

            self.TemptextEdit.markerAdd(62, 2)
            self.TemptextEdit.markerAdd(63, 2)
            self.TemptextEdit.markerAdd(64, 2)

            self.TemptextEdit.markerAdd(67, 2)
            self.TemptextEdit.markerAdd(89, 2)

            self.TemptextEdit.markerAdd(97, 2)
            self.TemptextEdit.markerAdd(98, 2)
            self.TemptextEdit.markerAdd(99, 2)
            self.TemptextEdit.markerAdd(102, 2)

        except:
            self.TemptextEdit.setText('Plugin_temp file not found')
            pass

        self.retranslateUi2(Wizard)
        QtCore.QMetaObject.connectSlotsByName(Wizard)
Beispiel #30
0
    def __init__(self, parent=None):
        super(PythonEditor, self).__init__(parent)

        self.filename = 'untitled.py'

        # self.setIndentationWidth(4)

        # Editor settings

        self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXWIDTH, 0)
        self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXHEIGHT, 0)

        self.setUtf8(True)  # Set encoding to UTF-8
        self.setEolMode(QsciScintilla.EolUnix)  # lf text endings
        self.setIndentationsUseTabs(False)
        self.setTabWidth(4)
        self.setIndentationGuides(True)
        self.setTabIndents(True)
        self.setAutoIndent(True)
        self.setWrapMode(QsciScintilla.WrapNone)
        self.setWrapVisualFlags(QsciScintilla.WrapFlagByText)

        self.setEolVisibility(False)

        # Make the backspace jump back to the tab width guides
        # instead of deleting one character, but only when
        # there are ONLY whitespaces on the left side of the
        # cursor
        self.setBackspaceUnindents(True)

        # Set the default font
        font = QFont()
        font.setFamily(FONT_NAME)
        font.setFixedPitch(True)
        font.setPointSize(FONT_SIZE)
        self.setFont(font)
        self.setMarginsFont(font)

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

        # Clickable margin 1 for showing markers
        # self.setMarginSensitivity(1, True)
        # self.marginClicked.connect(self.on_margin_clicked)
        # self.markerDefine(QsciScintilla.RightArrow,
        #                   self.ARROW_MARKER_NUM)
        # self.setMarkerBackgroundColor(QColor("#ee1111"),
        #                               self.ARROW_MARKER_NUM)

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

        # Current text visible with special background color
        self.setCaretLineVisible(True)
        self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
        self.setCaretWidth(3)

        # Set Python lexer
        lexer = QsciLexerPython()
        lexer.setDefaultFont(font)
        self.setLexer(lexer)

        # Set style for Python comments (style number 1) to a fixed-width font.
        self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, FONT_NAME_b)
        self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, 1, FONT_SIZE)

        # 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, 1)

        """
        Customization - AUTOCOMPLETION
        """
        # Set the autocompletions to case INsensitive
        self.setAutoCompletionCaseSensitivity(False)

        # Set the autocompletion to not replace the word to the right of the cursor
        self.setAutoCompletionReplaceWord(False)

        # Set the autocompletion source to be the words in the
        # document
        self.setAutoCompletionSource(PyQt5.Qsci.QsciScintilla.AcsDocument)

        # Set the autocompletion dialog to appear as soon as 2 characters are typed
        self.setAutoCompletionThreshold(2)

        # not too small
        self.setMinimumSize(600, 450)