コード例 #1
0
    def __init__(self, parent=None):
        QSyntaxHighlighter.__init__(self, parent)
        self.parent = parent
        sqlKeyword = QTextCharFormat()
        sqlOperator = QTextCharFormat()

        self.highlightingRules = []

        #Keywords
        sqlKeyword.setFontWeight(QFont.Bold)
        sqlKeyword.setForeground(Qt.blue)

        sqlKeywords = ["AND", "OR", "LIKE"]
        for word in sqlKeywords:
            regExp = QRegExp("\\b" + word + "\\b", Qt.CaseInsensitive)
            rule = HighlightingRule(regExp, sqlKeyword)
            self.highlightingRules.append(rule)

        #Comparison Operators
        sqlOperator.setForeground(Qt.magenta)
        sqlOperators = ["<", ">", "="]
        for operator in sqlOperators:
            regExp = QRegExp("\\W" + operator + "\\W", Qt.CaseInsensitive)
            rule = HighlightingRule(regExp, sqlOperator)
            self.highlightingRules.append(rule)
コード例 #2
0
 def finish_execution(self, exitCode, exitStatus):
     """Print a message and hide the input line when the execution ends."""
     self.lblInput.hide()
     self.input.hide()
     format_ = QTextCharFormat()
     format_.setAnchor(True)
     font = settings.FONT
     format_.setFont(font)
     self.output.textCursor().insertText('\n\n')
     if exitStatus == QProcess.NormalExit:
         format_.setForeground(
             QBrush(
                 QColor(
                     resources.CUSTOM_SCHEME.get(
                         "keyword", resources.COLOR_SCHEME["keyword"]))))
         self.output.textCursor().insertText(
             self.tr("Execution Successful!"), format_)
     else:
         format_.setForeground(
             QBrush(
                 QColor(
                     resources.CUSTOM_SCHEME.get(
                         "error-underline",
                         resources.COLOR_SCHEME["error-underline"]))))
         self.output.textCursor().insertText(
             self.tr("Execution Interrupted"), format_)
     self.output.textCursor().insertText('\n\n')
     self.__post_execution()
コード例 #3
0
ファイル: asciiItem.py プロジェクト: udgover/modules
    def colorizeDiff(self, diffinfos):
        cursor = self.textCursor()
        cursor.setPosition(QTextCursor.Start)

        text = self.toPlainText()

        keys = diffinfos.keys()
        keys.sort()

        for offset in keys:
            difflen = diffinfos[offset]
            pos = offset + (offset / 16)
#            count =  offset / 16

#            print "offset ", offset, " count ", count

            count = difflen + (((offset + difflen) / 16) - (offset / 16))
#            count = difflen
            cursor.setPosition(pos, QTextCursor.MoveAnchor)
#            print "L", l, " len ", pos + difflen
            cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor, count)

            format = QTextCharFormat()
            format.setFont(self.sfont)
            format.setForeground(QBrush(QColor(Qt.red)))
            cursor.setCharFormat(format)
            cursor.setPosition(QTextCursor.Start, QTextCursor.MoveAnchor)
コード例 #4
0
    def __init__(self, parent=None):
        self.keywordFormat = QTextCharFormat()
        self.keywordFormat.setForeground(QBrush(Qt.blue))
        self.keywordFormat.setFontWeight(QFont.Bold)
        self.stringFormat = QTextCharFormat()
        self.stringFormat.setForeground(QBrush(Qt.darkGreen))
        self.defFormat = QTextCharFormat()
        self.defFormat.setForeground(QBrush(Qt.black))
        self.defFormat.setFontWeight(QFont.Bold)
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setForeground(QBrush(Qt.lightGray))
        self.decoratorFormat = QTextCharFormat()
        self.decoratorFormat.setForeground(QBrush(Qt.darkGray))

        self.keywords = list(keyword.kwlist)

        self.rules = [(QRegExp(r"\b%s\b" % kwd), self.keywordFormat)
                      for kwd in self.keywords] + \
                     [(QRegExp(r"\bdef\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("),
                       self.defFormat),
                      (QRegExp(r"\bclass\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("),
                       self.defFormat),
                      (QRegExp(r"'.*'"), self.stringFormat),
                      (QRegExp(r'".*"'), self.stringFormat),
                      (QRegExp(r"#.*"), self.commentFormat),
                      (QRegExp(r"@[A-Za-z_]+[A-Za-z0-9_]+"),
                       self.decoratorFormat)]

        self.multilineStart = QRegExp(r"(''')|" + r'(""")')
        self.multilineEnd = QRegExp(r"(''')|" + r'(""")')

        QSyntaxHighlighter.__init__(self, parent)
コード例 #5
0
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        self.clb = ConfigurationLineBuilder(ErtKeywords())

        self.comment_format = QTextCharFormat()
        self.comment_format.setForeground(QColor(0, 128, 0))
        self.comment_format.setFontItalic(True)

        self.keyword_format = QTextCharFormat()
        self.keyword_format.setForeground(QColor(200, 100, 0))
        # self.keyword_format.setFontWeight(QFont.Bold)

        self.error_format = QTextCharFormat()
        # self.error_format.setForeground(QColor(255, 0, 0))
        self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline)
        self.error_format.setUnderlineColor(QColor(255, 0, 0))

        self.search_format = QTextCharFormat()
        self.search_format.setBackground(QColor(220, 220, 220))

        self.builtin_format = QTextCharFormat()
        self.builtin_format.setForeground(QColor(0, 170, 227))

        self.search_string = ""
コード例 #6
0
ファイル: outputview.py プロジェクト: wibrt/orange3
def update_char_format(baseformat,
                       color=None,
                       background=None,
                       weight=None,
                       italic=None,
                       underline=None,
                       font=None):
    """
    Return a copy of `baseformat` :class:`QTextCharFormat` with
    updated color, weight, background and font properties.

    """
    charformat = QTextCharFormat(baseformat)

    if color is not None:
        charformat.setForeground(color)

    if background is not None:
        charformat.setBackground(background)

    if font is not None:
        charformat.setFont(font)
    else:
        font = update_font(baseformat.font(), weight, italic, underline)
        charformat.setFont(font)

    return charformat
コード例 #7
0
    def __init__(self, parent=None):
        super(DiffsMenu, self).__init__(parent)

        self.ui = Ui_Diffs()
        self.ui.setupUi(self)

        self.ui.actionCopyPath = QtGui.QAction("Copy path",
                                               None,
                                               triggered=self.copyPath)
        self.ui.treeResults.addAction(self.ui.actionCopyPath)

        self.folder1 = None
        self.folder2 = None
        self.files = None
        self.files_nodupes = None
        self.files_missing = None

        self.saved_diffs = {}

        self.format1 = QTextCharFormat()
        self.format1.setBackground(QColor(255, 224, 224))

        self.format2 = QTextCharFormat()
        self.format2.setBackground(QColor(224, 240, 255))

        self.menu_name = "Diffs"

        self.format_plain = QTextCharFormat()
コード例 #8
0
ファイル: hm.py プロジェクト: hasanakgoz/Pardus-2011-Svn-
    def setDateBackground(self, color):
        brush = QBrush(color)

        frmt = QTextCharFormat()
        frmt.setBackground(brush)

        return frmt
コード例 #9
0
    def __init__(self, parent=None):
        super(ReferenceHighlighter, self).__init__(parent)

        self.format = QTextCharFormat()
        self.format.setForeground(QColor(0, 0, 255))

        self.references = []
コード例 #10
0
ファイル: highlighter.py プロジェクト: berland/ert
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        self.clb = ConfigurationLineBuilder(ErtKeywords())


        self.comment_format = QTextCharFormat()
        self.comment_format.setForeground(QColor(0, 128, 0))
        self.comment_format.setFontItalic(True)

        self.keyword_format = QTextCharFormat()
        self.keyword_format.setForeground(QColor(200, 100, 0))
        # self.keyword_format.setFontWeight(QFont.Bold)

        self.error_format = QTextCharFormat()
        # self.error_format.setForeground(QColor(255, 0, 0))
        self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline)
        self.error_format.setUnderlineColor(QColor(255, 0, 0))

        self.search_format = QTextCharFormat()
        self.search_format.setBackground(QColor(220, 220, 220))

        self.builtin_format = QTextCharFormat()
        self.builtin_format.setForeground(QColor(0, 170, 227))

        self.search_string = ""
コード例 #11
0
ファイル: run_widget.py プロジェクト: DevNIX/ninja-ide
    def __init__(self, parent):
        QPlainTextEdit.__init__(self, parent)
        self._parent = parent
        self.setReadOnly(True)
        self.maxValue = 0
        self.actualValue = 0
        #traceback pattern
        self.patLink = re.compile(r'(\s)*File "(.*?)", line \d.+')
        #formats
        self.plain_format = QTextCharFormat()
        self.plain_format.setForeground(QBrush(QColor(
            resources.CUSTOM_SCHEME.get("editor-text",
            resources.COLOR_SCHEME["editor-text"]))))
        self.error_format = QTextCharFormat()
        self.error_format.setAnchor(True)
        self.error_format.setFontUnderline(True)
        self.error_format.setUnderlineStyle(QTextCharFormat.SingleUnderline)
        self.error_format.setUnderlineColor(Qt.red)
        self.error_format.setForeground(Qt.blue)
        self.error_format.setToolTip(self.tr("Click to show the source"))

        self.connect(self, SIGNAL("blockCountChanged(int)"), self._scroll_area)

        css = 'QPlainTextEdit {color: %s; background-color: %s;' \
            'selection-color: %s; selection-background-color: %s;}' \
            % (resources.CUSTOM_SCHEME.get('editor-text',
            resources.COLOR_SCHEME['editor-text']),
            resources.CUSTOM_SCHEME.get('editor-background',
                resources.COLOR_SCHEME['editor-background']),
            resources.CUSTOM_SCHEME.get('editor-selection-color',
                resources.COLOR_SCHEME['editor-selection-color']),
            resources.CUSTOM_SCHEME.get('editor-selection-background',
                resources.COLOR_SCHEME['editor-selection-background']))
        self.setStyleSheet(css)
コード例 #12
0
 def __init__(self, parent = None):
   super(DiffsMenu, self).__init__(parent)
   
   self.ui = Ui_Diffs()
   self.ui.setupUi(self)
   
   self.ui.actionCopyPath = QtGui.QAction("Copy path", None, triggered = self.copyPath)
   self.ui.treeResults.addAction(self.ui.actionCopyPath)
   
   self.folder1        = None
   self.folder2        = None
   self.files          = None
   self.files_nodupes  = None
   self.files_missing  = None
   
   self.saved_diffs    = {}
   
   self.format1 = QTextCharFormat()
   self.format1.setBackground(QColor(255, 224, 224))
   
   self.format2 = QTextCharFormat()
   self.format2.setBackground(QColor(224, 240, 255))
   
   self.menu_name = "Diffs"
   
   self.format_plain = QTextCharFormat()
コード例 #13
0
    def setDateBackground(self, color):
        brush = QBrush(color)

        frmt = QTextCharFormat()
        frmt.setBackground(brush)

        return frmt
コード例 #14
0
ファイル: run_widget.py プロジェクト: kennyfm91/ninja-ide
 def __post_execution_message(self):
     """Print post execution message."""
     self.output.textCursor().insertText("\n\n")
     format = QTextCharFormat()
     format.setAnchor(True)
     format.setForeground(Qt.green)
     self.output.textCursor().insertText(self.tr("Post Execution Script Successfully executed."), format)
コード例 #15
0
    def __init__(self, parent=None):
        self.keywordFormat = QTextCharFormat()
        self.keywordFormat.setForeground(QBrush(Qt.blue))
        self.keywordFormat.setFontWeight(QFont.Bold)
        self.stringFormat = QTextCharFormat()
        self.stringFormat.setForeground(QBrush(Qt.darkGreen))
        self.defFormat = QTextCharFormat()
        self.defFormat.setForeground(QBrush(Qt.black))
        self.defFormat.setFontWeight(QFont.Bold)
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setForeground(QBrush(Qt.lightGray))
        self.decoratorFormat = QTextCharFormat()
        self.decoratorFormat.setForeground(QBrush(Qt.darkGray))

        self.keywords = list(keyword.kwlist)

        self.rules = [(QRegExp(r"\b%s\b" % kwd), self.keywordFormat)
                      for kwd in self.keywords] + \
                     [(QRegExp(r"\bdef\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("),
                       self.defFormat),
                      (QRegExp(r"\bclass\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("),
                       self.defFormat),
                      (QRegExp(r"'.*'"), self.stringFormat),
                      (QRegExp(r'".*"'), self.stringFormat),
                      (QRegExp(r"#.*"), self.commentFormat),
                      (QRegExp(r"@[A-Za-z_]+[A-Za-z0-9_]+"),
                       self.decoratorFormat)]

        self.multilineStart = QRegExp(r"(''')|" + r'(""")')
        self.multilineEnd = QRegExp(r"(''')|" + r'(""")')

        QSyntaxHighlighter.__init__(self, parent)
コード例 #16
0
ファイル: about.py プロジェクト: gltn/stdm
    def _insert_metadata_info(self):
        #Insert version and build numbers respectively.
        if not self._metadata is None:
            installed_version = self._metadata.get('version_installed', None)
        else:
            installed_version = version_from_metadata()

        if installed_version is None:
            return

        cursor = self.txtAbout.textCursor()
        cursor.movePosition(QTextCursor.End)
        cursor.insertBlock()
        cursor.insertBlock()

        #Insert installed version text
        version_msg = QApplication.translate(
            'AboutSTDMDialog',
            'STDM version'
        )
        version_text = u'{0} {1}'.format(version_msg, installed_version)
        char_format = cursor.blockCharFormat()
        text_format = QTextCharFormat(char_format)
        text_format.setFontWeight(75)
        cursor.insertText(version_text, text_format)
コード例 #17
0
class ViewHighlighter(widgets.arbitraryhighlighter.ArbitraryHighlighter, plugin.Plugin):
    def __init__(self, view):
        super(ViewHighlighter, self).__init__(view)
        self._cursorFormat = QTextCharFormat()
        self._cursorFormat.setProperty(QTextFormat.FullWidthSelection, True)
        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
        bookmarks.bookmarks(view.document()).marksChanged.connect(self.updateMarkedLines)
        self.updateMarkedLines()
        view.cursorPositionChanged.connect(self.updateCursor)
        view.installEventFilter(self)

    def updateMarkedLines(self):
        """Called when something changes in the bookmarks."""
        for type, marks in bookmarks.bookmarks(self.parent().document()).marks().items():
            self.highlight(type, marks, -1)
    
    def eventFilter(self, view, ev):
        if ev.type() in (QEvent.FocusIn, QEvent.FocusOut):
            self.updateCursor(view)
        return False
    
    def updateCursor(self, view=None):
        """Called when the textCursor has moved. Highlights the current line.
        
        If view is None (the default), our parent() is assumed to be the
        view. The eventFilter() method calls us with the view, this is
        done because the event filter is sometimes called very late in
        the destructor phase, when our parent is possibly not valid
        anymore.
        
        """
        if view is None:
			view = self.parent()
        # highlight current line
        color = QColor(self._baseColors['current'])
        color.setAlpha(200 if view.hasFocus() else 100)
        self._cursorFormat.setBackground(color)
        cursor = view.textCursor()
        cursor.clearSelection()
        self.highlight(self._cursorFormat, [cursor], 0)
        
    def readSettings(self):
        data = textformats.formatData('editor')
        self._baseColors = data.baseColors
        self.updateCursor()
        self.reload()

    def textFormat(self, name):
        """(Internal) Returns a QTextCharFormat setup according to the preferences.
        
        For bookmarks and the current line, FullWidthSelection is automatically enabled.
        
        """
        f = QTextCharFormat()
        f.setBackground(self._baseColors[name])
        if name in ('current', 'mark', 'error'):
            f.setProperty(QTextFormat.FullWidthSelection, True)
        return f
コード例 #18
0
ファイル: console.py プロジェクト: spirali/shampoo
 def write_info(self, text):
     old_format = self.currentCharFormat();
     format = QTextCharFormat()
     format.setForeground(QColor("white"))
     format.setBackground(QColor("darkgreen"))
     self.setCurrentCharFormat(format);
     self.appendPlainText("Done.\n");
     self.setCurrentCharFormat(old_format);
コード例 #19
0
 def setBold(self):
     format = QTextCharFormat()
     if self.boldAct.isChecked():
         weight = QFont.Bold
     else:
         weight = QFont.Normal
     format.setFontWeight(weight)
     self.setFormat(format)
コード例 #20
0
ファイル: stickynotes.py プロジェクト: realitee/leo-editor
 def setBold(self):
     format = QTextCharFormat()
     if self.boldAct.isChecked():
             weight = QFont.Bold
     else:
             weight = QFont.Normal
     format.setFontWeight(weight)
     self.setFormat(format)
コード例 #21
0
 def load(self, scheme):
     """Load the settings for the scheme. Called on init."""
     s = QSettings()
     s.beginGroup("fontscolors/" + scheme)
     
     # load font
     defaultfont = "Lucida Console" if os.name == "nt" else "monospace"
     self.font = QFont(s.value("fontfamily", defaultfont, type("")))
     self.font.setPointSizeF(s.value("fontsize", 10.0, float))
     
     # load base colors
     s.beginGroup("basecolors")
     for name in baseColors:
         if s.contains(name):
             self.baseColors[name] = QColor(s.value(name, "", type("")))
         else:
             self.baseColors[name] = baseColorDefaults[name]()
     s.endGroup()
     
     # get the list of supported styles from ly.colorize
     all_styles = ly.colorize.default_mapping()
     default_styles = set()
     for group, styles in all_styles:
         d = self._inherits[group] = {}
         for style in styles:
             if style.base:
                 default_styles.add(style.base)
                 d[style.name] = style.base
     
     default_scheme = ly.colorize.default_scheme
     
     # load default styles
     s.beginGroup("defaultstyles")
     for name in default_styles:
         self.defaultStyles[name] = f = QTextCharFormat()
         css = default_scheme[None].get(name)
         if css:
             css2fmt(css, f)
         s.beginGroup(name)
         self.loadTextFormat(f, s)
         s.endGroup()
     s.endGroup()
     
     # load specific styles
     s.beginGroup("allstyles")
     for group, styles in all_styles:
         self.allStyles[group]= {}
         s.beginGroup(group)
         for style in styles:
             self.allStyles[group][style.name] = f = QTextCharFormat()
             css = default_scheme[group].get(style.name)
             if css:
                 css2fmt(css, f)
             s.beginGroup(style.name)
             self.loadTextFormat(f, s)
             s.endGroup()
         s.endGroup()
     s.endGroup()
コード例 #22
0
ファイル: FilterHighlighter.py プロジェクト: einaru/luma
def format(color, style=''):
    """Return a QTextCharFormat with the given attributes.
    """
    c = QColor(color)
    #c.setNamedColor(color)

    f = QTextCharFormat()
    f.setForeground(c)
    return f
コード例 #23
0
ファイル: edit.py プロジェクト: EdwardBetts/frescobaldi
class Matcher(widgets.matcher.Matcher):
    def __init__(self, edit):
        super(Matcher, self).__init__(edit)
        self.readSettings()
        app.settingsChanged.connect(self.readSettings)
    
    def readSettings(self):
        self.format = QTextCharFormat()
        self.format.setBackground(textformats.formatData('editor').baseColors['match'])
コード例 #24
0
 def _insertAnchors(self, cursor, plainText, matcher, hrefFunc):
     for start, end, matcher in self._iterMatchedRanges(matcher, plainText):
         cursor.setPosition(start);
         cursor.setPosition(end, QTextCursor.KeepAnchor)
 
         fmt = QTextCharFormat()
         fmt.setAnchor(True)
         fmt.setAnchorHref(hrefFunc(matcher.cap()))
         cursor.mergeCharFormat(fmt)
コード例 #25
0
ファイル: syntaxer.py プロジェクト: robertbasic/ape
    def getFormat(self, format):
        color = QColor()
        color.setRed(self.formats[format]['color'][0])
        color.setGreen(self.formats[format]['color'][1])
        color.setBlue(self.formats[format]['color'][2])
        format = QTextCharFormat()
        format.setForeground(color)

        return format
コード例 #26
0
ファイル: shell.py プロジェクト: koll00/Gui_SM
 def set_font(self, font):
     """Set shell styles font"""
     self.set_pythonshell_font(font)
     cursor = self.textCursor()
     cursor.select(QTextCursor.Document)
     charformat = QTextCharFormat()
     charformat.setFontFamily(font.family())
     charformat.setFontPointSize(font.pointSize())
     cursor.mergeCharFormat(charformat)
コード例 #27
0
def format(color, style=''):
    """Return a QTextCharFormat with the given attributes.
    """
    c = QColor(color)
    #c.setNamedColor(color)

    f = QTextCharFormat()
    f.setForeground(c)
    return f
コード例 #28
0
ファイル: syntax.py プロジェクト: lostboycody/booster
def format(color):
    #Return a QTextCharFormat with the given attributes.

    _color = QColor()
    _color.setNamedColor(color)

    _format = QTextCharFormat()
    _format.setForeground(_color)

    return _format
コード例 #29
0
ファイル: TextEdit.py プロジェクト: straszheim/spec
 def set_char_format(self, format, start, end):
     oldcur = self.textCursor()
     cur = QtGui.QTextEdit.textCursor(self)
     cur.setPosition(start)
     cur.setPosition(end, QtGui.QTextCursor.KeepAnchor)
     cur.setCharFormat(format)
     fmt2 = QTextCharFormat()
     fmt2.setUnderlineStyle(QTextCharFormat.NoUnderline)
     oldcur.setCharFormat(fmt2)
     self.setTextCursor(oldcur)
コード例 #30
0
ファイル: MainWindow.py プロジェクト: arneboe/codecomment
 def clear_markers(self):
     cursor = self.ui.plainTextEditCode.textCursor()
     cursor.setPosition(0, QTextCursor.MoveAnchor)
     cursor.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
     format = QTextCharFormat()
     color = QColor()
     color.setAlpha(0) #nice trick to get the original background color back
     brush = QBrush(color)
     format.setBackground(brush)
     cursor.mergeCharFormat(format)
コード例 #31
0
    def __init__(self, parent=None):
        super(SpellCheckHighlighter, self).__init__(parent)

        self.set_language("en_US")

        self.format = QTextCharFormat()
        self.format.setUnderlineColor(QColor(255, 0, 0))
        self.format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)

        self.errors = []
コード例 #32
0
def imagiformat(color, style=''):
    _color = QColor()
    _color.setNamedColor(color)
    _format = QTextCharFormat()
    _format.setForeground(_color)

    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)

    return _format
コード例 #33
0
 def __init__(self, widget):
     QSyntaxHighlighter.__init__(self, widget)
     self.regex = None
     # create format type
     self.odd_format = QTextCharFormat()
     self.odd_format.setFontWeight(QFont.Bold)
     self.odd_format.setForeground(Qt.darkBlue)
     self.even_format = QTextCharFormat()
     self.even_format.setFontWeight(QFont.Bold)
     self.even_format.setForeground(Qt.darkMagenta)
コード例 #34
0
ファイル: edit.py プロジェクト: shimpe/frescobaldi
class Matcher(widgets.matcher.Matcher):
    def __init__(self, edit):
        super(Matcher, self).__init__(edit)
        self.readSettings()
        app.settingsChanged.connect(self.readSettings)

    def readSettings(self):
        self.format = QTextCharFormat()
        self.format.setBackground(
            textformats.formatData('editor').baseColors['match'])
コード例 #35
0
    def __init__(self, parent=None):
        super(KeywordHighlighter, self).__init__(parent)

        self.format = QTextCharFormat()
        self.format.setForeground(QColor(255, 0, 0))

        self.keywords = []
        self.matches = []

        self.re_flags = re.IGNORECASE | re.UNICODE
コード例 #36
0
 def toggleBold(self):
     #self.setFontWeight(QFont.Normal if self.fontWeight() > QFont.Normal else QFont.Bold)
     if self.which_header():
         return
     bold = self.fontWeight() > QFont.Normal
     cursor = self.textCursor()
     char_format = QTextCharFormat()
     char_format.setFont(self.font)
     char_format.setFontWeight(QFont.Normal if bold else QFont.Bold)
     cursor.setCharFormat(char_format)
コード例 #37
0
 def toggleItalic(self):
     if self.which_header():
         return
     #self.setFontItalic(not self.fontItalic())
     italic = self.fontItalic()
     cursor = self.textCursor()
     char_format = QTextCharFormat()
     char_format.setFont(self.font)
     char_format.setFontItalic(not italic)
     cursor.setCharFormat(char_format)
コード例 #38
0
ファイル: widgets.py プロジェクト: marad/deadline-framework
	def __init__(self, parent = None, theme = None, prefix = ''):
		QSyntaxHighlighter.__init__(self, parent)
		self.rules = []
		self.prefix = prefix

		kwFormat = QTextCharFormat()
		kwFormat.setForeground( Qt.blue )
		#kwFormat.setFontWeight( QFont.Bold )

		quoteFormat = QTextCharFormat()
		quoteFormat.setForeground( Qt.red )

		commentFormat = QTextCharFormat()
		commentFormat.setForeground( Qt.darkGray )

		keywords = ["and", "del", "for", "is", "raise",
					"assert", "elif", "from", "lambda",
					"break", "else", "global", "not", "try",
					"class", "except", "if", "or", "while",
					"continue", "exec", "import", "pass", "yield",
					"def", "finally", "in", "print", "self"
					]

		for kw in keywords:
			self.rules.append( (QRegExp("\\b" + kw + "\\b"), kwFormat) )

		self.rules.append( (QRegExp(r'"(?:[^"\\]|\\.)*"'), quoteFormat) )
		self.rules.append( (QRegExp(r"'(?:[^\']+|\.)*'"), quoteFormat) )

		self.rules.append( (QRegExp(r"#.*$"), commentFormat) )
コード例 #39
0
class ConsoleFontStyle(object):
    def __init__(self, foregroundcolor, backgroundcolor, bold, italic,
                 underline):
        self.foregroundcolor = foregroundcolor
        self.backgroundcolor = backgroundcolor
        self.bold = bold
        self.italic = italic
        self.underline = underline
        self.format = None

    def apply_style(self, font, light_background, is_default):
        self.format = QTextCharFormat()
        self.format.setFont(font)
        foreground = QColor(self.foregroundcolor)
        if not light_background and is_default:
            inverse_color(foreground)
        self.format.setForeground(foreground)
        background = QColor(self.backgroundcolor)
        if not light_background:
            inverse_color(background)
        self.format.setBackground(background)
        font = self.format.font()
        font.setBold(self.bold)
        font.setItalic(self.italic)
        font.setUnderline(self.underline)
        self.format.setFont(font)
コード例 #40
0
ファイル: miniconsole.py プロジェクト: Fealum/WebScriptRS
 def updateFonts(self, font):    
     self.base_format.setFont(font)
     self.empty_format = QTextCharFormat(self.base_format)
     #self.empty_format.setFontPointSize(font.pointSize()/4.0)
     
     self.keywordFormat = QTextCharFormat(self.base_format)
     self.keywordFormat.setForeground(QColor(scheme.syntax_keyword))
     self.keywordFormat.setFontWeight(QFont.Bold)
     self.builtinFormat = QTextCharFormat(self.base_format)
     self.builtinFormat.setForeground(QColor(scheme.syntax_builtin))
     self.magicFormat = QTextCharFormat(self.base_format)
     self.magicFormat.setForeground(QColor(scheme.syntax_magic))
     #self.qtFormat = QTextCharFormat(self.base_format)
     #self.qtFormat.setForeground(QColor(scheme.syntax_qt))
     ##self.qtFormat.setFontWeight(QFont.Bold)
     self.selfFormat = QTextCharFormat(self.base_format)
     self.selfFormat.setForeground(QColor(scheme.syntax_self))
     #self.selfFormat.setFontItalic(True)
     self.singleLineCommentFormat = QTextCharFormat(self.base_format)
     self.singleLineCommentFormat.setForeground(QColor(scheme.syntax_comment))
     self.singleLineCommentFormat.setFontItalic(True)
     self.multiLineStringFormat = QTextCharFormat(self.base_format)
     self.multiLineStringFormat.setForeground(QColor(scheme.syntax_string))
     #self.multiLineStringFormat.setBackground(QBrush(Qt.green))
     self.quotationFormat1 = QTextCharFormat(self.base_format)
     self.quotationFormat1.setForeground(QColor(scheme.syntax_string))
     self.quotationFormat2 = QTextCharFormat(self.base_format)
     self.quotationFormat2.setForeground(QColor(scheme.syntax_string))
     self.numFormat = QTextCharFormat(self.base_format)
     self.numFormat.setForeground(QColor(scheme.syntax_number))
コード例 #41
0
ファイル: base.py プロジェクト: koll00/Gui_SM
class ConsoleFontStyle(object):
    def __init__(self, foregroundcolor, backgroundcolor, 
                 bold, italic, underline):
        self.foregroundcolor = foregroundcolor
        self.backgroundcolor = backgroundcolor
        self.bold = bold
        self.italic = italic
        self.underline = underline
        self.format = None
        
    def apply_style(self, font, light_background, is_default):
        self.format = QTextCharFormat()
        self.format.setFont(font)
        foreground = QColor(self.foregroundcolor)
        if not light_background and is_default:
            inverse_color(foreground)
        self.format.setForeground(foreground)
        background = QColor(self.backgroundcolor)
        if not light_background:
            inverse_color(background)
        self.format.setBackground(background)
        font = self.format.font()
        font.setBold(self.bold)
        font.setItalic(self.italic)
        font.setUnderline(self.underline)
        self.format.setFont(font)
コード例 #42
0
 def textFormat(self, name):
     """(Internal) Returns a QTextCharFormat setup according to the preferences.
     
     For bookmarks and the current line, FullWidthSelection is automatically enabled.
     
     """
     f = QTextCharFormat()
     f.setBackground(self._baseColors[name])
     if name in ('current', 'mark', 'error'):
         f.setProperty(QTextFormat.FullWidthSelection, True)
     return f
コード例 #43
0
ファイル: miniconsole.py プロジェクト: Fealum/WebScriptRS
    def __init__(self, edit):
        self.textedit = edit
        document = edit.document()
        QSyntaxHighlighter.__init__(self, document)

        base_format = QTextCharFormat()
        base_format.setFont(edit.font())
        self.base_format = base_format
        self.document = document
        
        self.updateHighlighter(base_format.font())
コード例 #44
0
    def make_plain_text(self):
        cursor = self.textCursor()

        char_format = QTextCharFormat()
        char_format.setFont(self.font)

        cursor.setCharFormat(char_format)

        block_format = QTextBlockFormat()
        block_format.setNonBreakableLines(False)
        cursor.setBlockFormat(block_format)
コード例 #45
0
ファイル: viewhighlighter.py プロジェクト: shimpe/frescobaldi
 def __init__(self, view):
     super(ViewHighlighter, self).__init__(view)
     self._cursorFormat = QTextCharFormat()
     self._cursorFormat.setProperty(QTextFormat.FullWidthSelection, True)
     app.settingsChanged.connect(self.readSettings)
     self.readSettings()
     bookmarks.bookmarks(view.document()).marksChanged.connect(
         self.updateMarkedLines)
     self.updateMarkedLines()
     view.cursorPositionChanged.connect(self.updateCursor)
     view.installEventFilter(self)
コード例 #46
0
ファイル: highlighter.py プロジェクト: berland/ert
    def formatKeyword(self, keyword, validation_status):
        assert isinstance(keyword, Keyword)
        if keyword.hasKeywordDefinition():
            keyword_format = QTextCharFormat(self.keyword_format)

            if not validation_status:
                keyword_format.merge(self.error_format)

            self.formatToken(keyword, keyword_format)
        else:
            self.formatToken(keyword, self.error_format)
コード例 #47
0
    def make_plain_text(self):
        cursor = self.textCursor()

        char_format = QTextCharFormat()
        char_format.setFont(self.font)

        cursor.setCharFormat(char_format)

        block_format = QTextBlockFormat()
        block_format.setNonBreakableLines(False)
        cursor.setBlockFormat(block_format)
コード例 #48
0
    def formatKeyword(self, keyword, validation_status):
        assert isinstance(keyword, Keyword)
        if keyword.hasKeywordDefinition():
            keyword_format = QTextCharFormat(self.keyword_format)

            if not validation_status:
                keyword_format.merge(self.error_format)

            self.formatToken(keyword, keyword_format)
        else:
            self.formatToken(keyword, self.error_format)
コード例 #49
0
    def __init__(self, edit):
        self.textedit = edit
        document = edit.document()
        QSyntaxHighlighter.__init__(self, document)

        base_format = QTextCharFormat()
        base_format.setFont(edit.font())
        self.base_format = base_format
        self.document = document

        self.updateHighlighter(base_format.font())
コード例 #50
0
 def setup_formats(self, font=None):
     base_format = QTextCharFormat()
     if font is not None:
         base_format.setFont(font)
     self.formats = {}
     for name, color, bold, italic in self.COLORS[self.color_scheme]:
         format = QTextCharFormat(base_format)
         format.setForeground(QColor(color))
         if bold:
             format.setFontWeight(QFont.Bold)
         format.setFontItalic(italic)
         self.formats[name] = format
コード例 #51
0
ファイル: run_widget.py プロジェクト: kennyfm91/ninja-ide
 def process_error(self, error):
     """Listen to the error signals from the running process."""
     self.lblInput.hide()
     self.input.hide()
     self._proc.kill()
     format = QTextCharFormat()
     format.setAnchor(True)
     format.setForeground(Qt.red)
     if error == 0:
         self.output.textCursor().insertText(self.tr("Failed to start"), format)
     else:
         self.output.textCursor().insertText(self.tr("Error during execution, QProcess error: %d" % error), format)
コード例 #52
0
ファイル: MainWindow.py プロジェクト: arneboe/codecomment
 def highlight_marker(self, marker_meta_data, color=None):
     '''
     highlights text according to the marker and the color in the current file
     use metadata.color_name if color is None
     '''
     cursor = self.ui.plainTextEditCode.textCursor()
     cursor.setPosition(marker_meta_data.start_pos)
     cursor.setPosition(marker_meta_data.end_pos, QTextCursor.KeepAnchor)
     format = QTextCharFormat()
     if color is None:
         color = QColor(marker_meta_data.color_name)
     brush = QBrush(color)
     format.setBackground(brush)
     cursor.mergeCharFormat(format)
コード例 #53
0
    def make_heading(self, heading):
        # not finished
        cursor = self.textCursor()
        cursor.select(QTextCursor.BlockUnderCursor) #QTextCursor.LineUnderCursor

        char_format = QTextCharFormat()
        #font = self.font this is a problem  because it changes self.font gets changed below
        font = QFont()
        font.setFamily("helvetica")
        font.setPointSize({1:20, 2:15, 3:12}[heading])
        font.setBold(True)
        char_format.setFont(font)

        cursor.setCharFormat(char_format)
コード例 #54
0
class SpellCheckHighlighter(QtGui.QSyntaxHighlighter):
    def __init__(self, parent=None):
        super(SpellCheckHighlighter, self).__init__(parent)

        self.set_language("en_US")

        self.format = QTextCharFormat()
        self.format.setUnderlineColor(QColor(255, 0, 0))
        self.format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)

        self.errors = []

    def set_language(self, lang):
        dict = enchant.DictWithPWL(lang, "data/dict/enchant.txt")
        self.checker = SpellChecker(dict, chunkers=(HTMLChunker, ))

    def get_language(self):
        return self.checker.dict.tag

    def highlightBlock(self, text):

        # If there is no previous state, then it's -1, which makes the first line 0.
        # And every line after that increases as expected.
        line = self.previousBlockState() + 1
        self.setCurrentBlockState(line)

        # Make sure our error list is long enough to hold this line.
        for i in range(len(self.errors), line + 1):
            self.errors.append([])

        text = common.qt_to_unicode(text)
        text = RE_ANGLED_APOST.sub("'", text)

        self.errors[line] = []
        self.checker.set_text(text)

        for err in self.checker:
            self.setFormat(err.wordpos, len(err.word), self.format)
            self.errors[line].append((err.word, err.wordpos))

    def add(self, word):
        self.checker.add(word)
        self.rehighlight()

    def ignore(self, word):
        self.checker.ignore_always(word)
        self.rehighlight()


### EOF ###
コード例 #55
0
    def __init__(self, text_edit, level_file):
        super().__init__(text_edit)

        text = level_file.read()
        text = SuperTuxLispHighlighter.clean_text(text)
        text_edit.setText(text)

        self.highlighting_rules += SuperTuxHighlighter.load_patterns(
            "highlighters/patterns.json")

        string_format = QTextCharFormat()
        string_format.setForeground(Qt.darkRed)
        string_pattern = '"'
        self.string = HighlightingRule(string_pattern, string_format, "string")
コード例 #56
0
ファイル: pqEdit.py プロジェクト: jlg234bob/PPQT
 def __init__(self, parent=None):
     global reWord
     super(wordHighLighter, self).__init__(parent)
     # store a local reference to the global regex
     self.wordMatch = reWord
     # Initialize text formats to apply to words from various lists.
     #  - Scanno candidates get a light lilac background.
     self.scannoFormat = QTextCharFormat()
     self.scannoFormat.setBackground(QBrush(QColor("#EBD7E6")))
     # Set the style for misspelt words. We underline in red using the
     # well-known wavy red underline, the same on all platforms.
     self.misspeltFormat = QTextCharFormat()
     self.misspeltFormat.setUnderlineStyle(QTextCharFormat.WaveUnderline)
     self.misspeltFormat.setUnderlineColor(QColor("red"))
コード例 #57
0
def format(color, style=''):
    """Return a QTextCharFormat with the given attributes."""
    _color = QColor()
    _color.setNamedColor(color)

    _format = QTextCharFormat()
    _format.setFontFamily(settings.FONT)
    _format.setForeground(_color)
    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)
    if 'italic' in style:
        _format.setFontItalic(True)

    return _format
コード例 #58
0
    def __init__(self, dockwidget):
        """Creates the Music View for the dockwidget."""
        super(MusicView, self).__init__(dockwidget)

        self._positions = weakref.WeakKeyDictionary()
        self._currentDocument = None
        self._links = None
        self._clicking_link = False

        self._highlightFormat = QTextCharFormat()
        self._highlightMusicFormat = Highlighter()
        self._highlightRange = None
        self._highlightTimer = QTimer(singleShot=True,
                                      interval=250,
                                      timeout=self.updateHighlighting)
        self._highlightRemoveTimer = QTimer(singleShot=True,
                                            timeout=self.clearHighlighting)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.view = popplerview.View(self)
        self.view.MAX_ZOOM = 8.0
        layout.addWidget(self.view)
        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
        self.view.setViewMode(qpopplerview.FitWidth)
        self.view.surface().setPageLayout(qpopplerview.RowLayout())
        self.view.surface().linkClicked.connect(self.slotLinkClicked)
        self.view.surface().linkHovered.connect(self.slotLinkHovered)
        self.view.surface().linkLeft.connect(self.slotLinkLeft)
        self.view.surface().setShowUrlTips(False)
        self.view.surface().linkHelpRequested.connect(
            self.slotLinkHelpRequested)

        self.view.viewModeChanged.connect(self.updateZoomInfo)
        self.view.surface().pageLayout().scaleChanged.connect(
            self.updateZoomInfo)
        self.view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.view.customContextMenuRequested.connect(self.showContextMenu)

        # react if cursor of current text document moves
        dockwidget.mainwindow().currentViewChanged.connect(
            self.slotCurrentViewChanged)
        view = dockwidget.mainwindow().currentView()
        if view:
            self.slotCurrentViewChanged(view)
コード例 #59
0
class ReferenceHighlighter(QtGui.QSyntaxHighlighter):
    ### SIGNALS ###
    refs_edited = pyqtSignal()

    def __init__(self, parent=None):
        super(ReferenceHighlighter, self).__init__(parent)

        self.format = QTextCharFormat()
        self.format.setForeground(QColor(0, 0, 255))

        self.references = []

    def highlightBlock(self, text):

        # If there is no previous state, then it's -1, which makes the first line 0.
        # And every line after that increases as expected.
        line = self.previousBlockState() + 1
        self.setCurrentBlockState(line)

        old_refs = copy.deepcopy(self.references)

        # Make sure we aren't too long.
        if len(self.references) > self.parent().blockCount():
            self.references = self.references[:self.parent().blockCount()]

        # Make sure our matches list is long enough to hold this line.
        for i in range(len(self.references), line + 1):
            self.references.append([])

        if len(self.references) == 0:
            return

        self.references[line] = []

        text = common.qt_to_unicode(text).lower()

        matches = RE_REFERENCE.finditer(text)

        for match in matches:
            self.setFormat(match.start(),
                           match.end() - match.start(), self.format)
            self.references[line].append((match.group(1), match.start() + 1))

        if not old_refs == self.references:
            self.refs_edited.emit()


### EOF ###
コード例 #60
0
 def apply_style(self, font, light_background, is_default):
     self.format = QTextCharFormat()
     self.format.setFont(font)
     foreground = QColor(self.foregroundcolor)
     if not light_background and is_default:
         inverse_color(foreground)
     self.format.setForeground(foreground)
     background = QColor(self.backgroundcolor)
     if not light_background:
         inverse_color(background)
     self.format.setBackground(background)
     font = self.format.font()
     font.setBold(self.bold)
     font.setItalic(self.italic)
     font.setUnderline(self.underline)
     self.format.setFont(font)