Exemple #1
0
    def __init__(self):
        super(ScriptPage, self).__init__()
        self.setupUi(self)

        self.scriptCodeEditor.setUtf8(1)

        lex = Qsci.QsciLexerPython(self)
        api = Qsci.QsciAPIs(lex)
        api.load(API_FILE)
        api.prepare()
        self.current_script = None  # type: model.Script
        self.scriptCodeEditor.setLexer(lex)

        self.scriptCodeEditor.setBraceMatching(
            Qsci.QsciScintilla.SloppyBraceMatch)
        self.scriptCodeEditor.setAutoIndent(True)
        self.scriptCodeEditor.setBackspaceUnindents(True)
        self.scriptCodeEditor.setIndentationWidth(4)
        self.scriptCodeEditor.setIndentationGuides(True)
        self.scriptCodeEditor.setIndentationsUseTabs(False)
        self.scriptCodeEditor.setAutoCompletionThreshold(3)
        self.scriptCodeEditor.setAutoCompletionSource(
            Qsci.QsciScintilla.AcsAll)
        self.scriptCodeEditor.setCallTipsStyle(
            Qsci.QsciScintilla.CallTipsNoContext)
        lex.setFont(ui_common.monospace_font())
    def __init__(self, parent):
        super ().__init__(parent)

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

        fontMetrics = QtGui.QFontMetrics(font)
        self.setMarginsFont(font)
        self.setMarginWidth(0, fontMetrics.width("00000") + 6)
        self.setMarginLineNumbers(0, True)
        self.setMarginsBackgroundColor(QtGui.QColor("#cccccc"))

        self.markerDefine(Qsci.QsciScintilla.RightArrow, self.SC_MARK_MINUS)
        self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"), self.SC_MARK_MINUS)

        self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)

        self.setCaretLineVisible(True)
        self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4"))

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

        self.SendScintilla(Qsci.QsciScintilla.SCI_SETEOLMODE, Qsci.QsciScintilla.SC_EOL_CR)

        self.setTabWidth(4)
        self.setIndentationsUseTabs(False)
        self.setAutoIndent(True)

        self.setAcceptDrops(True)
Exemple #3
0
        def __init__(self, parent=None):
            """
            very similar to:
            https://stackoverflow.com/questions/40002373/qscintilla-based-text-editor-in-pyqt5-with-clickable-functions-and-variables
            """
            super(SimplePythonEditorWidget, 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.set_font(font)

            self.setMarginLineNumbers(0, True)
            self.setMarginsBackgroundColor(QColor("#cccccc"))

            # Clickable margin 1 for showing markers
            self.setMarginSensitivity(1, True)
            if qt_version == 'pyqt4':
                self.connect(self,
                             QtCore.SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),
                             self.on_margin_clicked)
            else:
                self.marginClicked.connect(self.on_margin_clicked)

            self.markerDefine(Qsci.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(Qsci.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 = Qsci.QsciLexerPython()
            lexer.setDefaultFont(font)
            self.setLexer(lexer)

            if qt_version == 'pyqt4':
                self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')
            else:
                font_style = bytearray(str.encode("Courier"))
                self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, font_style)

            # 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(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
Exemple #4
0
 def set_Lexer(self, type=2):  #设置解释器
     dic = {
         0: Qsci.QsciLexerBash(),
         1: Qsci.QsciLexerCPP(),
         2: Qsci.QsciLexerPython(),
         3: Qsci.QsciLexerJava(),
     }
     textLexer = dic[type]
     # textLexer->setColor(QColor(Qt:: yellow), QsciLexerCPP::CommentLine); // 设置自带的注释行为绿色
     self.setLexer(textLexer)
Exemple #5
0
 def __init__(self, parent=None):
     super().__init__(parent=parent)
     self.lexer = Qsci.QsciLexerPython()
     api = Qsci.QsciAPIs(self.lexer)
     api.prepare()
     self.setLexer(self.lexer)
     self.setAutoCompletionThreshold(1)
     self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs)
     self.init_ui()
     return
Exemple #6
0
    def __init__(self,
                 parent=None,
                 *,
                 fontsize=11,
                 fontfamily='monospace',
                 autocompletion_words=(),
                 autocomplete_python=True,
                 theme='dark',
                 **kwds):
        super().__init__(parent)

        # Fonts
        self.setAllFonts(fontfamily, fontsize)
        self.setMarginSensitivity(1, False)
        self.setCaretLineVisible(True)

        # Configure lexer and api for autocompletion
        lexer = Qsci.QsciLexerPython(self)
        lexer.setDefaultFont(self.font())
        words = list(autocompletion_words)
        if autocomplete_python:
            words.extend(PYTHON_WORDS)
        if words:
            api = Qsci.QsciAPIs(lexer)
            for word in words:
                api.add(word)
            api.prepare()
        self.setLexer(lexer)

        # Set font for lexer again?
        bfamily = bytes(fontfamily, encoding='utf8')
        self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, bfamily)
        self.setAllFonts(fontfamily, fontsize, True)

        # General indentation behavior
        self.setAutoIndent(True)
        self.setTabWidth(4)
        self.setIndentationsUseTabs(False)
        self.setTabIndents(True)
        self.setBackspaceUnindents(True)
        self.setIndentationGuides(True)

        # Configure autocompletion and brace matching
        self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)
        self.setAutoCompletionThreshold(2)
        self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs)

        # Set colors
        self._theme = theme
        color_kwds = {k: v for (k, v) in kwds.items() if k.endswith('_color')}
        self.setTheme(theme, **color_kwds)

        # Check for any rogue parameter
        if kwds:
            raise TypeError('invalid parameter: %r' % kwds.popitem()[0])
    def __init__(self, parent=None, lexer=Qsci.QsciLexerPython(), source=None, autocomplete_source=None):
        super(Qsci.QsciScintilla, self).__init__(parent)

        # Set the default font
        font = make_font('Courier', 10)
        font.setFixedPitch(True)
        self.setFont(font)

        # Indentation
        self.setIndentationsUseTabs(False)
        self.setTabWidth(4)
        self.setAutoIndent(True)

        # Margins
        self.setMarginsFont(font)
        self.setMarginsBackgroundColor(QtGui.QColor('#5d5d5d'))
        self.setMarginsForegroundColor(QtGui.QColor(QtCore.Qt.yellow))

        # Margin 0 is used for line numbers
        self.setMarginType(0, Qsci.QsciScintilla.NumberMargin)
        self.setMarginWidth(0, '00000')
        self.setMarginLineNumbers(0, True)

        # Clickable margin 1 for showing markers
        self.setMarginType(1, Qsci.QsciScintilla.SymbolMargin)
        self.setMarginWidth(1, 20)
        self.setMarginSensitivity(1, True)
        self.marginClicked.connect(self.on_margin_clicked)
        self.markerDefine(Qsci.QsciScintilla.RightArrow, SynEditor.ARROW_MARKER_NUM)
        self.setMarkerBackgroundColor(QtGui.QColor(QtCore.Qt.magenta), SynEditor.ARROW_MARKER_NUM)

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

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

        ## Python lexer
        self.lexer = lexer
        # Set style for Python comments (style number 1) to a fixed-width font
        self.lexer.setDefaultFont(font)
        self.setLexer(self.lexer)
        # set font
        self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, bytearray(str.encode(font.family())))
        # tab guides
        self.setIndentationGuides(True)
        ## `list`|`None` autocompletion source
        self.autocomplete_source = autocomplete_source
        self._config_autocomplete()

        # set source
        if source: self.setText(source)
 def __init__(self, lexer=Qsci.QsciLexerPython(), source=None, autocomplete_source=None,
             minsize=(600, 400), icon='file.png', title=':: Code Editor ::'):
     super().__init__()
     ## `QtWidgets.QVBoxLayout` main window layout
     self.layout_main = QtWidgets.QVBoxLayout()
     self.add_elements(lexer, source, autocomplete_source)
     self.setLayout(self.layout_main)
     # set minimum widget size
     if minsize: self.setMinimumSize(*minsize)
     self.setWindowIcon(QtGui.QIcon(f"{ICONFOLDER}/{icon}"))
     self.setWindowTitle(title)
Exemple #9
0
    def new_editor(self) -> Qsci.QsciScintilla:
        """"""
        # Create editor object
        editor = Qsci.QsciScintilla()

        # Set editor font
        font = QtGui.QFont()
        font.setFamily('Consolas')
        font.setFixedPitch(True)
        font.setPointSize(10)

        editor.setFont(font)
        editor.setMarginsFont(font)

        # Set margin for line numbers
        font_metrics = QtGui.QFontMetrics(font)
        editor.setMarginWidth(0, font_metrics.width("00000") + 6)
        editor.setMarginLineNumbers(0, True)
        editor.setMarginsBackgroundColor(QtGui.QColor("#cccccc"))

        # Set brace matching
        editor.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)

        # Hide horizontal scroll bar
        editor.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)

        # Set current line color
        editor.setCaretLineVisible(True)
        editor.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4"))

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

        # Add minimum editor size
        editor.setMinimumSize(600, 450)

        # Enable auto complete
        editor.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll)
        editor.setAutoCompletionThreshold(2)
        editor.setAutoCompletionCaseSensitivity(False)
        editor.setAutoCompletionReplaceWord(False)

        # Use space indentation
        editor.setIndentationsUseTabs(False)
        editor.setTabWidth(4)
        editor.setIndentationGuides(True)

        # Enable folding
        editor.setFolding(True)

        return editor
    def _setLexer(self):
        lexer = _Qsci.QsciLexerPython()
        lexer.setDefaultFont(_QtGui.QFont('Courier', 10))
        # Set the comment options
        lexer.comment_string = "#"
        # Set the lexer for the current scintilla document
        lexer.setParent(self)
        self.setLexer(lexer)

        for style in self.styles:
            paper = _QtGui.QColor(getattr(PythonColor, style))
            lexer.setPaper(paper, self.styles[style])
            self.setLexerFont(lexer, style, getattr(PythonFont, style))
        # self.setMatchedBraceBackgroundColor(settings.Editor.brace_color)
        self.SendScintilla(_Qsci.QsciScintillaBase.SCI_STYLESETFONT, 1, b'Courier')
        self.setFolding(_Qsci.QsciScintilla.PlainFoldStyle)
Exemple #11
0
    def __init__(self, parent=None):
        super(MyQScintilla, self).__init__(parent)

        lexer = Qsci.QsciLexerPython()
        self.setLexer(lexer)
        self.setWhitespaceVisibility(Qsci.QsciScintilla.WsVisible)
        self.setMarginLineNumbers(1, True)
        self.setMarginWidth(1, 25)
        self.setReadOnly(False)
        self.setIndentationGuides(True)
        self.setIndentationWidth(4)
        self.setIndentationsUseTabs(False)
        self.setWrapMode(Qsci.QsciScintilla.WrapWord)
        self.setUtf8(True)
        self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)
        self.setCaretLineVisible(True) # highlight current line
        self.setCaretLineBackgroundColor(QColor("#e5e5e5"))
Exemple #12
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.setMargins(1)
        self.setMarginWidth(0, '00000000')
        self.setMarginType(0, Qsci.QsciScintilla.NumberMargin)

        self.setTabWidth(4)
        self.setIndentationGuides(True)
        self.setAutoIndent(True)

        self.setScrollWidth(1)
        self.setScrollWidthTracking(True)

        font = QtGui.QFontDatabase.systemFont(QtGui.QFontDatabase.FixedFont)
        font.setPointSize(11)

        lexer = Qsci.QsciLexerPython()
        lexer.setFont(font)
        lexer.setDefaultFont(font)
        self.setLexer(lexer)
Exemple #13
0
    def setupEditor(self):
        #Font
        self.font = QtGui.QFont()
        self.font.setFamily('Inconsolata')
        self.font.setPointSize(12)
        self.ui.textEdit.setFont(self.font)
        self.ui.textEdit.setMarginsFont(self.font)

        #Syntax
        self.lexer = Qsci.QsciLexerPython()
        self.lexer.setFont(self.font)
        self.lexer.setDefaultFont(self.font)

        #Autocomplete
        api = Qsci.QsciAPIs(self.lexer)
        keys = dir(builtins) + keyword.kwlist
        [api.add(key) for key in keys]
        api.prepare()
        self.ui.textEdit.setLexer(self.lexer)
        self.ui.textEdit.setAutoCompletionThreshold(1)
        self.ui.textEdit.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll)

        #Indent
        self.ui.textEdit.setIndentationWidth(4)
        self.ui.textEdit.setTabWidth(4)
        self.ui.textEdit.setIndentationsUseTabs(False)
        self.ui.textEdit.setAutoIndent(True)

        #Current line
        self.ui.textEdit.SendScintilla(Qsci.QsciScintilla.SCI_SETINDICATORCURRENT, 0, 0)
        self.ui.textEdit.setCaretLineVisible(True)
        self.ui.textEdit.setCaretLineBackgroundColor(QtGui.QColor("#f0f0ff"))

        #Margin
        self.ui.textEdit.setMarginWidth(0, 15)
        self.ui.textEdit.setMarginWidth(1, 15)
        self.ui.textEdit.setMarginLineNumbers(0, False)
        self.ui.textEdit.setMarginLineNumbers(1, True)
        self.ui.textEdit.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle)
Exemple #14
0
    def __init__(self,
                 parent=None,
                 ShowPrint=True,
                 ShowError=True,
                 StatusBar=None,
                 AsDock=False,
                 logCount=30,
                 ScriptsPath='Scripts/',
                 InitalizeScripts=True,
                 btnText="Console",
                 btnIcon="F:/04/06/29.PNG",
                 addObj=None):
        '''
        Parent - Pass QWIDGET based objects. Else I will create my own.
        ShowPrint - Redirect standard prints
        ShowError - Redirect standard errors
        StatusBar - Attach DevC Invoke button to this status bar else You should invoke DevC explicitly
        AsDock - If True creates DevC as a dock else as a dialog window
        '''
        last_update_date = 'July 02 2015'  # July 02 2015 , Jan 12 2013
        self.addObj = addObj
        self.parent = parent
        self.asDock = AsDock
        self.logCount = logCount

        super(DevConsole, self).__init__(self.parent)
        atexit.register(self.writeToLog)

        # Load File
        self.loadedFile = False
        self.loadedFileName = ''
        self.pyDesigner = 'C:\Python34\Lib\site-packages\PyQt5\designer.exe'

        #Flags
        self.qtTools = kmxQtCommonTools.CommonTools(self)
        self.ttls = kmxTools.Tools()
        self.qtTree = kmxQtTreeWidget.TreeWidget()
        self.qtMenu = kmxQtMenuBuilder.MenuBuilder()
        self.qtConn = kmxQtConnections.QtConnections(self)
        self.qtIcon = kmxQtCommonTools.iconSetup(self)

        self.standalone = 0 if self.parent else 1

        if self.standalone:
            print('No parent specified! Creating standalone console!')
            self.parent = self.win = QtWidgets.QMainWindow()
            self.win.resize(689, 504)

            self.mainWidget = QtWidgets.QWidget(self.win)
            self.setupUi(self.mainWidget)
            self.win.setCentralWidget(self.mainWidget)
            self.toolbar = QtWidgets.QToolBar('Main Tools', self)
            self.toolbar2 = QtWidgets.QToolBar('Additional Tools', self)
            self.toolbar.setFloatable(True)
            self.toolbar2.setFloatable(True)
            self.win.addToolBar(self.toolbar)
            self.win.addToolBar(self.toolbar2)
            self.setStandAloneModeFeatures()

            self.btnExecute.setVisible(0)
            self.btnLoadScript.setVisible(0)
            self.btnSaveScript.setVisible(0)
            self.btnNewScript.setVisible(0)
            self.btnQuickSaveScript.setVisible(0)

            self.label.setVisible(1)
            self.label.setText('Output:')
            self.line.setVisible(0)
            #self.sciOutput.resize(self.sciOutput.width(), self.sciOutput.height() + 90)

        elif self.asDock:
            if hasattr(self.parent, 'addDockWidget'):
                print('Creating dock based console!')
                self.win = QtWidgets.QDockWidget(self.parent)
                base = QtWidgets.QWidget()
                self.setupUi(base)
                self.win.setWidget(base)
                self.parent.addDockWidget(QtCore.Qt.DockWidgetArea(2),
                                          self.win)

                # print ('Creating dock based console!')
                # self.dck = QtWidgets.QDockWidget(self.parent)
                #
                # dlg = QtWidgets.QWidget()
                #
                # self.win = QtWidgets.QMainWindow()
                # lyt = QtWidgets.QVBoxLayout()
                # lyt.addWidget(self.win)
                # wdgt = QtWidgets.QWidget(self.dck)
                # self.setupUi(wdgt)
                # self.win.setCentralWidget(wdgt)
                #
                # dlg.setLayout(lyt)
                #
                # self.dck.setWidget(dlg)
                # self.parent.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.dck)

            else:
                print('Unsupported Parent for creating dock based console! ' +
                      str(self.parent))
                print('Connecting console to given parent as a dialog...' +
                      str(self.parent))
                self.win = QtWidgets.QDialog(self.parent)
                self.setupUi(self.win)
        else:
            print('Connecting console to given parent as a dialog...' +
                  str(self.parent))
            self.win = QtWidgets.QDialog(self.parent)
            self.setupUi(self.win)

        self.outputFont = self.sciOutput.font()
        self.outputFont.setFamily("Courier")
        self.outputFont.setPointSize(10)
        self.outputFont.setFixedPitch(True)
        self.sciOutput.setFont(self.outputFont)
        self.sciOutput.setMarginsFont(self.outputFont)

        print(
            "Outputs Redirected to HaPy. Check HaPy console log for furthur system messages."
        )
        if ShowPrint: sys.stdout = self
        if ShowError: sys.stderr = self

        self.inter = InteractiveInterpreter()
        self.inter.locals['dev'] = self
        globals()['dev'] = self

        self.win.setWindowIcon(self.parent.windowIcon())
        self.win.setWindowTitle('HaPy')

        self.PLX = Qsci.QsciLexerPython(self)
        self.ABS = Qsci.QsciAPIs(self.PLX)
        # self.PLX.setAPIs(self.ABS)
        self.ABS.prepare()

        self.sciOutput.setReadOnly(1)
        self._setQSci(self.sciOutput)

        # Connections
        self.tabWidget.tabCloseRequested.connect(self.tabClose)

        if not self.standalone:
            self.btnExecute.clicked.connect(self.btnRedirector)
            #self.btnExecute_2.clicked.connect(self.btnRedirector)
            self.btnLoadScript.clicked.connect(self.btnRedirector)
            self.btnSaveScript.clicked.connect(self.btnRedirector)
            self.btnNewScript.clicked.connect(self.btnRedirector)
            self.btnQuickSaveScript.clicked.connect(self.btnRedirector)

        self.qtTools.connectToRightClick(self.treeWidget,
                                         self.pluginRightClick)
        self.tabWidget.__class__.keyReleaseEvent = self.tabKeyPress

        if StatusBar:
            self.stsBtnDebugger = QtWidgets.QToolButton(self.parent)
            self.stsBtnDebugger.setText(btnText)
            self.stsBtnDebugger.setToolTip(btnText)
            self.stsBtnDebugger.setAutoRaise(1)
            self.stsBtnDebugger.setMaximumHeight(18)
            StatusBar.addPermanentWidget(self.stsBtnDebugger, 0)
            self.stsBtnDebugger.clicked.connect(self.btnRedirector)
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(btnIcon), QtGui.QIcon.Normal,
                           QtGui.QIcon.On)
            self.stsBtnDebugger.setIcon(icon)
        else:
            self.stsBtnDebugger = None

        self.win.hide()

        # Plugin Lister
        #self.treeWidget.headerItem().setText(0, "DevS")
        self.treeWidget.itemDoubleClicked.connect(self.pluginSelected)

        self.treeWidget.setVisible(False)

        print('---------------------------------------')
        print('HaPy - Handy Python')
        print('Interactive Interpreter')
        print('---------------------------------------')
        print('Initiated!')

        print('\nLog Start Time: ' + str(strftime("%Y/%m/%d %H:%M:%S")))
        print('\n---------------------------------------\n')
        print('*** Python %s on %s.***' % (sys.version, sys.platform))
        print(sys.copyright)
        print('')
        print('Platform: ' + sys.platform)
        print('Version: ' + str(sys.getwindowsversion()))
        print('FileSys encodeing: ' + str(sys.getfilesystemencoding()))

        drline = "\n---------------------------------------\n"
        self.credit = drline + 'About HaPy:\nHandy Python - Interactive Interpreter/Scripting Environment \nAn expreimental project by \nKumaresan Lakshmanan\nFor Quick, Portable windows automation. \nDate: ' + last_update_date + drline
        print(self.credit)

        self.InitalizeScripts = InitalizeScripts
        self.scriptsDirName = ScriptsPath
        self.scriptsPath = os.path.abspath(self.scriptsDirName)
        print("Checking scripts path..." + os.path.abspath(self.scriptsPath))

        if self.scriptsPath:
            if self.InitalizeScripts and self.scriptsPath and not os.path.exists(
                    self.scriptsPath):
                os.makedirs(self.scriptsPath)
        else:
            print('Invalid script path!')

        #Start loading the scripts...
        try:
            self.execPlugin()
            self.treeWidget.setVisible(True)
        except:
            print(errorReport())

        try:
            if self.InitalizeScripts:
                self.execStartUp()
            else:
                self.addEmptyTab()
        except:
            print(errorReport())

        if self.standalone:
            self.qtConn.uiMain = self.win
            self.qtConn.installEventHandler()
            self.qtConn.addEventConnection(self.win, 'WindowDeactivate',
                                           self.onWinDeAct)
            self.qtConn.addEventConnection(self.win, 'Close', self.onClose)
            self.qtConn.addEventConnection(self.win, 'Hide', self.onHide)
            self.qtConn.addEventConnection(self.win, 'Show', self.onShow)

            if (os.path.exists('layout.lyt')):
                customList = self.qtTools.uiLayoutRestore(
                    'layout.lyt', [self.splitter, self.splitter_2])
                if (customList):
                    self.win.resize(customList[0])
                    self.win.move(customList[1])
            self.loadTabs()
        print("All set, You are ready to go...")
Exemple #15
0
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        self.setWindowTitle("Code Editor")
        self.setWindowIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_FileIcon))

        font = QtGui.QFont("Courier New", 10)
        font.setFixedPitch(True)
        self.setFont(font)
        self.setMarginsFont(font)

        fontmetrics = QtGui.QFontMetrics(font)
        self.setMarginsFont(font)
        self.setMarginWidth(0, fontmetrics.width("00000") + 6)
        self.setMarginLineNumbers(0, True)
        self.setMarginsForegroundColor(QtGui.QColor("#00f"))
        self.setMarginsBackgroundColor(QtGui.QColor("#111"))

        self.setMarginSensitivity(1, True)
        self.marginClicked.connect(self.on_margin_clicked)

        self.markerDefine(Qsci.QsciScintilla.RightArrow, self.ARROW_MARKER_NUM)
        self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"),
                                      self.ARROW_MARKER_NUM)

        self.setAutoIndent(True)
        self.setIndentationWidth(4)
        self.setIndentationGuides(True)
        self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)

        self.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle)
        self.setFoldMarginColors(QtGui.QColor("#111"), QtGui.QColor("#111"))

        self.setCaretLineVisible(True)
        self.setCaretLineBackgroundColor(QtGui.QColor("#222"))

        self.setAutoCompletionSource(Qsci.QsciScintilla.AcsDocument)
        self.setAutoCompletionThreshold(4)

        self.lexer = Qsci.QsciLexerPython()
        self.lexer.setDefaultFont(self.font())
        self.lexer.setDefaultPaper(QtGui.QColor("#000"))
        self.lexer.setDefaultColor(QtGui.QColor("#FFF"))

        colors = {
            "FunctionMethodName": "#0000ff",
            "ClassName": "#0000ff",
            "Comment": "#dd0000",
            "Decorator": "#ff7700",
            "Keyword": "#ff7700"
        }
        colors.update({
            key: "#00aa00"
            for key in [
                "UnclosedString", "DoubleQuotedString", "SingleQuotedString",
                "TripleDoubleQuotedString", "TripleSingleQuotedString"
            ]
        })

        for key, color in colors.items():
            try:
                style = getattr(self.lexer, key)
                self.lexer.setColor(QtGui.QColor(color), style)
                self.lexer.setFont(QtGui.QFont(self.font()), style)
            except:
                pass

        self.setLexer(self.lexer)
        self.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
Exemple #16
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setLexer(Qsci.QsciLexerPython(self))
Exemple #17
0
 def __init__(self, methods, lexer=Qsci.QsciLexerPython(), source=None,
              minsize=(800, 500), icon='file.png', title=_(':: Code Editor ::')):
     ## `list` list of methods exposed to plugins
     self.methods = methods
     super().__init__(lexer, source, self._get_autocomplete_source(source), minsize, icon, title)
     self._config_editor()