Esempio n. 1
0
    def __init__(self, parent, filename='', lexer='', autosave=True):
        FocusProxy.__init__(self)
        WinterObject.__init__(self)
        self.QSCI_SUPPORT = QSCI_SUPPORT
        self.parent = parent
        self.autosave = autosave
        try:
            self.api = parent.API()
        except AttributeError:
            from baseQt import API

            self.api = API()
        self.filename = filename
        lay = QVBoxLayout()
        self.tb = QToolBar(self)
        lay.addWidget(self.tb)

        self.tb_save = QToolButton()
        #        self.tb_save.setIcon(QIcon.fromTheme('document-save', QIcon(self.api.icons['filesave'])))
        #        self.connect(self.tb_save, SIGNAL("clicked()"), self.save)
        #        self.tb.addWidget(self.tb_save)

        if QSCI_SUPPORT:
            editor = QsciScintilla(self)
            editor.setUtf8(True)
            self.lexers = {'Bash': QsciLexerBash, 'Batch': QsciLexerBatch, 'CMake': QsciLexerCMake, 'CPP': QsciLexerCPP,
                           'CSS': QsciLexerCSS, 'D': QsciLexerD, 'Diff': QsciLexerDiff, 'Fortran': QsciLexerFortran77,
                           'HTML': QsciLexerHTML, 'Lua': QsciLexerLua, 'Make': QsciLexerMakefile,
                           'Pascal': QsciLexerPascal,
                           'Perl': QsciLexerPerl, 'PostScript': QsciLexerPostScript, 'POV': QsciLexerPOV,
                           'Properties': QsciLexerProperties, 'Python': QsciLexerPython, 'Ruby': QsciLexerRuby,
                           'SQL': QsciLexerSQL, 'TCL': QsciLexerTCL, 'TeX': QsciLexerTeX,
                           'VHDL': QsciLexerVHDL, 'YAML': QsciLexerYAML, 'Plain': QsciLexerPython}

            if lexer:
                lex = self.lexers[lexer]()
                lex.setPaper(QColor(self.parent.config.options.qsci.bg_color))
                #lex.setColor(QColor(self.parent.config.options.qsci.fg_color))
                editor.setLexer(lex)

            editor.resetSelectionBackgroundColor()
            editor.resetSelectionForegroundColor()
            editor.setCaretLineBackgroundColor(QColor(self.parent.config.options.qsci.caretline_color))
            editor.setMarginsBackgroundColor(QColor(self.parent.config.options.qsci.margins_bg_color))
            editor.setMarginsForegroundColor(QColor(self.parent.config.options.qsci.margins_fg_color))
            editor.setFoldMarginColors(QColor(self.parent.config.options.qsci.foldmargin_prim_color),
                QColor(self.parent.config.options.qsci.foldmargin_sec_color))
            editor.setSelectionBackgroundColor(QColor(self.parent.config.options.qsci.selection_bg_color))
            editor.setSelectionForegroundColor(QColor(self.parent.config.options.qsci.selection_fg_color))
            editor.setFolding(self.parent.config.options.qsci.folding)
            editor.setPaper(QColor(self.parent.config.options.qsci.bg_color))
            editor.setColor(QColor(self.parent.config.options.qsci.fg_color))

            font = QFont()
            font.setFamily(self.parent.config.options.qsci.font)
            font.setFixedPitch(True)
            font.setPointSize(self.parent.config.options.qsci.font_size)
            fm = QFontMetrics(font)
            editor.setFont(font)
            if self.parent.config.options.qsci.linenumbers:
                editor.setMarginsFont(font)
                editor.setMarginWidth(0, fm.width("000") + 5)
                editor.setMarginLineNumbers(0, True)
            if self.parent.config.options.qsci.folding:
                editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)
            editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)
            editor.setCaretLineVisible(self.parent.config.options.qsci.caretline)




        else:
            editor = QTextEdit(self)

        self.editor = editor
        self.focused = editor
        lay.addWidget(editor)
        if filename:
            self.open(filename)

        self.setLayout(lay)

        if self.autosave:
            self.editor.focusOutEvent = self.focusOutEvent